Class: JekyllOpenSdgPlugins::GoalPage

Inherits:
Jekyll::Page
  • Object
show all
Defined in:
lib/jekyll-open-sdg-plugins/create_goals.rb

Overview

A Page subclass used in the ‘CreateGoals` class.

Instance Method Summary collapse

Constructor Details

#initialize(site, base, dir, goal, language, layout, goal_index) ⇒ GoalPage

Returns a new instance of GoalPage.



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
# File 'lib/jekyll-open-sdg-plugins/create_goals.rb', line 60

def initialize(site, base, dir, goal, language, layout, goal_index)
  @site = site
  @base = base
  @dir  = dir
  @name = 'index.html'

  goal_heading = ''
  goal_content = ''
  goal_content_heading = ''
  if site.config['create_goals'].has_key?('goal_content_heading')
    goal_content_heading = site.config['create_goals']['goal_content_heading']
  end
  if site.config['create_goals'].has_key?('goals')
    # Try to find goal content by match the goal ID with a "goal" property on each item
    # in the create_goals.goals site config. Otherwise fallback to the order they appear
    # in that list.
    goal_by_goal = site.config['create_goals']['goals'].detect {|g| g['goal'].to_s == goal.to_s }
    goal_by_index = site.config['create_goals']['goals'][goal_index]
    if !goal_by_goal.nil?
      goal_content = goal_by_goal['content']
      if goal_by_goal.has_key?('content_heading') && goal_by_goal['content_heading'] != ''
        goal_content_heading = goal_by_goal['content_heading']
      end
      if goal_by_goal.has_key?('heading')
        goal_heading = goal_by_goal['heading']
      end
    elsif !goal_by_index.nil?
      if !goal_by_index.has_key?('goal') || goal_by_index['goal'].to_s == goal.to_s
        goal_content = goal_by_index['content']
        if goal_by_index.has_key?('content_heading') && goal_by_index['content_heading'] != ''
          goal_content_heading = goal_by_index['content_heading']
        end
        if goal_by_index.has_key?('heading')
          goal_heading = goal_by_index['heading']
        end
      end
    end
  end
  @content = goal_content

  self.process(@name)
  self.data = {}
  self.data['goal_number'] = goal.to_s
  self.data['language'] = language
  self.data['layout'] = layout
  self.data['goal_content_heading'] = goal_content_heading
  self.data['goal_heading'] = goal_heading
end