D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
opt
/
td-agent
/
embedded
/
lib
/
ruby
/
gems
/
2.1.0
/
gems
/
erubis-2.7.0
/
doc-api
/
classes
/
Erubis
/
Filename :
Context.html
back
Copy
<?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="#M000232">[]</a> <a href="#M000233">[]=</a> <a href="#M000235">each</a> <a href="#M000234">keys</a> <a href="#M000231">new</a> <a href="#M000236">to_hash</a> <a href="#M000237">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-M000231" class="method-detail"> <a name="M000231"></a> <div class="method-heading"> <a href="#M000231" 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('M000231-source');return false;">[Source]</a></p> <div class="method-source-code" id="M000231-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-M000232" class="method-detail"> <a name="M000232"></a> <div class="method-heading"> <a href="#M000232" 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('M000232-source');return false;">[Source]</a></p> <div class="method-source-code" id="M000232-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-M000233" class="method-detail"> <a name="M000233"></a> <div class="method-heading"> <a href="#M000233" 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('M000233-source');return false;">[Source]</a></p> <div class="method-source-code" id="M000233-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-M000235" class="method-detail"> <a name="M000235"></a> <div class="method-heading"> <a href="#M000235" 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('M000235-source');return false;">[Source]</a></p> <div class="method-source-code" id="M000235-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-M000234" class="method-detail"> <a name="M000234"></a> <div class="method-heading"> <a href="#M000234" 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('M000234-source');return false;">[Source]</a></p> <div class="method-source-code" id="M000234-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-M000236" class="method-detail"> <a name="M000236"></a> <div class="method-heading"> <a href="#M000236" 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('M000236-source');return false;">[Source]</a></p> <div class="method-source-code" id="M000236-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-M000237" class="method-detail"> <a name="M000237"></a> <div class="method-heading"> <a href="#M000237" 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('M000237-source');return false;">[Source]</a></p> <div class="method-source-code" id="M000237-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>