In: |
lib/amrita/format.rb
|
Parent: | Object |
format_attr_default | -> | format_attr |
asxml | [RW] | If set, single tag like <hr> will be printed as <hr /> Default is false |
compact_space | [RW] | If set, the spaces and new-lines in text will be compacted. Default is false |
delete_span | [RW] | If set, <span> with no attribute will be deleted. Default is true |
escape | [RW] | If set, text will be escaped by Sanitizer#sanitize_text Default is true. |
stream is any object that has << method. All output is done by << method.
# File lib/amrita/format.rb, line 154 def initialize(stream="", tagdict=DefaultHtmlTagInfo, &element_filter) @stream = stream @tagdict = tagdict @escape = true @asxml = false @delete_span = true @sanitized = false @compact_space = false @element_filter = element_filter end
# File lib/amrita/format.rb, line 295 def format_attr_of_element(attr, element) taginfo = taginfo_of_element(element) format_attr(attr, taginfo && taginfo.url_attr?(attr.key)) end
# File lib/amrita/format.rb, line 300 def format_element_attrs(element) format_attrs(element.attrs, taginfo_of_element(element)) end
set replacing attribute.
f.set_attr_filter(:__id=>:id)
<p __id="x"> is printed as <p id="x">
# File lib/amrita/format.rb, line 234 def set_attr_filter(hash) src = [ "def self.format_attr(a, flag)" ] src << "case a.key" hash.each do |key, val| src << %[ when "#{key}" ; format_attr_default(Attr.new(:#{val}, a.value), flag)] end src << "else; format_attr_default(a, flag)" src << "end" src << "end" src << "" #puts src eval src.join("\n") rescue SctiptError, NameError puts src end