jekyll-ical-tag 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +97 -0
- data/README.md +52 -0
- data/_plugins/ical_tag.rb +189 -0
- data/jekyll-ical-tag.gemspec +41 -0
- data/lib/jekyll-ical-tag/calendar_limiter.rb +43 -0
- data/lib/jekyll-ical-tag/calendar_parser.rb +29 -0
- data/lib/jekyll-ical-tag/event.rb +40 -0
- data/lib/jekyll-ical-tag/version.rb +8 -0
- data/lib/jekyll-ical-tag.rb +138 -0
- metadata +155 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5b682456bd14cbe8d3461a834f13069b3a3f21b784262cd34539544f7f75cf1d
|
4
|
+
data.tar.gz: 7b8e9cf431e0461b8e42e8dd9dee886e3ac162b3ea98803827b1f4eca7f8dc14
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2f85c6e83e0169978388495bb42ed92a4015aa6a7db3445fd574e056f23de724980933c466415ef50a26214dd3150a29640d163b21a2c86266eaf1bdb43c740a
|
7
|
+
data.tar.gz: 6616759701233047f4fd9994ff4d2d58426900d3e30fb46fcf19628719d400b9ffa86321417ea0876ac3bea6d0b257f8922fe73be526c5ebb410b2e73253bdb2
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activesupport (5.2.1)
|
5
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
6
|
+
i18n (>= 0.7, < 2)
|
7
|
+
minitest (~> 5.1)
|
8
|
+
tzinfo (~> 1.1)
|
9
|
+
addressable (2.5.2)
|
10
|
+
public_suffix (>= 2.0.2, < 4.0)
|
11
|
+
api_cache (0.3.0)
|
12
|
+
coderay (1.1.2)
|
13
|
+
colorator (1.1.0)
|
14
|
+
concurrent-ruby (1.0.5)
|
15
|
+
diff-lcs (1.3)
|
16
|
+
ffi (1.9.25)
|
17
|
+
forwardable-extended (2.6.0)
|
18
|
+
i18n (1.1.1)
|
19
|
+
concurrent-ruby (~> 1.0)
|
20
|
+
icalendar (2.5.0)
|
21
|
+
ice_cube (~> 0.16)
|
22
|
+
ice_cube (0.16.3)
|
23
|
+
jekyll (3.6.3)
|
24
|
+
addressable (~> 2.4)
|
25
|
+
colorator (~> 1.0)
|
26
|
+
jekyll-sass-converter (~> 1.0)
|
27
|
+
jekyll-watch (~> 1.1)
|
28
|
+
kramdown (~> 1.14)
|
29
|
+
liquid (~> 4.0)
|
30
|
+
mercenary (~> 0.3.3)
|
31
|
+
pathutil (~> 0.9)
|
32
|
+
rouge (>= 1.7, < 3)
|
33
|
+
safe_yaml (~> 1.0)
|
34
|
+
jekyll-sass-converter (1.5.2)
|
35
|
+
sass (~> 3.4)
|
36
|
+
jekyll-watch (1.5.1)
|
37
|
+
listen (~> 3.0)
|
38
|
+
kramdown (1.17.0)
|
39
|
+
liquid (4.0.1)
|
40
|
+
listen (3.1.5)
|
41
|
+
rb-fsevent (~> 0.9, >= 0.9.4)
|
42
|
+
rb-inotify (~> 0.9, >= 0.9.7)
|
43
|
+
ruby_dep (~> 1.2)
|
44
|
+
mercenary (0.3.6)
|
45
|
+
method_source (0.9.0)
|
46
|
+
mini_portile2 (2.4.0)
|
47
|
+
minitest (5.11.3)
|
48
|
+
nokogiri (1.10.1)
|
49
|
+
mini_portile2 (~> 2.4.0)
|
50
|
+
pathutil (0.16.1)
|
51
|
+
forwardable-extended (~> 2.6)
|
52
|
+
pry (0.11.3)
|
53
|
+
coderay (~> 1.1.0)
|
54
|
+
method_source (~> 0.9.0)
|
55
|
+
public_suffix (3.0.3)
|
56
|
+
rb-fsevent (0.10.3)
|
57
|
+
rb-inotify (0.9.10)
|
58
|
+
ffi (>= 0.5.0, < 2)
|
59
|
+
rouge (2.2.1)
|
60
|
+
rspec (3.7.0)
|
61
|
+
rspec-core (~> 3.7.0)
|
62
|
+
rspec-expectations (~> 3.7.0)
|
63
|
+
rspec-mocks (~> 3.7.0)
|
64
|
+
rspec-core (3.7.0)
|
65
|
+
rspec-support (~> 3.7.0)
|
66
|
+
rspec-expectations (3.7.0)
|
67
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
68
|
+
rspec-support (~> 3.7.0)
|
69
|
+
rspec-mocks (3.7.0)
|
70
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
71
|
+
rspec-support (~> 3.7.0)
|
72
|
+
rspec-support (3.7.0)
|
73
|
+
ruby_dep (1.5.0)
|
74
|
+
safe_yaml (1.0.4)
|
75
|
+
sass (3.6.0)
|
76
|
+
sass-listen (~> 4.0.0)
|
77
|
+
sass-listen (4.0.0)
|
78
|
+
rb-fsevent (~> 0.9, >= 0.9.4)
|
79
|
+
rb-inotify (~> 0.9, >= 0.9.7)
|
80
|
+
thread_safe (0.3.6)
|
81
|
+
tzinfo (1.2.5)
|
82
|
+
thread_safe (~> 0.1)
|
83
|
+
|
84
|
+
PLATFORMS
|
85
|
+
ruby
|
86
|
+
|
87
|
+
DEPENDENCIES
|
88
|
+
activesupport
|
89
|
+
api_cache
|
90
|
+
icalendar
|
91
|
+
jekyll
|
92
|
+
nokogiri
|
93
|
+
pry
|
94
|
+
rspec
|
95
|
+
|
96
|
+
BUNDLED WITH
|
97
|
+
1.17.3
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# Jekyll ical tag
|
2
|
+
|
3
|
+
Author: Ricky Chilcott https://www.rakefire.io
|
4
|
+
|
5
|
+
Description: Pull ICS feed and provide a for-like loop of calendar events
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
To your Gemfile:
|
10
|
+
|
11
|
+
`gem 'jekyll-ical-tag', git: "https://github.com/Rakefire/jekyll-ical-tag.git"`
|
12
|
+
|
13
|
+
To your `_config.yml`
|
14
|
+
|
15
|
+
```yml
|
16
|
+
plugins:
|
17
|
+
- jekyll-ical-tag
|
18
|
+
```
|
19
|
+
|
20
|
+
## Syntax
|
21
|
+
|
22
|
+
```html
|
23
|
+
{% calendar url: https://space.floern.com/launch.ics reverse: true only_future: true %}
|
24
|
+
{{ event.summary }}
|
25
|
+
{{ event.description }}
|
26
|
+
{{ event.simple_html_description }}
|
27
|
+
{{ event.start_time }}
|
28
|
+
{{ event.end_time }}
|
29
|
+
{{ event.url }}
|
30
|
+
{{ event.attendees }}
|
31
|
+
{% endcalendar %}
|
32
|
+
```
|
33
|
+
|
34
|
+
## Options
|
35
|
+
|
36
|
+
- `reverse` - Defaults to 'false', ordering events by start_time (or reverse start_time).
|
37
|
+
- `only_past` - Defaults to 'false', limits returned events to start_times before now.
|
38
|
+
- `only_future` - Defaults to 'false', limits returned events to start_time after now.
|
39
|
+
|
40
|
+
- `before_date` - limits returned events to dates before a specific date. This gets parsed with Ruby's Time.parse (e.g. 01-01-2018)
|
41
|
+
- `after_date` - limits returned events to dates before a specific date. This gets parsed with Ruby's Time.parse (e.g. 01-01-2018).
|
42
|
+
|
43
|
+
## Event Attributes:
|
44
|
+
|
45
|
+
- `summary` - Title or name of event
|
46
|
+
- `description` - Notes/description of event
|
47
|
+
- `simple_html_description` - Notes/description of event with urls auto-linked
|
48
|
+
- `location` - Location of event
|
49
|
+
- `start_time` - start time of event
|
50
|
+
- `end_time` - end time of event
|
51
|
+
- `url` - url of event, if provided, if not, take the first url from the description.
|
52
|
+
- `attendees` - [Array] of attendees names/emails
|
@@ -0,0 +1,189 @@
|
|
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
|
+
else
|
50
|
+
parser.events
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
attr_reader :parser, :options
|
57
|
+
end
|
58
|
+
|
59
|
+
module Jekyll
|
60
|
+
class CalendarTag < Liquid::Block
|
61
|
+
include Convertible
|
62
|
+
|
63
|
+
def initialize(tag_name, markup, parse_context)
|
64
|
+
super
|
65
|
+
|
66
|
+
@markup = markup
|
67
|
+
|
68
|
+
scan_attributes!
|
69
|
+
set_reverse!
|
70
|
+
set_url!
|
71
|
+
set_only!
|
72
|
+
set_before_date!
|
73
|
+
set_after_date!
|
74
|
+
end
|
75
|
+
|
76
|
+
def render(context)
|
77
|
+
context.registers[:ical] ||= Hash.new(0)
|
78
|
+
|
79
|
+
result = []
|
80
|
+
|
81
|
+
parser = CalendarParser.new(@url)
|
82
|
+
parser = CalendarLimiter.new(parser, only: @only)
|
83
|
+
parser = CalendarLimiter.new(parser, reverse: @reverse)
|
84
|
+
parser = CalendarLimiter.new(parser, before_date: @before_date)
|
85
|
+
parser = CalendarLimiter.new(parser, after_date: @after_date)
|
86
|
+
|
87
|
+
events = parser.events
|
88
|
+
length = events.length
|
89
|
+
|
90
|
+
context.stack do
|
91
|
+
events.each_with_index do |event, index|
|
92
|
+
|
93
|
+
attendees = event.attendee.map(&:to_s).map {|a| a.slice!("mailto:"); a }
|
94
|
+
|
95
|
+
context['event'] = {
|
96
|
+
'index' => index,
|
97
|
+
'uid' => event.uid,
|
98
|
+
'summary' => event.summary,
|
99
|
+
'description' => event.description,
|
100
|
+
'location' => event.location,
|
101
|
+
'url' => event.url&.to_s,
|
102
|
+
'start_time' => event.dtstart&.to_time,
|
103
|
+
'end_time' => event.dtend&.to_time,
|
104
|
+
'attendees' => attendees,
|
105
|
+
}
|
106
|
+
|
107
|
+
context['forloop'] = {
|
108
|
+
'name' => 'calendar',
|
109
|
+
'length' => length,
|
110
|
+
'index' => index + 1,
|
111
|
+
'index0' => index,
|
112
|
+
'rindex' => length - index,
|
113
|
+
'rindex0' => length - index - 1,
|
114
|
+
'first' => (index == 0),
|
115
|
+
'last' => (index == length - 1)
|
116
|
+
}
|
117
|
+
|
118
|
+
result << nodelist.map do |n|
|
119
|
+
if n.respond_to? :render
|
120
|
+
n.render(context)
|
121
|
+
else
|
122
|
+
n
|
123
|
+
end
|
124
|
+
end.join
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
result
|
129
|
+
end
|
130
|
+
|
131
|
+
private
|
132
|
+
|
133
|
+
def scan_attributes!
|
134
|
+
@attributes = {}
|
135
|
+
@markup.scan(Liquid::TagAttributes) do |key, value|
|
136
|
+
@attributes[key] = value
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def set_reverse!
|
141
|
+
@reverse = @attributes['order'] == 'reverse'
|
142
|
+
end
|
143
|
+
|
144
|
+
def set_url!
|
145
|
+
@url = @attributes['url']
|
146
|
+
raise "No URL provided" unless @url
|
147
|
+
end
|
148
|
+
|
149
|
+
def set_only!
|
150
|
+
only_future = @attributes["only_future"] == "true"
|
151
|
+
only_past = @attributes["only_past"] == "true"
|
152
|
+
|
153
|
+
raise "Set only_future OR only_past, not both" if only_future && only_past
|
154
|
+
@only =
|
155
|
+
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 =
|
167
|
+
begin
|
168
|
+
if @attributes['before_date']
|
169
|
+
Time.parse(@attributes['before_date'])
|
170
|
+
end
|
171
|
+
rescue => e
|
172
|
+
nil
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
def set_after_date!
|
177
|
+
@after_date =
|
178
|
+
begin
|
179
|
+
if @attributes['after_date']
|
180
|
+
Time.parse(@attributes['after_date'])
|
181
|
+
end
|
182
|
+
rescue => e
|
183
|
+
nil
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
Liquid::Template.register_tag('ical', Jekyll::CalendarTag)
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path("lib", __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
|
6
|
+
require 'jekyll'
|
7
|
+
require "jekyll-ical-tag/version"
|
8
|
+
|
9
|
+
Gem::Specification.new do |spec|
|
10
|
+
spec.name = "jekyll-ical-tag"
|
11
|
+
spec.version = Jekyll::IcalTag::VERSION
|
12
|
+
spec.authors = ["Ricky Chilcott"]
|
13
|
+
spec.email = ["ricky@rakefire.io"]
|
14
|
+
spec.summary = "A Jekyll plugin to pull ICS feed and provide a for-like loop of calendar events"
|
15
|
+
spec.homepage = "https://github.com/rakefire/jekyll-ical-tag"
|
16
|
+
spec.license = "MIT"
|
17
|
+
|
18
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
19
|
+
# delete this section to allow pushing this gem to any host.
|
20
|
+
if spec.respond_to?(:metadata)
|
21
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
22
|
+
else
|
23
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
24
|
+
end
|
25
|
+
|
26
|
+
spec.required_ruby_version = ">= 2.3.0"
|
27
|
+
|
28
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r!^(test|spec|features)/!) }
|
29
|
+
spec.bindir = "exe"
|
30
|
+
spec.executables = spec.files.grep(%r!^exe/!) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
spec.add_dependency "jekyll", "~> 3.3"
|
34
|
+
spec.add_dependency "api_cache"
|
35
|
+
spec.add_dependency "activesupport"
|
36
|
+
spec.add_dependency "icalendar"
|
37
|
+
spec.add_dependency "pry"
|
38
|
+
|
39
|
+
spec.add_development_dependency "bundler", "~> 1.15"
|
40
|
+
spec.add_development_dependency "rspec", "~> 3.5"
|
41
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
class IcalTag
|
5
|
+
class CalendarLimiter
|
6
|
+
def initialize(parser, options = {})
|
7
|
+
@parser = parser
|
8
|
+
@options = options
|
9
|
+
end
|
10
|
+
|
11
|
+
def events
|
12
|
+
case
|
13
|
+
when options[:only] == :future
|
14
|
+
now = Time.now
|
15
|
+
parser.events.select do |event|
|
16
|
+
event.dtstart.to_time >= now
|
17
|
+
end
|
18
|
+
when options[:only] == :past
|
19
|
+
now = Time.now
|
20
|
+
parser.events.select do |event|
|
21
|
+
event.dtstart.to_time < now
|
22
|
+
end
|
23
|
+
when options[:reverse]
|
24
|
+
parser.events.reverse
|
25
|
+
when options[:after_date]
|
26
|
+
parser.events.select do |event|
|
27
|
+
event.dtstart.to_time >= options[:after_date]
|
28
|
+
end
|
29
|
+
when options[:before_date]
|
30
|
+
parser.events.select do |event|
|
31
|
+
event.dtstart.to_time < options[:before_date]
|
32
|
+
end
|
33
|
+
else
|
34
|
+
parser.events
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
attr_reader :parser, :options
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "api_cache"
|
4
|
+
require "active_support"
|
5
|
+
require "icalendar"
|
6
|
+
|
7
|
+
module Jekyll
|
8
|
+
class IcalTag
|
9
|
+
class CalendarParser
|
10
|
+
def initialize(url)
|
11
|
+
@url = URI.unescape(url)
|
12
|
+
end
|
13
|
+
|
14
|
+
def events
|
15
|
+
@events ||= begin
|
16
|
+
Icalendar::Event.parse(ics_feed)
|
17
|
+
.sort { |e1, e2| e1.dtstart <=> e2.dtstart }
|
18
|
+
.map{|e| Jekyll::IcalTag::Event.new(e) }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def ics_feed
|
25
|
+
@ics_feed ||= APICache.get(@url)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "uri"
|
4
|
+
|
5
|
+
module Jekyll
|
6
|
+
class IcalTag
|
7
|
+
class Event
|
8
|
+
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
|
+
extend Forwardable
|
10
|
+
|
11
|
+
def initialize(event)
|
12
|
+
@event = event
|
13
|
+
end
|
14
|
+
|
15
|
+
def_delegators :event, :attendee, :uid, :summary, :description, :location, :url, :dtstart, :dtend
|
16
|
+
|
17
|
+
def simple_html_description
|
18
|
+
@simple_html_description ||= begin
|
19
|
+
description.clone.tap do |d|
|
20
|
+
description_urls.each do |url|
|
21
|
+
d.gsub! url, %(<a href='#{url}'>#{url}</a>)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def attendees
|
28
|
+
attendee.map(&:to_s).map {|a| a.slice!("mailto:"); a }
|
29
|
+
end
|
30
|
+
|
31
|
+
def description_urls
|
32
|
+
@description_urls ||= description.scan(URL_REGEX).to_a
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
attr_reader :event
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,138 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "jekyll"
|
4
|
+
require "jekyll-ical-tag/version"
|
5
|
+
require "pry"
|
6
|
+
|
7
|
+
module Jekyll
|
8
|
+
class IcalTag < Liquid::Block
|
9
|
+
require_relative "jekyll-ical-tag/event"
|
10
|
+
require_relative "jekyll-ical-tag/calendar_parser"
|
11
|
+
require_relative "jekyll-ical-tag/calendar_limiter"
|
12
|
+
|
13
|
+
include Convertible
|
14
|
+
|
15
|
+
def initialize(tag_name, markup, parse_context)
|
16
|
+
super
|
17
|
+
@markup = markup
|
18
|
+
|
19
|
+
scan_attributes!
|
20
|
+
set_reverse!
|
21
|
+
set_url!
|
22
|
+
set_only!
|
23
|
+
set_before_date!
|
24
|
+
set_after_date!
|
25
|
+
end
|
26
|
+
|
27
|
+
def render(context)
|
28
|
+
context.registers[:ical] ||= Hash.new(0)
|
29
|
+
|
30
|
+
result = []
|
31
|
+
|
32
|
+
parser = CalendarParser.new(@url)
|
33
|
+
parser = CalendarLimiter.new(parser, only: @only)
|
34
|
+
parser = CalendarLimiter.new(parser, reverse: @reverse)
|
35
|
+
parser = CalendarLimiter.new(parser, before_date: @before_date)
|
36
|
+
parser = CalendarLimiter.new(parser, after_date: @after_date)
|
37
|
+
|
38
|
+
events = parser.events
|
39
|
+
length = events.length
|
40
|
+
|
41
|
+
context.stack do
|
42
|
+
events.each_with_index do |event, index|
|
43
|
+
context['event'] = {
|
44
|
+
'index' => index,
|
45
|
+
'uid' => event.uid.presence,
|
46
|
+
'summary' => event.summary.presence,
|
47
|
+
'description' => event.description.presence,
|
48
|
+
'simple_html_description' => event.simple_html_description.presence,
|
49
|
+
'location' => event.location.presence,
|
50
|
+
'url' => event.url&.to_s.presence || event.description_urls.first,
|
51
|
+
'start_time' => event.dtstart&.to_time.presence,
|
52
|
+
'end_time' => event.dtend&.to_time.presence,
|
53
|
+
'attendees' => event.attendees,
|
54
|
+
}
|
55
|
+
|
56
|
+
context['forloop'] = {
|
57
|
+
'name' => 'ical',
|
58
|
+
'length' => length,
|
59
|
+
'index' => index + 1,
|
60
|
+
'index0' => index,
|
61
|
+
'rindex' => length - index,
|
62
|
+
'rindex0' => length - index - 1,
|
63
|
+
'first' => (index == 0),
|
64
|
+
'last' => (index == length - 1)
|
65
|
+
}
|
66
|
+
|
67
|
+
result << nodelist.map do |n|
|
68
|
+
if n.respond_to? :render
|
69
|
+
n.render(context)
|
70
|
+
else
|
71
|
+
n
|
72
|
+
end
|
73
|
+
end.join
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
result
|
78
|
+
end
|
79
|
+
|
80
|
+
private
|
81
|
+
|
82
|
+
def scan_attributes!
|
83
|
+
@attributes = {}
|
84
|
+
@markup.scan(Liquid::TagAttributes) do |key, value|
|
85
|
+
@attributes[key] = value
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def set_reverse!
|
90
|
+
@reverse = @attributes['order'] == 'reverse'
|
91
|
+
end
|
92
|
+
|
93
|
+
def set_url!
|
94
|
+
@url = @attributes['url']
|
95
|
+
raise "No URL provided" unless @url
|
96
|
+
end
|
97
|
+
|
98
|
+
def set_only!
|
99
|
+
only_future = @attributes["only_future"] == "true"
|
100
|
+
only_past = @attributes["only_past"] == "true"
|
101
|
+
|
102
|
+
raise "Set only_future OR only_past, not both" if only_future && only_past
|
103
|
+
@only =
|
104
|
+
case
|
105
|
+
when only_future
|
106
|
+
:future
|
107
|
+
when only_past
|
108
|
+
:past
|
109
|
+
else
|
110
|
+
:all
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def set_before_date!
|
115
|
+
@before_date =
|
116
|
+
begin
|
117
|
+
if @attributes['before_date']
|
118
|
+
Time.parse(@attributes['before_date'])
|
119
|
+
end
|
120
|
+
rescue => e
|
121
|
+
nil
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def set_after_date!
|
126
|
+
@after_date =
|
127
|
+
begin
|
128
|
+
if @attributes['after_date']
|
129
|
+
Time.parse(@attributes['after_date'])
|
130
|
+
end
|
131
|
+
rescue => e
|
132
|
+
nil
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
Liquid::Template.register_tag('ical', Jekyll::IcalTag)
|
metadata
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll-ical-tag
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ricky Chilcott
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-02-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: jekyll
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.3'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: api_cache
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: activesupport
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: icalendar
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
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
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: bundler
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.15'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.15'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '3.5'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '3.5'
|
111
|
+
description:
|
112
|
+
email:
|
113
|
+
- ricky@rakefire.io
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- Gemfile
|
120
|
+
- Gemfile.lock
|
121
|
+
- README.md
|
122
|
+
- _plugins/ical_tag.rb
|
123
|
+
- jekyll-ical-tag.gemspec
|
124
|
+
- lib/jekyll-ical-tag.rb
|
125
|
+
- lib/jekyll-ical-tag/calendar_limiter.rb
|
126
|
+
- lib/jekyll-ical-tag/calendar_parser.rb
|
127
|
+
- lib/jekyll-ical-tag/event.rb
|
128
|
+
- lib/jekyll-ical-tag/version.rb
|
129
|
+
homepage: https://github.com/rakefire/jekyll-ical-tag
|
130
|
+
licenses:
|
131
|
+
- MIT
|
132
|
+
metadata:
|
133
|
+
allowed_push_host: https://rubygems.org
|
134
|
+
post_install_message:
|
135
|
+
rdoc_options: []
|
136
|
+
require_paths:
|
137
|
+
- lib
|
138
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
139
|
+
requirements:
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: 2.3.0
|
143
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - ">="
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0'
|
148
|
+
requirements: []
|
149
|
+
rubyforge_project:
|
150
|
+
rubygems_version: 2.7.6
|
151
|
+
signing_key:
|
152
|
+
specification_version: 4
|
153
|
+
summary: A Jekyll plugin to pull ICS feed and provide a for-like loop of calendar
|
154
|
+
events
|
155
|
+
test_files: []
|