class Jekyll::Minibundle::MiniBundleBlock
Public Class Methods
default_bundle_config()
click to toggle source
# File lib/jekyll/minibundle/mini_bundle_block.rb 47 def self.default_bundle_config 48 { 49 'source_dir' => '_assets', 50 'destination_path' => 'assets/site', 51 'baseurl' => '', 52 'destination_baseurl' => '', 53 'assets' => [], 54 'attributes' => {}, 55 'minifier_cmd' => nil 56 } 57 end
new(tag_name, type, _tokens)
click to toggle source
Calls superclass method
# File lib/jekyll/minibundle/mini_bundle_block.rb 12 def initialize(tag_name, type, _tokens) 13 super 14 15 @type = type.strip.downcase.to_sym 16 17 raise ArgumentError, "Missing asset type for minibundle block; pass value such as 'css' or 'js' as the argument" if @type.empty? 18 end
Public Instance Methods
render(context)
click to toggle source
Calls superclass method
# File lib/jekyll/minibundle/mini_bundle_block.rb 20 def render(context) 21 site = context.registers.fetch(:site) 22 23 bundle_config = get_current_bundle_config(parse_contents(super), site) 24 baseurl = bundle_config.fetch('baseurl') 25 destination_baseurl = bundle_config.fetch('destination_baseurl') 26 attributes = bundle_config.fetch('attributes') 27 28 do_form_destination_baseurl = !destination_baseurl.empty? 29 destination_dir_path = Pathname.new(File.dirname(bundle_config.fetch('destination_path'))) if do_form_destination_baseurl 30 31 register_asset_files(site, bundle_config).map do |file| 32 dst_path = Files.strip_dot_slash_from_path_start(file.destination_path_for_markup) 33 34 url = 35 if do_form_destination_baseurl 36 destination_baseurl + Pathname.new(dst_path).relative_path_from(destination_dir_path).to_s 37 elsif !baseurl.empty? 38 File.join(baseurl, dst_path) 39 else 40 dst_path 41 end 42 43 AssetTagMarkup.make_markup(@type, url, attributes) 44 end.join("\n") 45 end
Private Instance Methods
environment_bundle_config(site)
click to toggle source
# File lib/jekyll/minibundle/mini_bundle_block.rb 90 def environment_bundle_config(site) 91 {'minifier_cmd' => Environment.minifier_command(site, @type)} 92 end
get_current_bundle_config(local_bundle_config, site)
click to toggle source
# File lib/jekyll/minibundle/mini_bundle_block.rb 77 def get_current_bundle_config(local_bundle_config, site) 78 config = 79 MiniBundleBlock 80 .default_bundle_config 81 .merge(environment_bundle_config(site)) 82 .merge(local_bundle_config) 83 .merge('type' => @type) 84 85 baseurl, destination_path = normalize_baseurl_and_destination_path(config.fetch('baseurl'), config.fetch('destination_path')) 86 87 config.merge('baseurl' => baseurl, 'destination_path' => destination_path) 88 end
normalize_baseurl_and_destination_path(baseurl, destination_path)
click to toggle source
# File lib/jekyll/minibundle/mini_bundle_block.rb 94 def normalize_baseurl_and_destination_path(baseurl, destination_path) 95 baseurl = '' if baseurl.nil? || baseurl == '.' 96 baseurl = '/' if destination_path.start_with?('/') && baseurl.empty? 97 98 [Files.strip_dot_slash_from_path_start(baseurl), destination_path.sub(%r{\A/+}, '')] 99 end
parse_contents(contents)
click to toggle source
# File lib/jekyll/minibundle/mini_bundle_block.rb 61 def parse_contents(contents) 62 raise ArgumentError, 'Missing configuration for minibundle block; pass configuration in YAML syntax' if contents =~ /\A\s+\z/ 63 64 structure = parse_structure(contents) 65 66 raise ArgumentError, "Unsupported minibundle block contents type (#{structure.class}), only Hash is supported: #{contents}" unless structure.is_a?(Hash) 67 68 structure 69 end
parse_structure(contents)
click to toggle source
# File lib/jekyll/minibundle/mini_bundle_block.rb 71 def parse_structure(contents) 72 ::SafeYAML.load(contents) 73 rescue StandardError => e 74 raise ArgumentError, "Failed parsing minibundle block contents syntax as YAML: #{contents.strip.inspect}. Cause: #{e}" 75 end
register_asset_files(site, bundle_config)
click to toggle source
# File lib/jekyll/minibundle/mini_bundle_block.rb 101 def register_asset_files(site, bundle_config) 102 registry_config = Hashes.pick( 103 bundle_config, 104 'type', 105 'source_dir', 106 'destination_path', 107 'assets', 108 'minifier_cmd' 109 ) 110 111 if Environment.development?(site) 112 AssetFileRegistry.register_development_file_collection(site, registry_config).files 113 else 114 [AssetFileRegistry.register_bundle_file(site, registry_config)] 115 end 116 end