Class: Jekyll::IcalTag

Inherits:
Liquid::Block
  • Object
show all
Includes:
Convertible
Defined in:
lib/jekyll-ical-tag.rb,
lib/jekyll-ical-tag/event.rb,
lib/jekyll-ical-tag/version.rb,
lib/jekyll-ical-tag/calendar_parser.rb,
lib/jekyll-ical-tag/calendar_fetcher.rb,
lib/jekyll-ical-tag/calendar_limiter.rb,
lib/jekyll-ical-tag/calendar_feed_coordinator.rb

Defined Under Namespace

Classes: CalendarFeedCoordinator, CalendarFetcher, CalendarLimiter, CalendarParser, Event

Constant Summary collapse

VERSION =
"1.3.1"

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, markup, parse_context) ⇒ IcalTag

Returns a new instance of IcalTag.



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/jekyll-ical-tag.rb', line 17

def initialize(tag_name, markup, parse_context)
  super
  @markup = markup
  @attributes = {}

  scan_attributes!
  set_limit!
  set_reverse!
  set_url!
  set_only!
  set_before_date!
  set_after_date!
end

Instance Method Details

#render(context) ⇒ Object



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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/jekyll-ical-tag.rb', line 31

def render(context)
  context.registers[:ical] ||= Hash.new(0)

  result = []

  context.stack do
    url = get_dereferenced_url(context) || @url

    calendar_feed_coordinator = CalendarFeedCoordinator.new(
      url: url, only: @only, reverse: @reverse,
      before_date: @before_date, after_date: @after_date,
      limit: @limit
    )
    events = calendar_feed_coordinator.events
    event_count = events.length

    events.each_with_index do |event, index|
      # Init
      context["event"] = {}

      # Jekyll helper variables
      context["event"]["index"] = index

      # RFC 5545 conformant and custom properties.
      context["event"].merge!(event.all_properties)

      # Supported but non-standard attributes.
      context["event"]["attendees"] = event.attendees
      context["event"]["simple_html_description"] = event.simple_html_description

      # Overridden values
      context["event"]["url"] ||= event.description_urls.first

      # Deprecated attribute names.
      context["event"]["end_time"] = context["event"]["dtend"]
      context["event"]["start_time"] = context["event"]["dtstart"]

      context["forloop"] = {
        "name" => "ical",
        "length" => event_count,
        "index" => index + 1,
        "index0" => index,
        "rindex" => event_count - index,
        "rindex0" => event_count - index - 1,
        "first" => (index == 0),
        "last" => (index == event_count - 1),
      }

      result << nodelist.map do |n|
        if n.respond_to? :render
          n.render(context)
        else
          n
        end
      end.join
    end
  end

  result
end