Class: Dictum::HtmlHelpers
- Inherits:
-
Object
- Object
- Dictum::HtmlHelpers
- Defined in:
- lib/dictum/html_helpers.rb
Constant Summary collapse
- BOOTSTRAP_JS =
'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js'.freeze
- BOOTSTRAP_CSS =
'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css'.freeze
- JQUERY =
'https://code.jquery.com/jquery-1.12.2.min.js'.freeze
- PRETTIFY =
'https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js'.freeze
Class Method Summary collapse
- .build {|_self| ... } ⇒ Object
- .button(text, glyphicon = 'glyphicon-menu-left') ⇒ Object
- .code(json) ⇒ Object
- .code_block(title, json) ⇒ Object
- .container(content) ⇒ Object
- .external_css(css_path) ⇒ Object
- .html_header(title, body_content, inline_css = nil) ⇒ Object
- .inline_css(style) ⇒ Object
- .jumbotron(content) ⇒ Object
- .link(href, content) ⇒ Object
- .list_item(content) ⇒ Object
- .paragraph(text, html_class = nil) ⇒ Object
- .row(content) ⇒ Object
- .script(script_path) ⇒ Object
- .sub_subtitle(text, html_class = nil) ⇒ Object
- .subtitle(text, html_class = nil) ⇒ Object
- .tag(name, content, attributes = {}) ⇒ Object
- .title(text, html_class = nil) ⇒ Object
- .unordered_list(elements) ⇒ Object
Class Method Details
.build {|_self| ... } ⇒ Object
9 10 11 |
# File 'lib/dictum/html_helpers.rb', line 9 def build yield self end |
.button(text, glyphicon = 'glyphicon-menu-left') ⇒ Object
80 81 82 83 84 85 86 87 88 |
# File 'lib/dictum/html_helpers.rb', line 80 def (text, glyphicon = 'glyphicon-menu-left') span = tag('span', nil, class: "glyphicon #{glyphicon}", 'aria-hidden' => 'true') paragraph = paragraph(text) = span.to_s + paragraph.to_s = tag('button', , 'type' => 'button', 'class' => 'btn btn-primary back dictum-button', 'aria-label' => 'Left Align') tag('a', .to_s, href: 'index.html') end |
.code(json) ⇒ Object
96 97 98 99 |
# File 'lib/dictum/html_helpers.rb', line 96 def code(json) return '' unless json tag('pre', json, class: 'prettyprint') end |
.code_block(title, json) ⇒ Object
90 91 92 93 94 |
# File 'lib/dictum/html_helpers.rb', line 90 def code_block(title, json) return '' unless json return code(json) unless title "#{sub_subtitle(title)}#{code(json)}" end |
.container(content) ⇒ Object
19 20 21 |
# File 'lib/dictum/html_helpers.rb', line 19 def container(content) tag('div', content.to_s, class: 'container-fluid') end |
.external_css(css_path) ⇒ Object
33 34 35 36 |
# File 'lib/dictum/html_helpers.rb', line 33 def external_css(css_path) return '' unless css_path "<link rel='stylesheet' href='#{css_path}' />" end |
.html_header(title, body_content, inline_css = nil) ⇒ Object
13 14 15 16 17 |
# File 'lib/dictum/html_helpers.rb', line 13 def html_header(title, body_content, inline_css = nil) "<!DOCTYPE html><html><head><title>#{title}</title>#{external_css(BOOTSTRAP_CSS)}"\ "#{inline_css(inline_css)}</head><body>#{body_content}" \ "#{script(JQUERY)}#{script(BOOTSTRAP_JS)}#{script(PRETTIFY)}</body></html>" end |
.inline_css(style) ⇒ Object
38 39 40 41 |
# File 'lib/dictum/html_helpers.rb', line 38 def inline_css(style) return '' unless style "<style>#{style}</style>" end |
.jumbotron(content) ⇒ Object
101 102 103 104 |
# File 'lib/dictum/html_helpers.rb', line 101 def jumbotron(content) return '' unless content tag('div', content, class: 'jumbotron') end |
.link(href, content) ⇒ Object
56 57 58 |
# File 'lib/dictum/html_helpers.rb', line 56 def link(href, content) tag('a', content, href: './' + href) end |
.list_item(content) ⇒ Object
52 53 54 |
# File 'lib/dictum/html_helpers.rb', line 52 def list_item(content) tag('li', content) end |
.paragraph(text, html_class = nil) ⇒ Object
75 76 77 78 |
# File 'lib/dictum/html_helpers.rb', line 75 def paragraph(text, html_class = nil) return "<p>#{text}</p>" unless html_class tag('p', text, class: html_class) end |
.row(content) ⇒ Object
23 24 25 26 |
# File 'lib/dictum/html_helpers.rb', line 23 def row(content) internal_div = tag('div', content.to_s, class: 'col-md-8 col-md-offset-2') tag('div', internal_div.to_s, class: 'row') end |
.script(script_path) ⇒ Object
28 29 30 31 |
# File 'lib/dictum/html_helpers.rb', line 28 def script(script_path) return '' unless script_path tag('script', nil, src: script_path) end |
.sub_subtitle(text, html_class = nil) ⇒ Object
70 71 72 73 |
# File 'lib/dictum/html_helpers.rb', line 70 def sub_subtitle(text, html_class = nil) return "<h4>#{text}</h4>" unless html_class tag('h4', text, class: html_class) end |
.subtitle(text, html_class = nil) ⇒ Object
65 66 67 68 |
# File 'lib/dictum/html_helpers.rb', line 65 def subtitle(text, html_class = nil) return "<h3>#{text}</h3>" unless html_class tag('h3', text, class: html_class) end |
.tag(name, content, attributes = {}) ⇒ Object
106 107 108 109 110 111 112 113 |
# File 'lib/dictum/html_helpers.rb', line 106 def tag(name, content, attributes = {}) return '' unless name answer = "<#{name}" attributes.each do |key, value| answer += " #{key}='#{value}'" end answer += ">#{content}</#{name}>" end |
.title(text, html_class = nil) ⇒ Object
60 61 62 63 |
# File 'lib/dictum/html_helpers.rb', line 60 def title(text, html_class = nil) return "<h1>#{text}</h1>" unless html_class tag('h1', text, class: html_class) end |
.unordered_list(elements) ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/dictum/html_helpers.rb', line 43 def unordered_list(elements) return '<ul></ul>' unless elements answer = '<ul>' elements.each do |element| answer += list_item(link("#{element.downcase}.html", element)) end answer += '</ul>' end |