Class: SimplePageLayout::Helper::PageLayout

Inherits:
Object
  • Object
show all
Defined in:
lib/simple-page-layout.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(view, site_name, options = {}) ⇒ PageLayout

Returns a new instance of PageLayout.



8
9
10
11
12
13
14
# File 'lib/simple-page-layout.rb', line 8

def initialize(view, site_name, options = {})
  @view = view

  @site_name = site_name
  @html_lang = options[:html_lang]
  @body_class = options[:body_class]
end

Instance Attribute Details

#html_langObject

Returns the value of attribute html_lang.



6
7
8
# File 'lib/simple-page-layout.rb', line 6

def html_lang
  @html_lang
end

#site_nameObject

Returns the value of attribute site_name.



6
7
8
# File 'lib/simple-page-layout.rb', line 6

def site_name
  @site_name
end

#viewObject

Returns the value of attribute view.



5
6
7
# File 'lib/simple-page-layout.rb', line 5

def view
  @view
end

Instance Method Details

#render(&block) ⇒ Object



16
17
18
19
20
21
# File 'lib/simple-page-layout.rb', line 16

def render(&block)
  @view.haml_tag :html, :lang => html_lang do
    render_page_layout_head
    render_page_layout_body(&block)
  end
end

#render_page_layout_body(&block) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/simple-page-layout.rb', line 36

def render_page_layout_body(&block)
  javascript_ext = @view.content_for :javascript

  @view.haml_tag :body, :class => @body_class do
    yield
    @view.haml_concat @view.javascript_include_tag(:application)
    @view.haml_concat @view.javascript_ext if javascript_ext.present?
  end
end

#render_page_layout_headObject



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/simple-page-layout.rb', line 23

def render_page_layout_head
  head_ext = @view.content_for :head
  css_ext  = @view.content_for :css

  @view.haml_tag :head do
    render_page_title
    @view.haml_concat @view.csrf_meta_tags
    @view.haml_concat @view.stylesheet_link_tag(:application)
    @view.haml_concat head_ext if head_ext.present?
    @view.haml_concat css_ext if css_ext.present?
  end
end

#render_page_titleObject



46
47
48
49
50
51
# File 'lib/simple-page-layout.rb', line 46

def render_page_title
  yield_title = @view.content_for :title
  page_title = yield_title.blank? ? @site_name : "#{@site_name} | #{yield_title}" rescue 'SITE_NAME'
  
  @view.haml_tag :title, page_title
end