Class | Amrita::Formatter |
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 xmlが真のときは、常にXMLスタイルで出力する。(asxml属性は無視される。) |
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. |
xml | [RW] | 真のとき、XMLモード。 偽のとき、HTMLモード。 |
stream is any object that has << method. All output is done by << method.
# File lib/amrita/format.rb, line 169 def initialize(stream="", tagdict=DefaultHtmlTagInfo, &element_filter) @stream = stream @tagdict = tagdict # validator @escape = true @asxml = false @delete_span = true @sanitized = false @compact_space = false @element_filter = element_filter 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 250 def set_attr_filter(hash) src = [ "def self.format_attr(a, flag)" ] src << "case a.key" hash.each do |key, val| src << %Q[ 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