jekyll-action-network 0.3.3 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/jekyll/action-network/action.rb +54 -0
- data/lib/jekyll/action-network/collection.rb +87 -0
- data/lib/jekyll/action-network/generator.rb +64 -125
- data/lib/jekyll/action-network/settings.yaml +14 -11
- data/lib/jekyll/action-network/utils.rb +44 -0
- data/lib/jekyll/action-network/version.rb +1 -1
- data/lib/jekyll-action-network.rb +3 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 65a9afd8b2fcbcc33e2f1f45ea6d25a07acc6bcc28e5b7ac3900443a5c4078dc
|
4
|
+
data.tar.gz: ba9411be015b223ded854fec35a3fb2f39c9cdaa60ce9271b0cddb4c80511ed7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e00cde2d4c9d533931f046f11b7272bfa33dfedebd94b26141d721d7990ffb6d8be48be770ccac1ff378504a8856b958987c25ddd0d7e26c2607c76fa6709399
|
7
|
+
data.tar.gz: 4b0c39e1b928efce610feb7ba9733853c022a33d4a20eba190d6518f465777324152c6eba58a4294da562f2931ce39298bf4a524d1a4f7c948822f526a44ba1b
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
module ActionNetwork
|
5
|
+
##
|
6
|
+
# An action network action, call the +doc+ method to get a
|
7
|
+
# Jekyll::Document for this action
|
8
|
+
class Action
|
9
|
+
def initialize(site, name, collection, config, action)
|
10
|
+
@site = site
|
11
|
+
@collection = collection
|
12
|
+
@config = config
|
13
|
+
@action = action
|
14
|
+
@name = name
|
15
|
+
@utils = Jekyll::ActionNetwork::Utils.new
|
16
|
+
end
|
17
|
+
|
18
|
+
def doc
|
19
|
+
return @doc if @doc
|
20
|
+
|
21
|
+
@doc = Jekyll::Document.new(path, collection: @collection, site: @site)
|
22
|
+
@doc.content = content
|
23
|
+
@doc.merge_data!(front_matter)
|
24
|
+
@doc
|
25
|
+
end
|
26
|
+
|
27
|
+
def slug
|
28
|
+
@slug ||= @action["browser_url"].split("/")[-1] if @action["browser_url"]
|
29
|
+
end
|
30
|
+
|
31
|
+
def path
|
32
|
+
@path ||= File.join(@site.source, "_#{@config["collection"]}", "#{slug}.md")
|
33
|
+
end
|
34
|
+
|
35
|
+
def front_matter
|
36
|
+
return @front_matter if @front_matter
|
37
|
+
|
38
|
+
@front_matter = {}
|
39
|
+
@config["mappings"].each do |a, d|
|
40
|
+
front_matter[d] = @action[a]
|
41
|
+
end
|
42
|
+
@front_matter["layout"] = @config["layout"]
|
43
|
+
@front_matter["slug"] = slug
|
44
|
+
@front_matter["embed_code"] = @utils.make_embed_code(@action["browser_url"])
|
45
|
+
@front_matter["action_type"] = @name
|
46
|
+
@front_matter
|
47
|
+
end
|
48
|
+
|
49
|
+
def content
|
50
|
+
@content ||= @action[@config["content"]]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
module ActionNetwork
|
5
|
+
##
|
6
|
+
# For creating Jekyll::Collections from an Action Network config
|
7
|
+
#
|
8
|
+
class Collection
|
9
|
+
UTILS = Jekyll::ActionNetwork::Utils.new
|
10
|
+
|
11
|
+
def initialize(site, client, config_init, settings)
|
12
|
+
@site = site
|
13
|
+
@settings = settings
|
14
|
+
@client = client
|
15
|
+
@config_init = config_init
|
16
|
+
end
|
17
|
+
|
18
|
+
def config
|
19
|
+
@name = @config_init["name"]
|
20
|
+
@defaults ||= @settings["defaults"]
|
21
|
+
@config ||= @defaults[@name].merge!(@config_init)
|
22
|
+
end
|
23
|
+
|
24
|
+
def collection
|
25
|
+
return @collection if @collection
|
26
|
+
|
27
|
+
Jekyll.logger.debug LOG_NAME, "Creating collection #{@name}"
|
28
|
+
@collection ||= @site.collections[@name] if @site.collections[@name]
|
29
|
+
@collection ||= Jekyll::Collection.new(@site, config["collection"])
|
30
|
+
end
|
31
|
+
|
32
|
+
def documents
|
33
|
+
documents = []
|
34
|
+
filtered_actions.each do |action_data|
|
35
|
+
action = Jekyll::ActionNetwork::Action.new(@site, @name, collection, config, action_data)
|
36
|
+
documents << action.doc
|
37
|
+
end
|
38
|
+
documents
|
39
|
+
end
|
40
|
+
|
41
|
+
def populate
|
42
|
+
collection.docs.concat(documents)
|
43
|
+
@collection
|
44
|
+
end
|
45
|
+
|
46
|
+
def actions
|
47
|
+
@actions ||= UTILS.get_full_list(@client, @name)
|
48
|
+
end
|
49
|
+
|
50
|
+
def filters
|
51
|
+
filters = @settings["filters"]["all"].merge(@settings["filters"][@name] || {})
|
52
|
+
filters.merge(config["filters"] || {})
|
53
|
+
end
|
54
|
+
|
55
|
+
def filtered_actions
|
56
|
+
public_actions = []
|
57
|
+
actions.each do |action|
|
58
|
+
next if action_filtered(action, filters)
|
59
|
+
|
60
|
+
public_actions << reduce_fields(action)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def action_filtered(action, filters)
|
65
|
+
filtered = false
|
66
|
+
filters.each do |key, value|
|
67
|
+
next if action[key] == value
|
68
|
+
|
69
|
+
next if value == "%" && action[key]
|
70
|
+
|
71
|
+
Jekyll.logger.debug @log_name, "#{name} filtered because #{action[key]} == #{value}"
|
72
|
+
filtered = true
|
73
|
+
break
|
74
|
+
end
|
75
|
+
filtered
|
76
|
+
end
|
77
|
+
|
78
|
+
def reduce_fields(action)
|
79
|
+
reduced_action = {}
|
80
|
+
@settings["fields"].each do |field|
|
81
|
+
reduced_action[field] = action[field] if action[field]
|
82
|
+
end
|
83
|
+
reduced_action
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -5,151 +5,90 @@ require "jekyll"
|
|
5
5
|
require "yaml"
|
6
6
|
require "dotenv/load"
|
7
7
|
|
8
|
-
##
|
9
|
-
# This class is a Jekyll::Generator that creates collections from
|
10
|
-
# Action Network
|
11
8
|
module Jekyll
|
12
9
|
##
|
13
|
-
#
|
14
|
-
|
15
|
-
|
16
|
-
def generate(site)
|
17
|
-
return unless site.config["action_network"]
|
18
|
-
|
19
|
-
@site = site
|
20
|
-
@log_name = "Action Network:"
|
21
|
-
@settings ||= settings
|
22
|
-
@config = site.config["action_network"]
|
23
|
-
return unless authenticate
|
24
|
-
|
25
|
-
@actions = Jekyll::Collection.new(site, "actions") if @config["actions"]
|
26
|
-
@config.each do |name, _config|
|
27
|
-
next unless @defaults[name]
|
28
|
-
|
29
|
-
make_collection(name)
|
30
|
-
end
|
31
|
-
site.collections["actions"] = @actions if @actions
|
32
|
-
end
|
10
|
+
# An integration with Action Network for a Jekyll site
|
11
|
+
module ActionNetwork
|
12
|
+
LOG_NAME = "Action Network: "
|
33
13
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
@filters = @settings["filters"]
|
39
|
-
@settings
|
40
|
-
end
|
14
|
+
##
|
15
|
+
# Generates Jekyll collections from the Action Network API
|
16
|
+
class Generator < Jekyll::Generator
|
17
|
+
UTILS = Jekyll::ActionNetwork::Utils.new
|
41
18
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
19
|
+
def generate(site)
|
20
|
+
return unless site.config["action_network"]
|
21
|
+
|
22
|
+
@site = site
|
23
|
+
@config = site.config["action_network"]
|
24
|
+
@utils = Jekyll::ActionNetwork::Utils.new
|
25
|
+
return unless authenticate
|
26
|
+
|
27
|
+
make_collections
|
46
28
|
end
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
filtered_actions.each do |action|
|
56
|
-
slug = action["browser_url"].split("/")[-1]
|
57
|
-
path = File.join(@site.source, "_#{config["collection"]}", "#{slug}.md")
|
58
|
-
doc = Jekyll::Document.new(path, collection: collection, site: @site)
|
59
|
-
doc.content = action[config["content"]]
|
60
|
-
frontmattter_data = {}
|
61
|
-
config["mappings"].each do |a, d|
|
62
|
-
frontmattter_data[d] = action[a]
|
29
|
+
|
30
|
+
def make_collections
|
31
|
+
@config["import"].each do |config|
|
32
|
+
name = config["name"] if config.is_a? Hash
|
33
|
+
name ||= config if config.is_a? String
|
34
|
+
next unless name
|
35
|
+
|
36
|
+
make_collection(name, config)
|
63
37
|
end
|
64
|
-
|
65
|
-
"layout" => config["layout"],
|
66
|
-
"slug" => slug,
|
67
|
-
"embed_code" => make_embed_code(action["browser_url"]),
|
68
|
-
"action_type" => name
|
69
|
-
})
|
70
|
-
doc.merge_data!(frontmattter_data)
|
71
|
-
collection.docs << doc
|
72
|
-
@actions.docs << doc if @actions
|
38
|
+
@site.collections["actions"] = actions if @config["actions"]
|
73
39
|
end
|
74
|
-
@site.collections[config["collection"]] = collection
|
75
|
-
end
|
76
40
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
<div id='can-#{resource}-area-#{slug}' style='width: 100%'></div>"
|
85
|
-
end
|
41
|
+
def make_collection(name, config)
|
42
|
+
return unless defaults[name]
|
43
|
+
|
44
|
+
collection = Jekyll::ActionNetwork::Collection.new(@site, @client, config, settings)
|
45
|
+
@site.collections[collection.config["collection"]] = collection.populate
|
46
|
+
actions.docs.concat(collection.collection.docs)
|
47
|
+
end
|
86
48
|
|
87
|
-
|
88
|
-
|
89
|
-
actions = []
|
90
|
-
loop do
|
91
|
-
action_page = @client.send(name).list(page: page)
|
92
|
-
break if action_page.empty?
|
49
|
+
def actions
|
50
|
+
return @actions if @actions
|
93
51
|
|
94
|
-
actions.
|
95
|
-
|
52
|
+
actions_config = @config["actions"] if @config["actions"].is_a? Hash
|
53
|
+
actions_settings = @settings["actions"].merge(actions_config || {})
|
54
|
+
@actions ||= Jekyll::Collection.new(@site, actions_settings["collection"])
|
96
55
|
end
|
97
|
-
actions
|
98
|
-
end
|
99
56
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
actions.each do |action|
|
108
|
-
filtered = true
|
109
|
-
filters.each do |key, value|
|
110
|
-
unless action[key] == value
|
111
|
-
if value == "%" && action[key]
|
112
|
-
filtered = false if action[key].length.positive?
|
113
|
-
else
|
114
|
-
Jekyll.logger.warn @log_name, "#{name} filtered because #{action[key]} == #{value}"
|
115
|
-
filtered = true
|
116
|
-
break
|
117
|
-
end
|
118
|
-
end
|
119
|
-
filtered = false
|
120
|
-
end
|
121
|
-
public << reduce_fields(action) unless filtered
|
57
|
+
def settings
|
58
|
+
return @settings if @settings
|
59
|
+
|
60
|
+
settings = YAML.load_file("#{File.expand_path(__dir__)}/settings.yaml")
|
61
|
+
@fields = settings["fields"]
|
62
|
+
@filters = settings["filters"]
|
63
|
+
@settings = settings
|
122
64
|
end
|
123
|
-
public
|
124
|
-
end
|
125
65
|
|
126
|
-
|
127
|
-
|
128
|
-
@fields.each do |field|
|
129
|
-
reduced_action[field] = action[field] if action[field]
|
66
|
+
def defaults
|
67
|
+
@defaults ||= settings["defaults"]
|
130
68
|
end
|
131
|
-
reduced_action
|
132
|
-
end
|
133
69
|
|
134
|
-
|
135
|
-
return unless key
|
136
|
-
return ENV.fetch(key[4..key.length - 1], nil) if key[0..3] == "ENV_"
|
137
|
-
return ENV["ACTION_NETWORK_API_KEY"] if ENV["ACTION_NETWORK_API_KEY"]
|
70
|
+
private
|
138
71
|
|
139
|
-
|
140
|
-
|
72
|
+
def api_key
|
73
|
+
key = @config["key"] || @settings["key"]
|
74
|
+
return ENV.fetch(key[4..key.length - 1], nil) if key[0..3] == "ENV_"
|
141
75
|
|
142
|
-
|
143
|
-
|
144
|
-
Jekyll.logger.warn "Action Network API Key not found." unless api_key
|
145
|
-
return unless api_key
|
76
|
+
key
|
77
|
+
end
|
146
78
|
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
79
|
+
def authenticate
|
80
|
+
unless api_key
|
81
|
+
Jekyll.logger.warn "Action Network API Key not found."
|
82
|
+
return
|
83
|
+
end
|
84
|
+
|
85
|
+
@client = ActionNetworkRest.new(api_key: api_key)
|
86
|
+
unless @client.entry_point.authenticated_successfully?
|
87
|
+
Jekyll.logger.warn "Action Network Authentication Unsucessful"
|
88
|
+
return
|
89
|
+
end
|
90
|
+
true
|
151
91
|
end
|
152
|
-
true
|
153
92
|
end
|
154
93
|
end
|
155
94
|
end
|
@@ -35,6 +35,9 @@ embed:
|
|
35
35
|
styles:
|
36
36
|
standard: <link href='https://actionnetwork.org/css/style-embed-v3.css' rel='stylesheet' type='text/css' />
|
37
37
|
layout_only: <link href='https://actionnetwork.org/css/style-embed-whitelabel-v3.css' rel='stylesheet' type='text/css' />
|
38
|
+
actions:
|
39
|
+
collection: actions
|
40
|
+
key: ENV_ACTION_NETWORK_API_KEY
|
38
41
|
defaults:
|
39
42
|
petitions:
|
40
43
|
collection: petitions
|
@@ -48,17 +51,6 @@ defaults:
|
|
48
51
|
featured_image_url: image
|
49
52
|
target: target
|
50
53
|
"action_network:sponsor": sponsor
|
51
|
-
# campaigns:
|
52
|
-
# collection: campaigns
|
53
|
-
# layout: an-campaign
|
54
|
-
# content: description
|
55
|
-
# mappings:
|
56
|
-
# title: title
|
57
|
-
# description: description
|
58
|
-
# browser_url: browser_url
|
59
|
-
# featured_image_url: image
|
60
|
-
# actions: actions
|
61
|
-
# "action_network:sponsor": sponsor
|
62
54
|
events:
|
63
55
|
collection: events
|
64
56
|
layout: an-event
|
@@ -112,4 +104,15 @@ defaults:
|
|
112
104
|
# call_to_action: call_to_action
|
113
105
|
# browser_url: browser_url
|
114
106
|
# featured_image_url: image
|
107
|
+
# "action_network:sponsor": sponsor
|
108
|
+
# campaigns:
|
109
|
+
# collection: campaigns
|
110
|
+
# layout: an-campaign
|
111
|
+
# content: description
|
112
|
+
# mappings:
|
113
|
+
# title: title
|
114
|
+
# description: description
|
115
|
+
# browser_url: browser_url
|
116
|
+
# featured_image_url: image
|
117
|
+
# actions: actions
|
115
118
|
# "action_network:sponsor": sponsor
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "yaml"
|
4
|
+
|
5
|
+
module Jekyll
|
6
|
+
module ActionNetwork
|
7
|
+
##
|
8
|
+
# Some commonly used tools for the Action Network generator
|
9
|
+
class Utils
|
10
|
+
def settings
|
11
|
+
return @settings if @settings
|
12
|
+
|
13
|
+
@settings = YAML.load_file("#{File.expand_path(__dir__)}/settings.yaml")
|
14
|
+
@defaults = @settings["defaults"]
|
15
|
+
@fields = @settings["fields"]
|
16
|
+
@filters = @settings["filters"]
|
17
|
+
@settings
|
18
|
+
end
|
19
|
+
|
20
|
+
def make_embed_code(browser_url, style = nil)
|
21
|
+
relative_url = browser_url.split("://")[1].sub("actionnetwork.org/", "")
|
22
|
+
split_url = relative_url.split("/")
|
23
|
+
css = settings["embed"]["styles"][style] if style
|
24
|
+
resource = settings["embed"]["resources"][split_url[0]]
|
25
|
+
slug = split_url[1]
|
26
|
+
"#{css}<script src='https://actionnetwork.org/widgets/v5/#{resource}/#{slug}?format=js&source=widget'></script>
|
27
|
+
<div id='can-#{resource}-area-#{slug}' style='width: 100%'></div>"
|
28
|
+
end
|
29
|
+
|
30
|
+
def get_full_list(client, name)
|
31
|
+
page = 1
|
32
|
+
actions = []
|
33
|
+
loop do
|
34
|
+
action_page = client.send(name).list(page: page)
|
35
|
+
break if action_page.empty?
|
36
|
+
|
37
|
+
actions.concat(action_page)
|
38
|
+
page += 1
|
39
|
+
end
|
40
|
+
actions
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-action-network
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joe Irving
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-09-
|
11
|
+
date: 2022-09-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: action_network_rest
|
@@ -128,8 +128,11 @@ extensions: []
|
|
128
128
|
extra_rdoc_files: []
|
129
129
|
files:
|
130
130
|
- lib/jekyll-action-network.rb
|
131
|
+
- lib/jekyll/action-network/action.rb
|
132
|
+
- lib/jekyll/action-network/collection.rb
|
131
133
|
- lib/jekyll/action-network/generator.rb
|
132
134
|
- lib/jekyll/action-network/settings.yaml
|
135
|
+
- lib/jekyll/action-network/utils.rb
|
133
136
|
- lib/jekyll/action-network/version.rb
|
134
137
|
homepage: https://github.com/joe-irving/jekyll-action-network/
|
135
138
|
licenses:
|