a5e08f7bcc
I installed the rails_xss plugin, for the main purpose of seeing what will break with Rails 3.0 (where the behaviour of the plugin is the default). I think I've fixed everything, but let me know if you see stuff that is HTML-escaped, which shouldn't be. As a side benefit, we now use Erubis, rather than ERB, to render templates. They tell me it's faster ...
344 lines
14 KiB
HTML
344 lines
14 KiB
HTML
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
<!DOCTYPE html
|
|
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
|
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
<head>
|
|
<title>Class: Erubis::Context</title>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
|
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
|
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
|
<script type="text/javascript">
|
|
// <![CDATA[
|
|
|
|
function popupCode( url ) {
|
|
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
|
}
|
|
|
|
function toggleCode( id ) {
|
|
if ( document.getElementById )
|
|
elem = document.getElementById( id );
|
|
else if ( document.all )
|
|
elem = eval( "document.all." + id );
|
|
else
|
|
return false;
|
|
|
|
elemStyle = elem.style;
|
|
|
|
if ( elemStyle.display != "block" ) {
|
|
elemStyle.display = "block"
|
|
} else {
|
|
elemStyle.display = "none"
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
// Make codeblocks hidden by default
|
|
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
|
|
|
// ]]>
|
|
</script>
|
|
|
|
</head>
|
|
<body>
|
|
|
|
|
|
|
|
<div id="classHeader">
|
|
<table class="header-table">
|
|
<tr class="top-aligned-row">
|
|
<td><strong>Class</strong></td>
|
|
<td class="class-name-in-header">Erubis::Context</td>
|
|
</tr>
|
|
<tr class="top-aligned-row">
|
|
<td><strong>In:</strong></td>
|
|
<td>
|
|
<a href="../../files/erubis/context_rb.html">
|
|
erubis/context.rb
|
|
</a>
|
|
<br />
|
|
</td>
|
|
</tr>
|
|
|
|
<tr class="top-aligned-row">
|
|
<td><strong>Parent:</strong></td>
|
|
<td>
|
|
Object
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
<!-- banner header -->
|
|
|
|
<div id="bodyContent">
|
|
|
|
|
|
|
|
<div id="contextContent">
|
|
|
|
<div id="description">
|
|
<p>
|
|
context object for Engine#evaluate
|
|
</p>
|
|
<p>
|
|
ex.
|
|
</p>
|
|
<pre>
|
|
template = <<'END'
|
|
Hello <%= @user %>!
|
|
<% for item in @list %>
|
|
- <%= item %>
|
|
<% end %>
|
|
END
|
|
|
|
context = Erubis::Context.new(:user=>'World', :list=>['a','b','c'])
|
|
# or
|
|
# context = Erubis::Context.new
|
|
# context[:user] = 'World'
|
|
# context[:list] = ['a', 'b', 'c']
|
|
|
|
eruby = Erubis::Eruby.new(template)
|
|
print eruby.evaluate(context)
|
|
</pre>
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
<div id="method-list">
|
|
<h3 class="section-bar">Methods</h3>
|
|
|
|
<div class="name-list">
|
|
<a href="#M000219">[]</a>
|
|
<a href="#M000220">[]=</a>
|
|
<a href="#M000222">each</a>
|
|
<a href="#M000221">keys</a>
|
|
<a href="#M000218">new</a>
|
|
<a href="#M000223">to_hash</a>
|
|
<a href="#M000224">update</a>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
<!-- if includes -->
|
|
<div id="includes">
|
|
<h3 class="section-bar">Included Modules</h3>
|
|
|
|
<div id="includes-list">
|
|
<span class="include-name">Enumerable</span>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="section">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!-- if method_list -->
|
|
<div id="methods">
|
|
<h3 class="section-bar">Public Class methods</h3>
|
|
|
|
<div id="method-M000218" class="method-detail">
|
|
<a name="M000218"></a>
|
|
|
|
<div class="method-heading">
|
|
<a href="#M000218" class="method-signature">
|
|
<span class="method-name">new</span><span class="method-args">(hash=nil)</span>
|
|
</a>
|
|
</div>
|
|
|
|
<div class="method-description">
|
|
<p><a class="source-toggle" href="#"
|
|
onclick="toggleCode('M000218-source');return false;">[Source]</a></p>
|
|
<div class="method-source-code" id="M000218-source">
|
|
<pre>
|
|
<span class="ruby-comment cmt"># File erubis/context.rb, line 33</span>
|
|
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">hash</span>=<span class="ruby-keyword kw">nil</span>)
|
|
<span class="ruby-identifier">hash</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">name</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">|</span>
|
|
<span class="ruby-keyword kw">self</span>[<span class="ruby-identifier">name</span>] = <span class="ruby-identifier">value</span>
|
|
<span class="ruby-keyword kw">end</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">hash</span>
|
|
<span class="ruby-keyword kw">end</span>
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<h3 class="section-bar">Public Instance methods</h3>
|
|
|
|
<div id="method-M000219" class="method-detail">
|
|
<a name="M000219"></a>
|
|
|
|
<div class="method-heading">
|
|
<a href="#M000219" class="method-signature">
|
|
<span class="method-name">[]</span><span class="method-args">(key)</span>
|
|
</a>
|
|
</div>
|
|
|
|
<div class="method-description">
|
|
<p><a class="source-toggle" href="#"
|
|
onclick="toggleCode('M000219-source');return false;">[Source]</a></p>
|
|
<div class="method-source-code" id="M000219-source">
|
|
<pre>
|
|
<span class="ruby-comment cmt"># File erubis/context.rb, line 39</span>
|
|
<span class="ruby-keyword kw">def</span> <span class="ruby-operator">[]</span>(<span class="ruby-identifier">key</span>)
|
|
<span class="ruby-keyword kw">return</span> <span class="ruby-identifier">instance_variable_get</span>(<span class="ruby-node">"@#{key}"</span>)
|
|
<span class="ruby-keyword kw">end</span>
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="method-M000220" class="method-detail">
|
|
<a name="M000220"></a>
|
|
|
|
<div class="method-heading">
|
|
<a href="#M000220" class="method-signature">
|
|
<span class="method-name">[]=</span><span class="method-args">(key, value)</span>
|
|
</a>
|
|
</div>
|
|
|
|
<div class="method-description">
|
|
<p><a class="source-toggle" href="#"
|
|
onclick="toggleCode('M000220-source');return false;">[Source]</a></p>
|
|
<div class="method-source-code" id="M000220-source">
|
|
<pre>
|
|
<span class="ruby-comment cmt"># File erubis/context.rb, line 43</span>
|
|
<span class="ruby-keyword kw">def</span> <span class="ruby-operator">[]=</span>(<span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span>)
|
|
<span class="ruby-keyword kw">return</span> <span class="ruby-identifier">instance_variable_set</span>(<span class="ruby-node">"@#{key}"</span>, <span class="ruby-identifier">value</span>)
|
|
<span class="ruby-keyword kw">end</span>
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="method-M000222" class="method-detail">
|
|
<a name="M000222"></a>
|
|
|
|
<div class="method-heading">
|
|
<a href="#M000222" class="method-signature">
|
|
<span class="method-name">each</span><span class="method-args">() {|key, value| ...}</span>
|
|
</a>
|
|
</div>
|
|
|
|
<div class="method-description">
|
|
<p><a class="source-toggle" href="#"
|
|
onclick="toggleCode('M000222-source');return false;">[Source]</a></p>
|
|
<div class="method-source-code" id="M000222-source">
|
|
<pre>
|
|
<span class="ruby-comment cmt"># File erubis/context.rb, line 51</span>
|
|
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">each</span>
|
|
<span class="ruby-identifier">instance_variables</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">name</span><span class="ruby-operator">|</span>
|
|
<span class="ruby-identifier">key</span> = <span class="ruby-identifier">name</span>[<span class="ruby-value">1</span><span class="ruby-operator">..</span><span class="ruby-value">-1</span>]
|
|
<span class="ruby-identifier">value</span> = <span class="ruby-identifier">instance_variable_get</span>(<span class="ruby-identifier">name</span>)
|
|
<span class="ruby-keyword kw">yield</span>(<span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span>)
|
|
<span class="ruby-keyword kw">end</span>
|
|
<span class="ruby-keyword kw">end</span>
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="method-M000221" class="method-detail">
|
|
<a name="M000221"></a>
|
|
|
|
<div class="method-heading">
|
|
<a href="#M000221" class="method-signature">
|
|
<span class="method-name">keys</span><span class="method-args">()</span>
|
|
</a>
|
|
</div>
|
|
|
|
<div class="method-description">
|
|
<p><a class="source-toggle" href="#"
|
|
onclick="toggleCode('M000221-source');return false;">[Source]</a></p>
|
|
<div class="method-source-code" id="M000221-source">
|
|
<pre>
|
|
<span class="ruby-comment cmt"># File erubis/context.rb, line 47</span>
|
|
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">keys</span>
|
|
<span class="ruby-keyword kw">return</span> <span class="ruby-identifier">instance_variables</span>.<span class="ruby-identifier">collect</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">name</span><span class="ruby-operator">|</span> <span class="ruby-identifier">name</span>[<span class="ruby-value">1</span><span class="ruby-operator">..</span><span class="ruby-value">-1</span>] }
|
|
<span class="ruby-keyword kw">end</span>
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="method-M000223" class="method-detail">
|
|
<a name="M000223"></a>
|
|
|
|
<div class="method-heading">
|
|
<a href="#M000223" class="method-signature">
|
|
<span class="method-name">to_hash</span><span class="method-args">()</span>
|
|
</a>
|
|
</div>
|
|
|
|
<div class="method-description">
|
|
<p><a class="source-toggle" href="#"
|
|
onclick="toggleCode('M000223-source');return false;">[Source]</a></p>
|
|
<div class="method-source-code" id="M000223-source">
|
|
<pre>
|
|
<span class="ruby-comment cmt"># File erubis/context.rb, line 59</span>
|
|
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">to_hash</span>
|
|
<span class="ruby-identifier">hash</span> = {}
|
|
<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">key</span><span class="ruby-operator">|</span> <span class="ruby-identifier">hash</span>[<span class="ruby-identifier">key</span>] = <span class="ruby-keyword kw">self</span>[<span class="ruby-identifier">key</span>] }
|
|
<span class="ruby-keyword kw">return</span> <span class="ruby-identifier">hash</span>
|
|
<span class="ruby-keyword kw">end</span>
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="method-M000224" class="method-detail">
|
|
<a name="M000224"></a>
|
|
|
|
<div class="method-heading">
|
|
<a href="#M000224" class="method-signature">
|
|
<span class="method-name">update</span><span class="method-args">(context_or_hash)</span>
|
|
</a>
|
|
</div>
|
|
|
|
<div class="method-description">
|
|
<p><a class="source-toggle" href="#"
|
|
onclick="toggleCode('M000224-source');return false;">[Source]</a></p>
|
|
<div class="method-source-code" id="M000224-source">
|
|
<pre>
|
|
<span class="ruby-comment cmt"># File erubis/context.rb, line 65</span>
|
|
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">update</span>(<span class="ruby-identifier">context_or_hash</span>)
|
|
<span class="ruby-identifier">arg</span> = <span class="ruby-identifier">context_or_hash</span>
|
|
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">arg</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Hash</span>)
|
|
<span class="ruby-identifier">arg</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">key</span>, <span class="ruby-identifier">val</span><span class="ruby-operator">|</span>
|
|
<span class="ruby-keyword kw">self</span>[<span class="ruby-identifier">key</span>] = <span class="ruby-identifier">val</span>
|
|
<span class="ruby-keyword kw">end</span>
|
|
<span class="ruby-keyword kw">else</span>
|
|
<span class="ruby-identifier">arg</span>.<span class="ruby-identifier">instance_variables</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">varname</span><span class="ruby-operator">|</span>
|
|
<span class="ruby-identifier">key</span> = <span class="ruby-identifier">varname</span>[<span class="ruby-value">1</span><span class="ruby-operator">..</span><span class="ruby-value">-1</span>]
|
|
<span class="ruby-identifier">val</span> = <span class="ruby-identifier">arg</span>.<span class="ruby-identifier">instance_variable_get</span>(<span class="ruby-identifier">varname</span>)
|
|
<span class="ruby-keyword kw">self</span>[<span class="ruby-identifier">key</span>] = <span class="ruby-identifier">val</span>
|
|
<span class="ruby-keyword kw">end</span>
|
|
<span class="ruby-keyword kw">end</span>
|
|
<span class="ruby-keyword kw">end</span>
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div id="validator-badges">
|
|
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
|
</div>
|
|
|
|
</body>
|
|
</html> |