Class: Jekyll::Geolexica::ConceptsGenerator

Inherits:
Generator
  • Object
show all
Includes:
Configuration
Defined in:
lib/jekyll/geolexica/concepts_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Configuration

#bibliography_path, #concepts_glob, #glossary_format, #glossary_path, #images_metadata_path, #images_path, #localized_concepts_path, #output_html?, #output_json?, #output_jsonld?, #output_tbx?, #output_turtle?, #output_yaml?, #report_issue_url, #suggest_translation_url, #term_languages

Instance Attribute Details

#generated_pagesObject (readonly)

Returns the value of attribute generated_pages.



11
12
13
# File 'lib/jekyll/geolexica/concepts_generator.rb', line 11

def generated_pages
  @generated_pages
end

#siteObject (readonly)

Returns the value of attribute site.



11
12
13
# File 'lib/jekyll/geolexica/concepts_generator.rb', line 11

def site
  @site
end

Instance Method Details

#add_page(*pages) ⇒ Object



67
68
69
# File 'lib/jekyll/geolexica/concepts_generator.rb', line 67

def add_page *pages
  self.generated_pages.concat(pages)
end

#find_page(name) ⇒ Object



71
72
73
# File 'lib/jekyll/geolexica/concepts_generator.rb', line 71

def find_page(name)
  site.pages.detect { |page| page.name == name }
end

#generate(site) ⇒ Object

Generates Geolexica concept pages, both HTML and machine-readable.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/jekyll/geolexica/concepts_generator.rb', line 14

def generate(site)
  Jekyll.logger.info("Geolexica:", "Generating concept pages")

  # Jekyll does not say why it's a good idea, and whether such approach
  # is thread-safe or not, but most plugins in the wild do exactly that,
  # including these authored by Jekyll team.
  @site = site
  @generated_pages = []

  make_pages
  sort_pages
  initialize_collections
  group_pages_in_collections
end

#group_pages_in_collectionsObject



61
62
63
64
65
# File 'lib/jekyll/geolexica/concepts_generator.rb', line 61

def group_pages_in_collections
  generated_pages.each do |page|
    site.collections[page.collection_name].docs.push(page)
  end
end

#initialize_collectionsObject



50
51
52
53
54
55
56
57
58
59
# File 'lib/jekyll/geolexica/concepts_generator.rb', line 50

def initialize_collections
  %w[
    concepts concepts_json concepts_jsonld
    concepts_ttl concepts_tbx concepts_yaml
  ].each do |label|
    next if site.collections[label]
    site.config["collections"][label] ||= { "output" => true }
    site.collections[label] = Jekyll::Collection.new(site, label)
  end
end

#make_pagesObject

Processes concepts and yields a bunch of Jekyll::Page instances.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/jekyll/geolexica/concepts_generator.rb', line 30

def make_pages
  site.glossary.each_concept do |concept|
    Jekyll.logger.debug("Geolexica:",
      "building pages for concept #{concept.termid}")
    concept.pages.replace({
      html: (ConceptPage::HTML.new(site, concept) if output_html?),
      json: (ConceptPage::JSON.new(site, concept) if output_json?),
      jsonld: (ConceptPage::JSONLD.new(site, concept) if output_jsonld?),
      tbx: (ConceptPage::TBX.new(site, concept) if output_tbx?),
      turtle: (ConceptPage::Turtle.new(site, concept) if output_turtle?),
      yaml: (ConceptPage::YAML.new(site, concept) if output_yaml?),
    })
    add_page(*concept.pages.values.compact)
  end
end

#sort_pagesObject



46
47
48
# File 'lib/jekyll/geolexica/concepts_generator.rb', line 46

def sort_pages
  generated_pages.sort_by! { |p| p.termid }
end