Class: Schoolkeep::Views::Layout

Inherits:
Object
  • Object
show all
Defined in:
lib/schoolkeep/views/layout.rb

Constant Summary collapse

BODY_CLASSES =
{
  "course_details.html.sktl" => "school_website-courses school_website-courses-show",
  "course_index.html.sktl" => "school_website-courses school_website-courses-index",
  "custom_page.html.sktl" => "school_website-custom_pages school_website-custom_pages-show",
  "homepage.html.sktl" => "school_website-homepages school_website-homepages-show",
  "my_content.html.sktl" => "school_website-my_content school_website-my_content-index"
}
LAYOUTS =
Hash.new("school_website")

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template) ⇒ Layout

Returns a new instance of Layout.



30
31
32
33
34
# File 'lib/schoolkeep/views/layout.rb', line 30

def initialize(template)
  @template = template
  @school = Fixture.globals[:current_school]
  @preview_banner = Fixture.globals[:preview_banner]
end

Class Attribute Details

.asset_hostObject

Returns the value of attribute asset_host.



11
12
13
# File 'lib/schoolkeep/views/layout.rb', line 11

def asset_host
  @asset_host
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



29
30
31
# File 'lib/schoolkeep/views/layout.rb', line 29

def body
  @body
end

Class Method Details

.asset_cacheObject



13
14
15
# File 'lib/schoolkeep/views/layout.rb', line 13

def asset_cache
  @asset_cache ||= AssetCache.new(asset_host)
end

Instance Method Details

#asset_url(path) ⇒ Object



40
41
42
# File 'lib/schoolkeep/views/layout.rb', line 40

def asset_url(path)
  self.class.asset_cache[path]
end

#body_classesObject



36
37
38
# File 'lib/schoolkeep/views/layout.rb', line 36

def body_classes
  BODY_CLASSES[@template.name]
end

#current_schoolObject



44
45
46
# File 'lib/schoolkeep/views/layout.rb', line 44

def current_school
  @school
end

#preview_bannerObject



48
49
50
# File 'lib/schoolkeep/views/layout.rb', line 48

def preview_banner
  @preview_banner
end

#render(variables: {}) ⇒ Object



57
58
59
60
61
62
63
# File 'lib/schoolkeep/views/layout.rb', line 57

def render(variables: {})
  @body = @template.render(variables: variables)
  layout_path = File.join(GEM_ROOT, "config/#{LAYOUTS[@template.name]}.html.erb")
  layout= File.read(layout_path)
  set_context_variables_for_layout
  ERB.new(layout).result(binding)
end

#render_skt(partial_name, variables: {}) ⇒ Object



52
53
54
55
# File 'lib/schoolkeep/views/layout.rb', line 52

def render_skt(partial_name, variables: {})
  name = "#{partial_name}.html.sktl"
  Template.new(name).render(variables: variables)
end