class Dictum::HtmlHelpers
rubocop:disable ClassLength
Constants
- BOOTSTRAP_CSS
- BOOTSTRAP_JS
- JQUERY
- PRETTIFY
Public Class Methods
build() { |self| ... }
click to toggle source
# File lib/dictum/html_helpers.rb, line 10 def build yield self end
code(json)
click to toggle source
# File lib/dictum/html_helpers.rb, line 97 def code(json) return '' unless json tag('pre', json, class: 'prettyprint') end
code_block(title, json)
click to toggle source
# File lib/dictum/html_helpers.rb, line 91 def code_block(title, json) return '' unless json return code(json) unless title "#{sub_subtitle(title)}#{code(json)}" end
container(content)
click to toggle source
# File lib/dictum/html_helpers.rb, line 20 def container(content) tag('div', content.to_s, class: 'container-fluid') end
external_css(css_path)
click to toggle source
# File lib/dictum/html_helpers.rb, line 34 def external_css(css_path) return '' unless css_path "<link rel='stylesheet' href='#{css_path}' />" end
html_header(title, body_content, inline_css = nil)
click to toggle source
# File lib/dictum/html_helpers.rb, line 14 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)
click to toggle source
# File lib/dictum/html_helpers.rb, line 39 def inline_css(style) return '' unless style "<style>#{style}</style>" end
jumbotron(content)
click to toggle source
# File lib/dictum/html_helpers.rb, line 102 def jumbotron(content) return '' unless content tag('div', content, class: 'jumbotron') end
link(href, content)
click to toggle source
# File lib/dictum/html_helpers.rb, line 57 def link(href, content) tag('a', content, href: './' + href) end
list_item(content)
click to toggle source
# File lib/dictum/html_helpers.rb, line 53 def list_item(content) tag('li', content) end
paragraph(text, html_class = nil)
click to toggle source
# File lib/dictum/html_helpers.rb, line 76 def paragraph(text, html_class = nil) return "<p>#{text}</p>" unless html_class tag('p', text, class: html_class) end
row(content)
click to toggle source
# File lib/dictum/html_helpers.rb, line 24 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)
click to toggle source
# File lib/dictum/html_helpers.rb, line 29 def script(script_path) return '' unless script_path tag('script', nil, src: script_path) end
sub_subtitle(text, html_class = nil)
click to toggle source
# File lib/dictum/html_helpers.rb, line 71 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)
click to toggle source
# File lib/dictum/html_helpers.rb, line 66 def subtitle(text, html_class = nil) return "<h3>#{text}</h3>" unless html_class tag('h3', text, class: html_class) end
table(headers, rows)
click to toggle source
# File lib/dictum/html_helpers.rb, line 116 def table(headers, rows) return '' unless headers answer = table_headers(headers) answer += table_rows(rows) tag('table', answer, class: 'table') end
tag(name, content, attributes = {})
click to toggle source
# File lib/dictum/html_helpers.rb, line 107 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)
click to toggle source
# File lib/dictum/html_helpers.rb, line 61 def title(text, html_class = nil) return "<h1>#{text}</h1>" unless html_class tag('h1', text, class: html_class) end
unordered_list(elements)
click to toggle source
# File lib/dictum/html_helpers.rb, line 44 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
Private Class Methods
table_headers(headers)
click to toggle source
# File lib/dictum/html_helpers.rb, line 125 def table_headers(headers) answer = '' headers.each { |header| answer += tag('th', header) } tag('tr', answer) end
table_rows(rows)
click to toggle source
# File lib/dictum/html_helpers.rb, line 131 def table_rows(rows) answer = '' rows.each do |row| answer += tag('tr', tag('td', row[0]) + tag('td', row[1]) + tag('td', row[2])) end answer end