jekyll-open-sdg-plugins 1.0.0 → 1.2.0.pre.beta4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,66 +1,132 @@
1
- # Simple collection of helper functions for use in these plugins.
2
-
3
- # Takes a translation key and returns a translated string according to the
4
- # language of the current page. Or if none is found, returns the original
5
- # key.
6
- def opensdg_translate_key(key, translations, language)
7
-
8
- # Safety code - abort now if key is nil.
9
- if key.nil?
10
- return ""
11
- end
12
-
13
- # Also make sure it is a string, and other just return it.
14
- if not key.is_a? String
15
- return key
16
- end
17
-
18
- # More safety code - abort now if key is empty.
19
- if key.empty?
20
- return ""
21
- end
22
-
23
- # Keep track of the last thing we drilled to.
24
- drilled = translations[language]
25
-
26
- # Keep track of how many levels we have drilled.
27
- levels_drilled = 0
28
- levels = key.split('.')
29
-
30
- # Loop through each level.
31
- levels.each do |level|
32
-
33
- # If we have drilled down to a scalar value too soon, abort.
34
- break if drilled.class != Hash
35
-
36
- if drilled.has_key? level
37
- # If we find something, continue drilling.
38
- drilled = drilled[level]
39
- levels_drilled += 1
40
- end
41
-
42
- end
43
-
44
- # If we didn't drill the right number of levels, return the
45
- # original string.
46
- if levels.length != levels_drilled
47
- return key
48
- end
49
-
50
- # Otherwise we must have drilled all they way.
51
- return drilled
52
- end
53
-
54
- # Takes a site object and decides whether it is using translated builds.
55
- def opensdg_translated_builds(site)
56
- # Assume the site is using translated builds.
57
- translated_builds = true
58
- site.config['languages'].each do |language|
59
- # If any languages don't have a key in site.data, the site is not using
60
- # translated builds.
61
- if !site.data.has_key? language
62
- translated_builds = false
63
- end
64
- end
65
- return translated_builds
66
- 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
@@ -0,0 +1,513 @@
1
+ {
2
+ "type": "object",
3
+ "title": "Open SDG indicator configuration",
4
+ "description": "This form will produce an indicator's configuration for your Open SDG implementation.",
5
+ "properties": {
6
+ "computation_units": {
7
+ "type": "string",
8
+ "title": "Unit of measurement",
9
+ "description": "Unit of measurement which displays below the indicator chart.",
10
+ "links": [
11
+ {
12
+ "rel": "More information on the units of measurement setting",
13
+ "href": "https://open-sdg.readthedocs.io/en/latest/metadata-format/#recommended-special-fields"
14
+ }
15
+ ]
16
+ },
17
+ "copyright": {
18
+ "type": "string",
19
+ "title": "Copyright",
20
+ "description": "Copyright which displays below the indicator chart.",
21
+ "links": [
22
+ {
23
+ "rel": "More information on the copyright setting",
24
+ "href": "https://open-sdg.readthedocs.io/en/latest/metadata-format/#footer"
25
+ }
26
+ ]
27
+ },
28
+ "data_footnote": {
29
+ "type": "string",
30
+ "format": "markdown",
31
+ "title": "Footnote",
32
+ "description": "Footnote which displays below the indicator chart.",
33
+ "links": [
34
+ {
35
+ "rel": "More information on the footnote setting",
36
+ "href": "https://open-sdg.readthedocs.io/en/latest/metadata-format/#footer"
37
+ }
38
+ ]
39
+ },
40
+ "data_non_statistical": {
41
+ "title": "Non-statistical data",
42
+ "type": "boolean",
43
+ "description": "Whether the indicator is statistical (can be charted/graphed) or not.",
44
+ "format": "checkbox",
45
+ "links": [
46
+ {
47
+ "rel": "More information the non-statistical setting",
48
+ "href": "https://open-sdg.readthedocs.io/en/latest/metadata-format/#mandatory-fields"
49
+ }
50
+ ]
51
+ },
52
+ "data_notice_class": {
53
+ "title": "Data notice - class",
54
+ "type": "string",
55
+ "description": "A CSS class to apply to the data notice for this indicator.",
56
+ "links": [
57
+ {
58
+ "rel": "More information on the data notice setting",
59
+ "href": "https://open-sdg.readthedocs.io/en/latest/metadata-format/#data-notice"
60
+ }
61
+ ]
62
+ },
63
+ "data_notice_heading": {
64
+ "title": "Data notice - heading",
65
+ "type": "string",
66
+ "description": "A title to display above the data notice for this indicator.",
67
+ "links": [
68
+ {
69
+ "rel": "More information on the data notice heading setting",
70
+ "href": "https://open-sdg.readthedocs.io/en/latest/metadata-format/#data-notice"
71
+ }
72
+ ]
73
+ },
74
+ "data_notice_text": {
75
+ "title": "Data notice - text",
76
+ "type": "string",
77
+ "format": "markdown",
78
+ "description": "Text to display as a data notice for this indicator, intended to contain very important information which site viewers must keep in mind when using the data provided.",
79
+ "links": [
80
+ {
81
+ "rel": "More information on the data notice text setting",
82
+ "href": "https://open-sdg.readthedocs.io/en/latest/metadata-format/#data-notice"
83
+ }
84
+ ]
85
+ },
86
+ "data_show_map": {
87
+ "title": "Show map",
88
+ "type": "boolean",
89
+ "description": "Whether the indicator should display a Map tab.",
90
+ "format": "checkbox",
91
+ "links": [
92
+ {
93
+ "rel": "More information on the map setting",
94
+ "href": "https://open-sdg.readthedocs.io/en/latest/maps/#metadata-field-data_show_map"
95
+ }
96
+ ]
97
+ },
98
+ "data_start_values": {
99
+ "options": {"collapsed": true},
100
+ "format": "table",
101
+ "type": "array",
102
+ "title": "Starting values",
103
+ "description": "Disaggregation values for a an indicator to start with already selected",
104
+ "items": {
105
+ "type": "object",
106
+ "title": "Starting value",
107
+ "properties": {
108
+ "field": {
109
+ "type": "string",
110
+ "minLength": 1,
111
+ "title": "Field",
112
+ "description": "The field (column) name."
113
+ },
114
+ "value": {
115
+ "type": "string",
116
+ "minLength": 1,
117
+ "title": "Value",
118
+ "description": "The value in that field to pre-select."
119
+ }
120
+ }
121
+ },
122
+ "links": [
123
+ {
124
+ "rel": "More information on the starting values setting",
125
+ "href": "https://open-sdg.readthedocs.io/en/latest/metadata-format/#starting-values"
126
+ }
127
+ ]
128
+ },
129
+ "embedded_feature_footer": {
130
+ "type": "string",
131
+ "format": "markdown",
132
+ "title": "Embedded feature - Footer",
133
+ "description": "A footer that displays below the embedded feature. Only used with either embedded_feature_url or embedded_feature_html.",
134
+ "links": [
135
+ {
136
+ "rel": "More information on the embed footer setting",
137
+ "href": "https://open-sdg.readthedocs.io/en/latest/metadata-format/#embedded-feature-metadata"
138
+ }
139
+ ]
140
+ },
141
+ "embedded_feature_html": {
142
+ "type": "string",
143
+ "format": "textarea",
144
+ "title": "Embedded feature - HTML",
145
+ "description": "Any HTML to display in another tab, after Chart/Table/etc.",
146
+ "links": [
147
+ {
148
+ "rel": "More information on the embed HTML setting",
149
+ "href": "https://open-sdg.readthedocs.io/en/latest/metadata-format/#embedded-feature-metadata"
150
+ }
151
+ ]
152
+ },
153
+ "embedded_feature_tab_title": {
154
+ "type": "string",
155
+ "title": "Embedded feature - Tab Title",
156
+ "description": "A title for the embedded feature tab (ie, Chart/Table/[this]). Only used with either embedded_feature_url or embedded_feature_html.",
157
+ "links": [
158
+ {
159
+ "rel": "More information on the embed tab title setting",
160
+ "href": "https://open-sdg.readthedocs.io/en/latest/metadata-format/#embedded-feature-metadata"
161
+ }
162
+ ]
163
+ },
164
+ "embedded_feature_title": {
165
+ "type": "string",
166
+ "title": "Embedded feature - Title",
167
+ "description": "A title that displays above the embedded feature. Only used with either embedded_feature_url or embedded_feature_html.",
168
+ "links": [
169
+ {
170
+ "rel": "More information on the embed title setting",
171
+ "href": "https://open-sdg.readthedocs.io/en/latest/metadata-format/#embedded-feature-metadata"
172
+ }
173
+ ]
174
+ },
175
+ "embedded_feature_url": {
176
+ "type": "string",
177
+ "format": "url",
178
+ "title": "Embedded feature - URL",
179
+ "description": "Any URL to display as an iframe in another tab, after Chart/Table/etc.",
180
+ "links": [
181
+ {
182
+ "rel": "More information on the embed URL setting",
183
+ "href": "https://open-sdg.readthedocs.io/en/latest/metadata-format/#embedded-feature-metadata"
184
+ }
185
+ ]
186
+ },
187
+ "graph_annotations": {
188
+ "options": {"collapsed": true},
189
+ "type": "array",
190
+ "title": "Graph annotations",
191
+ "description": "This can be used to add line annotations to the graph, such as target lines to show the progress towards the 2030 goal for an indicator.",
192
+ "items": {
193
+ "type": "object",
194
+ "title": "Graph annotation",
195
+ "properties": {
196
+ "preset": {
197
+ "type": "string",
198
+ "title": "Preset",
199
+ "enum": ["target_line"],
200
+ "description": "A preset bundle of configurations."
201
+ },
202
+ "value": {
203
+ "type": "number",
204
+ "minimum": 0,
205
+ "title": "Value",
206
+ "description": "The value at which to draw the line. For horizontal lines, this number corresponds to your actual data. For vertical lines, this number should be between 0 (the left side of the chart) and the number of years minus 1 (the right side of the chart)."
207
+ },
208
+ "endValue": {
209
+ "type": "number",
210
+ "title": "End value",
211
+ "description": "Optionally add a different ending value for the line."
212
+ },
213
+ "description": {
214
+ "type": "string",
215
+ "title": "Description",
216
+ "description": "A description of the annotation to be read by screenreaders."
217
+ },
218
+ "unit": {
219
+ "type": "string",
220
+ "title": "Unit",
221
+ "description": "The unit of measurement the annotation displays on."
222
+ },
223
+ "series": {
224
+ "type": "string",
225
+ "title": "Series",
226
+ "description": "The series the annotation displays on."
227
+ },
228
+ "mode": {
229
+ "type": "string",
230
+ "title": "Mode",
231
+ "description": "Whether the line will be vertical or horizontal.",
232
+ "enum": ["horizontal", "vertical"]
233
+ },
234
+ "borderColor": {
235
+ "type": "string",
236
+ "format": "color",
237
+ "title": "Line color",
238
+ "description": "The color of the line.",
239
+ "links": [
240
+ {
241
+ "rel": "More information on the border color setting",
242
+ "href": "https://github.com/chartjs/chartjs-plugin-annotation/blob/master/README.md"
243
+ }
244
+ ]
245
+ },
246
+ "borderDash": {
247
+ "type": "string",
248
+ "title": "Line dash type",
249
+ "description": "The type of line dash.",
250
+ "links": [
251
+ {
252
+ "rel": "More information on the line dash setting",
253
+ "href": "https://github.com/chartjs/chartjs-plugin-annotation/blob/master/README.md"
254
+ }
255
+ ]
256
+ },
257
+ "label": {
258
+ "type": "object",
259
+ "title": "Label",
260
+ "description": "A text label for the annotation.",
261
+ "properties": {
262
+ "position": {
263
+ "type": "string",
264
+ "title": "Position",
265
+ "description": "Placement of the label along the line.",
266
+ "enum": [
267
+ "top",
268
+ "bottom",
269
+ "left",
270
+ "right",
271
+ "center"
272
+ ]
273
+ },
274
+ "content": {
275
+ "type": "string",
276
+ "minLength": 1,
277
+ "title": "Content",
278
+ "description": "Text of the line label."
279
+ },
280
+ "fontColor": {
281
+ "type": "string",
282
+ "format": "color",
283
+ "title": "Label color",
284
+ "description": "Color for the label text."
285
+ },
286
+ "backgroundColor": {
287
+ "type": "string",
288
+ "format": "color",
289
+ "default": "#FFFFFFF",
290
+ "title": "Background color",
291
+ "description": "Background color for the label text."
292
+ }
293
+ }
294
+ },
295
+ "highContrast": {
296
+ "type": "object",
297
+ "title": "High contrast options",
298
+ "description": "High-contrast overrides of certain color.",
299
+ "properties": {
300
+ "borderColor": {
301
+ "type": "string",
302
+ "format": "color",
303
+ "default": "#FFFFFF",
304
+ "title": "High-contrast line color",
305
+ "description": "The color of the line in high-contrast mode."
306
+ },
307
+ "label": {
308
+ "type": "object",
309
+ "title": "High contrast label",
310
+ "description": "High-contrast version of the label.",
311
+ "properties": {
312
+ "fontColor": {
313
+ "type": "string",
314
+ "format": "color",
315
+ "default": "#FFFFFF",
316
+ "title": "High-contrast label color",
317
+ "description": "Color for the label text in high-contrast mode."
318
+ },
319
+ "backgroundColor": {
320
+ "type": "string",
321
+ "format": "color",
322
+ "default": "#000000",
323
+ "title": "High-contrast background color",
324
+ "description": "Background color for the label text in high-contrast mode."
325
+ }
326
+ }
327
+ }
328
+ }
329
+ }
330
+ }
331
+ },
332
+ "links": [
333
+ {
334
+ "rel": "More information on the graph annotations setting",
335
+ "href": "https://open-sdg.readthedocs.io/en/latest/metadata-format/#graph-metadata"
336
+ }
337
+ ]
338
+ },
339
+ "graph_limits": {
340
+ "options": {"collapsed": true},
341
+ "format": "table",
342
+ "type": "array",
343
+ "title": "Graph limits",
344
+ "description": "A list of min/max limits controlling the lowest/highest values to be shown on the y-axis.",
345
+ "items": {
346
+ "type": "object",
347
+ "title": "Graph limit",
348
+ "properties": {
349
+ "minimum": {
350
+ "type": "number",
351
+ "minimum": 0,
352
+ "title": "Minimum",
353
+ "description": "Minimum value for the y axis."
354
+ },
355
+ "maximum": {
356
+ "type": "number",
357
+ "minimum": 0,
358
+ "title": "Maximum",
359
+ "description": "Maximum value for the y axis."
360
+ },
361
+ "unit": {
362
+ "type": "string",
363
+ "title": "Unit",
364
+ "description": "The unit of measurement the limits apply to."
365
+ },
366
+ "series": {
367
+ "type": "string",
368
+ "title": "Series",
369
+ "description": "The series the limits apply to."
370
+ }
371
+ }
372
+ },
373
+ "links": [
374
+ {
375
+ "rel": "More information on the graph limits setting",
376
+ "href": "https://open-sdg.readthedocs.io/en/latest/metadata-format/#graph-metadata"
377
+ }
378
+ ]
379
+ },
380
+ "graph_stacked_disaggregation": {
381
+ "type": "string",
382
+ "title": "Stacked disaggregation",
383
+ "description": "This can be used with the bar graph type to place a certain disaggregation into the same stacked bars.",
384
+ "links": [
385
+ {
386
+ "rel": "More information on the stacked disaggregation setting",
387
+ "href": "https://open-sdg.readthedocs.io/en/latest/metadata-format/#recommended-special-fields"
388
+ }
389
+ ]
390
+ },
391
+ "graph_title": {
392
+ "type": "string",
393
+ "title": "Graph title",
394
+ "description": "The title that displays above the graph/chart.",
395
+ "links": [
396
+ {
397
+ "rel": "More information on the graph title setting",
398
+ "href": "https://open-sdg.readthedocs.io/en/latest/metadata-format/#mandatory-for-statistical-indicators"
399
+ }
400
+ ]
401
+ },
402
+ "graph_titles": {
403
+ "options": {"collapsed": true},
404
+ "format": "table",
405
+ "type": "array",
406
+ "title": "Graph titles",
407
+ "description": "As an alternative to `graph_title`, this can be used to set specific titles for particular units and/or series.",
408
+ "items": {
409
+ "type": "object",
410
+ "title": "Graph title",
411
+ "properties": {
412
+ "title": {
413
+ "type": "string",
414
+ "minLength": 1,
415
+ "title": "Title",
416
+ "description": "The graph title."
417
+ },
418
+ "unit": {
419
+ "type": "string",
420
+ "title": "Unit",
421
+ "description": "The unit of measurement the title applies to."
422
+ },
423
+ "series": {
424
+ "type": "string",
425
+ "title": "Series",
426
+ "description": "The series the title applies to."
427
+ }
428
+ }
429
+ }
430
+ },
431
+ "graph_type": {
432
+ "type": "string",
433
+ "title": "Graph type",
434
+ "description": "What type of graph to use for the indicator.",
435
+ "enum": ["line", "bar", "binary"],
436
+ "links": [
437
+ {
438
+ "rel": "More information on the graph titles setting",
439
+ "href": "https://open-sdg.readthedocs.io/en/latest/metadata-format/#mandatory-for-statistical-indicators"
440
+ }
441
+ ]
442
+ },
443
+ "indicator_name": {
444
+ "type": "string",
445
+ "title": "Indicator name",
446
+ "description": "The name for the indicator, which displays at the top of the indicator page.",
447
+ "links": [
448
+ {
449
+ "rel": "More information on the indicator name setting",
450
+ "href": "https://open-sdg.readthedocs.io/en/latest/metadata-format/#mandatory-fields"
451
+ }
452
+ ]
453
+ },
454
+ "indicator_number": {
455
+ "type": "string",
456
+ "title": "Indicator number",
457
+ "description": "The number (or 'id') for the indicator.",
458
+ "links": [
459
+ {
460
+ "rel": "More information on the indicator number setting",
461
+ "href": "https://open-sdg.readthedocs.io/en/latest/metadata-format/#mandatory-fields"
462
+ }
463
+ ]
464
+ },
465
+ "national_geographical_coverage": {
466
+ "type": "string",
467
+ "title": "National geographical coverage",
468
+ "description": "A label used in the absence of any disaggregation.",
469
+ "links": [
470
+ {
471
+ "rel": "More information on the geographical coverage setting",
472
+ "href": "https://open-sdg.readthedocs.io/en/latest/metadata-format/#mandatory-for-statistical-indicators"
473
+ }
474
+ ]
475
+ },
476
+ "page_content": {
477
+ "type": "string",
478
+ "format": "markdown",
479
+ "title": "Page content",
480
+ "description": "Content which displays in the main content area of the indicator page."
481
+ },
482
+ "reporting_status": {
483
+ "type": "string",
484
+ "title": "Reporting status",
485
+ "enum": ["complete", "inprogress", "notstarted", "notapplicable"],
486
+ "description": "The status of the indicator.",
487
+ "links": [
488
+ {
489
+ "rel": "More information on the reporting status setting",
490
+ "href": "https://open-sdg.readthedocs.io/en/latest/metadata-format/#mandatory-fields"
491
+ }
492
+ ]
493
+ },
494
+ "tags": {
495
+ "options": {"collapsed": true},
496
+ "format": "table",
497
+ "type": "array",
498
+ "title": "Tags",
499
+ "description": "An optional list of 'tags' to display under an indicator when it is listed on its goal page.",
500
+ "items": {
501
+ "type": "string",
502
+ "title": "Tag"
503
+ },
504
+ "links": [
505
+ {
506
+ "rel": "More information on the tags setting",
507
+ "href": "https://open-sdg.readthedocs.io/en/latest/metadata-format/#recommended-special-fields"
508
+ }
509
+ ]
510
+ }
511
+ },
512
+ "additionalProperties": true
513
+ }