Class: Jekyll::Minibundle::MiniBundleBlock

Inherits:
Liquid::Block
  • Object
show all
Defined in:
lib/jekyll/minibundle/mini_bundle_block.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, type, _tokens) ⇒ MiniBundleBlock

Returns a new instance of MiniBundleBlock.

Raises:

  • (ArgumentError)


10
11
12
13
14
# File 'lib/jekyll/minibundle/mini_bundle_block.rb', line 10

def initialize(tag_name, type, _tokens)
  super
  @type = type.strip.downcase.to_sym
  raise ArgumentError, "Missing asset type for minibundle block; pass value such as 'css' or 'js' as the argument" if @type.empty?
end

Class Method Details

.default_bundle_configObject



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/jekyll/minibundle/mini_bundle_block.rb', line 43

def self.default_bundle_config
  {
    'source_dir'          => '_assets',
    'destination_path'    => 'assets/site',
    'baseurl'             => '',
    'destination_baseurl' => '',
    'assets'              => [],
    'attributes'          => {},
    'minifier_cmd'        => nil
  }
end

Instance Method Details

#render(context) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/jekyll/minibundle/mini_bundle_block.rb', line 16

def render(context)
  site = context.registers.fetch(:site)

  bundle_config = get_current_bundle_config(parse_contents(super), site)
  baseurl = bundle_config.fetch('baseurl')
  destination_baseurl = bundle_config.fetch('destination_baseurl')
  attributes = bundle_config.fetch('attributes')

  do_form_destination_baseurl = !destination_baseurl.empty?
  destination_dir_path = Pathname.new(File.dirname(bundle_config.fetch('destination_path'))) if do_form_destination_baseurl

  register_asset_files(site, bundle_config).map do |file|
    dst_path = Files.strip_dot_slash_from_path_start(file.destination_path_for_markup)

    url =
      if do_form_destination_baseurl
        destination_baseurl + Pathname.new(dst_path).relative_path_from(destination_dir_path).to_s
      elsif !baseurl.empty?
        File.join(baseurl, dst_path)
      else
        dst_path
      end

    AssetTagMarkup.make_markup(@type, url, attributes)
  end.join("\n")
end