Class: Jekyll::TimelineEventTag
- Inherits:
-
Liquid::Block
- Object
- Liquid::Block
- Jekyll::TimelineEventTag
- Defined in:
- lib/jekyll/timeline_tag.rb
Overview
Inner block tag — registered so Liquid knows about it. When rendered standalone (excerpt, search.json), outputs nothing silently. When rendered inside timeline %, its output is collected by the outer tag.
Instance Method Summary collapse
-
#initialize(tag_name, markup, tokens) ⇒ TimelineEventTag
constructor
A new instance of TimelineEventTag.
- #render(context) ⇒ Object
Constructor Details
#initialize(tag_name, markup, tokens) ⇒ TimelineEventTag
Returns a new instance of TimelineEventTag.
18 19 20 21 |
# File 'lib/jekyll/timeline_tag.rb', line 18 def initialize(tag_name, markup, tokens) super @attributes = Jekyll.parse_attrs(markup) end |
Instance Method Details
#render(context) ⇒ Object
23 24 25 26 27 28 29 30 31 32 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 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/jekyll/timeline_tag.rb', line 23 def render(context) site = context.registers[:site] config = site.config["timeline"] || {} default_prefix = config["default_icon_prefix"] || "fa-solid" content = super.strip rendered_content = begin converter = site.find_converter_instance(Jekyll::Converters::Markdown) converter.convert(content) rescue StandardError content end date = @attributes["date"] || "" title = @attributes["title"] || "" icon = @attributes["icon"] color = @attributes["color"] color_style = color ? %( style="--timeline-event-color: #{color};") : "" icon_html = if icon.nil? || icon.strip.empty? '<span class="timeline__icon timeline__icon--empty"></span>' elsif !icon.match?(/[a-zA-Z]/) || (icon.length <= 4 && !icon.include?("-")) %(<span class="timeline__icon timeline__icon--text">#{icon}</span>) else classes = icon.include?(" ") ? icon : "#{default_prefix} #{icon}" %(<span class="timeline__icon"><i class="#{classes}" aria-hidden="true"></i></span>) end html = <<~HTML <div class="timeline__event"#{color_style}> #{icon_html} <div class="timeline__content"> <div class="timeline__date">#{date}</div> <div class="timeline__title">#{title}</div> <div class="timeline__body">#{rendered_content.strip}</div> </div> </div> HTML # If inside a timeline, accumulate; otherwise silently drop if context.registers[:timeline_events] context.registers[:timeline_events] << html.strip end "" end |