jekyll-ical-tag 1.2.5 → 1.3

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: 91c6e8bb4e6260b727de3f135494c7abe007d6136cb62d959ba142e885727964
4
- data.tar.gz: 4f21845ffef36b8004af8d408d65fc4da36f342826032a397564662806388d3f
3
+ metadata.gz: 21b56f384e8ebf764e98c667f0c5d1def0bf4a15242d69d9faf7c7aa4c0aa91d
4
+ data.tar.gz: c7f6c97e3befba9801001ecf3f323323e140f20b4d7035eca117a518970b3e37
5
5
  SHA512:
6
- metadata.gz: 7616ae73da4c128dd77b3538d593f2961f260f06928164ca5b1ffa2c05999f1573203a38cdc065762452466a3e4c70cdcff405fc589d98959495e45d37be79b7
7
- data.tar.gz: e2322a1d26c1f695e4e2b7031ff35be8804074f8d0b224f7c35ef81ee4e4c9559982cd7ba373f917fce8dcfe911444841a06916a53676c73aff2f238f3b7e35f
6
+ metadata.gz: 4b526819666063d9643194de143026532777dd3e40883aee04a0e49a17413fa8e14bef518b7bd01e74241ce498d12a09d75c1f45401ebd7c0a3da9ea9456b2a9
7
+ data.tar.gz: 9ae1b75c37b044f2352fa2c20bf26de4a085675abe0f9acd83674d57fb47e783bd2230ab8769b8403fd6067db79866bdca6b409972620e3c043543b5773bc88d
data/.gitignore CHANGED
@@ -1,3 +1,5 @@
1
1
  .DS_Store
2
2
  .bundle
3
- *.gem
3
+ *.gem
4
+
5
+ spec/examples.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
@@ -36,7 +36,11 @@ module Jekyll
36
36
  context.stack do
37
37
  url = get_dereferenced_url(context) || @url
38
38
 
39
- calendar_feed_coordinator = CalendarFeedCoordinator.new(url: url)
39
+ calendar_feed_coordinator = CalendarFeedCoordinator.new(
40
+ url: url, only: @only, reverse: @reverse,
41
+ before_date: @before_date, after_date: @after_date,
42
+ limit: @limit
43
+ )
40
44
  events = calendar_feed_coordinator.events
41
45
  event_count = events.length
42
46
 
@@ -1,9 +1,6 @@
1
1
  # encoding: utf-8
2
2
  # frozen_string_literal: true
3
3
 
4
- require "cgi"
5
- require "api_cache"
6
-
7
4
  module Jekyll
8
5
  class IcalTag
9
6
  class CalendarFeedCoordinator
@@ -1,7 +1,6 @@
1
1
  # encoding: utf-8
2
2
  # frozen_string_literal: true
3
3
 
4
- require "api_cache"
5
4
  require "active_support"
6
5
  require "icalendar"
7
6
 
@@ -2,6 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require "uri"
5
+ require "active_support"
5
6
 
6
7
  module Jekyll
7
8
  class IcalTag
@@ -27,32 +28,60 @@ module Jekyll
27
28
  (?::\d{2,5})? # Optional port number
28
29
  (?:\/[^\s"]*)? # Anything that is not a space or a double quote
29
30
  /x
30
- extend Forwardable
31
31
 
32
- def initialize(event)
33
- @event = event
32
+ def initialize(ical_event)
33
+ @ical_event = ical_event
34
+ setup_all_properties!
35
+ setup_property_accessor_methods!
34
36
  end
35
37
 
36
- def_delegators :event, :dtstart, :dtend
38
+ attr_reader :all_properties
37
39
 
38
- def all_properties
39
- @props ||= begin
40
+ def simple_html_description
41
+ @simple_html_description ||= begin
42
+ description.clone.tap do |description|
43
+ description_urls.each do |url|
44
+ description.gsub! url, %(<a href='#{url}'>#{url}</a>)
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+ def attendees
51
+ ical_event.attendee.map(&:to_s).map { |a| a.slice!("mailto:"); a }
52
+ end
53
+
54
+ def description_urls
55
+ return [] unless description
56
+
57
+ @description_urls ||= description.scan(URL_REGEX).to_a
58
+ end
59
+
60
+ private
61
+
62
+ attr_reader :ical_event
63
+
64
+ def setup_all_properties!
65
+ @all_properties ||= begin
40
66
  props = {}
41
67
 
42
68
  # RFC 5545 Properties
43
- event.class.properties.each do |property|
44
- props[property] = event.property(property)
69
+ ical_event.class.properties.each do |property|
70
+ props[property] = ical_event.property(property)
45
71
  end
46
72
 
47
73
  # custom properties
48
- props = props.merge(event.custom_properties)
74
+ props = props.merge(ical_event.custom_properties)
49
75
 
76
+ # Ensure all arrays get flattened to utf8 encoded strings
50
77
  # Ensure all event values are utf8 encoded strings
51
78
  # Ensure times (from dates)
52
79
  # Ensure present
53
80
  props.transform_values! do |value|
54
81
  new_value =
55
82
  case value
83
+ when Array, Icalendar::Values::Array
84
+ value.join("\n").force_encoding("UTF-8")
56
85
  when String, Icalendar::Values::Text
57
86
  value.force_encoding("UTF-8")
58
87
  when Date, Icalendar::Values::DateTime
@@ -70,30 +99,13 @@ module Jekyll
70
99
  end
71
100
  end
72
101
 
73
- def simple_html_description
74
- @simple_html_description ||= begin
75
- description&.clone.tap do |description|
76
- description = description.join("\n") if description.is_a?(Icalendar::Values::Array)
77
-
78
- description_urls.each do |url|
79
- description.force_encoding("UTF-8").gsub! url, %(<a href='#{url}'>#{url}</a>)
80
- end
81
- end
102
+ def setup_property_accessor_methods!
103
+ all_properties.each do |prop, value|
104
+ define_singleton_method prop do
105
+ all_properties[prop]
82
106
  end
107
+ end
83
108
  end
84
-
85
- def attendees
86
- attendee.map(&:to_s).map { |a| a.slice!("mailto:"); a }
87
- end
88
-
89
- def description_urls
90
- @description_urls ||= description.to_s.force_encoding("UTF-8").scan(URL_REGEX).to_a
91
- end
92
-
93
- private
94
-
95
- def_delegators :event, :description, :attendee
96
- attr_reader :event
97
109
  end
98
110
  end
99
111
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jekyll
4
4
  class IcalTag < Liquid::Block
5
- VERSION = "1.2.5"
5
+ VERSION = "1.3"
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.2.5
4
+ version: '1.3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ricky Chilcott
@@ -102,10 +102,10 @@ extensions: []
102
102
  extra_rdoc_files: []
103
103
  files:
104
104
  - ".gitignore"
105
+ - ".rspec"
105
106
  - Gemfile
106
107
  - Gemfile.lock
107
108
  - README.md
108
- - _plugins/ical_tag.rb
109
109
  - bin/build-and-publish-gem
110
110
  - bin/rspec
111
111
  - jekyll-ical-tag.gemspec
@@ -1,187 +0,0 @@
1
- require "api_cache"
2
- require "active_support"
3
- require "icalendar"
4
-
5
- class CalendarParser
6
- def initialize(url)
7
- @url = URI.unescape(url)
8
- end
9
-
10
- def events
11
- @events ||= Icalendar::Event.parse(ics_feed).sort { |e1, e2| e1.dtstart <=> e2.dtstart }
12
- end
13
-
14
- private
15
-
16
- def ics_feed
17
- @ics_feed ||= APICache.get(@url)
18
- end
19
- end
20
-
21
- class CalendarLimiter
22
- def initialize(parser, options = {})
23
- @parser = parser
24
- @options = options
25
- end
26
-
27
- def events
28
- case
29
- when options[:only] == :future
30
- now = Time.now
31
- parser.events.select do |event|
32
- event.dtstart.to_time >= now
33
- end
34
- when options[:only] == :past
35
- now = Time.now
36
- parser.events.select do |event|
37
- event.dtstart.to_time < now
38
- end
39
- when options[:reverse]
40
- parser.events.reverse
41
- when options[:after_date]
42
- parser.events.select do |event|
43
- event.dtstart.to_time >= options[:after_date]
44
- end
45
- when options[:before_date]
46
- parser.events.select do |event|
47
- event.dtstart.to_time < options[:before_date]
48
- end
49
- when options[:limit]
50
- parser.events.first(options[:limit].to_i)
51
- else
52
- parser.events
53
- end
54
- end
55
-
56
- private
57
-
58
- attr_reader :parser, :options
59
- end
60
-
61
- module Jekyll
62
- class CalendarTag < Liquid::Block
63
- include Convertible
64
-
65
- def initialize(tag_name, markup, parse_context)
66
- super
67
-
68
- @markup = markup
69
-
70
- scan_attributes!
71
- set_reverse!
72
- set_url!
73
- set_only!
74
- set_before_date!
75
- set_after_date!
76
- end
77
-
78
- def render(context)
79
- context.registers[:ical] ||= Hash.new(0)
80
-
81
- result = []
82
-
83
- parser = CalendarParser.new(@url)
84
- parser = CalendarLimiter.new(parser, only: @only)
85
- parser = CalendarLimiter.new(parser, reverse: @reverse)
86
- parser = CalendarLimiter.new(parser, before_date: @before_date)
87
- parser = CalendarLimiter.new(parser, after_date: @after_date)
88
-
89
- events = parser.events
90
- length = events.length
91
-
92
- context.stack do
93
- events.each_with_index do |event, index|
94
- attendees = event.attendee.map(&:to_s).map { |a| a.slice!("mailto:"); a }
95
-
96
- context["event"] = {
97
- "index" => index,
98
- "uid" => event.uid,
99
- "summary" => event.summary,
100
- "description" => event.description,
101
- "location" => event.location,
102
- "url" => event.url&.to_s,
103
- "start_time" => event.dtstart&.to_time,
104
- "end_time" => event.dtend&.to_time,
105
- "attendees" => attendees,
106
- }
107
-
108
- context["forloop"] = {
109
- "name" => "calendar",
110
- "length" => length,
111
- "index" => index + 1,
112
- "index0" => index,
113
- "rindex" => length - index,
114
- "rindex0" => length - index - 1,
115
- "first" => (index == 0),
116
- "last" => (index == length - 1),
117
- }
118
-
119
- result << nodelist.map do |n|
120
- if n.respond_to? :render
121
- n.render(context)
122
- else
123
- n
124
- end
125
- end.join
126
- end
127
- end
128
-
129
- result
130
- end
131
-
132
- private
133
-
134
- def scan_attributes!
135
- @attributes = {}
136
- @markup.scan(Liquid::TagAttributes) do |key, value|
137
- @attributes[key] = value
138
- end
139
- end
140
-
141
- def set_reverse!
142
- @reverse = @attributes["order"] == "reverse"
143
- end
144
-
145
- def set_url!
146
- @url = @attributes["url"]
147
- raise "No URL provided" unless @url
148
- end
149
-
150
- def set_only!
151
- only_future = @attributes["only_future"] == "true"
152
- only_past = @attributes["only_past"] == "true"
153
-
154
- raise "Set only_future OR only_past, not both" if only_future && only_past
155
- @only = case
156
- when only_future
157
- :future
158
- when only_past
159
- :past
160
- else
161
- :all
162
- end
163
- end
164
-
165
- def set_before_date!
166
- @before_date = begin
167
- if @attributes["before_date"]
168
- Time.parse(@attributes["before_date"])
169
- end
170
- rescue => e
171
- nil
172
- end
173
- end
174
-
175
- def set_after_date!
176
- @after_date = begin
177
- if @attributes["after_date"]
178
- Time.parse(@attributes["after_date"])
179
- end
180
- rescue => e
181
- nil
182
- end
183
- end
184
- end
185
- end
186
-
187
- Liquid::Template.register_tag("ical", Jekyll::CalendarTag)