Class: Spider::TemplateBlocks::HTML
- Defined in:
- lib/spiderfw/templates/blocks/html.rb
Constant Summary collapse
- HTML_NO_CLOSE =
['br', 'img', 'input']
Instance Attribute Summary
Attributes inherited from Block
#allowed_blocks, #doctype, #el, #template
Instance Method Summary collapse
Methods inherited from Block
#compile_content, #compile_text, #escape_text, #get_following, #initialize, #inspect, #parse_content, var_to_scene, #var_to_scene, #vars_to_scene, vars_to_scene
Constructor Details
This class inherits a constructor from Spider::TemplateBlocks::Block
Instance Method Details
#compile(options = {}) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/spiderfw/templates/blocks/html.rb', line 8 def compile(={}) c = "" init = "" if @doctype c = "$out << '#{@doctype.raw_string}'\n" c += "$out << 10.chr\n" #newline end start = get_start() c += start is_root = [:root] .delete(:root) c += "unless self[:widget][:target_only] && !self[:widget][:is_target]\n" if ([:mode] == :widget && is_root) c, init = compile_content(c, init, ) c += "end\n" if ([:mode] == :widget && is_root) end_tag = get_end() c += "$out << '#{end_tag}'\n" if end_tag return CompiledBlock.new(init, c) end |
#get_end(options) ⇒ Object
59 60 61 62 63 64 |
# File 'lib/spiderfw/templates/blocks/html.rb', line 59 def get_end() return nil if [:doctype].html? && HTML_NO_CLOSE.include?(@el.name.downcase) str = escape_text(@el.etag.inspect) if @el.etag str = str[1..-2] if str && str[0].chr == '"' # FIXME: This is a workaround Hpricot 0.6 and 0.8 differences return str end |
#get_start(options) ⇒ Object
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 |
# File 'lib/spiderfw/templates/blocks/html.rb', line 27 def get_start() if [:mode] == :widget cl = @el.get_attribute('class') || '' if @el.has_attribute?('id') cl += ' ' unless cl.empty? cl += "id-#{@el.get_attribute('id')}" @el.remove_attribute('id') end if ([:root]) cl += " widget" if [:owner_class] cl += " wdgt-#{[:owner_class].name.gsub('::', '-')}" end @el.set_attribute('id', "{ @widget[:shown_id] }") cl += ' ' unless cl.empty? cl += '{ @widget[:css_classes] }' end @el.set_attribute('class', cl) unless cl.blank? end start = "$out << '<"+@el.name @el.attributes.to_hash.each do |key, val| if key =~ /sp::(.+)/ key = "sp:#{$1}" end start += " #{key}=\"" start += compile_text(val) start += "\"" end start += ">'\n" return start end |