class Bridgetown::Resource::TaxonomyType

Attributes

key[R]

@return [String] the key used in front matter

label[R]

@return [String] aka `category`, `tag`, `region`, etc.

metadata[R]

@return [HashWithDotAccess::Hash] any associated metadata

site[R]

@return [Bridgetown::Site]

Public Class Methods

new(site:, label:, key:, metadata:) click to toggle source

@param site [Bridgetown::Site] @param label [String] @param key [String]

# File lib/bridgetown-core/resource/taxonomy_type.rb, line 21
def initialize(site:, label:, key:, metadata:)
  @site = site
  @label = label
  @key = key
  @metadata = metadata
end

Public Instance Methods

as_json(*) click to toggle source
# File lib/bridgetown-core/resource/taxonomy_type.rb, line 47
def as_json(*)
  to_h
end
inspect() click to toggle source
# File lib/bridgetown-core/resource/taxonomy_type.rb, line 34
def inspect
  "#<#{self.class} label=#{label}>"
end
terms() click to toggle source
# File lib/bridgetown-core/resource/taxonomy_type.rb, line 28
def terms
  site.resources.map do |resource|
    resource.taxonomies[label].terms
  end.flatten.group_by(&:label).with_dot_access
end
to_h()
Alias for: to_liquid
to_json(*options) click to toggle source
# File lib/bridgetown-core/resource/taxonomy_type.rb, line 51
               def to_json(*options)
  as_json(*options).to_json(*options)
end
to_liquid() click to toggle source
# File lib/bridgetown-core/resource/taxonomy_type.rb, line 38
def to_liquid
  {
    "label"    => label,
    "key"      => key,
    "metadata" => metadata,
  }
end
Also aliased as: to_h