Class: Jekyll::ActionNetwork::Collection
- Inherits:
-
Object
- Object
- Jekyll::ActionNetwork::Collection
- Defined in:
- lib/jekyll/action-network/collection.rb
Overview
For creating Jekyll::Collections from an Action Network config
Constant Summary collapse
- UTILS =
Jekyll::ActionNetwork::Utils.new
Instance Method Summary collapse
- #action_filtered(action, filters) ⇒ Object
- #actions ⇒ Object
- #collection ⇒ Object
- #config ⇒ Object
- #documents ⇒ Object
- #filtered_actions ⇒ Object
- #filters ⇒ Object
-
#initialize(site, generator, client, config_init, settings) ⇒ Collection
constructor
A new instance of Collection.
- #populate ⇒ Object
- #reduce_fields(action) ⇒ Object
Constructor Details
#initialize(site, generator, client, config_init, settings) ⇒ Collection
Returns a new instance of Collection.
11 12 13 14 15 16 17 |
# File 'lib/jekyll/action-network/collection.rb', line 11 def initialize(site, generator, client, config_init, settings) @site = site @generator = generator @settings = settings @client = client @config_init = config_init end |
Instance Method Details
#action_filtered(action, filters) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/jekyll/action-network/collection.rb', line 65 def action_filtered(action, filters) filtered = false filters.each do |key, value| next if action[key] == value next if value == "%" && action[key] Jekyll.logger.debug @log_name, "#{action["title"]} filtered because #{action[key]} == #{value}" filtered = true break end filtered end |
#actions ⇒ Object
47 48 49 |
# File 'lib/jekyll/action-network/collection.rb', line 47 def actions @actions ||= @generator.get_full_list(@name) end |
#collection ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/jekyll/action-network/collection.rb', line 25 def collection return @collection if @collection Jekyll.logger.debug LOG_NAME, "Creating collection #{@name}" @collection ||= @site.collections[@name] if @site.collections[@name] @collection ||= Jekyll::Collection.new(@site, config["collection"]) end |
#config ⇒ Object
19 20 21 22 23 |
# File 'lib/jekyll/action-network/collection.rb', line 19 def config @name = @config_init["name"] @defaults ||= @settings["defaults"] @config ||= @defaults[@name].merge!(@config_init) end |
#documents ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/jekyll/action-network/collection.rb', line 33 def documents documents = [] filtered_actions.each do |action_data| action = Jekyll::ActionNetwork::Action.new(@site, @name, collection, config, action_data) documents << action.doc end documents end |
#filtered_actions ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/jekyll/action-network/collection.rb', line 56 def filtered_actions public_actions = [] actions.each do |action| next if action_filtered(action, filters) public_actions << reduce_fields(action) end end |
#filters ⇒ Object
51 52 53 54 |
# File 'lib/jekyll/action-network/collection.rb', line 51 def filters filters = @settings["filters"]["all"].merge(@settings["filters"][@name] || {}) filters.merge(config["filters"] || {}) end |
#populate ⇒ Object
42 43 44 45 |
# File 'lib/jekyll/action-network/collection.rb', line 42 def populate collection.docs.concat(documents) @collection end |
#reduce_fields(action) ⇒ Object
79 80 81 82 83 84 85 |
# File 'lib/jekyll/action-network/collection.rb', line 79 def reduce_fields(action) reduced_action = {} @settings["fields"].each do |field| reduced_action[field] = action[field] if action[field] end reduced_action end |