jekyll-dictionaries 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 36df1371462bb937a7af666ad4db6b25f286f5ade437a76f6b1ecfcabf6c5ffe
4
- data.tar.gz: 546ec1819e6f760ec135d340820f11de48bf09d1f5d70bfdf63ebe79f647bc9c
3
+ metadata.gz: 0ae6fbb1a2c9e99134e6a3c2efa23a802b6b23b9a2990f3cb24de390d86e3b2a
4
+ data.tar.gz: daec5bcd991748fbcc89e55bc74f1c86998ad3d8d68ef3a11c4de77a792dcb7f
5
5
  SHA512:
6
- metadata.gz: dc4e3620041b4f8e892ce2684f0030906cafdecac9e9e12a5ab8c0838e9749854c2e8390c1211e390650961cb21830610bb48077b99c7e2265ccfa085c6dc870
7
- data.tar.gz: 1128d9b0a9c36e1ca95943e0db3600ca76d45b05e64ac049a2b033d61108f0a2b887865ff9bd761343d80e88dee0cd51a7ca5d25edf552cd0d5e4f5ab51bbd49
6
+ metadata.gz: f7ccbf3eb1883c6286a4059eaa019cb6975480e57eaeedd351cd8e23a2d1f9505b2a8cf500e733249d31085ada93d076997d8934934fc45e7b86942f5efedbc6
7
+ data.tar.gz: b9ad86763fa24cfc53ee6abfc77f0d052a2927db263b8a4e5f99fa9034a10ce6a26b55da14c6f988887face3cab1cd9c1f9be73e1d2ac3b8204e4610e8f7b931
data/.DS_Store CHANGED
Binary file
data/.idea/workspace.xml CHANGED
@@ -5,8 +5,25 @@
5
5
  </component>
6
6
  <component name="ChangeListManager">
7
7
  <list default="true" id="a0de0db4-04ba-4a6e-9544-85d905789a03" name="Changes" comment="">
8
+ <change afterPath="$PROJECT_DIR$/lib/jekyll-dictionaries/generators/dictionaries.rb" afterDir="false" />
9
+ <change afterPath="$PROJECT_DIR$/lib/jekyll-dictionaries/generators/theme.rb" afterDir="false" />
10
+ <change afterPath="$PROJECT_DIR$/lib/jekyll-dictionaries/pages/dictionary.rb" afterDir="false" />
11
+ <change afterPath="$PROJECT_DIR$/lib/jekyll-dictionaries/pages/dictionary_api.rb" afterDir="false" />
12
+ <change afterPath="$PROJECT_DIR$/spec/fixtures/jekyll/_includes/head.html" afterDir="false" />
8
13
  <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
9
14
  <change beforePath="$PROJECT_DIR$/README.md" beforeDir="false" afterPath="$PROJECT_DIR$/README.md" afterDir="false" />
15
+ <change beforePath="$PROJECT_DIR$/jekyll-dictionaries.gemspec" beforeDir="false" afterPath="$PROJECT_DIR$/jekyll-dictionaries.gemspec" afterDir="false" />
16
+ <change beforePath="$PROJECT_DIR$/lib/jekyll-dictionaries.rb" beforeDir="false" afterPath="$PROJECT_DIR$/lib/jekyll-dictionaries.rb" afterDir="false" />
17
+ <change beforePath="$PROJECT_DIR$/lib/jekyll-dictionaries/dictionary_api_page.rb" beforeDir="false" />
18
+ <change beforePath="$PROJECT_DIR$/lib/jekyll-dictionaries/dictionary_page.rb" beforeDir="false" />
19
+ <change beforePath="$PROJECT_DIR$/lib/jekyll-dictionaries/generator.rb" beforeDir="false" afterPath="$PROJECT_DIR$/lib/jekyll-dictionaries/generator.rb" afterDir="false" />
20
+ <change beforePath="$PROJECT_DIR$/spec/fixtures/jekyll/_config.yml" beforeDir="false" afterPath="$PROJECT_DIR$/spec/fixtures/jekyll/_config.yml" afterDir="false" />
21
+ <change beforePath="$PROJECT_DIR$/spec/fixtures/jekyll/_layouts/dictionary.html" beforeDir="false" />
22
+ <change beforePath="$PROJECT_DIR$/spec/fixtures/jekyll/_layouts/dictionary_api.json" beforeDir="false" />
23
+ <change beforePath="$PROJECT_DIR$/spec/fixtures/snapshots/api/multiple.json" beforeDir="false" afterPath="$PROJECT_DIR$/spec/fixtures/snapshots/api/multiple.json" afterDir="false" />
24
+ <change beforePath="$PROJECT_DIR$/spec/fixtures/snapshots/api/single.json" beforeDir="false" afterPath="$PROJECT_DIR$/spec/fixtures/snapshots/api/single.json" afterDir="false" />
25
+ <change beforePath="$PROJECT_DIR$/spec/fixtures/snapshots/pages/multiple.html" beforeDir="false" afterPath="$PROJECT_DIR$/spec/fixtures/snapshots/pages/multiple.html" afterDir="false" />
26
+ <change beforePath="$PROJECT_DIR$/spec/fixtures/snapshots/pages/single.html" beforeDir="false" afterPath="$PROJECT_DIR$/spec/fixtures/snapshots/pages/single.html" afterDir="false" />
10
27
  </list>
11
28
  <option name="SHOW_DIALOG" value="false" />
12
29
  <option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -44,16 +61,17 @@
44
61
  <component name="RecentsManager">
45
62
  <key name="CopyFile.RECENT_KEYS">
46
63
  <recent name="$PROJECT_DIR$/spec/fixtures/snapshots/pages" />
64
+ <recent name="$PROJECT_DIR$/spec/fixtures/snapshots/api" />
47
65
  <recent name="$PROJECT_DIR$/spec/fixtures/jekyll" />
48
66
  <recent name="$PROJECT_DIR$" />
49
67
  <recent name="$PROJECT_DIR$/.idea" />
50
68
  </key>
51
69
  <key name="MoveFile.RECENT_KEYS">
70
+ <recent name="$PROJECT_DIR$/lib/jekyll-dictionaries/pages" />
71
+ <recent name="$PROJECT_DIR$/lib/jekyll-dictionaries/generators" />
72
+ <recent name="$PROJECT_DIR$/_includes/dictionary" />
52
73
  <recent name="$PROJECT_DIR$/" />
53
74
  <recent name="$PROJECT_DIR$/spec/fixtures/snapshots/pages" />
54
- <recent name="$PROJECT_DIR$/spec/fixtures/jekyll" />
55
- <recent name="$PROJECT_DIR$" />
56
- <recent name="$PROJECT_DIR$/spec/fixtures/snapshots/api" />
57
75
  </key>
58
76
  </component>
59
77
  <component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
@@ -67,7 +85,7 @@
67
85
  <updated>1696301317963</updated>
68
86
  <workItem from="1696301319406" duration="9538000" />
69
87
  <workItem from="1696310885150" duration="15107000" />
70
- <workItem from="1696338033417" duration="9652000" />
88
+ <workItem from="1696338033417" duration="29066000" />
71
89
  </task>
72
90
  <servers />
73
91
  </component>
data/README.md CHANGED
@@ -7,8 +7,8 @@ Welcome to the Jekyll Dictionaries Plugin project! This open-source project allo
7
7
 
8
8
  ## Table of Contents
9
9
 
10
+ - [Intro](#intro)
10
11
  - [Installation](#installation)
11
- - [Usage](#usage)
12
12
  - [Dictionaries Structure](#dictionaries-structure)
13
13
  - [Dictionary Types](#dictionary-types)
14
14
  - [1. Single Translation Dictionary](#1-single-translation-dictionary)
@@ -23,103 +23,46 @@ Welcome to the Jekyll Dictionaries Plugin project! This open-source project allo
23
23
  - [Push New Version Commands](#push-new-version-commands)
24
24
  - [License](#license)
25
25
 
26
+ ## Intro
27
+
28
+ The plugin will automatically generate dictionary and dictionary api pages for all dictionaries located into folder `_data/dictionaries` of jekyll project.
29
+
26
30
  ## Installation
27
31
 
28
- Add this line to your site's Gemfile:
32
+ 1. Add this line to your site's Gemfile:
29
33
 
30
34
  ```ruby
31
35
  gem 'jekyll-dictionaries'
32
36
  ```
33
37
 
34
- Generate 2 layouts for dictionary documentation and api:
38
+ 2. Include `dictionary/head.html` into default layout to add custom styles of the plugin (the plugin styles are added as inline css styles and it might be updated if it's needed):
35
39
 
36
- **_layouts/dictionary_api.json:**
37
-
38
- ```liquid
39
- ---
40
- ---
41
- {% assign content = page.content | jsonify %}{% assign docPage = page.related_page %}{% if docPage %}{"docPath":"{{ docPage.url | absolute_url }}",{{ content | remove_first: '{' }}{% else %}{{ content }}{% endif %}
40
+ ```html
41
+ <head>
42
+ ...
43
+ {% include dictionaries/head.html %}
44
+ </head>
42
45
  ```
43
46
 
44
- **_layouts/dictionary.html:**
45
-
46
- ```liquid
47
- ---
48
- layout: page
49
- ---
50
-
51
- <h1>Info</h1>
52
- <table>
53
- <tbody>
54
- <tr>
55
- <th>Name</th>
56
- <td>{{ page.content.name }}</td>
57
- </tr>
58
- <tr>
59
- <th>Version</th>
60
- <td>{{ page.content.version }}</td>
61
- </tr>
62
- <tr>
63
- <th>Learning</th>
64
- <td>{{ page.content.learning }}</td>
65
- </tr>
66
-
67
- <tr>
68
- <th>Translation Type</th>
69
- <td>{{ page.content.translationType }}</td>
70
- </tr>
71
-
72
- {% if page.content.translationType == 'multiple' %}
73
-
74
- <tr>
75
- <th>Translations</th>
76
- <td>{{ page.content.translations | join: ', ' }}</td>
77
- </tr>
78
- {% endif %}
79
-
80
- {% assign apiPage = page.related_page %}
81
-
82
- {% if apiPage %}
83
-
84
- <tr>
85
- <th> <a href="{{ apiPage.url | relative_url }}" target="_blank">API LINK</a> </th>
86
- <td>
87
- <button onclick="copyToClipboard('{{ apiPage.url | absolute_url }}')">Copy to Clipboard</button>
88
- </td>
89
- </tr>
90
- {% endif %}
91
-
92
-
93
- </tbody>
94
- </table>
95
-
96
- <script>
97
- function copyToClipboard(text) {
98
- // Copy the text inside the text field
99
- navigator.clipboard.writeText(text);
100
- }
101
- </script>
47
+ 3. Include `dictionaries/list.html` into index page to show a list of available dictionaries:
48
+
49
+ ```html
50
+ {% include dictionaries/list.html %}
102
51
  ```
103
52
 
104
- And then add this lines to your site's `_config.yml`:
53
+ 4. (OPTIONAL) Also it's possible to change layout and permalink of dictionary pages on site's `_config.yml`:
105
54
 
106
55
  ```yml
107
- plugins:
108
- - jekyll-dictionaries
109
-
110
56
  dictionaries:
111
- dictionary:
112
- layout: dictionary
113
- permalink: dictionaries/:name
114
- dictionary_api:
115
- layout: dictionary_api
116
- permalink: api/dictionaries/:name.json
57
+ pages:
58
+ dictionary:
59
+ layout: dictionary
60
+ permalink: dictionaries/:name
61
+ dictionary_api:
62
+ layout: dictionary_api
63
+ permalink: api/dictionaries/:name.json
117
64
  ```
118
65
 
119
- ## Usage
120
-
121
- The plugin will automatically generate dictionary and dictionary api pages for all dictionaries located into folder `_data/dictionaries` of jekyll project.
122
-
123
66
  ## Dictionaries Structure
124
67
 
125
68
  The dictionaries in this project have a specific structure that consists of the following components:
@@ -336,7 +279,7 @@ _data/dictionaries/single/unit1/numbers.json
336
279
  The plugin will generate JSON API **/api/dictionaries/single.json**
337
280
 
338
281
  ```json
339
- {"docPath":"http://example.org/dictionaries/single","version":"1.0.0","name":"Basic (One Language)","translationType":"single","learning":"es","data":[{"name":"Greetings","type":"collection","data":[{"learning":"¡Hola!","primary":"Hello!"}]},{"type":"folder","name":"unit1","data":[{"name":"numbers","type":"collection","data":[{"primary":"one","learning":"uno"},{"primary":"two","learning":"dos"},{"primary":"three","learning":"tres"},{"primary":"four","learning":"cuatro"},{"primary":"five","learning":"cinco"},{"primary":"six","elearnings":"seis"},{"primary":"seven","learning":"siete"},{"primary":"eight","learning":"ocho"},{"primary":"nine","learning":"nueve"},{"primary":"ten","learning":"diez"}]}]}]}
282
+ {"docUrl":"http://example.org/dictionaries/single","version":"1.0.0","name":"Basic (One Language)","translationType":"single","learning":"es","data":[{"name":"Greetings","type":"collection","data":[{"learning":"¡Hola!","primary":"Hello!"}]},{"type":"folder","name":"unit1","data":[{"name":"numbers","type":"collection","data":[{"primary":"one","learning":"uno"},{"primary":"two","learning":"dos"},{"primary":"three","learning":"tres"},{"primary":"four","learning":"cuatro"},{"primary":"five","learning":"cinco"},{"primary":"six","elearnings":"seis"},{"primary":"seven","learning":"siete"},{"primary":"eight","learning":"ocho"},{"primary":"nine","learning":"nueve"},{"primary":"ten","learning":"diez"}]}]}]}
340
283
  ```
341
284
 
342
285
  ### 2. Multiple Translations Dictionary Example
@@ -477,7 +420,7 @@ _data/dictionaries/multiple/unit1/numbers.json
477
420
  The plugin will generate JSON API **/api/dictionaries/multiple.json**
478
421
 
479
422
  ```json
480
- {"docPath":"http://example.org/dictionaries/multiple","version":"1.0.0","name":"Basic (Multiple Languages)","translationType":"multiple","learning":"es","translations":["en","ru","de","fr","pt"],"data":[{"name":"Greetings","type":"collection","data":[{"learning":"¡Hola!","en":"Hello!","ru":"Привет!","de":"Hallo!","fr":"Bonjour!","pt":"Olá!"}]},{"type":"folder","name":"Unit 1","data":[{"name":"numbers","type":"collection","data":[{"learning":"uno","en":"one","ru":"один","de":"eins","fr":"un","pt":"um"},{"learning":"dos","en":"two","ru":"два","de":"zwei","fr":"deux","pt":"dois"},{"learning":"tres","en":"three","ru":"три","de":"drei","fr":"trois","pt":"três"},{"learning":"cuatro","en":"four","ru":"четыре","de":"vier","fr":"quatre","pt":"quatro"},{"learning":"cinco","en":"five","ru":"пять","de":"fünf","fr":"cinq","pt":"cinco"},{"learning":"seis","en":"six","ru":"шесть","de":"sechs","fr":"six","pt":"seis"},{"learning":"siete","en":"seven","ru":"семь","de":"sieben","fr":"sept","pt":"sete"},{"learning":"ocho","en":"eight","ru":"восемь","de":"acht","fr":"huit","pt":"oito"},{"learning":"nueve","en":"nine","ru":"девять","de":"neun","fr":"neuf","pt":"nove"},{"learning":"diez","en":"ten","ru":"десять","de":"zehn","fr":"dix","pt":"dez"}]}]}]}
423
+ {"docUrl":"http://example.org/dictionaries/multiple","version":"1.0.0","name":"Basic (Multiple Languages)","translationType":"multiple","learning":"es","translations":["en","ru","de","fr","pt"],"data":[{"name":"Greetings","type":"collection","data":[{"learning":"¡Hola!","en":"Hello!","ru":"Привет!","de":"Hallo!","fr":"Bonjour!","pt":"Olá!"}]},{"type":"folder","name":"Unit 1","data":[{"name":"numbers","type":"collection","data":[{"learning":"uno","en":"one","ru":"один","de":"eins","fr":"un","pt":"um"},{"learning":"dos","en":"two","ru":"два","de":"zwei","fr":"deux","pt":"dois"},{"learning":"tres","en":"three","ru":"три","de":"drei","fr":"trois","pt":"três"},{"learning":"cuatro","en":"four","ru":"четыре","de":"vier","fr":"quatre","pt":"quatro"},{"learning":"cinco","en":"five","ru":"пять","de":"fünf","fr":"cinq","pt":"cinco"},{"learning":"seis","en":"six","ru":"шесть","de":"sechs","fr":"six","pt":"seis"},{"learning":"siete","en":"seven","ru":"семь","de":"sieben","fr":"sept","pt":"sete"},{"learning":"ocho","en":"eight","ru":"восемь","de":"acht","fr":"huit","pt":"oito"},{"learning":"nueve","en":"nine","ru":"девять","de":"neun","fr":"neuf","pt":"nove"},{"learning":"diez","en":"ten","ru":"десять","de":"zehn","fr":"dix","pt":"dez"}]}]}]}
481
424
  ```
482
425
 
483
426
  As you can see collection `greetings` and folder `un1` have names that are defined by property `name`.
@@ -486,11 +429,10 @@ As you can see collection `greetings` and folder `un1` have names that are defin
486
429
 
487
430
  ```bash
488
431
  gem bump
489
-
432
+ gem build jekyll-dictionaries.gemspec
433
+ gem push jekyll-dictionaries-1.0.2.gem
490
434
  ```
491
435
 
492
-
493
-
494
436
  ## License
495
437
 
496
438
  This project is licensed under the MIT License.
Binary file
@@ -0,0 +1,16 @@
1
+ <script>
2
+ var acc = document.getElementsByClassName("accordion");
3
+ var i;
4
+
5
+ for (i = 0; i < acc.length; i++) {
6
+ acc[i].addEventListener("click", function () {
7
+ this.classList.toggle("active");
8
+ var panel = this.nextElementSibling;
9
+ if (panel.style.display === "block") {
10
+ panel.style.display = "none";
11
+ } else {
12
+ panel.style.display = "block";
13
+ }
14
+ });
15
+ }
16
+ </script>
@@ -0,0 +1,4 @@
1
+ <p>{{ include.value }}</p>
2
+ {% if include.note %}
3
+ <p>({{ include.note }})</p>
4
+ {% endif %}
@@ -0,0 +1,2 @@
1
+ {% capture icon %}{% if include.item.type == 'folder' %}<i class="accordion-icon fa fa-folder" aria-hidden="true"></i>{% endif %}{% endcapture %}
2
+ <button class="accordion">{{ icon}} {{ include.item.name }}</button>
@@ -0,0 +1,37 @@
1
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css" integrity="sha512-z3gLpd7yknf1YoNbCzqRKc4qyor8gaKU1qmn+CShxbuBusANI9QpRohGBreCFkKxLhei6S9CQXFEbbKuqLg0DA==" crossorigin="anonymous" referrerpolicy="no-referrer" />
2
+
3
+ <style>
4
+ .accordion {
5
+ background-color: #eee;
6
+ color: #444;
7
+ cursor: pointer;
8
+ padding: 18px;
9
+ width: 100%;
10
+ border: none;
11
+ text-align: left;
12
+ outline: none;
13
+ font-size: 15px;
14
+ transition: 0.4s;
15
+ margin: 5px 0;
16
+ }
17
+ .accordion.active, .accordion:hover {
18
+ background-color: #ccc;
19
+ }
20
+ .accordion-panel {
21
+ padding: 5px;
22
+ padding-right: 0;
23
+ padding-left: 0;
24
+ display: none;
25
+ background-color: white;
26
+ overflow: hidden;
27
+ }
28
+ .accordion-panel.folder-container {
29
+ padding-left: 10px;
30
+ }
31
+ .accordion-icon {
32
+ margin-right: 10px;
33
+ }
34
+ .dictionary-list .list-header {
35
+ margin-bottom: 20px;
36
+ }
37
+ </style>
@@ -0,0 +1,13 @@
1
+ <div class="dictionary-list">
2
+ <h2 class="list-header">Dictionary APIs</h2>
3
+ {% assign dictPages = site.pages | where_exp: "item", "item.scope == 'dictionary'" %}
4
+ {% if dictPages.size > 0 %}
5
+ <ul>
6
+ {% for page in dictPages %}
7
+ <li>
8
+ <a href="{{ page.url | relative_url }}" target="blank">{{ page.name | escape }}</a>
9
+ </li>
10
+ {% endfor %}
11
+ </ul>
12
+ {% endif %}
13
+ </div>
@@ -0,0 +1,24 @@
1
+ <table>
2
+ <thead>
3
+ <tr>
4
+ <th>Learning</th>
5
+ {% for translation in include.translations %}
6
+ <th>{{ translation }}</th>
7
+ {% endfor %}
8
+ </tr>
9
+ </thead>
10
+ <tbody>
11
+ {% for item in include.items %}
12
+ <tr>
13
+ <td>
14
+ {% include dictionaries/collectionItem.html value=item.learning note=item.notes.learning %}
15
+ </td>
16
+ {% for translation in include.translations %}
17
+ {% assign value = item[translation] %}
18
+ {% assign note = item.notes[translation] %}
19
+ <td>{% include dictionaries/collectionItem.html value=value note=note %}</td>
20
+ {% endfor %}
21
+ </tr>
22
+ {% endfor %}
23
+ </tbody>
24
+ </table>
@@ -0,0 +1,13 @@
1
+ {% for item in include.items %}
2
+
3
+ {% include dictionaries/collectionName.html item=item %}
4
+
5
+ <div class="accordion-panel {{ item.type }}-container">
6
+ {% case item.type %}
7
+ {% when "folder" %}
8
+ {% include dictionaries/multiple/container.html items=item.data translations=include.translations %}
9
+ {% when "collection" %}
10
+ {% include dictionaries/multiple/collection.html items=item.data translations=include.translations %}
11
+ {% endcase %}
12
+ </div>
13
+ {% endfor %}
@@ -0,0 +1,20 @@
1
+ <table>
2
+ <thead>
3
+ <tr>
4
+ <th>Learning</th>
5
+ <th>Primary</th>
6
+ </tr>
7
+ </thead>
8
+ <tbody>
9
+ {% for item in include.items %}
10
+ <tr>
11
+ <td>
12
+ {% include dictionaries/collectionItem.html value=item.learning note=item.notes.learning %}
13
+ </td>
14
+ <td>
15
+ {% include dictionaries/collectionItem.html value=item.primary note=item.notes.primary %}
16
+ </td>
17
+ </tr>
18
+ {% endfor %}
19
+ </tbody>
20
+ </table>
@@ -0,0 +1,13 @@
1
+ {% for item in include.items %}
2
+
3
+ {% include dictionaries/collectionName.html item=item %}
4
+
5
+ <div class="accordion-panel {{ item.type }}-container">
6
+ {% case item.type %}
7
+ {% when "folder" %}
8
+ {% include dictionaries/single/container.html items=item.data %}
9
+ {% when "collection" %}
10
+ {% include dictionaries/single/collection.html items=item.data %}
11
+ {% endcase %}
12
+ </div>
13
+ {% endfor %}
@@ -0,0 +1,63 @@
1
+ ---
2
+ layout: page
3
+ ---
4
+
5
+ <h1>Info</h1>
6
+ <table>
7
+ <tbody>
8
+ <tr>
9
+ <th>Name</th>
10
+ <td>{{ page.content.name }}</td>
11
+ </tr>
12
+ <tr>
13
+ <th>Version</th>
14
+ <td>{{ page.content.version }}</td>
15
+ </tr>
16
+ <tr>
17
+ <th>Learning</th>
18
+ <td>{{ page.content.learning }}</td>
19
+ </tr>
20
+
21
+ <tr>
22
+ <th>Translation Type</th>
23
+ <td>{{ page.content.translationType }}</td>
24
+ </tr>
25
+
26
+ {% if page.content.translationType == 'multiple' %}
27
+
28
+ <tr>
29
+ <th>Translations</th>
30
+ <td>{{ page.content.translations | join: ', ' }}</td>
31
+ </tr>
32
+ {% endif %}
33
+
34
+ {% assign apiPage = page.related_page %}
35
+
36
+ {% if apiPage %}
37
+
38
+ <tr>
39
+ <th> <a href="{{ apiPage.url | relative_url }}" target="_blank">API LINK</a> </th>
40
+ <td>
41
+ <button onclick="copyToClipboard('{{ apiPage.url | absolute_url }}')">Copy to Clipboard</button>
42
+ </td>
43
+ </tr>
44
+ {% endif %}
45
+
46
+
47
+ </tbody>
48
+ </table>
49
+
50
+ {% if page.content.translationType == 'single' %}
51
+ {% include dictionaries/single/container.html items=page.content.data prefix='dict-level' %}
52
+ {% else %}
53
+ {% include dictionaries/multiple/container.html items=page.content.data translations=page.content.translations prefix='dict-level' %}
54
+ {% endif %}
55
+
56
+ {% include dictionaries/accordion.html %}
57
+
58
+ <script>
59
+ function copyToClipboard(text) {
60
+ // Copy the text inside the text field
61
+ navigator.clipboard.writeText(text);
62
+ }
63
+ </script>
@@ -0,0 +1,3 @@
1
+ ---
2
+ ---
3
+ {% assign content = page.content | jsonify %}{% assign docPage = page.related_page %}{% if docPage %}{"docUrl":"{{ docPage.url | absolute_url }}",{{ content | remove_first: '{' }}{% else %}{{ content }}{% endif %}
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
8
8
  spec.authors = ["hinkoulabs"]
9
9
  spec.email = ["siarhei.hinkou@hinkoulabs.com"]
10
10
 
11
- spec.summary = "A Jekyll plugin to generate JSON dictionaries for language learning applications"
11
+ spec.summary = "A Jekyll theme plugin to generate JSON dictionaries for language learning applications"
12
12
  spec.homepage = "https://github.com/hinkoulabs/jekyll-dictionaries"
13
13
  spec.license = "MIT"
14
14
  spec.required_ruby_version = ">= 2.6.0"
@@ -29,4 +29,5 @@ Gem::Specification.new do |spec|
29
29
  spec.require_paths = ["lib"]
30
30
 
31
31
  spec.add_development_dependency 'rspec'
32
+ spec.add_development_dependency 'minima', '~> 2.5'
32
33
  end
@@ -1,73 +1,53 @@
1
- require_relative './dictionary_page'
2
- require_relative './dictionary_api_page'
1
+ require_relative 'pages/dictionary'
2
+ require_relative 'pages/dictionary_api'
3
+
4
+ require_relative 'generators/dictionaries'
5
+ require_relative 'generators/theme'
3
6
 
4
7
  module JekyllDictionaries
5
8
  class Generator < Jekyll::Generator
6
- DICT_REGEX = /^_(.*)/
9
+ CONFIG = {
10
+ 'pages' => {
11
+ 'dictionary' => {
12
+ 'layout' => 'dictionary',
13
+ 'permalink' => 'dictionaries/:name'
14
+ },
15
+ 'dictionary_api' => {
16
+ 'layout' => 'dictionary_api',
17
+ 'permalink' => 'api/dictionaries/:name.json'
18
+ }
19
+ }
20
+ }
7
21
 
8
22
  safe true
9
23
 
10
24
  def generate(site)
11
25
  @site = site
12
- dicts = site.data['dictionaries'].inject([]) do |memo, (k, v)|
13
- # dictionary start with _
14
- m = k.match(DICT_REGEX)
15
- if m
16
- dict = v.merge('data' => [])
17
-
18
- name = m[1]
19
-
20
- folder = site.data['dictionaries'][name]
21
-
22
- if (folder)
23
- dict['data'] = build_collections(folder)
24
- end
25
26
 
26
- memo << OpenStruct.new(filename: name, content: dict)
27
- end
28
- memo
29
- end
30
-
31
- dicts.each do |dict|
32
- api_page = DictionaryApiPage.new(site, dict, config)
33
- doc_page = DictionaryPage.new(site, dict, config)
27
+ Generators::Theme.new(site).generate
34
28
 
35
- api_page.related_page = doc_page
36
- doc_page.related_page = api_page
29
+ dictionaries = Generators::Dictionaries.new(site).generate
37
30
 
38
- site.pages << api_page
39
- site.pages << doc_page
31
+ dictionaries.each do |dictionary|
32
+ build_dictionary_pages(dictionary)
40
33
  end
41
34
  end
42
35
 
43
36
  protected
44
37
 
45
38
  def config
46
- @config ||= @site.config["dictionaries"] || {}
39
+ @config ||= Jekyll::Utils.deep_merge_hashes(CONFIG, @site.config["dictionaries"] || {})
47
40
  end
48
41
 
49
- def build_collections(folder_content)
50
- folder_content.inject([]) do |memo, (k, v)|
51
- if v.is_a?(Hash)
52
- # collection is detected
53
- if (v['type'] == 'collection')
54
- # set k as title if title is missing
55
- memo << { 'name' => v['name'] || k }.merge(v)
56
- else
57
- metadata = v['_metadata']
58
- # folder is detected
59
- memo
60
- folder = {
61
- 'type' => 'folder',
62
- 'name' => metadata ? metadata['name'] : k,
63
- 'data' => build_collections(v.select { |kk, _| kk != '_metadata' })
64
- }
65
- memo << folder
66
- end
67
- end
42
+ def build_dictionary_pages(dictionary)
43
+ api_page = Pages::DictionaryApi.new(@site, dictionary, config['pages']['dictionary_api'])
44
+ doc_page = Pages::Dictionary.new(@site, dictionary, config['pages']['dictionary'])
68
45
 
69
- memo
70
- end
46
+ api_page.related_page = doc_page
47
+ doc_page.related_page = api_page
48
+
49
+ @site.pages << api_page
50
+ @site.pages << doc_page
71
51
  end
72
52
  end
73
53
  end
@@ -0,0 +1,62 @@
1
+ module JekyllDictionaries
2
+ module Generators
3
+ class Dictionaries
4
+ DICT_REGEX = /^_(.*)/
5
+
6
+ def initialize(site)
7
+ @site = site
8
+ end
9
+
10
+ def generate
11
+ build_dictionaries_from_data
12
+ end
13
+
14
+ protected
15
+
16
+ def build_dictionaries_from_data
17
+ @site.data['dictionaries'].inject([]) do |memo, (k, v)|
18
+ # dictionary start with _
19
+ m = k.match(DICT_REGEX)
20
+ if m
21
+ dict = v.merge('data' => [])
22
+
23
+ name = m[1]
24
+
25
+ folder = @site.data['dictionaries'][name]
26
+
27
+ if (folder)
28
+ dict['data'] = build_collections(folder)
29
+ end
30
+
31
+ memo << OpenStruct.new(filename: name, content: dict)
32
+ end
33
+ memo
34
+ end
35
+ end
36
+
37
+ def build_collections(folder_content)
38
+ folder_content.inject([]) do |memo, (k, v)|
39
+ if v.is_a?(Hash)
40
+ # collection is detected
41
+ if (v['type'] == 'collection')
42
+ # set k as title if title is missing
43
+ memo << { 'name' => v['name'] || k }.merge(v)
44
+ else
45
+ metadata = v['_metadata']
46
+ # folder is detected
47
+ memo
48
+ folder = {
49
+ 'type' => 'folder',
50
+ 'name' => metadata ? metadata['name'] : k,
51
+ 'data' => build_collections(v.select { |kk, _| kk != '_metadata' })
52
+ }
53
+ memo << folder
54
+ end
55
+ end
56
+
57
+ memo
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,61 @@
1
+ require 'delegate'
2
+
3
+ module JekyllDictionaries
4
+ module Generators
5
+ class Theme
6
+ attr_reader :site, :theme
7
+ def initialize(site)
8
+ @site = site
9
+ end
10
+
11
+ def generate
12
+ add_includes
13
+ add_layouts
14
+ end
15
+
16
+ protected
17
+
18
+ def theme
19
+ @theme ||= Jekyll::Theme.new("jekyll-dictionaries")
20
+ end
21
+
22
+ def add_includes
23
+ @site.includes_load_paths << theme.includes_path
24
+ end
25
+
26
+ def add_layouts
27
+ layouts_path = theme.layouts_path
28
+ wrap_custom_theme do
29
+ entries_in(layouts_path).each do |layout_file|
30
+ @site.layouts[theme_file_name(layout_file)] ||= Jekyll::Layout.new(@site, layouts_path, layout_file)
31
+ end
32
+ end
33
+ end
34
+
35
+ def wrap_custom_theme
36
+ site_theme = @site.theme
37
+ @site.theme = theme
38
+ yield
39
+ @site.theme = site_theme
40
+ end
41
+
42
+ def entries_in(dir)
43
+ entries = []
44
+ within(dir) do
45
+ entries = Jekyll::EntryFilter.new(@site).filter(Dir["**/*.*"])
46
+ end
47
+ entries
48
+ end
49
+
50
+ def within(directory)
51
+ return unless File.exist?(directory)
52
+
53
+ Dir.chdir(directory) { yield }
54
+ end
55
+
56
+ def theme_file_name(file)
57
+ file.split(".")[0..-2].join(".")
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,53 @@
1
+ module JekyllDictionaries
2
+ module Pages
3
+ class Dictionary < Jekyll::Page
4
+ attr_accessor :type
5
+ attr_reader :related_page
6
+
7
+ def initialize(site, dic, default_opts)
8
+ @site = site # the current site instance.
9
+ @base = site.source # path to the source directory.
10
+ @dir = dic.filename # the directory the page will reside in.
11
+
12
+ add_scope_data
13
+
14
+ # All pages have the same filename, so define attributes straight away.
15
+ @basename = dic.filename # filename without the extension.
16
+ @name = dic.content['name'] || dic.filename # basically @basename + @ext.
17
+
18
+ # Initialize data hash with a key pointing to all posts under current category.
19
+ # This allows accessing the list in a template via `page.linked_docs`.
20
+ @data = {
21
+ 'content' => dic.content,
22
+ 'scope' => @type
23
+ }
24
+
25
+ # Look up front matter defaults scoped to type `dictionary`, if given key
26
+ # doesn't exist in the `data` hash.
27
+ data.default_proc = proc do |_, key|
28
+ (default_opts || {})[key]
29
+ end
30
+ end
31
+
32
+ def related_page=(page)
33
+ @related_page = page
34
+ @data['related_page'] = @related_page
35
+ end
36
+
37
+ def add_scope_data
38
+ @type = :dictionary
39
+ @ext = '.html'
40
+ end
41
+
42
+ # Placeholders that are used in constructing page URL.
43
+ def url_placeholders
44
+ {
45
+ :path => @dir,
46
+ :name => @dir,
47
+ :basename => basename,
48
+ :output_ext => output_ext,
49
+ }
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,12 @@
1
+ require_relative 'dictionary'
2
+
3
+ module JekyllDictionaries
4
+ module Pages
5
+ class DictionaryApi < Dictionary
6
+ def add_scope_data
7
+ @type = :dictionary_api
8
+ @ext = '.json'
9
+ end
10
+ end
11
+ end
12
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JekyllDictionaries
4
- VERSION = "1.0.2"
4
+ VERSION = "1.0.3"
5
5
  end
@@ -4,9 +4,6 @@ require "jekyll"
4
4
  require "jekyll-dictionaries/generator"
5
5
 
6
6
  module JekyllDictionaries
7
- autoload :DictionaryPage, "jekyll-dictionaries/dictionary_page.rb"
8
- autoload :DictionaryApiPage, "jekyll-dictionaries/dictionary_api_page.rb"
9
-
10
7
  def self.root
11
8
  File.dirname __dir__
12
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-dictionaries
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - hinkoulabs
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-10-03 00:00:00.000000000 Z
11
+ date: 2023-10-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minima
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.5'
27
41
  description:
28
42
  email:
29
43
  - siarhei.hinkou@hinkoulabs.com
@@ -44,11 +58,25 @@ files:
44
58
  - LICENSE.txt
45
59
  - README.md
46
60
  - Rakefile
61
+ - _includes/.DS_Store
62
+ - _includes/dictionaries/accordion.html
63
+ - _includes/dictionaries/collectionItem.html
64
+ - _includes/dictionaries/collectionName.html
65
+ - _includes/dictionaries/head.html
66
+ - _includes/dictionaries/list.html
67
+ - _includes/dictionaries/multiple/collection.html
68
+ - _includes/dictionaries/multiple/container.html
69
+ - _includes/dictionaries/single/collection.html
70
+ - _includes/dictionaries/single/container.html
71
+ - _layouts/dictionary.html
72
+ - _layouts/dictionary_api.json
47
73
  - jekyll-dictionaries.gemspec
48
74
  - lib/jekyll-dictionaries.rb
49
- - lib/jekyll-dictionaries/dictionary_api_page.rb
50
- - lib/jekyll-dictionaries/dictionary_page.rb
51
75
  - lib/jekyll-dictionaries/generator.rb
76
+ - lib/jekyll-dictionaries/generators/dictionaries.rb
77
+ - lib/jekyll-dictionaries/generators/theme.rb
78
+ - lib/jekyll-dictionaries/pages/dictionary.rb
79
+ - lib/jekyll-dictionaries/pages/dictionary_api.rb
52
80
  - lib/jekyll-dictionaries/version.rb
53
81
  homepage: https://github.com/hinkoulabs/jekyll-dictionaries
54
82
  licenses:
@@ -73,5 +101,6 @@ requirements: []
73
101
  rubygems_version: 3.2.32
74
102
  signing_key:
75
103
  specification_version: 4
76
- summary: A Jekyll plugin to generate JSON dictionaries for language learning applications
104
+ summary: A Jekyll theme plugin to generate JSON dictionaries for language learning
105
+ applications
77
106
  test_files: []
@@ -1,10 +0,0 @@
1
- require_relative './dictionary_page'
2
-
3
- module JekyllDictionaries
4
- class DictionaryApiPage < DictionaryPage
5
- def add_scope_data
6
- @type = :dictionary_api
7
- @ext = '.json'
8
- end
9
- end
10
- end
@@ -1,51 +0,0 @@
1
- module JekyllDictionaries
2
- class DictionaryPage < Jekyll::Page
3
- attr_accessor :type
4
- attr_reader :related_page
5
-
6
- def initialize(site, dic, default_opts)
7
- @site = site # the current site instance.
8
- @base = site.source # path to the source directory.
9
- @dir = dic.filename # the directory the page will reside in.
10
-
11
- add_scope_data
12
-
13
- # All pages have the same filename, so define attributes straight away.
14
- @basename = dic.filename # filename without the extension.
15
- @name = dic.content['name'] || dic.filename # basically @basename + @ext.
16
-
17
- # Initialize data hash with a key pointing to all posts under current category.
18
- # This allows accessing the list in a template via `page.linked_docs`.
19
- @data = {
20
- 'content' => dic.content,
21
- 'scope' => @type
22
- }
23
-
24
- # Look up front matter defaults scoped to type `dictionary`, if given key
25
- # doesn't exist in the `data` hash.
26
- data.default_proc = proc do |_, key|
27
- (default_opts[@type.to_s] || {})[key]
28
- end
29
- end
30
-
31
- def related_page=(page)
32
- @related_page = page
33
- @data['related_page'] = @related_page
34
- end
35
-
36
- def add_scope_data
37
- @type = :dictionary
38
- @ext = '.html'
39
- end
40
-
41
- # Placeholders that are used in constructing page URL.
42
- def url_placeholders
43
- {
44
- :path => @dir,
45
- :name => @dir,
46
- :basename => basename,
47
- :output_ext => output_ext,
48
- }
49
- end
50
- end
51
- end