jekyll-ical-tag 1.2.4 → 1.2.5

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: 56b34cd54ee295b4125928f2d1c0ab010fc73073f013afcd485d3f94f2f7d1e7
4
- data.tar.gz: 6c04c4593314888e2f9f4dfbf13f9b3bd980d0739d5661bbf41243d1d8834cc8
3
+ metadata.gz: 91c6e8bb4e6260b727de3f135494c7abe007d6136cb62d959ba142e885727964
4
+ data.tar.gz: 4f21845ffef36b8004af8d408d65fc4da36f342826032a397564662806388d3f
5
5
  SHA512:
6
- metadata.gz: 69a6fd90da57c3b2b2a26065f83d4197d82e8e8fcba655acaba83485e56dd26a23dfda4b5353491027146045f740649ce01897552e9a433292fe45f9b88aa0bc
7
- data.tar.gz: dbdbb209e8fdfed7653383ffac23c45b00579a4384789c8e11d01110de3f62fe92dae6701eb8dd231e8ab4f4d48a1979f563474b22895b1b5388b8d148004b2f
6
+ metadata.gz: 7616ae73da4c128dd77b3538d593f2961f260f06928164ca5b1ffa2c05999f1573203a38cdc065762452466a3e4c70cdcff405fc589d98959495e45d37be79b7
7
+ data.tar.gz: e2322a1d26c1f695e4e2b7031ff35be8804074f8d0b224f7c35ef81ee4e4c9559982cd7ba373f917fce8dcfe911444841a06916a53676c73aff2f238f3b7e35f
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rspec' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("rspec-core", "rspec")
@@ -6,15 +6,18 @@ require "jekyll-ical-tag/version"
6
6
 
7
7
  module Jekyll
8
8
  class IcalTag < Liquid::Block
9
- require_relative "jekyll-ical-tag/event"
10
- require_relative "jekyll-ical-tag/calendar_parser"
9
+ require_relative "jekyll-ical-tag/calendar_feed_coordinator"
10
+ require_relative "jekyll-ical-tag/calendar_fetcher"
11
11
  require_relative "jekyll-ical-tag/calendar_limiter"
12
+ require_relative "jekyll-ical-tag/calendar_parser"
13
+ require_relative "jekyll-ical-tag/event"
12
14
 
13
15
  include Convertible
14
16
 
15
17
  def initialize(tag_name, markup, parse_context)
16
18
  super
17
19
  @markup = markup
20
+ @attributes = {}
18
21
 
19
22
  scan_attributes!
20
23
  set_limit!
@@ -31,22 +34,11 @@ module Jekyll
31
34
  result = []
32
35
 
33
36
  context.stack do
34
- url = get_dereferenced_url(context) ||
35
- @url
36
-
37
- raise "No URL provided or in innapropriate form '#{url}'" unless is_valid_url?(url)
38
-
39
- puts "Fetching #{url}"
37
+ url = get_dereferenced_url(context) || @url
40
38
 
41
- parser = CalendarParser.new(url)
42
- parser = CalendarLimiter.new(parser, only: @only)
43
- parser = CalendarLimiter.new(parser, reverse: @reverse)
44
- parser = CalendarLimiter.new(parser, before_date: @before_date)
45
- parser = CalendarLimiter.new(parser, after_date: @after_date)
46
- parser = CalendarLimiter.new(parser, limit: @limit)
47
-
48
- events = parser.events
49
- length = events.length
39
+ calendar_feed_coordinator = CalendarFeedCoordinator.new(url: url)
40
+ events = calendar_feed_coordinator.events
41
+ event_count = events.length
50
42
 
51
43
  events.each_with_index do |event, index|
52
44
  # Init
@@ -69,32 +61,15 @@ module Jekyll
69
61
  context["event"]["end_time"] = context["event"]["dtend"]
70
62
  context["event"]["start_time"] = context["event"]["dtstart"]
71
63
 
72
- # Ensure all event values are utf8 encoded strings
73
- # Ensure times (from dates)
74
- # Ensure present
75
- context["event"].transform_values! do |value|
76
- v = case value
77
- when String, Icalendar::Values::Text
78
- value.force_encoding("UTF-8")
79
- when Date, Icalendar::Values::DateTime
80
- value.to_time
81
- when Icalendar::Values::Uri
82
- value.to_s
83
- else
84
- value
85
- end
86
- v.presence
87
- end
88
-
89
64
  context["forloop"] = {
90
65
  "name" => "ical",
91
- "length" => length,
66
+ "length" => event_count,
92
67
  "index" => index + 1,
93
68
  "index0" => index,
94
- "rindex" => length - index,
95
- "rindex0" => length - index - 1,
69
+ "rindex" => event_count - index,
70
+ "rindex0" => event_count - index - 1,
96
71
  "first" => (index == 0),
97
- "last" => (index == length - 1),
72
+ "last" => (index == event_count - 1),
98
73
  }
99
74
 
100
75
  result << nodelist.map do |n|
@@ -112,10 +87,6 @@ module Jekyll
112
87
 
113
88
  private
114
89
 
115
- def is_valid_url?(url)
116
- !!(url =~ URI::regexp)
117
- end
118
-
119
90
  def get_dereferenced_url(context)
120
91
  return unless context.key?(@url)
121
92
 
@@ -123,7 +94,6 @@ module Jekyll
123
94
  end
124
95
 
125
96
  def scan_attributes!
126
- @attributes = {}
127
97
  @markup.scan(Liquid::TagAttributes) do |key, value|
128
98
  @attributes[key] = value
129
99
  end
@@ -147,10 +117,11 @@ module Jekyll
147
117
  only_past = @attributes["only_past"] == "true"
148
118
 
149
119
  raise "Set only_future OR only_past, not both" if only_future && only_past
150
- @only = case
151
- when only_future
120
+
121
+ @only =
122
+ if only_future
152
123
  :future
153
- when only_past
124
+ elsif only_past
154
125
  :past
155
126
  else
156
127
  :all
@@ -158,21 +129,19 @@ module Jekyll
158
129
  end
159
130
 
160
131
  def set_before_date!
161
- @before_date = begin
162
- if @attributes["before_date"]
163
- Time.parse(@attributes["before_date"])
164
- end
165
- rescue => e
132
+ @before_date =
133
+ begin
134
+ Time.parse(@attributes["before_date"])
135
+ rescue
166
136
  nil
167
137
  end
168
138
  end
169
139
 
170
140
  def set_after_date!
171
- @after_date = begin
172
- if @attributes["after_date"]
173
- Time.parse(@attributes["after_date"])
174
- end
175
- rescue => e
141
+ @after_date =
142
+ begin
143
+ Time.parse(@attributes["after_date"])
144
+ rescue
176
145
  nil
177
146
  end
178
147
  end
@@ -0,0 +1,43 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ require "cgi"
5
+ require "api_cache"
6
+
7
+ module Jekyll
8
+ class IcalTag
9
+ class CalendarFeedCoordinator
10
+ def initialize(url:, only: nil, reverse: nil, before_date: nil, after_date: nil, limit: nil)
11
+ @url = url
12
+ @only = only
13
+ @reverse = reverse
14
+ @before_date = before_date
15
+ @after_date = after_date
16
+ @limit = limit
17
+ end
18
+
19
+ def events
20
+ parser.events
21
+ end
22
+
23
+ private
24
+
25
+ attr_reader :url, :only, :reverse, :before_date, :after_date, :limit
26
+
27
+ def raw_ical
28
+ @raw_ical ||= CalendarFetcher.new(url).fetch
29
+ end
30
+
31
+ def parser
32
+ @parser ||= begin
33
+ parser = CalendarParser.new(raw_ical)
34
+ parser = CalendarLimiter.new(parser, only: only)
35
+ parser = CalendarLimiter.new(parser, reverse: reverse)
36
+ parser = CalendarLimiter.new(parser, before_date: before_date)
37
+ parser = CalendarLimiter.new(parser, after_date: after_date)
38
+ CalendarLimiter.new(parser, limit: limit)
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,30 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ require "cgi"
5
+ require "api_cache"
6
+
7
+ module Jekyll
8
+ class IcalTag
9
+ class CalendarFetcher
10
+ def initialize(url)
11
+ @url = CGI.unescape(url)
12
+
13
+ raise "No URL provided or in innapropriate form '#{url}'" unless is_valid_url?
14
+ end
15
+
16
+ def fetch
17
+ puts "Fetching #{url}"
18
+ @fetch ||= APICache.get(url)
19
+ end
20
+
21
+ private
22
+
23
+ attr_reader :url
24
+
25
+ def is_valid_url?
26
+ !!(url =~ URI::regexp)
27
+ end
28
+ end
29
+ end
30
+ end
@@ -8,22 +8,19 @@ require "icalendar"
8
8
  module Jekyll
9
9
  class IcalTag
10
10
  class CalendarParser
11
- def initialize(url)
12
- @url = URI.unescape(url)
11
+ def initialize(raw_feed)
12
+ @raw_feed = raw_feed
13
13
  end
14
14
 
15
15
  def events
16
- @events ||= begin
17
- Icalendar::Event.parse(ics_feed)
18
- .sort { |e1, e2| e1.dtstart <=> e2.dtstart }
19
- .map { |e| Jekyll::IcalTag::Event.new(e) }
20
- end
16
+ @events ||= parsed_feed.sort { |event1, event2| event1.dtstart <=> event2.dtstart }
17
+ .map { |event| Jekyll::IcalTag::Event.new(event) }
21
18
  end
22
19
 
23
20
  private
24
21
 
25
- def ics_feed
26
- @ics_feed ||= APICache.get(@url)
22
+ def parsed_feed
23
+ Icalendar::Event.parse(@raw_feed)
27
24
  end
28
25
  end
29
26
  end
@@ -37,25 +37,46 @@ module Jekyll
37
37
 
38
38
  def all_properties
39
39
  @props ||= begin
40
- props = {}
40
+ props = {}
41
41
 
42
- # RFC 5545 Properties
43
- event.class.properties.each do |property|
44
- props[property] = event.property(property)
45
- end
42
+ # RFC 5545 Properties
43
+ event.class.properties.each do |property|
44
+ props[property] = event.property(property)
45
+ end
46
+
47
+ # custom properties
48
+ props = props.merge(event.custom_properties)
46
49
 
47
- # custom properties
48
- props = props.merge(event.custom_properties)
50
+ # Ensure all event values are utf8 encoded strings
51
+ # Ensure times (from dates)
52
+ # Ensure present
53
+ props.transform_values! do |value|
54
+ new_value =
55
+ case value
56
+ when String, Icalendar::Values::Text
57
+ value.force_encoding("UTF-8")
58
+ when Date, Icalendar::Values::DateTime
59
+ value.to_time
60
+ when Icalendar::Values::Uri
61
+ value.to_s
62
+ else
63
+ value
64
+ end
49
65
 
50
- props
66
+ new_value.presence
51
67
  end
68
+
69
+ props
70
+ end
52
71
  end
53
72
 
54
73
  def simple_html_description
55
74
  @simple_html_description ||= begin
56
- description&.clone.tap do |d|
75
+ description&.clone.tap do |description|
76
+ description = description.join("\n") if description.is_a?(Icalendar::Values::Array)
77
+
57
78
  description_urls.each do |url|
58
- d.force_encoding("UTF-8").gsub! url, %(<a href='#{url}'>#{url}</a>)
79
+ description.force_encoding("UTF-8").gsub! url, %(<a href='#{url}'>#{url}</a>)
59
80
  end
60
81
  end
61
82
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jekyll
4
4
  class IcalTag < Liquid::Block
5
- VERSION = "1.2.4"
5
+ VERSION = "1.2.5"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-ical-tag
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.4
4
+ version: 1.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ricky Chilcott
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-09-10 00:00:00.000000000 Z
11
+ date: 2020-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -107,8 +107,11 @@ files:
107
107
  - README.md
108
108
  - _plugins/ical_tag.rb
109
109
  - bin/build-and-publish-gem
110
+ - bin/rspec
110
111
  - jekyll-ical-tag.gemspec
111
112
  - lib/jekyll-ical-tag.rb
113
+ - lib/jekyll-ical-tag/calendar_feed_coordinator.rb
114
+ - lib/jekyll-ical-tag/calendar_fetcher.rb
112
115
  - lib/jekyll-ical-tag/calendar_limiter.rb
113
116
  - lib/jekyll-ical-tag/calendar_parser.rb
114
117
  - lib/jekyll-ical-tag/event.rb