jekyll-ical-tag 1.0.9 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f0aa8b610c5113e232c010134e97b4ba1af55e07f92bba29cd820f1c2daaa0e1
4
- data.tar.gz: fe4a3829d1a32311f773ab8c3825de673dec80586f2e49a569a57748d5475ff4
3
+ metadata.gz: cdb49ea6fd0b6d006435344649a8a7d30f19155f7e1424683d8774b59e9bdcf2
4
+ data.tar.gz: e323590a17d904763e2169446a2152b24eeb90629fd4f88bba0adbac1bde523c
5
5
  SHA512:
6
- metadata.gz: 5848157e8929d51d128d372dd1d037f997ec74240ccf437bfe593deb70ec41b9299ef9364555dd2a290d235f984d413c9621706d012b38ab720e5f6aae9aeba3
7
- data.tar.gz: ee10e4e946fd367ee92ae463f44a8873d7d834b60b1eb8b27f939e3acb2296077440992db42967f84658d854ce7832da40d974745903a9da9bca8832fb8d4413
6
+ metadata.gz: 6b3abd193f1de3eea850f2218ad8f42b7186e889b9915335a5da89418d59913898e09dc84e9f1d5fcf858eff2e9f49d4e0b960494fa2d930e3e2cfe75ff941a6
7
+ data.tar.gz: 93db87869c4f8d9b8c0e019a0e6c9bdd201d30a6b1edae8a0f1b1c3a68beeaa3fe1940435fbefb78cb521b2364b9955492657fb0f3f93278253e60232bb2c833
data/README.md CHANGED
@@ -43,14 +43,21 @@ plugins:
43
43
 
44
44
  ## Event Attributes:
45
45
 
46
+ All RFC 5545 properties are supported, examples:
47
+
48
+ - `dtstart` - start time of event
49
+ - `dtend` - end time of event
46
50
  - `summary` - Title or name of event
47
51
  - `description` - Notes/description of event
48
- - `simple_html_description` - Notes/description of event with urls auto-linked
49
52
  - `location` - Location of event
50
- - `start_time` - start time of event
51
- - `end_time` - end time of event
52
53
  - `url` - url of event, if provided, if not, take the first url from the description.
54
+
55
+ A few helper properties are also supported:
56
+
53
57
  - `attendees` - [Array] of attendees names/emails
58
+ - `simple_html_description` - Notes/description of event with urls auto-linked
59
+ - `start_time` - start time of event
60
+ - `end_time` - end time of event
54
61
 
55
62
  # Special Thanks
56
63
 
@@ -30,35 +30,60 @@ module Jekyll
30
30
 
31
31
  result = []
32
32
 
33
- set_url_from_assigned_value!(context)
34
- set_url_from_page_attributes!(context)
33
+ context.stack do
34
+ url = get_url_from_assigned_value(context) ||
35
+ get_url_from_page_attributes(context) ||
36
+ @url
35
37
 
36
- raise "No URL provided or in innapropriate form '#{@url}'" unless has_valid_url?
38
+ raise "No URL provided or in innapropriate form '#{url}'" unless is_valid_url?(url)
37
39
 
38
- parser = CalendarParser.new(@url)
39
- parser = CalendarLimiter.new(parser, only: @only)
40
- parser = CalendarLimiter.new(parser, reverse: @reverse)
41
- parser = CalendarLimiter.new(parser, before_date: @before_date)
42
- parser = CalendarLimiter.new(parser, after_date: @after_date)
43
- parser = CalendarLimiter.new(parser, limit: @limit)
40
+ puts "Fetching #{url}"
44
41
 
45
- events = parser.events
46
- length = events.length
42
+ parser = CalendarParser.new(url)
43
+ parser = CalendarLimiter.new(parser, only: @only)
44
+ parser = CalendarLimiter.new(parser, reverse: @reverse)
45
+ parser = CalendarLimiter.new(parser, before_date: @before_date)
46
+ parser = CalendarLimiter.new(parser, after_date: @after_date)
47
+ parser = CalendarLimiter.new(parser, limit: @limit)
48
+
49
+ events = parser.events
50
+ length = events.length
47
51
 
48
- context.stack do
49
52
  events.each_with_index do |event, index|
50
- context["event"] = {
51
- "index" => index,
52
- "uid" => event.uid.presence,
53
- "summary" => as_utf8(event.summary).presence,
54
- "description" => as_utf8(event.description).presence,
55
- "simple_html_description" => as_utf8(event.simple_html_description).presence,
56
- "location" => as_utf8(event.location).presence,
57
- "url" => as_utf8(event.url&.to_s.presence || event.description_urls.first).presence,
58
- "start_time" => event.dtstart&.to_time.presence,
59
- "end_time" => event.dtend&.to_time.presence,
60
- "attendees" => event.attendees,
61
- }
53
+ # Init
54
+ context["event"] = {}
55
+
56
+ # Jekyll helper variables
57
+ context["event"]["index"] = index
58
+
59
+ # RFC 5545 conformant and custom properties.
60
+ context["event"].merge!(event.all_properties)
61
+
62
+ # Supported but non-standard attributes.
63
+ context["event"]["attendees"] = event.attendees
64
+ context["event"]["simple_html_description"] = event.simple_html_description
65
+
66
+ # Overridden values
67
+ context["event"]["url"] ||= event.description_urls.first
68
+
69
+ # Deprecated attribute names.
70
+ context["event"]["end_time"] = context["event"]["dtend"]
71
+ context["event"]["start_time"] = context["event"]["dtstart"]
72
+
73
+ # Ensure all event values are utf8 encoded strings
74
+ # Ensure times (from dates)
75
+ # Ensure present
76
+ context["event"].transform_values! do |value|
77
+ v = case value
78
+ when String, Icalendar::Values::Text
79
+ value.force_encoding("UTF-8")
80
+ when Date, Icalendar::Values::DateTime
81
+ value.to_time
82
+ else
83
+ value
84
+ end
85
+ v.presence
86
+ end
62
87
 
63
88
  context["forloop"] = {
64
89
  "name" => "ical",
@@ -86,34 +111,23 @@ module Jekyll
86
111
 
87
112
  private
88
113
 
89
- def has_valid_url?
90
- !!(@url =~ URI::regexp)
114
+ def is_valid_url?(url)
115
+ !!(url =~ URI::regexp)
91
116
  end
92
117
 
93
- def set_url_from_page_attributes!(context)
94
- return if has_valid_url?
95
-
96
- # Dereference @url from something like "page.calender_url" to the page's calendar_url
97
-
118
+ def get_url_from_page_attributes(context)
119
+ # Dereference url from something like "page.calender_url" to the page's calendar_url
98
120
  dig_attrs = @url.split(".")
99
121
  dig_attrs[0] = dig_attrs[0].to_sym if dig_attrs[0].present?
100
- if dug_result = context.registers.dig(*dig_attrs)
101
- @url = dug_result
102
- end
103
- end
104
122
 
105
- def set_url_from_assigned_value!(context)
106
- return if has_valid_url?
107
- return unless context.scopes.first[@url]
108
-
109
- # Dereference the URL if we were passed a variable name.
110
- @url = context.scopes.first[@url]
123
+ context.registers.dig(*dig_attrs) # will return result or nil (if not found)
111
124
  end
112
125
 
113
- def as_utf8(str)
114
- return unless str
126
+ def get_url_from_assigned_value(context)
127
+ return unless scope = context.scopes.find { |scope| scope[@url] }
115
128
 
116
- str.force_encoding("UTF-8")
129
+ # Dereference the URL if we were passed a variable name.
130
+ scope[@url]
117
131
  end
118
132
 
119
133
  def scan_attributes!
@@ -13,7 +13,23 @@ module Jekyll
13
13
  @event = event
14
14
  end
15
15
 
16
- def_delegators :event, :attendee, :uid, :summary, :description, :location, :url, :dtstart, :dtend
16
+ def_delegators :event, :dtstart, :dtend
17
+
18
+ def all_properties
19
+ @props ||= begin
20
+ props = {}
21
+
22
+ # RFC 5545 Properties
23
+ event.class.properties.each do |property|
24
+ props[property] = event.property(property)
25
+ end
26
+
27
+ # custom properties
28
+ props = props.merge(event.custom_properties)
29
+
30
+ props
31
+ end
32
+ end
17
33
 
18
34
  def simple_html_description
19
35
  @simple_html_description ||= begin
@@ -35,6 +51,7 @@ module Jekyll
35
51
 
36
52
  private
37
53
 
54
+ def_delegators :event, :description, :attendee
38
55
  attr_reader :event
39
56
  end
40
57
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jekyll
4
4
  class IcalTag < Liquid::Block
5
- VERSION = "1.0.9"
5
+ VERSION = "1.1.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-ical-tag
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.9
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ricky Chilcott