9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
# File 'lib/jekyll-open-sdg-plugins/create_indicators.rb', line 9
def generate(site)
language_config = site.config['languages']
indicator_config = site.config['create_indicators']
form_settings_config = site.config['indicator_config_form']
form_settings_meta = site.config['indicator_metadata_form']
form_settings_data = site.config['indicator_data_form']
config_builder_layout = 'config-builder'
translations = site.data['translations']
if (language_config and indicator_config)
layout = 'indicator'
languages_public = Hash.new
if site.config['languages_public']
languages_public = opensdg_languages_public(site)
end
language_config.each_with_index do |language, index|
language_public = language
if languages_public[language]
language_public = languages_public[language]
end
metadata = {}
metadata = site.data[language]['meta']
metadata.each do |inid, meta|
permalink = inid
if (meta.has_key?('permalink') and meta['permalink'] != '')
permalink = meta['permalink']
end
dir = index == 0 ? permalink : File.join(language_public, permalink)
site.collections['indicators'].docs << IndicatorPage.new(site, site.source, dir, inid, language, layout)
iframe_layout = 'indicator-iframe'
iframe_permalink = permalink + '-iframe'
iframe_dir = index == 0 ? iframe_permalink : File.join(language_public, iframe_permalink)
site.collections['pages'].docs << IndicatorPage.new(site, site.source, iframe_dir, inid, language, iframe_layout)
end
end
do_indicator_config_forms = form_settings_config && form_settings_config['enabled']
do_indicator_meta_forms = form_settings_meta && form_settings_meta['enabled']
do_indicator_data_forms = form_settings_data && form_settings_data['enabled']
use_translated_metadata = form_settings_meta && form_settings_meta['translated']
if do_indicator_config_forms || do_indicator_meta_forms || do_indicator_data_forms
metadata = {}
if site.data.has_key?('untranslated')
metadata = site.data['untranslated']['meta']
else
default_language = language_config[0]
metadata = site.data[default_language]['meta']
end
metadata_by_language = {}
language_config.each do |language|
metadata_by_language[language] = site.data[language]['meta']
end
if do_indicator_config_forms
site.config['configuration_edit_url'] = 'config'
end
if do_indicator_meta_forms
site.config['metadata_edit_url'] = 'metadata'
end
if do_indicator_data_forms
site.config['data_edit_url'] = 'data'
end
if !metadata.empty?
language_config.each_with_index do |language, index|
language_public = language
if languages_public[language]
language_public = languages_public[language]
end
metadata.each do |inid, meta|
permalink = inid
if (meta.has_key?('permalink') and meta['permalink'] != '')
permalink = meta['permalink']
end
dir_base = File.join(permalink)
if index != 0
dir_base = File.join(language_public, permalink)
end
if do_indicator_config_forms
dir = File.join(dir_base, 'config')
title = opensdg_translate_key('indicator.edit_configuration', translations, language)
config_type = 'indicator'
site.collections['pages'].docs << IndicatorConfigPage.new(site, site.source, dir, inid, language, meta, title, config_type, form_settings_config, config_builder_layout)
end
if do_indicator_meta_forms
metadata_to_use = meta
if use_translated_metadata
metadata_to_use = metadata_by_language[language][inid]
end
dir = File.join(dir_base, 'metadata')
title = opensdg_translate_key('indicator.edit_metadata', translations, language)
config_type = 'metadata'
site.collections['pages'].docs << IndicatorConfigPage.new(site, site.source, dir, inid, language, metadata_to_use, title, config_type, form_settings_meta, config_builder_layout)
end
if do_indicator_data_forms
dir = File.join(dir_base, 'data')
title = opensdg_translate_key('indicator.edit_data', translations, language)
site.collections['pages'].docs << IndicatorDataPage.new(site, site.source, dir, inid, language, title, form_settings_data)
end
end
end
end
end
end
end
|