jekyll-open-sdg-plugins 1.0.0.rc21 → 1.2.0.pre.beta1

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,516 @@
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",
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",
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",
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",
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",
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",
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",
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",
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",
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",
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",
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",
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",
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",
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
+ "format": "choices",
199
+ "title": "Preset",
200
+ "enum": ["target_line"],
201
+ "description": "A preset bundle of configurations."
202
+ },
203
+ "value": {
204
+ "type": "number",
205
+ "minimum": 0,
206
+ "title": "Value",
207
+ "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)."
208
+ },
209
+ "endValue": {
210
+ "type": "number",
211
+ "title": "End value",
212
+ "description": "Optionally add a different ending value for the line."
213
+ },
214
+ "description": {
215
+ "type": "string",
216
+ "title": "Description",
217
+ "description": "A description of the annotation to be read by screenreaders."
218
+ },
219
+ "unit": {
220
+ "type": "string",
221
+ "title": "Unit",
222
+ "description": "The unit of measurement the annotation displays on."
223
+ },
224
+ "series": {
225
+ "type": "string",
226
+ "title": "Series",
227
+ "description": "The series the annotation displays on."
228
+ },
229
+ "mode": {
230
+ "type": "string",
231
+ "title": "Mode",
232
+ "description": "Whether the line will be vertical or horizontal.",
233
+ "enum": ["horizontal", "vertical"]
234
+ },
235
+ "borderColor": {
236
+ "type": "string",
237
+ "format": "color",
238
+ "title": "Line color",
239
+ "description": "The color of the line.",
240
+ "links": [
241
+ {
242
+ "rel": "More information",
243
+ "href": "https://github.com/chartjs/chartjs-plugin-annotation/blob/master/README.md"
244
+ }
245
+ ]
246
+ },
247
+ "borderDash": {
248
+ "type": "string",
249
+ "title": "Line dash type",
250
+ "description": "The type of line dash.",
251
+ "links": [
252
+ {
253
+ "rel": "More information",
254
+ "href": "https://github.com/chartjs/chartjs-plugin-annotation/blob/master/README.md"
255
+ }
256
+ ]
257
+ },
258
+ "label": {
259
+ "type": "object",
260
+ "title": "Label",
261
+ "description": "A text label for the annotation.",
262
+ "properties": {
263
+ "position": {
264
+ "type": "string",
265
+ "title": "Position",
266
+ "description": "Placement of the label along the line.",
267
+ "enum": [
268
+ "top",
269
+ "bottom",
270
+ "left",
271
+ "right",
272
+ "center"
273
+ ]
274
+ },
275
+ "content": {
276
+ "type": "string",
277
+ "minLength": 1,
278
+ "title": "Content",
279
+ "description": "Text of the line label."
280
+ },
281
+ "fontColor": {
282
+ "type": "string",
283
+ "format": "color",
284
+ "title": "Label color",
285
+ "description": "Color for the label text."
286
+ },
287
+ "backgroundColor": {
288
+ "type": "string",
289
+ "format": "color",
290
+ "default": "#FFFFFFF",
291
+ "title": "Background color",
292
+ "description": "Background color for the label text."
293
+ }
294
+ }
295
+ },
296
+ "highContrast": {
297
+ "type": "object",
298
+ "title": "High contrast options",
299
+ "description": "High-contrast overrides of certain color.",
300
+ "properties": {
301
+ "borderColor": {
302
+ "type": "string",
303
+ "format": "color",
304
+ "default": "#FFFFFF",
305
+ "title": "High-contrast line color",
306
+ "description": "The color of the line in high-contrast mode."
307
+ },
308
+ "label": {
309
+ "type": "object",
310
+ "title": "High contrast label",
311
+ "description": "High-contrast version of the label.",
312
+ "properties": {
313
+ "fontColor": {
314
+ "type": "string",
315
+ "format": "color",
316
+ "default": "#FFFFFF",
317
+ "title": "High-contrast label color",
318
+ "description": "Color for the label text in high-contrast mode."
319
+ },
320
+ "backgroundColor": {
321
+ "type": "string",
322
+ "format": "color",
323
+ "default": "#000000",
324
+ "title": "High-contrast background color",
325
+ "description": "Background color for the label text in high-contrast mode."
326
+ }
327
+ }
328
+ }
329
+ }
330
+ }
331
+ }
332
+ },
333
+ "links": [
334
+ {
335
+ "rel": "More information",
336
+ "href": "https://open-sdg.readthedocs.io/en/latest/metadata-format/#graph-metadata"
337
+ }
338
+ ]
339
+ },
340
+ "graph_limits": {
341
+ "options": {"collapsed": true},
342
+ "format": "table",
343
+ "type": "array",
344
+ "title": "Graph limits",
345
+ "description": "A list of min/max limits controlling the lowest/highest values to be shown on the y-axis.",
346
+ "items": {
347
+ "type": "object",
348
+ "title": "Graph limit",
349
+ "properties": {
350
+ "minimum": {
351
+ "type": "number",
352
+ "minimum": 0,
353
+ "title": "Minimum",
354
+ "description": "Minimum value for the y axis."
355
+ },
356
+ "maximum": {
357
+ "type": "number",
358
+ "minimum": 0,
359
+ "title": "Maximum",
360
+ "description": "Maximum value for the y axis."
361
+ },
362
+ "unit": {
363
+ "type": "string",
364
+ "title": "Unit",
365
+ "description": "The unit of measurement the limits apply to."
366
+ },
367
+ "series": {
368
+ "type": "string",
369
+ "title": "Series",
370
+ "description": "The series the limits apply to."
371
+ }
372
+ }
373
+ },
374
+ "links": [
375
+ {
376
+ "rel": "More information",
377
+ "href": "https://open-sdg.readthedocs.io/en/latest/metadata-format/#graph-metadata"
378
+ }
379
+ ]
380
+ },
381
+ "graph_stacked_disaggregation": {
382
+ "type": "string",
383
+ "title": "Stacked disaggregation",
384
+ "description": "This can be used with the bar graph type to place a certain disaggregation into the same stacked bars.",
385
+ "links": [
386
+ {
387
+ "rel": "More information",
388
+ "href": "https://open-sdg.readthedocs.io/en/latest/metadata-format/#recommended-special-fields"
389
+ }
390
+ ]
391
+ },
392
+ "graph_title": {
393
+ "type": "string",
394
+ "title": "Graph title",
395
+ "description": "The title that displays above the graph/chart.",
396
+ "links": [
397
+ {
398
+ "rel": "More information",
399
+ "href": "https://open-sdg.readthedocs.io/en/latest/metadata-format/#mandatory-for-statistical-indicators"
400
+ }
401
+ ]
402
+ },
403
+ "graph_titles": {
404
+ "options": {"collapsed": true},
405
+ "format": "table",
406
+ "type": "array",
407
+ "title": "Graph titles",
408
+ "description": "As an alternative to `graph_title`, this can be used to set specific titles for particular units and/or series.",
409
+ "items": {
410
+ "type": "object",
411
+ "title": "Graph title",
412
+ "properties": {
413
+ "title": {
414
+ "type": "string",
415
+ "minLength": 1,
416
+ "title": "Title",
417
+ "description": "The graph title."
418
+ },
419
+ "unit": {
420
+ "type": "string",
421
+ "title": "Unit",
422
+ "description": "The unit of measurement the title applies to."
423
+ },
424
+ "series": {
425
+ "type": "string",
426
+ "title": "Series",
427
+ "description": "The series the title applies to."
428
+ }
429
+ }
430
+ }
431
+ },
432
+ "graph_type": {
433
+ "type": "string",
434
+ "format": "choices",
435
+ "title": "Graph type",
436
+ "description": "What type of graph to use for the indicator.",
437
+ "enum": ["line", "bar", "binary"],
438
+ "links": [
439
+ {
440
+ "rel": "More information",
441
+ "href": "https://open-sdg.readthedocs.io/en/latest/metadata-format/#mandatory-for-statistical-indicators"
442
+ }
443
+ ]
444
+ },
445
+ "indicator_name": {
446
+ "type": "string",
447
+ "title": "Indicator name",
448
+ "description": "The name for the indicator, which displays at the top of the indicator page.",
449
+ "links": [
450
+ {
451
+ "rel": "More information",
452
+ "href": "https://open-sdg.readthedocs.io/en/latest/metadata-format/#mandatory-fields"
453
+ }
454
+ ]
455
+ },
456
+ "indicator_number": {
457
+ "type": "string",
458
+ "title": "Indicator number",
459
+ "description": "The number (or 'id') for the indicator.",
460
+ "links": [
461
+ {
462
+ "rel": "More information",
463
+ "href": "https://open-sdg.readthedocs.io/en/latest/metadata-format/#mandatory-fields"
464
+ }
465
+ ]
466
+ },
467
+ "national_geographical_coverage": {
468
+ "type": "string",
469
+ "title": "National geographical coverage",
470
+ "description": "A label used in the absence of any disaggregation.",
471
+ "links": [
472
+ {
473
+ "rel": "More information",
474
+ "href": "https://open-sdg.readthedocs.io/en/latest/metadata-format/#mandatory-for-statistical-indicators"
475
+ }
476
+ ]
477
+ },
478
+ "page_content": {
479
+ "type": "string",
480
+ "format": "markdown",
481
+ "title": "Page content",
482
+ "description": "Content which displays in the main content area of the indicator page."
483
+ },
484
+ "reporting_status": {
485
+ "type": "string",
486
+ "format": "choices",
487
+ "title": "Reporting status",
488
+ "enum": ["complete", "inprogress", "notstarted", "notapplicable"],
489
+ "description": "The status of the indicator.",
490
+ "links": [
491
+ {
492
+ "rel": "More information",
493
+ "href": "https://open-sdg.readthedocs.io/en/latest/metadata-format/#mandatory-fields"
494
+ }
495
+ ]
496
+ },
497
+ "tags": {
498
+ "options": {"collapsed": true},
499
+ "format": "table",
500
+ "type": "array",
501
+ "title": "Tags",
502
+ "description": "An optional list of 'tags' to display under an indicator when it is listed on its goal page.",
503
+ "items": {
504
+ "type": "string",
505
+ "title": "Tag"
506
+ },
507
+ "links": [
508
+ {
509
+ "rel": "More information",
510
+ "href": "https://open-sdg.readthedocs.io/en/latest/metadata-format/#recommended-special-fields"
511
+ }
512
+ ]
513
+ }
514
+ },
515
+ "additionalProperties": true
516
+ }