Class: Jekyll::ActionNetwork::Generator
- Inherits:
-
Generator
- Object
- Generator
- Jekyll::ActionNetwork::Generator
- Defined in:
- lib/jekyll/action-network/generator.rb
Overview
Generates Jekyll collections from the Action Network API
Constant Summary collapse
- UTILS =
Jekyll::ActionNetwork::Utils.new
Instance Method Summary collapse
- #actions ⇒ Object
- #api_key ⇒ Object
- #authenticate ⇒ Object
- #client ⇒ Object
- #defaults ⇒ Object
- #entry_point ⇒ Object
- #generate(site) ⇒ Object
- #get_full_list(name) ⇒ Object
- #make_collection(name, config) ⇒ Object
- #make_collection_config(col_config_init) ⇒ Object
- #make_collections ⇒ Object
- #page_size ⇒ Object
- #settings ⇒ Object
Instance Method Details
#actions ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/jekyll/action-network/generator.rb', line 56 def actions return @actions if @actions actions_config = @config["actions"] if @config["actions"].is_a? Hash actions_settings = settings["actions"].merge(actions_config || {}) @actions ||= Jekyll::Collection.new(@site, actions_settings["collection"]) end |
#api_key ⇒ Object
77 78 79 80 81 82 |
# File 'lib/jekyll/action-network/generator.rb', line 77 def api_key key = @config["key"] || settings["key"] return ENV.fetch(key[4..key.length - 1], nil) if key[0..3] == "ENV_" key end |
#authenticate ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/jekyll/action-network/generator.rb', line 84 def authenticate unless api_key Jekyll.logger.warn "Action Network API Key not found." return end unless entry_point.dig("_links", "osdi:tags").present? Jekyll.logger.warn "Action Network Authentication Unsucessful" return end true end |
#client ⇒ Object
97 98 99 |
# File 'lib/jekyll/action-network/generator.rb', line 97 def client @client ||= ActionNetworkRest.new(api_key: api_key) end |
#defaults ⇒ Object
73 74 75 |
# File 'lib/jekyll/action-network/generator.rb', line 73 def defaults @defaults ||= settings["defaults"] end |
#entry_point ⇒ Object
101 102 103 |
# File 'lib/jekyll/action-network/generator.rb', line 101 def entry_point @entry_point ||= client.entry_point.get end |
#generate(site) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/jekyll/action-network/generator.rb', line 19 def generate(site) return unless site.config["action_network"] @site = site @config = site.config["action_network"] @utils = Jekyll::ActionNetwork::Utils.new return unless authenticate make_collections end |
#get_full_list(name) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/jekyll/action-network/generator.rb', line 109 def get_full_list(name) page = 1 actions = [] loop do action_page = @client.send(name).list(page: page) actions.concat(action_page) break if action_page.size < page_size page += 1 end actions end |
#make_collection(name, config) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/jekyll/action-network/generator.rb', line 48 def make_collection(name, config) return unless defaults[name] collection = Jekyll::ActionNetwork::Collection.new(@site, self, @client, config, settings) @site.collections[collection.config["collection"]] = collection.populate actions.docs.concat(collection.collection.docs) end |
#make_collection_config(col_config_init) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/jekyll/action-network/generator.rb', line 41 def make_collection_config(col_config_init) return col_config_init if col_config_init.is_a? Hash return { "name" => col_config_init } if col_config_init.is_a? String Jekyll.logger.warn LOG_NAME, "Config format #{col_config_init} not recognised" end |
#make_collections ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/jekyll/action-network/generator.rb', line 30 def make_collections @config["import"].each do |config| col_config = make_collection_config(config) name = col_config["name"] next unless col_config["name"] make_collection(name, col_config) end @site.collections["actions"] = actions if @config["actions"] end |
#page_size ⇒ Object
105 106 107 |
# File 'lib/jekyll/action-network/generator.rb', line 105 def page_size @page_size ||= @entry_point["max_page_size"] end |
#settings ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'lib/jekyll/action-network/generator.rb', line 64 def settings return @settings if @settings settings = YAML.load_file("#{File.expand_path(__dir__)}/settings.yaml") @fields = settings["fields"] @filters = settings["filters"] @settings = settings end |