Class: Jekyll::Assets::HTML

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

Direct Known Subclasses

Audio, CSS, Component, Favicon, IMG, JS, Pic, SVG, Video

Defined Under Namespace

Classes: Audio, CSS, Component, Favicon, IMG, JS, Pic, SVG, Video

Instance Attribute Summary collapse

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, internal!, internal?, requirements

Constructor Details

#initialize(doc:, **kwd) ⇒ HTML



19
20
21
22
# File 'lib/jekyll/assets/html.rb', line 19

def initialize(doc:, **kwd)
  super(**kwd)
  @doc = doc
end

Instance Attribute Details

#docObject (readonly)

Returns the value of attribute doc.



11
12
13
# File 'lib/jekyll/assets/html.rb', line 11

def doc
  @doc
end

Class Method Details

.build(args:, asset:, ctx:) ⇒ String

Note:

look inside of plugins for examples.

– Search for plugins and runners and then run them. –

Parameters:

  • args (Hash)

    the arguments.

  • type (String)

    the content type.

  • the (Sprockets::Asset)

    current asset.

  • env (Env)

    the env.

Returns:

  • (String)

    the final result.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/jekyll/assets/html.rb', line 33

def self.build(args:, asset:, ctx:)
  rtn = inherited.select do |o|
    o.for?({
      type: asset.content_type,
      args: args,
    })
  end

  doc = make_doc(rtn, asset: asset)
  rtn.each do |o|
    o = o.new({
      doc: doc,
      asset: asset,
      args: args,
      ctx: ctx,
    })

    o.run
  end

  # SVG will need to_xml!
  out = doc.is_a?(Nokogiri::XML::Document) ? doc.to_xml : doc.to_html
  rtn.select { |v| v.respond_to?(:cleanup) }.each do |o|
    out = o.cleanup(out)
  end
  out
end

.make_doc(builders, asset:) ⇒ Nokogiri::Document

Note:

see ‘self.wants_html?` to control this.

– Make an HTML/XML doc to work on. –

Returns:

  • (Nokogiri::Document)


75
76
77
78
79
# File 'lib/jekyll/assets/html.rb', line 75

def self.make_doc(builders, asset:)
  wants = builders.map(&:wants_xml?).uniq
  raise "incompatible wants xml/html for builders" if wants.size > 1
  !wants[0] ? Utils.html_fragment("") : Utils.xml(asset.to_s)
end

.skipsObject



14
15
16
# File 'lib/jekyll/assets/html.rb', line 14

def self.skips
  %i(inline path data pic) | Proxy.keys
end

.wants_xml?true, false

Note:

technically this can break sub-plugins later.

– Allows a plugin to inform us if they want XML. –

Returns:

  • (true, false)


66
67
68
# File 'lib/jekyll/assets/html.rb', line 66

def self.wants_xml?
  false
end