Module: Emjay::Skeleton

Defined in:
lib/emjay/skeleton.rb

Class Method Summary collapse

Class Method Details

.call(options) ⇒ Object

Builds the full HTML document skeleton. Port of skeleton.js.



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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/emjay/skeleton.rb', line 10

def self.call(options)
  before_doctype = options[:before_doctype] || ""
  breakpoint = options[:breakpoint] || "480px"
  content = options[:content] || ""
  fonts = options[:fonts] || {}
  media_queries = options[:media_queries] || {}
  head_style = options[:head_style] || {}
  components_head_style = options[:components_head_style] || []
  head_raw = options[:head_raw] || []
  title = options[:title] || ""
  style = options[:style] || []
  force_owa_desktop = options[:force_owa_desktop] || false
  printer_support = options[:printer_support] || false
  inline_style = options[:inline_style] || []
  lang = options[:lang] || "und"
  dir = options[:dir] || "auto"

  before_doctype_str = before_doctype.empty? ? "" : "#{before_doctype}\n"

  fonts_tags = Fonts.build_tags(content, inline_style, fonts)
  media_query_tags = MediaQueries.build_tags(breakpoint, media_queries,
    force_owa_desktop: force_owa_desktop,
    printer_support: printer_support)
  component_styles = Styles.build_from_components(breakpoint, components_head_style, head_style)
  tag_styles = Styles.build_from_tags(breakpoint, style)
  raw = head_raw.compact.join("\n")

  <<~HTML
    #{before_doctype_str}<!doctype html>
    <html lang="#{lang}" dir="#{dir}" xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">
      <head>
        <title>#{title}</title>
        <!--[if !mso]><!-->
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <!--<![endif]-->
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <style type="text/css">
          #outlook a { padding:0; }
          body { margin:0;padding:0;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%; }
          table, td { border-collapse:collapse;mso-table-lspace:0pt;mso-table-rspace:0pt; }
          img { border:0;height:auto;line-height:100%; outline:none;text-decoration:none;-ms-interpolation-mode:bicubic; }
          p { display:block;margin:13px 0; }
        </style>
        <!--[if mso]>
        <noscript>
        <xml>
        <o:OfficeDocumentSettings>
          <o:AllowPNG/>
          <o:PixelsPerInch>96</o:PixelsPerInch>
        </o:OfficeDocumentSettings>
        </xml>
        </noscript>
        <![endif]-->
        <!--[if lte mso 11]>
        <style type="text/css">
          .mj-outlook-group-fix { width:100% !important; }
        </style>
        <![endif]-->
        #{fonts_tags}
        #{media_query_tags}
        #{component_styles}
        #{tag_styles}
        #{raw}
      </head>
      #{content}
    </html>
  HTML
end