1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253
|
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<html><head>
<title>Class: Amrita::Formatter</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel=StyleSheet href="../.././rdoc-style.css" type="text/css" media="screen" />
<script type="text/javascript" language="JavaScript">
<!--
function popCode(url) {
window.open(url, "Code",
"resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
}
//-->
</script>
</head>
<body bgcolor="white">
<table summary="Information on class" width="100%" border="0" cellspacing="0">
<tr class="title-row">
<td class="big-title-font">
<sup><font color="aqua">Class</font></sup> Amrita::Formatter
</td>
<td align="right">
<table summary="layout" cellspacing="0" cellpadding="2">
<tr valign="top">
<td class="small-title-font">In:</td>
<td class="small-title-font">
<a href="../../files/lib/amrita/format_rb.html" class="aqua">
lib/amrita/format.rb
</a>
<br />
</td>
</tr>
<tr>
<td class="small-title-font">Parent:</td>
<td class="small-title-font">
Object
</td>
</tr>
</table>
</td>
</tr>
</table>
<!-- banner header -->
<div class="description"><p>
A <a href="Formatter.html">Formatter</a> object prints a <a
href="Node.html">Node</a> object as HTML text.
</p>
</div>
<table summary="Methods" cellpadding="5" width="100%">
<tr><td class="tablesubtitle">Methods</td></tr>
</table>
<div class="name-list">
<a href="#M000182">format</a>
<a href="#M000184">format_attr_of_element</a>
<a href="#M000185">format_element_attrs</a>
<a href="#M000181">new</a>
<a href="#M000183">set_attr_filter</a>
<a href="#M000186">taginfo_of_element</a>
</div>
<table summary="Attributes" cellpadding="5" width="100%">
<tr><td class="tablesubtitle">Attributes</td></tr>
</table>
<table summary="Attribute details" cellspacing="5">
<tr valign="top">
<td class="attr-name">:asxml</td>
<td align="center" class="attr-rw"> [RW] </td>
<td><p>
If set, single tag like <tt><hr></tt> will be printed as <tt><hr
/></tt> Default is false
</p>
</td>
</tr>
<tr valign="top">
<td class="attr-name">:compact_space</td>
<td align="center" class="attr-rw"> [RW] </td>
<td><p>
If set, the spaces and new-lines in text will be compacted. Default is
false
</p>
</td>
</tr>
<tr valign="top">
<td class="attr-name">:delete_span</td>
<td align="center" class="attr-rw"> [RW] </td>
<td><p>
If set, <tt><span></tt> with no attribute will be deleted. Default is
true
</p>
</td>
</tr>
<tr valign="top">
<td class="attr-name">:escape</td>
<td align="center" class="attr-rw"> [RW] </td>
<td><p>
If set, text will be escaped by Sanitizer#sanitize_text Default is true.
</p>
</td>
</tr>
<tr valign="top">
<td class="attr-name">:stream</td>
<td align="center" class="attr-rw"> [R] </td>
<td></td>
</tr>
</table>
<table summary="Included modules" cellpadding="5" width="100%">
<tr><td class="tablesubtitle">Included modules</td></tr>
</table>
<div class="name-list">
<span class="method-name"><a href="../Amrita.html">Amrita</a></span>
</div>
<table summary="Method list" cellpadding="5" width="100%">
<tr><td class="tablesubtitle">Public Class methods</td></tr>
</table>
<table summary="method" width="100%" cellspacing="0" cellpadding="5" border="0">
<tr><td class="methodtitle">
<a name="M000181"></a>
<b>new</b>(stream="", tagdict=DefaultHtmlTagInfo, &element_filter)
</td></tr>
</table>
<div class="description">
<p>
stream is any object that has << method. All output is done by
<< method.
</p>
</div>
<pre class="source">
<span class="cmt"># File lib/amrita/format.rb, line 154</span>
<span class="kw">def</span> initialize(stream=<span class="str">""</span>, tagdict=DefaultHtmlTagInfo, &element_filter)
@stream = stream
@tagdict = tagdict
@escape = <span class="kw">true</span>
@asxml = <span class="kw">false</span>
@delete_span = <span class="kw">true</span>
@sanitized = <span class="kw">false</span>
@compact_space = <span class="kw">false</span>
@element_filter = element_filter
<span class="kw">end</span>
</pre>
<table summary="Method list" cellpadding="5" width="100%">
<tr><td class="tablesubtitle">Public Instance methods</td></tr>
</table>
<table summary="method" width="100%" cellspacing="0" cellpadding="5" border="0">
<tr><td class="methodtitle">
<a name="M000182"></a>
<b>format</b>(node, stream=nil)
</td></tr>
</table>
<div class="description">
<p>
Format a <a href="Node.html">Node</a> object.
</p>
<p>
If <tt>stream</tt> is given, the output is changed to it in this method.
</p>
</div>
<pre class="source">
<span class="cmt"># File lib/amrita/format.rb, line 168</span>
<span class="kw">def</span> format(node, stream=<span class="kw">nil</span>)
node = Node::to_node(node)
with_stream(stream) <span class="kw">do</span>
node.format(<span class="kw">self</span>)
<span class="kw">end</span>
<span class="kw">end</span>
</pre>
<table summary="method" width="100%" cellspacing="0" cellpadding="5" border="0">
<tr><td class="methodtitle">
<a name="M000183"></a>
<b>set_attr_filter</b>(hash)
</td></tr>
</table>
<div class="description">
<p>
set replacing attribute.
</p>
<pre>
f.set_attr_filter(:__id=>:id)
</pre>
<p>
<p __id="x"> is printed as <p id="x">
</p>
</div>
<pre class="source">
<span class="cmt"># File lib/amrita/format.rb, line 234</span>
<span class="kw">def</span> set_attr_filter(hash)
src = [ <span class="str">"def self.format_attr(a, flag)"</span> ]
src << <span class="str">"case a.key"</span>
hash.each <span class="kw">do</span> |key, val|
src << ] when "#{key}" ; format_attr_default(Attr.new(:#{val}, a.value), flag)]
<span class="kw">end</span>
src << <span class="str">"else; format_attr_default(a, flag)"</span>
src << <span class="str">"end"</span>
src << <span class="str">"end"</span>
src << <span class="str">""</span>
<span class="cmt">#puts src</span>
eval src.join(<span class="str">"\n"</span>)
<span class="kw">rescue</span> SctiptError, NameError
puts src
<span class="kw">end</span>
</pre>
<table summary="method" width="100%" cellspacing="0" cellpadding="5" border="0">
<tr><td class="methodtitle">
<a name="M000184"></a>
<b>format_attr_of_element</b>(attr, element)
</td></tr>
</table>
<pre class="source">
<span class="cmt"># File lib/amrita/format.rb, line 295</span>
<span class="kw">def</span> format_attr_of_element(attr, element)
taginfo = taginfo_of_element(element)
format_attr(attr, taginfo && taginfo.url_attr?(attr.key))
<span class="kw">end</span>
</pre>
<table summary="method" width="100%" cellspacing="0" cellpadding="5" border="0">
<tr><td class="methodtitle">
<a name="M000185"></a>
<b>format_element_attrs</b>(element)
</td></tr>
</table>
<pre class="source">
<span class="cmt"># File lib/amrita/format.rb, line 300</span>
<span class="kw">def</span> format_element_attrs(element)
format_attrs(element.attrs, taginfo_of_element(element))
<span class="kw">end</span>
</pre>
<table summary="method" width="100%" cellspacing="0" cellpadding="5" border="0">
<tr><td class="methodtitle">
<a name="M000186"></a>
<b>taginfo_of_element</b>(element)
</td></tr>
</table>
<pre class="source">
<span class="cmt"># File lib/amrita/format.rb, line 304</span>
<span class="kw">def</span> taginfo_of_element(element)
@tagdict.get_tag_info(element.tagname_symbol)
<span class="kw">end</span>
</pre>
</body>
|