Class: JekyllSupport::HrefSummary

Inherits:
JekyllTag
  • Object
show all
Includes:
JekyllHrefVersion
Defined in:
lib/href_summary_tag.rb

Constant Summary

Constants included from JekyllHrefVersion

JekyllHrefVersion::VERSION

Class Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.hrefsObject

Returns the value of attribute hrefs.



18
19
20
# File 'lib/href_summary_tag.rb', line 18

def hrefs
  @hrefs
end

.hrefs_localObject

Returns the value of attribute hrefs_local.



18
19
20
# File 'lib/href_summary_tag.rb', line 18

def hrefs_local
  @hrefs_local
end

Instance Method Details

#render_global_refsObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/href_summary_tag.rb', line 49

def render_global_refs
  hrefs = HashArray.instance_variable_get(:@global_hrefs)
  entries = hrefs[@path]&.select { |h| h.path == @path }
  return '' if entries.nil? || entries.empty?

  summaries = entries.map { |href| "<li>#{href.summary_href}</li>" }

  <<~END_RENDER
    <h2 id="reference">References</h2>
    <ol>
      #{summaries.join "\n  "}
    </ol>
  END_RENDER
rescue StandardError => e
  @logger.error { "#{self.class} died with a #{e.full_message}" }
  exit 1
end

#render_implString

Method prescribed by the Jekyll plugin lifecycle.

Parameters:

  • liquid_context (Liquid::Context)

Returns:

  • (String)


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/href_summary_tag.rb', line 26

def render_impl
  @helper.gem_file __FILE__ # Enables attribution
  @include_local = @helper.parameter_specified? 'include_local'

  @die_on_href_error = @tag_config['die_on_href_error'] == true if @tag_config
  @pry_on_href_error = @tag_config['pry_on_href_error'] == true if @tag_config

  @path = @page['path']
  global_refs = render_global_refs
  local_refs  = render_local_refs
  have_refs = !(global_refs + local_refs).empty?
  <<~END_RENDER
    #{global_refs}
    #{local_refs}
    #{@helper.attribute if @helper.attribution && have_refs}
  END_RENDER
rescue HRefError => e # jekyll_plugin_support handles StandardError
  @logger.error { e.logger_message }
  exit! 1 if @die_on_demo_block_error

  e.html_message
end

#render_local_refsObject



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/href_summary_tag.rb', line 67

def render_local_refs
  return '' unless @include_local

  hrefs = HashArray.instance_variable_get(:@local_hrefs)
  entries = hrefs[@path]&.select { |h| h.path == @path }
  return '' if entries.nil? || entries.empty?

  summary = entries.map { |href| "<li>#{href.summary_href}</li>" }
  <<~END_RENDER
    <h2 id="local_reference">Local References</h2>
    <ol>
    #{summary.join("\n  ")}
    </ol>
  END_RENDER
end