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
|
# File 'lib/jekyll-open-sdg-plugins/validate_indicator_config.rb', line 11
def generate(site)
schema_path = File.join(File.dirname(__FILE__), 'schema-indicator-config.json')
json_from_file = File.read(schema_path)
schema = JSON.parse(json_from_file)
schemer = JSONSchemer.schema(schema)
if site.config.has_key?('validate_indicator_config') && site.config['validate_indicator_config']
language = 'en'
if site.config.has_key?('languages')
language = site.config['languages'][0]
end
metadata = {}
metadata = site.data[language]['meta']
validation_failed = false
metadata.each do |inid, meta|
unless schemer.valid?(meta)
validation_failed = true
opensdg_notice('Indicator ' + inid + ' configuration invalid:')
errors = schemer.validate(meta).to_a
errors.each { |error| opensdg_validation_error(error) }
end
end
if validation_failed
opensdg_notice "Some indicator configuration was not valid. See feedback above."
raise "Invalid indicator configuration"
end
end
site.data['schema-indicator-config'] = schema
end
|