Class: Jekyll::Assets::Default

Inherits:
Extensible show all
Defined in:
lib/jekyll/assets/default.rb,
lib/jekyll/assets/plugins/html/defaults/js.rb,
lib/jekyll/assets/plugins/html/defaults/css.rb,
lib/jekyll/assets/plugins/html/defaults/img.rb,
lib/jekyll/assets/plugins/html/defaults/vid.rb,
lib/jekyll/assets/plugins/html/defaults/audio.rb,
lib/jekyll/assets/plugins/html/defaults/favicon.rb,
lib/jekyll/assets/plugins/html/defaults/component.rb

Direct Known Subclasses

Audio, CSS, Component, Favicon, Img, JS, Video

Defined Under Namespace

Classes: Audio, CSS, Component, Favicon, Img, JS, Video

Instance Attribute Summary

Attributes inherited from Extensible

#args, #asset, #ctx, #env, #jekyll

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Extensible

for?, for_args?, for_type?, inherited, #initialize, internal!, internal?, requirements

Constructor Details

This class inherits a constructor from Jekyll::Assets::Extensible

Class Method Details

.get(type:, args:) ⇒ Hash

– Get all of the static defaults. –

Parameters:

  • type (String)

    the content type.

  • args (Hash)

    the args from the liquid tag.

Returns:

  • (Hash)


19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/jekyll/assets/default.rb', line 19

def self.get(type:, args:)
  rtn = Default.inherited.select do |o|
    o.for?({
      type: type,
      args: args,
    })
  end

  ida = HashWithIndifferentAccess.new
  rtn.sort { |v| v.internal? ? 1 : - 1 }.each_with_object(ida) do |v, h|
    h.deep_merge!(v.static)
  end
end

.set(args, asset:, ctx:) ⇒ Object

– Set non-static defaults around the asset. –

Parameters:

  • args (Hash)

    the arguments to work on.

  • type (String)

    the content type to work with.

  • asset (Sprockets::Asset)

    the asset.

  • env (Env)

    the environment.

Returns:

  • nil



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/jekyll/assets/default.rb', line 41

def self.set(args, asset:, ctx:)
  set_static(args, asset: asset)
  rtn = Default.inherited.select do |o|
    o.for?(type: asset.content_type, args: args)
  end

  rtn.each do |o|
    o.new({
      args: args,
      asset: asset,
      ctx: ctx,
    }).run
  end
end

.set_static(args, asset:) ⇒ Object



57
58
59
60
61
62
63
64
65
66
# File 'lib/jekyll/assets/default.rb', line 57

def self.set_static(args, asset:)
  get(type: asset.content_type, args: args).each do |k, v|
    k = k.to_sym

    unless args.key?(k)
      args[k] = args[k].is_a?(Hash) ?
        args[k].deep_merge(v) : v
    end
  end
end

.static(hash = nil) ⇒ Object

Note:

this is used from your inherited class.

– Allows you to set static defaults for your defaults. –

Parameters:

  • hash (Hash) (defaults to: nil)

    the defaults.

Returns:

  • nil



74
75
76
77
# File 'lib/jekyll/assets/default.rb', line 74

def self.static(hash = nil)
  return @static ||= {}.with_indifferent_access if hash.nil?
  static.deep_merge!(hash)
end

Instance Method Details

#configObject



92
93
94
95
# File 'lib/jekyll/assets/default.rb', line 92

def config
  @config ||= @env.asset_config[:defaults][self.class
    .name.split("::").last.downcase]
end

#runObject

Note:

this shouldn’t be used directly by end-users.

– Search for set_* methods and run those setters. –

Returns:

  • nile



84
85
86
87
88
89
# File 'lib/jekyll/assets/default.rb', line 84

def run
  methods = self.class.instance_methods - Object.instance_methods
  methods.grep(%r!^set_!).each do |v|
    send(v)
  end
end