jekyll-open-sdg-plugins 1.6.0.pre.beta1 → 1.7.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 +64 -61
  10. data/lib/jekyll-open-sdg-plugins/create_goals.rb +85 -85
  11. data/lib/jekyll-open-sdg-plugins/create_indicators.rb +206 -206
  12. data/lib/jekyll-open-sdg-plugins/create_pages.rb +135 -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 +1652 -1617
  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 +73 -52
  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 +3 -3
@@ -1,132 +1,132 @@
1
- # Simple collection of helper functions for use in these plugins.
2
-
3
- require "jekyll"
4
-
5
- # Takes a translation key and returns a translated string according to the
6
- # language of the current page. Or if none is found, returns the original
7
- # key.
8
- def opensdg_translate_key(key, translations, language)
9
-
10
- # Safety code - abort now if key is nil.
11
- if key.nil?
12
- return ""
13
- end
14
-
15
- # Also make sure it is a string, and other just return it.
16
- if not key.is_a? String
17
- return key
18
- end
19
-
20
- # More safety code - abort now if key is empty.
21
- if key.empty?
22
- return ""
23
- end
24
-
25
- # Keep track of the last thing we drilled to.
26
- drilled = translations[language]
27
-
28
- # Keep track of how many levels we have drilled.
29
- levels_drilled = 0
30
- levels = key.split('.')
31
-
32
- # Loop through each level.
33
- levels.each do |level|
34
-
35
- # If we have drilled down to a scalar value too soon, abort.
36
- break if drilled.class != Hash
37
-
38
- if drilled.has_key? level
39
- # If we find something, continue drilling.
40
- drilled = drilled[level]
41
- levels_drilled += 1
42
- end
43
-
44
- end
45
-
46
- # If we didn't drill the right number of levels, return the
47
- # original string.
48
- if levels.length != levels_drilled
49
- return key
50
- end
51
-
52
- # Otherwise we must have drilled all they way.
53
- return drilled
54
- end
55
-
56
- # Takes a site object and decides whether it is using translated builds.
57
- def opensdg_translated_builds(site)
58
- # Assume the site is using translated builds.
59
- translated_builds = true
60
- site.config['languages'].each do |language|
61
- # If any languages don't have a key in site.data, the site is not using
62
- # translated builds.
63
- if !site.data.has_key? language
64
- translated_builds = false
65
- end
66
- end
67
- return translated_builds
68
- end
69
-
70
- # Print a notice during compilation.
71
- def opensdg_notice(message)
72
- Jekyll.logger.warn message.yellow
73
- end
74
-
75
- # Get the public language codes for a site, keyed by the actual language codes.
76
- def opensdg_languages_public(site)
77
- languages_public = site.config['languages_public']
78
-
79
- # The current structure of the setting is an array of hashes, each containing
80
- # keys for "language" and "language_public".
81
- if languages_public.is_a?(Array)
82
- converted_languages_public = Hash.new
83
- languages_public.each do |language_public|
84
- language_code = language_public['language']
85
- language_code_public = language_public['language_public']
86
- converted_languages_public[language_code] = language_code_public
87
- end
88
- return converted_languages_public
89
- end
90
-
91
- # Fallback to exactly what was retrieved from site.confg['languages_public'],
92
- # since the deprecated structure is exactly what this function wants.
93
- return languages_public
94
- end
95
-
96
- # Print notices about a validation error.
97
- def opensdg_validation_error(error)
98
- if error['type'] == 'required'
99
- missing = []
100
- error['schema']['required'].each do |required_property|
101
- unless error['data'].has_key?(required_property)
102
- message = 'Missing configuration setting: ' + required_property
103
- if error['schema'].has_key?('title')
104
- message += ' (' + error['schema']['title'] + ')'
105
- end
106
- opensdg_notice(message)
107
- end
108
- end
109
- else
110
- message = 'Validation error of type: ' + error['type']
111
- if error['schema'] && error['schema'].has_key?('title')
112
- message += ' (' + error['schema']['title'] + ')'
113
- end
114
- opensdg_notice(message)
115
- if error['schema']
116
- opensdg_notice('Expected schema:')
117
- puts error['schema'].inspect
118
- end
119
- if error['data']
120
- opensdg_notice('Actual data:')
121
- puts error['data'].inspect
122
- end
123
- end
124
- end
125
-
126
- # Is this path a remote path?
127
- def opensdg_is_path_remote(path)
128
- if path.nil?
129
- return false
130
- end
131
- return path.start_with?('http')
132
- end
1
+ # Simple collection of helper functions for use in these plugins.
2
+
3
+ require "jekyll"
4
+
5
+ # Takes a translation key and returns a translated string according to the
6
+ # language of the current page. Or if none is found, returns the original
7
+ # key.
8
+ def opensdg_translate_key(key, translations, language)
9
+
10
+ # Safety code - abort now if key is nil.
11
+ if key.nil?
12
+ return ""
13
+ end
14
+
15
+ # Also make sure it is a string, and other just return it.
16
+ if not key.is_a? String
17
+ return key
18
+ end
19
+
20
+ # More safety code - abort now if key is empty.
21
+ if key.empty?
22
+ return ""
23
+ end
24
+
25
+ # Keep track of the last thing we drilled to.
26
+ drilled = translations[language]
27
+
28
+ # Keep track of how many levels we have drilled.
29
+ levels_drilled = 0
30
+ levels = key.split('.')
31
+
32
+ # Loop through each level.
33
+ levels.each do |level|
34
+
35
+ # If we have drilled down to a scalar value too soon, abort.
36
+ break if drilled.class != Hash
37
+
38
+ if drilled.has_key? level
39
+ # If we find something, continue drilling.
40
+ drilled = drilled[level]
41
+ levels_drilled += 1
42
+ end
43
+
44
+ end
45
+
46
+ # If we didn't drill the right number of levels, return the
47
+ # original string.
48
+ if levels.length != levels_drilled
49
+ return key
50
+ end
51
+
52
+ # Otherwise we must have drilled all they way.
53
+ return drilled
54
+ end
55
+
56
+ # Takes a site object and decides whether it is using translated builds.
57
+ def opensdg_translated_builds(site)
58
+ # Assume the site is using translated builds.
59
+ translated_builds = true
60
+ site.config['languages'].each do |language|
61
+ # If any languages don't have a key in site.data, the site is not using
62
+ # translated builds.
63
+ if !site.data.has_key? language
64
+ translated_builds = false
65
+ end
66
+ end
67
+ return translated_builds
68
+ end
69
+
70
+ # Print a notice during compilation.
71
+ def opensdg_notice(message)
72
+ Jekyll.logger.warn message.yellow
73
+ end
74
+
75
+ # Get the public language codes for a site, keyed by the actual language codes.
76
+ def opensdg_languages_public(site)
77
+ languages_public = site.config['languages_public']
78
+
79
+ # The current structure of the setting is an array of hashes, each containing
80
+ # keys for "language" and "language_public".
81
+ if languages_public.is_a?(Array)
82
+ converted_languages_public = Hash.new
83
+ languages_public.each do |language_public|
84
+ language_code = language_public['language']
85
+ language_code_public = language_public['language_public']
86
+ converted_languages_public[language_code] = language_code_public
87
+ end
88
+ return converted_languages_public
89
+ end
90
+
91
+ # Fallback to exactly what was retrieved from site.confg['languages_public'],
92
+ # since the deprecated structure is exactly what this function wants.
93
+ return languages_public
94
+ end
95
+
96
+ # Print notices about a validation error.
97
+ def opensdg_validation_error(error)
98
+ if error['type'] == 'required'
99
+ missing = []
100
+ error['schema']['required'].each do |required_property|
101
+ unless error['data'].has_key?(required_property)
102
+ message = 'Missing configuration setting: ' + required_property
103
+ if error['schema'].has_key?('title')
104
+ message += ' (' + error['schema']['title'] + ')'
105
+ end
106
+ opensdg_notice(message)
107
+ end
108
+ end
109
+ else
110
+ message = 'Validation error of type: ' + error['type']
111
+ if error['schema'] && error['schema'].has_key?('title')
112
+ message += ' (' + error['schema']['title'] + ')'
113
+ end
114
+ opensdg_notice(message)
115
+ if error['schema']
116
+ opensdg_notice('Expected schema:')
117
+ puts error['schema'].inspect
118
+ end
119
+ if error['data']
120
+ opensdg_notice('Actual data:')
121
+ puts error['data'].inspect
122
+ end
123
+ end
124
+ end
125
+
126
+ # Is this path a remote path?
127
+ def opensdg_is_path_remote(path)
128
+ if path.nil?
129
+ return false
130
+ end
131
+ return path.start_with?('http')
132
+ end
@@ -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