jekyll-open-sdg-plugins 1.6.1 → 1.8.0.pre.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. checksums.yaml +4 -4
  2. data/.editorconfig +16 -16
  3. data/.github/workflows/test-pull-requests.yml +17 -17
  4. data/.gitignore +6 -6
  5. data/LICENSE +21 -21
  6. data/Makefile +33 -33
  7. data/README.md +7 -7
  8. data/jekyll-open-sdg-plugins.gemspec +18 -18
  9. data/lib/jekyll-open-sdg-plugins/backwards_compatibility.rb +97 -64
  10. data/lib/jekyll-open-sdg-plugins/create_goals.rb +88 -85
  11. data/lib/jekyll-open-sdg-plugins/create_indicators.rb +209 -206
  12. data/lib/jekyll-open-sdg-plugins/create_pages.rb +150 -135
  13. data/lib/jekyll-open-sdg-plugins/fetch_remote_data.rb +188 -188
  14. data/lib/jekyll-open-sdg-plugins/helpers.rb +132 -132
  15. data/lib/jekyll-open-sdg-plugins/metadata_schema_to_config.rb +72 -72
  16. data/lib/jekyll-open-sdg-plugins/schema-indicator-config.json +787 -709
  17. data/lib/jekyll-open-sdg-plugins/schema-site-config.json +1712 -1607
  18. data/lib/jekyll-open-sdg-plugins/sdg_variables.rb +614 -549
  19. data/lib/jekyll-open-sdg-plugins/search_index.rb +102 -102
  20. data/lib/jekyll-open-sdg-plugins/site_configuration.rb +87 -73
  21. data/lib/jekyll-open-sdg-plugins/translate_date.rb +122 -122
  22. data/lib/jekyll-open-sdg-plugins/translate_key.rb +20 -20
  23. data/lib/jekyll-open-sdg-plugins/translate_metadata_field.rb +111 -111
  24. data/lib/jekyll-open-sdg-plugins/validate_indicator_config.rb +52 -52
  25. data/lib/jekyll-open-sdg-plugins/validate_site_config.rb +34 -34
  26. data/lib/jekyll-open-sdg-plugins/version.rb +3 -3
  27. data/lib/jekyll-open-sdg-plugins.rb +18 -18
  28. data/tests/Gemfile +7 -7
  29. data/tests/_config.yml +168 -168
  30. metadata +5 -5
@@ -1,72 +1,72 @@
1
- require "jekyll"
2
- require_relative "helpers"
3
-
4
- module JekyllOpenSdgPlugins
5
- class MetadataSchemaToConfig < Jekyll::Generator
6
- safe true
7
- priority :lowest
8
-
9
- def generate(site)
10
-
11
- # Convert the metadata schema from the internal format into JSONSchema so
12
- # it can be used to create config forms.
13
-
14
- language_config = site.config['languages']
15
- form_settings = site.config['indicator_metadata_form']
16
- t = site.data['translations']
17
- lang = language_config[0]
18
-
19
- if form_settings && form_settings['enabled']
20
- scopes = ['national', 'global']
21
- if form_settings && form_settings.has_key?('scopes')
22
- if form_settings['scopes'].kind_of?(Array) && form_settings['scopes'].length() > 0
23
- scopes = form_settings['scopes']
24
- end
25
- end
26
- exclude_fields = []
27
- if form_settings && form_settings.has_key?('exclude_fields')
28
- if form_settings['exclude_fields'].kind_of?(Array) && form_settings['exclude_fields'].length() > 0
29
- exclude_fields = form_settings['exclude_fields']
30
- end
31
- end
32
- if form_settings && form_settings.has_key?('language') && form_settings['language'] != ''
33
- lang = form_settings['language']
34
- end
35
-
36
- schema = {
37
- "type" => "object",
38
- "title" => opensdg_translate_key('indicator.edit_metadata', t, lang),
39
- "properties" => {},
40
- }
41
-
42
- site.data['schema'].each do |field|
43
- field_name = field['name']
44
- field_scope = field['field']['scope']
45
- next unless scopes.include?(field_scope)
46
- next if exclude_fields.include?(field_name)
47
-
48
- to_translate = field_name
49
- if field['field'].has_key?('translation_key')
50
- to_translate = field['field']['translation_key']
51
- elsif t[lang].has_key?('metadata_fields') && t[lang]['metadata_fields'].has_key?(field_name)
52
- to_translate = 'metadata_fields.' + field_name
53
- elsif field['field'].has_key?('label')
54
- to_translate = field['field']['label']
55
- end
56
- field_label = opensdg_translate_key(to_translate, t, lang)
57
-
58
- schema['properties'][field_name] = {
59
- "type" => "string",
60
- "format" => "markdown",
61
- "title" => field_label,
62
- "description" => 'Scope: ' + field_scope + ', Field: ' + field_name,
63
- }
64
- schema['additionalProperties'] = true
65
- end
66
-
67
- # Regardless place the schema in site data so it can be used in Jekyll templates.
68
- site.data['schema-indicator-metadata'] = schema
69
- end
70
- end
71
- end
72
- end
1
+ require "jekyll"
2
+ require_relative "helpers"
3
+
4
+ module JekyllOpenSdgPlugins
5
+ class MetadataSchemaToConfig < Jekyll::Generator
6
+ safe true
7
+ priority :lowest
8
+
9
+ def generate(site)
10
+
11
+ # Convert the metadata schema from the internal format into JSONSchema so
12
+ # it can be used to create config forms.
13
+
14
+ language_config = site.config['languages']
15
+ form_settings = site.config['indicator_metadata_form']
16
+ t = site.data['translations']
17
+ lang = language_config[0]
18
+
19
+ if form_settings && form_settings['enabled']
20
+ scopes = ['national', 'global']
21
+ if form_settings && form_settings.has_key?('scopes')
22
+ if form_settings['scopes'].kind_of?(Array) && form_settings['scopes'].length() > 0
23
+ scopes = form_settings['scopes']
24
+ end
25
+ end
26
+ exclude_fields = []
27
+ if form_settings && form_settings.has_key?('exclude_fields')
28
+ if form_settings['exclude_fields'].kind_of?(Array) && form_settings['exclude_fields'].length() > 0
29
+ exclude_fields = form_settings['exclude_fields']
30
+ end
31
+ end
32
+ if form_settings && form_settings.has_key?('language') && form_settings['language'] != ''
33
+ lang = form_settings['language']
34
+ end
35
+
36
+ schema = {
37
+ "type" => "object",
38
+ "title" => opensdg_translate_key('indicator.edit_metadata', t, lang),
39
+ "properties" => {},
40
+ }
41
+
42
+ site.data['schema'].each do |field|
43
+ field_name = field['name']
44
+ field_scope = field['field']['scope']
45
+ next unless scopes.include?(field_scope)
46
+ next if exclude_fields.include?(field_name)
47
+
48
+ to_translate = field_name
49
+ if field['field'].has_key?('translation_key')
50
+ to_translate = field['field']['translation_key']
51
+ elsif t[lang].has_key?('metadata_fields') && t[lang]['metadata_fields'].has_key?(field_name)
52
+ to_translate = 'metadata_fields.' + field_name
53
+ elsif field['field'].has_key?('label')
54
+ to_translate = field['field']['label']
55
+ end
56
+ field_label = opensdg_translate_key(to_translate, t, lang)
57
+
58
+ schema['properties'][field_name] = {
59
+ "type" => "string",
60
+ "format" => "markdown",
61
+ "title" => field_label,
62
+ "description" => 'Scope: ' + field_scope + ', Field: ' + field_name,
63
+ }
64
+ schema['additionalProperties'] = true
65
+ end
66
+
67
+ # Regardless place the schema in site data so it can be used in Jekyll templates.
68
+ site.data['schema-indicator-metadata'] = schema
69
+ end
70
+ end
71
+ end
72
+ end