Class: Jekyll::Assets::Default
- Inherits:
-
Extensible
- Object
- Extensible
- Jekyll::Assets::Default
- 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
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
-
.get(type:, args:) ⇒ Hash
– Get all of the static defaults.
-
.set(args, asset:, ctx:) ⇒ Object
– Set non-static defaults around the asset.
-
.set_static(args, asset:) ⇒ Object
–.
-
.static(hash = nil) ⇒ Object
– Allows you to set static defaults for your defaults.
Instance Method Summary collapse
-
#config ⇒ Object
–.
-
#run ⇒ Object
– Search for set_* methods and run those setters.
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. –
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. –
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. –
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
#config ⇒ Object
–
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 |
#run ⇒ Object
Note:
this shouldn’t be used directly by end-users.
– Search for set_* methods and run those setters. –
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 |