jekyll-geolexica 1.6.0 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fa082f698405c5747b8479196495e0f13c46d8abab8e805225436f51a4583bf7
4
- data.tar.gz: c2281b410069a7eacb57eee814b0f2ba02a0f523ab6ae27ccc76216265a81d41
3
+ metadata.gz: fa802c4886074ed1d31877ba7f6f0b7c6dce2348d7a87ca403479b3ce761c5d2
4
+ data.tar.gz: 736a47a0e7f68a190e93103f6a1f75202b3280e6441c88401f3fd0a9476aa937
5
5
  SHA512:
6
- metadata.gz: 82b6e04b1eaf33573a03878d63743581c57a274ae64ec49434395b4b0cbb39de3112d97e4bd54f48bb2dc4f137ca3f0d50bed277e91a13727e998c83c71a7cd9
7
- data.tar.gz: 13bfc507093d9beef13813c160c4d3974f5533813bf7306688606fa16d8289eb575e978f5cb9adae1daae0170605678092e747fdaa82860be0e1e8c26303b444
6
+ metadata.gz: 7944380bdcac0b8e92d25b15b95be5cd0290651d151fb8999089d6048e9ddfa9250b54c1d63de252171dde384245e51cfc98e22ada0421fdb09ffa19357429a5
7
+ data.tar.gz: ce110a70c7d5e9d411f70bcf0a60eb55871a3b697cb5aa66347bf713d544cd6b2b91841be2e8910062d7379abe31b7bafce3637ce0d6ac547aff6e1298795a67
@@ -0,0 +1,37 @@
1
+ ---
2
+ permalink: "/api/concept-search-index.json"
3
+ ---
4
+ {% jbuilder %}
5
+
6
+ # } # (fixes syntax highlight in Sublime)
7
+
8
+ json.array! site["concepts"].each_with_index.to_a do |(concept, idx)|
9
+ json.termid concept.termid
10
+ json.term concept.data.dig("eng", "terms", 0, "designation")
11
+ json.term_url concept.url
12
+
13
+ json.sort_order do
14
+ json.natural idx + 1 # loop index, indexing from 1
15
+ end
16
+
17
+ for lang in site["geolexica"]["term_languages"]
18
+ json.set! lang do
19
+ english = concept.data["eng"] || {}
20
+ localized = concept.data[lang]
21
+
22
+ unless localized
23
+ json.merge! Hash.new # A trick to force an empty object
24
+ next
25
+ end
26
+
27
+ json.term localized.dig("terms", 0, "designation")
28
+ json.id localized["id"]
29
+ json.term_url "#{concept.url}#entry-lang-#{lang}"
30
+ json.entry_status english["entry_status"]
31
+ json.language_code localized["language_code"]
32
+ json.review_decision english["review_decision"]
33
+ end
34
+ end
35
+ end
36
+
37
+ {% endjbuilder %}
@@ -0,0 +1,20 @@
1
+ ---
2
+ permalink: "/api/concepts.json"
3
+ ---
4
+ {% jbuilder %}
5
+
6
+ # } # (fixes syntax highlight in Sublime)
7
+
8
+ for concept_page in site["concepts"]
9
+ concept_json_page = concept_page.concept.pages[:json]
10
+
11
+ # JSON keys must be strings
12
+ json.set! concept_page.termid.to_s do
13
+ json.term concept_page.data["term"]
14
+ json.termid concept_page.termid
15
+ json.set! "uri-html", concept_page.url
16
+ json.set! "uri-json", concept_json_page&.url
17
+ end
18
+ end
19
+
20
+ {% endjbuilder %}
@@ -0,0 +1,11 @@
1
+ ---
2
+ permalink: "/api/stats.json"
3
+ layout: null
4
+ ---
5
+ {% jbuilder %}
6
+
7
+ # } # (fixes syntax highlight in Sublime)
8
+
9
+ json.merge! context["glossary"]["language_statistics"]
10
+
11
+ {% endjbuilder %}
@@ -40,6 +40,7 @@ Gem::Specification.new do |spec|
40
40
  # either.
41
41
  # See: https://jekyllrb.com/news/2020/06/24/jekyll-4-1-1-released/
42
42
  spec.add_runtime_dependency "jekyll", ">= 3.8.5", "< 4.3", "!= 4.1.0"
43
+ spec.add_runtime_dependency "jbuilder"
43
44
 
44
45
  spec.add_runtime_dependency "jekyll-asciidoc"
45
46
 
@@ -0,0 +1,120 @@
1
+ # (c) Copyright 2021 Ribose Inc.
2
+ #
3
+
4
+ # TODO Extract that to a separate gem.
5
+
6
+ require "jbuilder"
7
+
8
+ module Jekyll
9
+ module Geolexica
10
+ class JbuilderTag < Liquid::Block
11
+ def render(context)
12
+ source = super
13
+ wrapper = JbuilderWrapper.new(context)
14
+ wrapper.eval_source(source)
15
+ wrapper.target!
16
+ rescue
17
+ Jekyll.logger.error $!.detailed_message
18
+ raise
19
+ end
20
+
21
+ # Instance of this class becomes +self+ in Jbuilder templates.
22
+ # It provides access to Jbuilder instance and current Jekyll context
23
+ # via +json+ and +context+ accessors, respectively.
24
+ # There are convenient accessors to +site+ and +page+ Jekyll context
25
+ # variables, too.
26
+ #
27
+ # @example
28
+ # # Should render {"time": "<time when site was generated>"}
29
+ # json.now context["site"]["time"]
30
+ # # Alternatively
31
+ # json.now site["time"]
32
+ class JbuilderWrapper
33
+ def initialize(context)
34
+ @builder = Jbuilder.new
35
+ @context = context
36
+ end
37
+
38
+ def json
39
+ @builder
40
+ end
41
+
42
+ def context
43
+ @context
44
+ end
45
+
46
+ def page
47
+ @context["page"]
48
+ end
49
+
50
+ def site
51
+ @context["site"]
52
+ end
53
+
54
+ def eval_source(source)
55
+ instance_eval(source)
56
+ rescue
57
+ raise Error.new(source)
58
+ end
59
+
60
+ # This generates pretty output contrary to Jbuilder#target!.
61
+ def target!
62
+ JSON.pretty_generate(@builder.attributes!)
63
+ end
64
+ end
65
+
66
+ class Error < StandardError
67
+ attr_reader :template_body
68
+
69
+ def initialize(template_body)
70
+ @template_body = template_body.dup
71
+ end
72
+
73
+ def template_backtrace_location
74
+ @template_backtrace_location ||=
75
+ cause.backtrace_locations.detect { |bl| bl.path == "(eval)" }
76
+ end
77
+
78
+ # This is tricky! The line number relates to the tag content,
79
+ # not to the Liquid template.
80
+ def template_lineno
81
+ template_backtrace_location.lineno
82
+ end
83
+
84
+ def message
85
+ "Error when processing Jbuilder template"
86
+ end
87
+
88
+ # Works only if error has been raised already (requires +#cause+
89
+ # to be set).
90
+ def detailed_message
91
+ <<~MSG
92
+ #{message}:
93
+
94
+ #{location_surroundings}
95
+
96
+ Caused by:
97
+ #{cause.message}
98
+ MSG
99
+ end
100
+
101
+ # Displays line that the error has occurred at.
102
+ def location_surroundings(before: 2, after: 2)
103
+ line_idx = template_lineno - 1 # template_lineno is indexed from 1
104
+
105
+ before_lines = template_body.lines[line_idx - before, before]
106
+ after_lines = template_body.lines[line_idx + 1, after]
107
+ that_line = template_body.lines[line_idx]
108
+
109
+ before_lines.each { |l| l.prepend("\s" * 4) }
110
+ after_lines.each { |l| l.prepend("\s" * 4) }
111
+ that_line.prepend("==> ")
112
+
113
+ [*before_lines, that_line, *after_lines].join("")
114
+ end
115
+ end
116
+ end
117
+ end
118
+ end
119
+
120
+ Liquid::Template.register_tag("jbuilder", Jekyll::Geolexica::JbuilderTag)
@@ -3,6 +3,6 @@
3
3
 
4
4
  module Jekyll
5
5
  module Geolexica
6
- VERSION = "1.6.0".freeze
6
+ VERSION = "1.7.0".freeze
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-geolexica
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-01-22 00:00:00.000000000 Z
11
+ date: 2021-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -36,6 +36,20 @@ dependencies:
36
36
  - - "!="
37
37
  - !ruby/object:Gem::Version
38
38
  version: 4.1.0
39
+ - !ruby/object:Gem::Dependency
40
+ name: jbuilder
41
+ requirement: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ type: :runtime
47
+ prerelease: false
48
+ version_requirements: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
39
53
  - !ruby/object:Gem::Dependency
40
54
  name: jekyll-asciidoc
41
55
  requirement: !ruby/object:Gem::Requirement
@@ -163,14 +177,14 @@ files:
163
177
  - _layouts/resource-page.html
164
178
  - _pages/404.adoc
165
179
  - _pages/api/rdf-profile.ttl
166
- - _pages/concept-search-index.json
167
- - _pages/concepts-index.json
180
+ - _pages/concept-search-index.jbuilder
181
+ - _pages/concepts-index.jbuilder
168
182
  - _pages/concepts.adoc
169
183
  - _pages/index.adoc
170
184
  - _pages/posts.adoc
171
185
  - _pages/robots.txt
172
186
  - _pages/stats.adoc
173
- - _pages/stats.json
187
+ - _pages/stats.jbuilder
174
188
  - _sass/adoc-markup.scss
175
189
  - _sass/concept.scss
176
190
  - _sass/concepts.scss
@@ -207,6 +221,7 @@ files:
207
221
  - lib/jekyll/geolexica/filters.rb
208
222
  - lib/jekyll/geolexica/glossary.rb
209
223
  - lib/jekyll/geolexica/hooks.rb
224
+ - lib/jekyll/geolexica/jbuilder_tag.rb
210
225
  - lib/jekyll/geolexica/meta_pages_generator.rb
211
226
  - lib/jekyll/geolexica/version.rb
212
227
  - lib/tasks/deploy.rake
@@ -1,29 +0,0 @@
1
- ---
2
- permalink: "/api/concept-search-index.json"
3
- ---
4
- [
5
- {% for concept in site.concepts %}
6
- {
7
- "termid": {{ concept.termid | jsonify }},
8
- "term": {{ concept.eng.terms.first.designation | jsonify }},
9
- "term_url": {{ concept.url | jsonify }},
10
- "sort_order": {
11
- "natural": {{ forloop.index }}
12
- },
13
-
14
- {% assign english_concept = concept["eng"] %}
15
- {% for lang in site.geolexica.term_languages %}
16
-
17
- "{{ lang }}": {% if concept[lang] %}{
18
- "term": {{ concept[lang].terms.first.designation | jsonify }},
19
- "id": {{ concept[lang].id | jsonify }},
20
- "term_url": {{ concept.url | append: "#entry-lang-" | append: lang | jsonify }},
21
- "entry_status": {{ english_concept.entry_status | jsonify }},
22
- "language_code": {{ concept[lang].language_code | jsonify }},
23
- "review_decision": {{ english_concept.review_decision | jsonify }}
24
- }{% else %}{}{% endif %}{% unless forloop.last %},{% endunless %}
25
-
26
- {% endfor %}
27
- }{% unless forloop.last %},{% endunless %}
28
- {% endfor %}
29
- ]
@@ -1,15 +0,0 @@
1
- ---
2
- permalink: "/api/concepts.json"
3
- ---
4
- {
5
- {% for concept in site.concepts %}
6
- {% assign json_concept = concept.representations.json %}
7
- {% comment %}"append" below ensures conversion to string{% endcomment -%}
8
- {{ concept.termid | append: '' | jsonify }}: {
9
- "term": {{ concept.term | jsonify }},
10
- "termid": {{ concept.termid | jsonify }},
11
- "uri-html": {{ concept.url | jsonify }},
12
- "uri-json": {{ json_concept.url | jsonify }}
13
- }{% unless forloop.last %},{% endunless %}
14
- {% endfor %}
15
- }
data/_pages/stats.json DELETED
@@ -1,5 +0,0 @@
1
- ---
2
- permalink: "/api/stats.json"
3
- layout: null
4
- ---
5
- {{ glossary.language_statistics | jsonify }}