jekyll-ical-tag 1.2.0 → 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: a3390276b35fd0dd3b56ad571b8f780d2a34392d9bc2bf96e8598bc60a6ee2b8
4
- data.tar.gz: 419bf7845e4bf1eafee30201c2a601676511b1938b5e4f277af6197eef7c7c80
3
+ metadata.gz: 91c6e8bb4e6260b727de3f135494c7abe007d6136cb62d959ba142e885727964
4
+ data.tar.gz: 4f21845ffef36b8004af8d408d65fc4da36f342826032a397564662806388d3f
5
5
  SHA512:
6
- metadata.gz: e63cf230c1b23a6e75b2c4aeb7806bb0d4f6627cbf8b3bc72940f858f0f9f8328ca40227c4e0983664bb54989280a8043bd7c616456640d2dab0e7ff86d83cbb
7
- data.tar.gz: bcab893dac34848a1da83809417ce24974f73ad629fe121016d8b18d3e76d94e3f72a7172e9ceead74bccda95dc68019596dca9a05de37be97c2c7d8fd4244df
6
+ metadata.gz: 7616ae73da4c128dd77b3538d593f2961f260f06928164ca5b1ffa2c05999f1573203a38cdc065762452466a3e4c70cdcff405fc589d98959495e45d37be79b7
7
+ data.tar.gz: e2322a1d26c1f695e4e2b7031ff35be8804074f8d0b224f7c35ef81ee4e4c9559982cd7ba373f917fce8dcfe911444841a06916a53676c73aff2f238f3b7e35f
data/Gemfile CHANGED
@@ -7,7 +7,6 @@ gem 'icalendar'
7
7
  gem 'activesupport'
8
8
 
9
9
  group :development, :test do
10
- gem 'pry'
11
10
  gem 'rspec'
12
11
  gem 'nokogiri'
13
12
  end
@@ -1,7 +1,7 @@
1
1
  GEM
2
2
  remote: https://rubygems.org/
3
3
  specs:
4
- activesupport (5.2.1)
4
+ activesupport (5.2.4.3)
5
5
  concurrent-ruby (~> 1.0, >= 1.0.2)
6
6
  i18n (>= 0.7, < 2)
7
7
  minitest (~> 5.1)
@@ -9,9 +9,8 @@ GEM
9
9
  addressable (2.7.0)
10
10
  public_suffix (>= 2.0.2, < 5.0)
11
11
  api_cache (0.3.0)
12
- coderay (1.1.2)
13
12
  colorator (1.1.0)
14
- concurrent-ruby (1.0.5)
13
+ concurrent-ruby (1.1.6)
15
14
  diff-lcs (1.3)
16
15
  em-websocket (0.5.1)
17
16
  eventmachine (>= 0.12.9)
@@ -20,7 +19,7 @@ GEM
20
19
  ffi (1.12.2)
21
20
  forwardable-extended (2.6.0)
22
21
  http_parser.rb (0.6.0)
23
- i18n (1.1.1)
22
+ i18n (1.8.2)
24
23
  concurrent-ruby (~> 1.0)
25
24
  icalendar (2.5.0)
26
25
  ice_cube (~> 0.16)
@@ -44,7 +43,8 @@ GEM
44
43
  sassc (> 2.0.1, < 3.0)
45
44
  jekyll-watch (2.2.1)
46
45
  listen (~> 3.0)
47
- kramdown (2.1.0)
46
+ kramdown (2.3.0)
47
+ rexml
48
48
  kramdown-parser-gfm (1.1.0)
49
49
  kramdown (~> 2.0)
50
50
  liquid (4.0.3)
@@ -52,20 +52,17 @@ GEM
52
52
  rb-fsevent (~> 0.10, >= 0.10.3)
53
53
  rb-inotify (~> 0.9, >= 0.9.10)
54
54
  mercenary (0.3.6)
55
- method_source (0.9.0)
56
55
  mini_portile2 (2.4.0)
57
- minitest (5.11.3)
56
+ minitest (5.14.1)
58
57
  nokogiri (1.10.8)
59
58
  mini_portile2 (~> 2.4.0)
60
59
  pathutil (0.16.2)
61
60
  forwardable-extended (~> 2.6)
62
- pry (0.11.3)
63
- coderay (~> 1.1.0)
64
- method_source (~> 0.9.0)
65
61
  public_suffix (4.0.3)
66
62
  rb-fsevent (0.10.3)
67
63
  rb-inotify (0.10.1)
68
64
  ffi (~> 1.0)
65
+ rexml (3.2.4)
69
66
  rouge (3.17.0)
70
67
  rspec (3.7.0)
71
68
  rspec-core (~> 3.7.0)
@@ -86,7 +83,7 @@ GEM
86
83
  terminal-table (1.8.0)
87
84
  unicode-display_width (~> 1.1, >= 1.1.1)
88
85
  thread_safe (0.3.6)
89
- tzinfo (1.2.5)
86
+ tzinfo (1.2.7)
90
87
  thread_safe (~> 0.1)
91
88
  unicode-display_width (1.7.0)
92
89
 
@@ -99,7 +96,6 @@ DEPENDENCIES
99
96
  icalendar
100
97
  jekyll
101
98
  nokogiri
102
- pry
103
99
  rspec
104
100
 
105
101
  BUNDLED WITH
@@ -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")
@@ -30,11 +30,10 @@ Gem::Specification.new do |spec|
30
30
  spec.executables = spec.files.grep(%r!^exe/!) { |f| File.basename(f) }
31
31
  spec.require_paths = ["lib"]
32
32
 
33
- spec.add_dependency "jekyll", "~> 3"
33
+ spec.add_dependency "jekyll", "> 3"
34
34
  spec.add_dependency "api_cache"
35
35
  spec.add_dependency "activesupport"
36
36
  spec.add_dependency "icalendar"
37
- spec.add_dependency "pry"
38
37
 
39
38
  spec.add_development_dependency "bundler", "~> 1.15"
40
39
  spec.add_development_dependency "rspec", "~> 3.5"
@@ -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
@@ -6,7 +6,27 @@ require "uri"
6
6
  module Jekyll
7
7
  class IcalTag
8
8
  class Event
9
- URL_REGEX = /(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?/
9
+ URL_REGEX = /
10
+ (?:(?:https?|ftp):\/\/) # Allowable schemes
11
+ (?:\S+(?::\S*)?@)? # username:password, which is optional
12
+ (?: # Domain part follows; non-capturing
13
+ # These IP addresses are valid domain values
14
+ (?!10(?:\.\d{1,3}){3})
15
+ (?!127(?:\.\d{1,3}){3})
16
+ (?!169\.254(?:\.\d{1,3}){2})
17
+ (?!192\.168(?:\.\d{1,3}){2})
18
+ (?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})
19
+ (?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])
20
+ (?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}
21
+ (?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))
22
+ |
23
+ (?:(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)
24
+ (?:\.(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)*
25
+ (?:\.(?:[a-z\u00a1-\uffff]{2,}))
26
+ )
27
+ (?::\d{2,5})? # Optional port number
28
+ (?:\/[^\s"]*)? # Anything that is not a space or a double quote
29
+ /x
10
30
  extend Forwardable
11
31
 
12
32
  def initialize(event)
@@ -17,25 +37,46 @@ module Jekyll
17
37
 
18
38
  def all_properties
19
39
  @props ||= begin
20
- props = {}
40
+ props = {}
21
41
 
22
- # RFC 5545 Properties
23
- event.class.properties.each do |property|
24
- props[property] = event.property(property)
25
- 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)
26
49
 
27
- # custom properties
28
- 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
29
65
 
30
- props
66
+ new_value.presence
31
67
  end
68
+
69
+ props
70
+ end
32
71
  end
33
72
 
34
73
  def simple_html_description
35
74
  @simple_html_description ||= begin
36
- description&.clone.tap do |d|
75
+ description&.clone.tap do |description|
76
+ description = description.join("\n") if description.is_a?(Icalendar::Values::Array)
77
+
37
78
  description_urls.each do |url|
38
- 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>)
39
80
  end
40
81
  end
41
82
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jekyll
4
4
  class IcalTag < Liquid::Block
5
- VERSION = "1.2.0"
5
+ VERSION = "1.2.5"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-ical-tag
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ricky Chilcott
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-04-09 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
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '3'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3'
27
27
  - !ruby/object:Gem::Dependency
@@ -66,20 +66,6 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: pry
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :runtime
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
69
  - !ruby/object:Gem::Dependency
84
70
  name: bundler
85
71
  requirement: !ruby/object:Gem::Requirement
@@ -108,7 +94,7 @@ dependencies:
108
94
  - - "~>"
109
95
  - !ruby/object:Gem::Version
110
96
  version: '3.5'
111
- description:
97
+ description:
112
98
  email:
113
99
  - ricky@rakefire.io
114
100
  executables: []
@@ -121,8 +107,11 @@ files:
121
107
  - README.md
122
108
  - _plugins/ical_tag.rb
123
109
  - bin/build-and-publish-gem
110
+ - bin/rspec
124
111
  - jekyll-ical-tag.gemspec
125
112
  - lib/jekyll-ical-tag.rb
113
+ - lib/jekyll-ical-tag/calendar_feed_coordinator.rb
114
+ - lib/jekyll-ical-tag/calendar_fetcher.rb
126
115
  - lib/jekyll-ical-tag/calendar_limiter.rb
127
116
  - lib/jekyll-ical-tag/calendar_parser.rb
128
117
  - lib/jekyll-ical-tag/event.rb
@@ -132,7 +121,7 @@ licenses:
132
121
  - MIT
133
122
  metadata:
134
123
  allowed_push_host: https://rubygems.org
135
- post_install_message:
124
+ post_install_message:
136
125
  rdoc_options: []
137
126
  require_paths:
138
127
  - lib
@@ -148,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
137
  version: '0'
149
138
  requirements: []
150
139
  rubygems_version: 3.1.2
151
- signing_key:
140
+ signing_key:
152
141
  specification_version: 4
153
142
  summary: A Jekyll plugin to pull ICS feed and provide a for-like loop of calendar
154
143
  events