module WWW_App::HTML
Constants
- ATTRIBUTES
- ATTRIBUTES_TO_TAGS
- NO_NEW_LINES
- SELF_CLOSING_TAGS
- TAGS
- TAGS_TO_ATTRIBUTES
Public Instance Methods
^(*names) { || ... }
click to toggle source
Example:
div.^(:alert, :red_hot) { 'my content' }
# File lib/www_app/HTML.rb, line 174 def ^ *names @tag[:class] ||= [] @tag[:class].concat(names) if block_given? close { yield } else self end end
alter_attribute(name, val) { || ... }
click to toggle source
# File lib/www_app/HTML.rb, line 75 def alter_attribute name, val allowed = @tag && ATTRIBUTES_TO_TAGS[name] && ATTRIBUTES_TO_TAGS[name].include?(@tag[:tag_name]) fail "#{name.inspect} not allowed to be set here." unless allowed @tag[name] = val block_given? ? close { yield } : self end
id(new_id) { || ... }
click to toggle source
# File lib/www_app/HTML.rb, line 106 def id new_id if !@tag fail "No HTML tag found. Try using _.id(#{new_id.inspect})" end if !ancestor?(:group) old_id = @tag[:id] if old_id && old_id != new_id fail("Id already set: #{old_id} new: #{new_id}") end if @html_ids[new_id] fail(HTML_ID_Duplicate, "Id already used: #{new_id.inspect}, tag index: #{@html_ids[new_id]}") end @html_ids[ new_id ] = new_id end @tag[:id] = new_id if block_given? close { yield } else self end end
input(*args)
click to toggle source
Calls superclass method
# File lib/www_app/HTML.rb, line 201 def input *args case when args.size === 3 create(:input, :type=>args[0].to_s, :name=>args[1].to_s, :value=>args[2], :closed=>true) go_up else super end end
is_doc?()
click to toggle source
# File lib/www_app/HTML.rb, line 136 def is_doc? @is_doc ||= begin found = false tags = @tags.dup while !found && !tags.empty? t = tags.shift found = begin (t[:tag_name] == :body && (t[:id] || t[:css]) ) || t[:tag_name] == :style || t[:tag_name] == :script || t[:tag_name] == :meta || t[:css] || (t[:tag_name] == :title && t[:parent] && t[:parent][:tag_name] == :body) end if !found && t[:children] tags = t[:children].concat(tags) end end found end end
is_fragment?()
click to toggle source
# File lib/www_app/HTML.rb, line 132 def is_fragment? !is_doc? end
lang(name)
click to toggle source
# File lib/www_app/HTML.rb, line 159 def lang name fail "Tag has to be placed tomost of the page." if parent fail "Block not allowed here." if block_given? create :html_tag_attr do @tag[:lang] = name.to_s.downcase.gsub(/[^a-z0-9\_\-]+/, ''.freeze) @tag[:lang] = 'en' if @tag[:lang].empty? end self end
meta(*args)
click to toggle source
# File lib/www_app/HTML.rb, line 89 def meta *args fail "No block allowed." if block_given? fail "Not allowed here." if parent create(:meta, *args) end
render_if(name) { || ... }
click to toggle source
# File lib/www_app/HTML.rb, line 185 def render_if name fail ::ArgumentError, "Not a symbol: #{name.inspect}" unless name.is_a?(Symbol) raw_text %^{{#coll.#{name}}}^ yield raw_text %^{{/coll.#{name}}}^ nil end
render_unless(name) { || ... }
click to toggle source
# File lib/www_app/HTML.rb, line 193 def render_unless name fail ::ArgumentError, "Not a symbol: #{name.inspect}" unless name.is_a?(Symbol) raw_text %!{{^coll.#{name}}}! yield raw_text %!{{/coll.#{name}}}! nil end
script(src = nil) { || ... }
click to toggle source
# File lib/www_app/HTML.rb, line 211 def script src = nil if src.is_a?(String) && src['.js'.freeze] return create(:script, :src=>src) { } end attrs = { :type => src || "text/mustache" } create :script, attrs close { yield } if block_given? self end
title(str = :none) { || ... }
click to toggle source
# File lib/www_app/HTML.rb, line 95 def title str = :none fail ":title not allowed here" if parent if !block_given? && str != :none create(:title) { text str } else create :title do yield end end end