class Jekyll::Minibundle::MiniStampTag
Public Class Methods
default_stamp_config()
click to toggle source
# File lib/jekyll/minibundle/mini_stamp_tag.rb 39 def self.default_stamp_config 40 { 41 'source_path' => '', 42 'destination_path' => '', 43 'baseurl' => '', 44 'render_basename_only' => false, 45 'use_template' => false 46 } 47 end
new(tag_name, text, _tokens)
click to toggle source
Calls superclass method
# File lib/jekyll/minibundle/mini_stamp_tag.rb 10 def initialize(tag_name, text, _tokens) 11 super 12 @local_stamp_config = 13 MiniStampTag 14 .default_stamp_config 15 .merge(parse_arguments(text.strip)) 16 end
Public Instance Methods
render(context)
click to toggle source
# File lib/jekyll/minibundle/mini_stamp_tag.rb 18 def render(context) 19 site = context.registers.fetch(:site) 20 21 stamp_config = get_current_stamp_config(context) 22 source_path = stamp_config.fetch('source_path') 23 destination_path = stamp_config.fetch('destination_path') 24 render_basename_only = stamp_config.fetch('render_basename_only') 25 26 file = register_asset_file(site, source_path, destination_path) 27 dst_path = Files.strip_dot_slash_from_path_start(file.destination_path_for_markup) 28 29 url = 30 if render_basename_only 31 File.basename(dst_path) 32 else 33 stamp_config.fetch('baseurl') + dst_path 34 end 35 36 CGI.escape_html(url) 37 end
Private Instance Methods
get_current_stamp_config(context)
click to toggle source
# File lib/jekyll/minibundle/mini_stamp_tag.rb 101 def get_current_stamp_config(context) 102 source_path = @local_stamp_config.fetch('source_path') 103 destination_path = @local_stamp_config.fetch('destination_path') 104 render_basename_only = @local_stamp_config.fetch('render_basename_only') 105 106 if @local_stamp_config.fetch('use_template') 107 source_path = VariableTemplateRegistry.register_template(source_path).render(context) 108 destination_path = VariableTemplateRegistry.register_template(destination_path).render(context) 109 end 110 111 baseurl, destination_path = normalize_destination_path(destination_path) 112 113 { 114 'source_path' => source_path, 115 'destination_path' => destination_path, 116 'baseurl' => baseurl, 117 'render_basename_only' => render_basename_only 118 } 119 end
normalize_destination_path(destination_path)
click to toggle source
# File lib/jekyll/minibundle/mini_stamp_tag.rb 121 def normalize_destination_path(destination_path) 122 if destination_path.start_with?('/') 123 ['/', destination_path.sub(%r{\A/+}, '')] 124 else 125 ['', destination_path] 126 end 127 end
parse_arguments(args)
click to toggle source
# File lib/jekyll/minibundle/mini_stamp_tag.rb 51 def parse_arguments(args) 52 raise ArgumentError, 'Missing asset source and destination paths for ministamp tag; specify value such as "_assets/source.css assets/destination.css" as the argument' if args.empty? 53 54 structure = parse_structure(args) 55 56 case structure 57 when String 58 parse_string_argument(structure) 59 when Hash 60 parse_hash_argument(structure) 61 else 62 raise ArgumentError, "Unsupported ministamp tag argument type (#{structure.class}), only String and Hash are supported: #{args}" 63 end 64 end
parse_hash_argument(hash)
click to toggle source
# File lib/jekyll/minibundle/mini_stamp_tag.rb 85 def parse_hash_argument(hash) 86 source_path = hash.fetch('source_path', '').to_s 87 destination_path = hash.fetch('destination_path', '').to_s 88 render_basename_only = hash.fetch('render_basename_only', false) 89 90 raise ArgumentError, 'Missing asset source path for ministamp tag; specify Hash entry such as "source_path: _assets/site.css"' if source_path.empty? 91 raise ArgumentError, 'Missing asset destination path for ministamp tag; specify Hash entry such as "destination_path: assets/site.css"' if destination_path.empty? 92 93 { 94 'source_path' => source_path, 95 'destination_path' => destination_path, 96 'render_basename_only' => render_basename_only, 97 'use_template' => true 98 } 99 end
parse_string_argument(str)
click to toggle source
# File lib/jekyll/minibundle/mini_stamp_tag.rb 72 def parse_string_argument(str) 73 source_path, destination_path = str.split(/\s+/, 3)[0, 2] 74 75 unless destination_path 76 raise ArgumentError, 'Missing asset destination path for ministamp tag; specify value such as "assets/destination.css" after asset source path argument, separated with a space' 77 end 78 79 { 80 'source_path' => source_path, 81 'destination_path' => destination_path 82 } 83 end
parse_structure(args)
click to toggle source
# File lib/jekyll/minibundle/mini_stamp_tag.rb 66 def parse_structure(args) 67 ::SafeYAML.load(args) 68 rescue StandardError => e 69 raise ArgumentError, "Failed parsing ministamp tag argument syntax as YAML: #{args.inspect}. Cause: #{e}" 70 end
register_asset_file(site, source_path, destination_path)
click to toggle source
# File lib/jekyll/minibundle/mini_stamp_tag.rb 129 def register_asset_file(site, source_path, destination_path) 130 if Environment.development?(site) 131 AssetFileRegistry.register_development_file(site, source_path, destination_path) 132 else 133 AssetFileRegistry.register_stamp_file(site, source_path, destination_path) 134 end 135 end