class Weaver::Elements
Add accordion to elements
Add tables to elements
add modal dialog to elements
Add row and column elements
Base element class for all HTML elements
Public Class Methods
new(page, anchors)
click to toggle source
# File lib/weaver/elements.rb, line 6 def initialize(page, anchors) @inner_content = [] @anchors = anchors @page = page end
Public Instance Methods
accordion(&block)
click to toggle source
# File lib/weaver/element_types/accordion.rb, line 117 def accordion(&block) acc = Accordion.new(@page, @anchors) acc.instance_eval(&block) @inner_content << acc.generate end
background(&block)
click to toggle source
# File lib/weaver/elements.rb, line 60 def background(&block) @page.background(block) end
badge(label, options = {})
click to toggle source
# File lib/weaver/elements.rb, line 200 def badge(label, options = {}) options[:type] ||= 'plain' kind = 'label' kind = 'badge' if options[:rounded] tag_options = options.clone tag_options[:class] = "#{kind} #{kind}-#{options[:type]}" span tag_options do text label end end
center(content = nil, options = {}, &block)
click to toggle source
# File lib/weaver/elements.rb, line 92 def center(content = nil, options = {}, &block) options[:style] = '' unless options[:style] options[:style] += '; text-align: center;' if !content div options, &block else div content, options, &block end end
col(occupies, options = {}, &block)
click to toggle source
# File lib/weaver/element_types/row.rb, line 114 def col(occupies, options = {}, &block) column = Column.new(occupies, @page, @anchors, options, &block) text column.generate end
crossfade_image(image_normal, image_hover)
click to toggle source
# File lib/weaver/elements.rb, line 149 def crossfade_image(image_normal, image_hover) div class: 'crossfade' do image image_hover, class: 'bottom' image image_normal, class: 'top' end image image_hover @page.request_css 'css/crossfade_style.css' end
gallery(images, thumbnails = images, options = {})
click to toggle source
# File lib/weaver/elements.rb, line 158 def gallery(images, thumbnails = images, options = {}) @page.request_css 'css/plugins/blueimp/css/blueimp-gallery.min.css' div class: 'lightBoxGallery' do (0...images.length).to_a.each do |index| title = options[:titles][index] if options[:titles] a href: (images[index]).to_s, title: title.to_s, "data-gallery": '' do img src: (thumbnails[index]).to_s, style: 'margin: 5px;' end end div id: 'blueimp-gallery', class: 'blueimp-gallery' do div class: 'slides' do end h3 class: 'title' do end a class: 'prev' do end a class: 'next' do end a class: 'close' do end a class: 'play-pause' do end ol class: 'indicator' do end end end @page.request_js 'js/plugins/blueimp/jquery.blueimp-gallery.min.js' end
generate()
click to toggle source
# File lib/weaver/elements.rb, line 405 def generate @inner_content.join end
half(&block)
click to toggle source
# File lib/weaver/element_types/row.rb, line 81 def half(&block) opts = { xs: 12, sm: 12, md: 12, lg: 6 } col(4, opts, &block) end
hyperlink(url, title = nil, &block)
click to toggle source
# File lib/weaver/elements.rb, line 213 def hyperlink(url, title = nil, &block) url = url.dup title ||= url if url.start_with? '/' url.sub!(%r{^/}, @page.root) if block a href: url, &block else a title, href: url end else if block a href: url, target: '_blank' do span do span &block icon :external_link end end else a href: url, target: '_blank' do span do text title text ' ' icon :external_link end end end end end
ibox(options = {}, &block)
click to toggle source
# File lib/weaver/elements.rb, line 86 def ibox(options = {}, &block) panel = Panel.new(@page, @anchors, options) panel.instance_eval(&block) @inner_content << panel.generate end
icon(type)
click to toggle source
# File lib/weaver/elements.rb, line 68 def icon(type) iconname = type.to_s.tr('_', '-') if type.is_a? Symbol i class: "fa fa-#{iconname}" do end else i class: 'fa' do text type end end end
image(name, options = {})
click to toggle source
# File lib/weaver/elements.rb, line 128 def image(name, options = {}) style = (options[:style]).to_s if options[:rounded_corners] == true style += ' border-radius: 8px' elsif options[:rounded_corners] == :top style += ' border-radius: 8px 8px 0px 0px' else style += " border-radius: #{options[:rounded_corners]}px" if options[:rounded_corners] end img_options = { class: "img-responsive #{options[:class]}", src: "#{@page.root}images/#{name}", style: style } img_options[:id] = options[:id] if options[:id] img img_options end
jumbotron(options = {}, &block)
click to toggle source
# File lib/weaver/elements.rb, line 260 def jumbotron(options = {}, &block) additional_style = '' if options[:background] additional_style += " background-image: url('#{@page.root}images/#{options[:background]}'); background-position: center center; background-size: cover;" end additional_style += " height: #{options[:height]}px;" if options[:height] if options[:min_height] additional_style += " min-height: #{options[:min_height]}px;" end if options[:max_height] additional_style += " max-height: #{options[:max_height]}px;" end div class: 'jumbotron', style: additional_style, &block end
math(string)
click to toggle source
# File lib/weaver/elements.rb, line 401 def math(string) text "$$$MATH$$$#{string}$$$ENDMATH$$$" end
method_missing(name, *args, &block)
click to toggle source
# File lib/weaver/elements.rb, line 12 def method_missing(name, *args, &block) tag = "<#{name} />" inner = args.shift if args[0].is_a? String if block elem = Elements.new(@page, @anchors) elem.instance_eval(&block) inner = elem.generate end if !inner options = args[0] || [] opts = options.map { |key, value| "#{key}=\"#{value}\"" }.join ' ' tag = "<#{name} #{opts} />" elsif args.empty? tag = "<#{name}>#{inner}</#{name}>" elsif (args.length == 1) && args[0].is_a?(Hash) options = args[0] opts = options.map { |key, value| "#{key}=\"#{value}\"" }.join ' ' tag = "<#{name} #{opts}>#{inner}</#{name}>" end @inner_content << tag tag end
modal(id = nil, &block)
click to toggle source
# File lib/weaver/element_types/modal_dialog.rb, line 65 def modal(id = nil, &block) mm = ModalDialog.new(@page, @anchors, id, &block) @inner_content << mm.generate end
on_page_load(script)
click to toggle source
# File lib/weaver/elements.rb, line 52 def on_page_load(script) @page.on_page_load(script) end
p(*args, &block)
click to toggle source
# File lib/weaver/elements.rb, line 192 def p(*args, &block) method_missing(:p, *args, &block) end
panel(title, &block)
click to toggle source
# File lib/weaver/elements.rb, line 103 def panel(title, &block) div class: 'panel panel-default' do div class: 'panel-heading' do h5 title end div class: 'panel-body', &block end end
quarter(&block)
click to toggle source
# File lib/weaver/element_types/row.rb, line 103 def quarter(&block) opts = { xs: 12, sm: 12, md: 6, lg: 3 } col(3, opts, &block) end
request_css(path)
click to toggle source
# File lib/weaver/elements.rb, line 48 def request_css(path) @page.request_css(path) end
request_js(path)
click to toggle source
# File lib/weaver/elements.rb, line 44 def request_js(path) @page.request_js(path) end
root()
click to toggle source
# File lib/weaver/elements.rb, line 40 def root @page.root end
row(options = {}, &block)
click to toggle source
# File lib/weaver/element_types/row.rb, line 63 def row(options = {}, &block) options[:class] = 'row' div options do instance_eval(&block) end end
syntax(lang = :javascript, &block)
click to toggle source
# File lib/weaver/elements.rb, line 119 def syntax(lang = :javascript, &block) code = Code.new(@page, @anchors, lang) code.instance_eval(&block) @inner_content << code.generate @page.scripts << code.generate_script end
table(options = {}, &block)
click to toggle source
# File lib/weaver/element_types/dynamic_table.rb, line 224 def table(options = {}, &block) table_name = options[:id] || @page.create_anchor('table') table_style = '' table_style = options[:style] unless options[:style].nil? classname = 'table' classname += ' table-bordered' if options[:bordered] classname += ' table-hover' if options[:hover] classname += ' table-striped' if options[:striped] table_options = { class: classname, id: table_name, style: table_style } if options[:system] == :data_table @page.request_js 'js/plugins/dataTables/jquery.dataTables.js' @page.request_js 'js/plugins/dataTables/dataTables.bootstrap.js' @page.request_js 'js/plugins/dataTables/dataTables.responsive.js' @page.request_js 'js/plugins/dataTables/dataTables.tableTools.min.js' @page.request_css 'css/plugins/dataTables/dataTables.bootstrap.css' @page.request_css 'css/plugins/dataTables/dataTables.responsive.css' @page.request_css 'css/plugins/dataTables/dataTables.tableTools.min.css' @page.scripts << <<-DATATABLE_SCRIPT $('##{table_name}').DataTable(); DATATABLE_SCRIPT end if options[:system] == :foo_table table_options[:"data-filtering"] = true table_options[:"data-sorting"] = true table_options[:"data-paging"] = true table_options[:"data-show-toggle"] = true table_options[:"data-toggle-column"] = 'last' table_options[:"data-paging-size"] = (options[:max_items_per_page] || 8).to_i.to_s table_options[:class] = table_options[:class] + ' toggle-arrow-tiny' @page.request_js 'js/plugins/footable/footable.all.min.js' @page.request_css 'css/plugins/footable/footable.core.css' @page.scripts << <<-DATATABLE_SCRIPT $('##{table_name}').footable({ paging: { size: #{(options[:max_items_per_page] || 8).to_i} } }); $('##{table_name}').append(this.html).trigger('footable_redraw'); DATATABLE_SCRIPT @page.onload_scripts << <<-SCRIPT SCRIPT end method_missing(:table, table_options, &block) ul class: 'pagination' end
table_from_hashes(hashes, options = {})
click to toggle source
# File lib/weaver/element_types/dynamic_table.rb, line 299 def table_from_hashes(hashes, options = {}) keys = {} hashes.each do |hash| hash.each do |key, _value| keys[key] = '' end end table options do thead do keys.each do |key, _| th key.to_s end end tbody do hashes.each do |hash| tr do keys.each do |key, _| td (hash[key]).to_s || ' ' end end end end end end
table_from_source(url, options = {}, &block)
click to toggle source
# File lib/weaver/element_types/dynamic_table.rb, line 291 def table_from_source(url, options = {}, &block) dyn_table = DynamicTable.new(@page, @anchors, url, options, &block) text dyn_table.generate_table @page.scripts << dyn_table.generate_script end
tabs(&block)
click to toggle source
# File lib/weaver/elements.rb, line 112 def tabs(&block) tabs = Tabs.new(@page, @anchors) tabs.instance_eval(&block) @inner_content << tabs.generate end
text(theText)
click to toggle source
# File lib/weaver/elements.rb, line 196 def text(theText) @inner_content << theText end
third(&block)
click to toggle source
# File lib/weaver/element_types/row.rb, line 92 def third(&block) opts = { xs: 12, sm: 12, md: 4, lg: 4 } col(4, opts, &block) end
twothirds(&block)
click to toggle source
# File lib/weaver/element_types/row.rb, line 70 def twothirds(&block) opts = { xs: 12, sm: 12, md: 8, lg: 8 } col(4, opts, &block) end
wform(options = {}, &block)
click to toggle source
# File lib/weaver/elements.rb, line 80 def wform(options = {}, &block) theform = Form.new(@page, @anchors, options, &block) @inner_content << theform.generate @page.scripts << theform.generate_script end
widget(options = {}, &block)
click to toggle source
# File lib/weaver/elements.rb, line 245 def widget(options = {}, &block) # gray-bg # white-bg # navy-bg # blue-bg # lazur-bg # yellow-bg # red-bg # black-bg color = "#{options[:color]}-bg" || 'navy-bg' div class: "widget style1 #{color}", &block end
write_script_once(script)
click to toggle source
# File lib/weaver/elements.rb, line 56 def write_script_once(script) @page.write_script_once(script) end