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 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
|
<?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: Amx::Template</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> Amx::Template
</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/amx_rb.html" class="aqua">
lib/amrita/amx.rb
</a>
<br />
</td>
</tr>
<tr>
<td class="small-title-font">Parent:</td>
<td class="small-title-font">
<a href="../Amrita/Template.html" class="aqua">
Amrita::Template
</a>
</td>
</tr>
</table>
</td>
</tr>
</table>
<!-- banner header -->
<table summary="Methods" cellpadding="5" width="100%">
<tr><td class="tablesubtitle">Methods</td></tr>
</table>
<div class="name-list">
<a href="#M000008">[]</a>
<a href="#M000015">befor_expand</a>
<a href="#M000011">define_method</a>
<a href="#M000014">expand</a>
<a href="#M000012">get_model</a>
<a href="#M000010">init_amx</a>
<a href="#M000009">new</a>
<a href="#M000017">rexml2amrita</a>
<a href="#M000013">setup_context</a>
<a href="#M000016">setup_template</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">:doc</td>
<td align="center" class="attr-rw"> [R] </td>
<td></td>
</tr>
<tr valign="top">
<td class="attr-name">:root</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">ExpandByMember</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="M000008"></a>
<b>[]</b>(f)
</td></tr>
</table>
<pre class="source">
<span class="cmt"># File lib/amrita/amx.rb, line 49</span>
<span class="kw">def</span> Template::[](f)
path = <span class="kw">case</span> f
<span class="kw">when</span> String
f
<span class="kw">when</span> REXML::Document
f.template_href
<span class="kw">else</span>
raise "unknown param #{f.type}"
<span class="kw">end</span>
doc = REXML::Document.new(REXML::File.new(path))
root = doc.elements[<span class="str">'amx'</span>]
req = root.attributes[<span class="str">'require'</span>]
require(req) <span class="kw">if</span> req
clsname = root.attributes[<span class="str">'class'</span>]
cls = <span class="kw">if</span> clsname
eval clsname
<span class="kw">else</span>
Template
<span class="kw">end</span>
cls.new(path, doc)
<span class="kw">end</span>
</pre>
<table summary="method" width="100%" cellspacing="0" cellpadding="5" border="0">
<tr><td class="methodtitle">
<a name="M000009"></a>
<b>new</b>(path, doc)
</td></tr>
</table>
<pre class="source">
<span class="cmt"># File lib/amrita/amx.rb, line 73</span>
<span class="kw">def</span> initialize(path, doc)
<span class="kw">super</span>()
@template_root = doc
@path = path
@xml = @asxml = <span class="kw">true</span>
init_amx
<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="M000010"></a>
<b>init_amx</b>()
</td></tr>
</table>
<pre class="source">
<span class="cmt"># File lib/amrita/amx.rb, line 81</span>
<span class="kw">def</span> init_amx
@template_root.elements.to_a(<span class="str">"amx/method"</span>).each <span class="kw">do</span> |m|
method_name = m.attributes[<span class="str">'id'</span>].to_s
code = m.elements[<span class="str">'method_body'</span>].get_text.to_s
define_method(method_name, code)
<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="M000011"></a>
<b>define_method</b>(method_name, code)
</td></tr>
</table>
<pre class="source">
<span class="cmt"># File lib/amrita/amx.rb, line 89</span>
<span class="kw">def</span> define_method(method_name, code)
instance_eval <span class="str">" def \#{method_name}\n \#{code}\n end\n"</span>
<span class="kw">end</span>
</pre>
<table summary="method" width="100%" cellspacing="0" cellpadding="5" border="0">
<tr><td class="methodtitle">
<a name="M000012"></a>
<b>get_model</b>()
</td></tr>
</table>
<pre class="source">
<span class="cmt"># File lib/amrita/amx.rb, line 98</span>
<span class="kw">def</span> get_model
<span class="kw">self</span>
<span class="kw">end</span>
</pre>
<table summary="method" width="100%" cellspacing="0" cellpadding="5" border="0">
<tr><td class="methodtitle">
<a name="M000013"></a>
<b>setup_context</b>()
</td></tr>
</table>
<pre class="source">
<span class="cmt"># File lib/amrita/amx.rb, line 102</span>
<span class="kw">def</span> setup_context
context = AmxContext.new(<span class="kw">self</span>)
context.delete_id = <span class="kw">false</span> <span class="kw">if</span> keep_id
context
<span class="kw">end</span>
</pre>
<table summary="method" width="100%" cellspacing="0" cellpadding="5" border="0">
<tr><td class="methodtitle">
<a name="M000014"></a>
<b>expand</b>(stream, doc)
</td></tr>
</table>
<pre class="source">
<span class="cmt"># File lib/amrita/amx.rb, line 108</span>
<span class="kw">def</span> expand(stream, doc)
@doc = doc
befor_expand
<span class="kw">super</span>(stream, get_model)
puts <span class="str">""</span>
<span class="kw">ensure</span>
@doc = <span class="kw">nil</span>
<span class="kw">end</span>
</pre>
<table summary="method" width="100%" cellspacing="0" cellpadding="5" border="0">
<tr><td class="methodtitle">
<a name="M000015"></a>
<b>befor_expand</b>()
</td></tr>
</table>
<pre class="source">
<span class="cmt"># File lib/amrita/amx.rb, line 117</span>
<span class="kw">def</span> befor_expand
<span class="kw">end</span>
</pre>
<table summary="method" width="100%" cellspacing="0" cellpadding="5" border="0">
<tr><td class="methodtitle">
<a name="M000016"></a>
<b>setup_template</b>()
</td></tr>
</table>
<pre class="source">
<span class="cmt"># File lib/amrita/amx.rb, line 120</span>
<span class="kw">def</span> setup_template
@template = rexml2amrita(@template_root.elements[<span class="str">'amx/template'</span>].elements)
<span class="kw">end</span>
</pre>
<table summary="method" width="100%" cellspacing="0" cellpadding="5" border="0">
<tr><td class="methodtitle">
<a name="M000017"></a>
<b>rexml2amrita</b>(xml)
</td></tr>
</table>
<pre class="source">
<span class="cmt"># File lib/amrita/amx.rb, line 124</span>
<span class="kw">def</span> rexml2amrita(xml)
<span class="kw">case</span> xml
<span class="kw">when</span> REXML::Element
h = {}
xml.attributes.each <span class="kw">do</span> |k,v|
h[k] = convert(v)
<span class="kw">end</span>
e(xml.name, h) {
xml.collect <span class="kw">do</span> |x|
rexml2amrita(x)
<span class="kw">end</span>
}
<span class="kw">when</span> REXML::Elements
ret = xml.collect <span class="kw">do</span> |x|
rexml2amrita(x)
<span class="kw">end</span>
Node::to_node(ret)
<span class="kw">when</span> REXML::Text
TextElement.new convert(xml.to_s)
<span class="kw">when</span> REXML::Instruction
<span class="str">"REXML::Instruction here(PENDING)"</span>
<span class="kw">else</span>
raise "can't convert #{xml.type}"
<span class="kw">end</span>
<span class="kw">end</span>
</pre>
</body>
|