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 :
Engine.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::Engine</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::Engine</td> </tr> <tr class="top-aligned-row"> <td><strong>In:</strong></td> <td> <a href="../../files/erubis/engine_rb.html"> erubis/engine.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> (abstract) abstract engine class. subclass must include evaluator and converter module. </p> </div> </div> <div id="method-list"> <h3 class="section-bar">Methods</h3> <div class="name-list"> <a href="#M000223">convert!</a> <a href="#M000224">load_file</a> <a href="#M000222">new</a> <a href="#M000225">process</a> <a href="#M000226">process_proc</a> </div> </div> </div> <!-- if includes --> <div id="section"> <!-- if method_list --> <div id="methods"> <h3 class="section-bar">Public Class methods</h3> <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">load_file</span><span class="method-args">(filename, properties={})</span> </a> </div> <div class="method-description"> <p> load file, write cache file, and return engine object. this method create code cache file automatically. cachefile name can be specified with properties[:cachename], or filname + ‘cache’ is used as default. </p> <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/engine.rb, line 48</span> <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">load_file</span>(<span class="ruby-identifier">filename</span>, <span class="ruby-identifier">properties</span>={}) <span class="ruby-identifier">cachename</span> = <span class="ruby-identifier">properties</span>[<span class="ruby-identifier">:cachename</span>] <span class="ruby-operator">||</span> (<span class="ruby-identifier">filename</span> <span class="ruby-operator">+</span> <span class="ruby-value str">'.cache'</span>) <span class="ruby-identifier">properties</span>[<span class="ruby-identifier">:filename</span>] = <span class="ruby-identifier">filename</span> <span class="ruby-identifier">timestamp</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">mtime</span>(<span class="ruby-identifier">filename</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">test</span>(<span class="ruby-value">?f</span>, <span class="ruby-identifier">cachename</span>) <span class="ruby-operator">&&</span> <span class="ruby-identifier">timestamp</span> <span class="ruby-operator">==</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">mtime</span>(<span class="ruby-identifier">cachename</span>) <span class="ruby-identifier">engine</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">new</span>(<span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">properties</span>) <span class="ruby-identifier">engine</span>.<span class="ruby-identifier">src</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">cachename</span>) <span class="ruby-keyword kw">else</span> <span class="ruby-identifier">input</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">filename</span>, <span class="ruby-value str">'rb'</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">f</span><span class="ruby-operator">|</span> <span class="ruby-identifier">f</span>.<span class="ruby-identifier">read</span> } <span class="ruby-identifier">engine</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">input</span>, <span class="ruby-identifier">properties</span>) <span class="ruby-identifier">tmpname</span> = <span class="ruby-identifier">cachename</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">rand</span>().<span class="ruby-identifier">to_s</span>[<span class="ruby-value">1</span>,<span class="ruby-value">8</span>] <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">tmpname</span>, <span class="ruby-value str">'wb'</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">f</span><span class="ruby-operator">|</span> <span class="ruby-identifier">f</span>.<span class="ruby-identifier">write</span>(<span class="ruby-identifier">engine</span>.<span class="ruby-identifier">src</span>) } <span class="ruby-constant">File</span>.<span class="ruby-identifier">rename</span>(<span class="ruby-identifier">tmpname</span>, <span class="ruby-identifier">cachename</span>) <span class="ruby-constant">File</span>.<span class="ruby-identifier">utime</span>(<span class="ruby-identifier">timestamp</span>, <span class="ruby-identifier">timestamp</span>, <span class="ruby-identifier">cachename</span>) <span class="ruby-keyword kw">end</span> <span class="ruby-identifier">engine</span>.<span class="ruby-identifier">src</span>.<span class="ruby-identifier">untaint</span> <span class="ruby-comment cmt"># ok?</span> <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">engine</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">new</span><span class="method-args">(input=nil, properties={})</span> </a> </div> <div class="method-description"> <p> include <a href="Evaluator.html">Evaluator</a> include <a href="Converter.html">Converter</a> include <a href="Generator.html">Generator</a> </p> <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/engine.rb, line 25</span> <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">input</span>=<span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">properties</span>={}) <span class="ruby-comment cmt">#@input = input</span> <span class="ruby-identifier">init_generator</span>(<span class="ruby-identifier">properties</span>) <span class="ruby-identifier">init_converter</span>(<span class="ruby-identifier">properties</span>) <span class="ruby-identifier">init_evaluator</span>(<span class="ruby-identifier">properties</span>) <span class="ruby-ivar">@src</span> = <span class="ruby-identifier">convert</span>(<span class="ruby-identifier">input</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">input</span> <span class="ruby-keyword kw">end</span> </pre> </div> </div> </div> <h3 class="section-bar">Public Instance methods</h3> <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">convert!</span><span class="method-args">(input)</span> </a> </div> <div class="method-description"> <p> convert input string and set it to @src </p> <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/engine.rb, line 37</span> <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">convert!</span>(<span class="ruby-identifier">input</span>) <span class="ruby-ivar">@src</span> = <span class="ruby-identifier">convert</span>(<span class="ruby-identifier">input</span>) <span class="ruby-keyword kw">end</span> </pre> </div> </div> </div> <div id="method-M000225" class="method-detail"> <a name="M000225"></a> <div class="method-heading"> <a href="#M000225" class="method-signature"> <span class="method-name">process</span><span class="method-args">(input, context=nil, filename=nil)</span> </a> </div> <div class="method-description"> <p> helper method to convert and evaluate input text with context object. context may be Binding, Hash, or Object. </p> <p><a class="source-toggle" href="#" onclick="toggleCode('M000225-source');return false;">[Source]</a></p> <div class="method-source-code" id="M000225-source"> <pre> <span class="ruby-comment cmt"># File erubis/engine.rb, line 72</span> <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">process</span>(<span class="ruby-identifier">input</span>, <span class="ruby-identifier">context</span>=<span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">filename</span>=<span class="ruby-keyword kw">nil</span>) <span class="ruby-identifier">code</span> = <span class="ruby-identifier">convert</span>(<span class="ruby-identifier">input</span>) <span class="ruby-identifier">filename</span> <span class="ruby-operator">||=</span> <span class="ruby-value str">'(erubis)'</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">context</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Binding</span>) <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">eval</span>(<span class="ruby-identifier">code</span>, <span class="ruby-identifier">context</span>, <span class="ruby-identifier">filename</span>) <span class="ruby-keyword kw">else</span> <span class="ruby-identifier">context</span> = <span class="ruby-constant">Context</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">context</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">context</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Hash</span>) <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">context</span>.<span class="ruby-identifier">instance_eval</span>(<span class="ruby-identifier">code</span>, <span class="ruby-identifier">filename</span>) <span class="ruby-keyword kw">end</span> <span class="ruby-keyword kw">end</span> </pre> </div> </div> </div> <div id="method-M000226" class="method-detail"> <a name="M000226"></a> <div class="method-heading"> <a href="#M000226" class="method-signature"> <span class="method-name">process_proc</span><span class="method-args">(proc_obj, context=nil, filename=nil)</span> </a> </div> <div class="method-description"> <p> helper method evaluate Proc object with contect object. context may be Binding, Hash, or Object. </p> <p><a class="source-toggle" href="#" onclick="toggleCode('M000226-source');return false;">[Source]</a></p> <div class="method-source-code" id="M000226-source"> <pre> <span class="ruby-comment cmt"># File erubis/engine.rb, line 88</span> <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">process_proc</span>(<span class="ruby-identifier">proc_obj</span>, <span class="ruby-identifier">context</span>=<span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">filename</span>=<span class="ruby-keyword kw">nil</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">context</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Binding</span>) <span class="ruby-identifier">filename</span> <span class="ruby-operator">||=</span> <span class="ruby-value str">'(erubis)'</span> <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">eval</span>(<span class="ruby-identifier">proc_obj</span>, <span class="ruby-identifier">context</span>, <span class="ruby-identifier">filename</span>) <span class="ruby-keyword kw">else</span> <span class="ruby-identifier">context</span> = <span class="ruby-constant">Context</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">context</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">context</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Hash</span>) <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">context</span>.<span class="ruby-identifier">instance_eval</span>(<span class="ruby-operator">&</span><span class="ruby-identifier">proc_obj</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>