Class: JekyllOpenSdgPlugins::BackwardsCompatibility
- Inherits:
-
Jekyll::Generator
- Object
- Jekyll::Generator
- JekyllOpenSdgPlugins::BackwardsCompatibility
- Defined in:
- lib/jekyll-open-sdg-plugins/backwards_compatibility.rb
Instance Method Summary collapse
- #add_translation_keys(statuses, site) ⇒ Object
-
#generate(site) ⇒ Object
This file is used to avoid any backwards compatibility issues as the Open SDG API changes over time.
Instance Method Details
#add_translation_keys(statuses, site) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/jekyll-open-sdg-plugins/backwards_compatibility.rb', line 9 def add_translation_keys(statuses, site) statuses.each do |status| status_var = 'value' unless status.has_key?(status_var) status_var = 'status' end status_in_site_config = site.config['reporting_status']['status_types'].detect {|s| s['value'] == status[status_var] } if status_in_site_config.nil? opensdg_notice('Unexpected reporting status type: ' + status[status_var] + '. Expected reporting status types:') puts site.config['reporting_status']['status_types'].map { |s| s['value'] } end status['translation_key'] = status_in_site_config['label'] end end |
#generate(site) ⇒ Object
This file is used to avoid any backwards compatibility issues as the Open SDG API changes over time.
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 |
# File 'lib/jekyll-open-sdg-plugins/backwards_compatibility.rb', line 26 def generate(site) # Handle legacy treatment of reporting status types. unless (site.config.has_key?('reporting_status') && site.config['reporting_status'].has_key?('status_types') && site.config['reporting_status']['status_types'].count > 0) reporting_status = site.data['schema'].detect {|f| f['name'] == 'reporting_status' } reporting_status_types = reporting_status['field']['options'] unless site.config.has_key?('reporting_status') site.config['reporting_status'] = {} end site.config['reporting_status']['status_types'] = reporting_status_types.map do |status_type| { 'value' => status_type['value'], 'label' => status_type['translation_key'], } end end # Also fill in the "reporting" data with things needed by older templates. add_translation_keys(site.data['reporting']['statuses'], site) add_translation_keys(site.data['reporting']['overall']['statuses'], site) if site.data['reporting'].has_key?('extra_fields') site.data['reporting']['extra_fields'].each do |key, extra_field| extra_field.each do |extra_field_value| add_translation_keys(extra_field_value['statuses'], site) end end end if site.data['reporting'].has_key?('goals') site.data['reporting']['goals'].each do |goal| add_translation_keys(goal['statuses'], site) end end end |