Class: Bridgetown::Resource::TaxonomyType

Inherits:
Object
  • Object
show all
Defined in:
bridgetown-core/lib/bridgetown-core/resource/taxonomy_type.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(site:, label:, key:, metadata:) ⇒ TaxonomyType

Returns a new instance of TaxonomyType.

Parameters:



23
24
25
26
27
28
# File 'bridgetown-core/lib/bridgetown-core/resource/taxonomy_type.rb', line 23

def initialize(site:, label:, key:, metadata:)
  @site = site
  @label = label
  @key = key
  @metadata = 
end

Instance Attribute Details

#keyString (readonly)

Returns the key used in front matter.

Returns:

  • (String)

    the key used in front matter



15
16
17
# File 'bridgetown-core/lib/bridgetown-core/resource/taxonomy_type.rb', line 15

def key
  @key
end

#labelString (readonly)

Returns aka category, tag, region, etc.

Returns:

  • (String)

    aka category, tag, region, etc.



12
13
14
# File 'bridgetown-core/lib/bridgetown-core/resource/taxonomy_type.rb', line 12

def label
  @label
end

#metadataHashWithDotAccess::Hash (readonly)

Returns any associated metadata.

Returns:



18
19
20
# File 'bridgetown-core/lib/bridgetown-core/resource/taxonomy_type.rb', line 18

def 
  @metadata
end

#siteBridgetown::Site (readonly)

Returns:



9
10
11
# File 'bridgetown-core/lib/bridgetown-core/resource/taxonomy_type.rb', line 9

def site
  @site
end

Instance Method Details

#as_jsonObject



49
50
51
# File 'bridgetown-core/lib/bridgetown-core/resource/taxonomy_type.rb', line 49

def as_json(*)
  to_h
end

#inspectObject



36
37
38
# File 'bridgetown-core/lib/bridgetown-core/resource/taxonomy_type.rb', line 36

def inspect
  "#<#{self.class} label=#{label}>"
end

#termsObject



30
31
32
33
34
# File 'bridgetown-core/lib/bridgetown-core/resource/taxonomy_type.rb', line 30

def terms
  site.resources.map do |resource|
    resource.taxonomies[label].terms
  end.flatten.group_by(&:label).as_dots
end

#to_jsonObject



53
54
55
# File 'bridgetown-core/lib/bridgetown-core/resource/taxonomy_type.rb', line 53

def to_json(...)
  as_json(...).to_json(...)
end

#to_liquidObject Also known as: to_h



40
41
42
43
44
45
46
# File 'bridgetown-core/lib/bridgetown-core/resource/taxonomy_type.rb', line 40

def to_liquid
  {
    "label"    => label,
    "key"      => key,
    "metadata" => ,
  }
end