Module: Blot::Helpers::Layout

Included in:
Blot::Helpers
Defined in:
lib/blot/helpers/layout.rb

Instance Method Summary collapse

Instance Method Details

#layout(options = {}) ⇒ Object



4
5
6
7
8
9
10
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
# File 'lib/blot/helpers/layout.rb', line 4

def layout(options={})
  doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'
  html =  :html, xmlns: 'http://www.w3.org/1999/xhtml' do
    head =  :head do
      content_type = tag :meta, 'http-equiv' => 'Content-Type', content: 'text/html; charset=utf-8'
      viewport     = tag :meta, name: 'viewport', content: 'width=device-width'
      ink          =  :style, rel: 'text/css' do
        Rails.application.assets[options[:ink]].to_s.html_safe
      end if options[:ink]
      styles       =  :style, rel: 'text/css' do
        app_styles = []
        options[:styles].each do |style|
          app_styles << Rails.application.assets[style].to_s.html_safe
        end
        app_styles.join(' ').html_safe
      end if options[:styles]

      [content_type, viewport, ink, styles].join.html_safe
    end

    body =  :body do
       :table, class: 'body' do
         :tr do
           :td, class: 'center', align: 'center', valign: 'top' do
             :center do
              yield.try(:html_safe) if block_given?
            end
          end
        end
      end
    end

    [head, body].join.html_safe
  end

  [doctype, html].join.html_safe
end