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



86
87
88
# File 'lib/jekyll/geolexica/concepts_generator.rb', line 86

def add_page *pages
  generated_pages.concat(pages)
end

#find_page(name) ⇒ Object



90
91
92
# File 'lib/jekyll/geolexica/concepts_generator.rb', line 90

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



80
81
82
83
84
# File 'lib/jekyll/geolexica/concepts_generator.rb', line 80

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

#initialize_collectionsObject



68
69
70
71
72
73
74
75
76
77
78
# File 'lib/jekyll/geolexica/concepts_generator.rb', line 68

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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# 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: (if output_html?
                                     ConceptPage::HTML.new(site,
                                                           concept)
                                   end),
                            json: (if output_json?
                                     ConceptPage::JSON.new(site,
                                                           concept)
                                   end),
                            jsonld: (if output_jsonld?
                                       ConceptPage::JSONLD.new(site,
                                                               concept)
                                     end),
                            tbx: (if output_tbx?
                                    ConceptPage::TBX.new(site,
                                                         concept)
                                  end),
                            turtle: (if output_turtle?
                                       ConceptPage::Turtle.new(site,
                                                               concept)
                                     end),
                            yaml: (if output_yaml?
                                     ConceptPage::YAML.new(site,
                                                           concept)
                                   end),
                          })
    add_page(*concept.pages.values.compact)
  end
end

#sort_pagesObject



64
65
66
# File 'lib/jekyll/geolexica/concepts_generator.rb', line 64

def sort_pages
  generated_pages.sort_by!(&:termid)
end