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 :
Main.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::Main</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::Main</td> </tr> <tr class="top-aligned-row"> <td><strong>In:</strong></td> <td> <a href="../../files/erubis/main_rb.html"> erubis/main.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> <a href="Main.html#M000228">main</a> class of command </p> <p> ex. </p> <pre> Main.main(ARGV) </pre> </div> </div> <div id="method-list"> <h3 class="section-bar">Methods</h3> <div class="name-list"> <a href="#M000230">execute</a> <a href="#M000228">main</a> <a href="#M000229">new</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-M000228" class="method-detail"> <a name="M000228"></a> <div class="method-heading"> <a href="#M000228" class="method-signature"> <span class="method-name">main</span><span class="method-args">(argv=ARGV)</span> </a> </div> <div class="method-description"> <p><a class="source-toggle" href="#" onclick="toggleCode('M000228-source');return false;">[Source]</a></p> <div class="method-source-code" id="M000228-source"> <pre> <span class="ruby-comment cmt"># File erubis/main.rb, line 40</span> <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">main</span>(<span class="ruby-identifier">argv</span>=<span class="ruby-constant">ARGV</span>) <span class="ruby-identifier">status</span> = <span class="ruby-value">0</span> <span class="ruby-keyword kw">begin</span> <span class="ruby-constant">Main</span>.<span class="ruby-identifier">new</span>.<span class="ruby-identifier">execute</span>(<span class="ruby-constant">ARGV</span>) <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">CommandOptionError</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">ex</span> <span class="ruby-identifier">$stderr</span>.<span class="ruby-identifier">puts</span> <span class="ruby-identifier">ex</span>.<span class="ruby-identifier">message</span> <span class="ruby-identifier">status</span> = <span class="ruby-value">1</span> <span class="ruby-keyword kw">end</span> <span class="ruby-identifier">exit</span>(<span class="ruby-identifier">status</span>) <span class="ruby-keyword kw">end</span> </pre> </div> </div> </div> <div id="method-M000229" class="method-detail"> <a name="M000229"></a> <div class="method-heading"> <a href="#M000229" class="method-signature"> <span class="method-name">new</span><span class="method-args">()</span> </a> </div> <div class="method-description"> <p><a class="source-toggle" href="#" onclick="toggleCode('M000229-source');return false;">[Source]</a></p> <div class="method-source-code" id="M000229-source"> <pre> <span class="ruby-comment cmt"># File erubis/main.rb, line 51</span> <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span> <span class="ruby-ivar">@single_options</span> = <span class="ruby-value str">"hvxztTSbeBXNUC"</span> <span class="ruby-ivar">@arg_options</span> = <span class="ruby-value str">"pcrfKIlaE"</span> <span class="ruby-comment cmt">#C</span> <span class="ruby-ivar">@option_names</span> = { <span class="ruby-value str">'h'</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">:help</span>, <span class="ruby-value str">'v'</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">:version</span>, <span class="ruby-value str">'x'</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">:source</span>, <span class="ruby-value str">'z'</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">:syntax</span>, <span class="ruby-value str">'T'</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">:unexpand</span>, <span class="ruby-value str">'t'</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">:untabify</span>, <span class="ruby-comment cmt"># obsolete</span> <span class="ruby-value str">'S'</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">:intern</span>, <span class="ruby-value str">'b'</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">:bodyonly</span>, <span class="ruby-value str">'B'</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">:binding</span>, <span class="ruby-value str">'p'</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">:pattern</span>, <span class="ruby-value str">'c'</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">:context</span>, <span class="ruby-comment cmt">#'C' => :class,</span> <span class="ruby-value str">'e'</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">:escape</span>, <span class="ruby-value str">'r'</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">:requires</span>, <span class="ruby-value str">'f'</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">:datafiles</span>, <span class="ruby-value str">'K'</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">:kanji</span>, <span class="ruby-value str">'I'</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">:includes</span>, <span class="ruby-value str">'l'</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">:lang</span>, <span class="ruby-value str">'a'</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">:action</span>, <span class="ruby-value str">'E'</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">:enhancers</span>, <span class="ruby-value str">'X'</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">:notext</span>, <span class="ruby-value str">'N'</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">:linenum</span>, <span class="ruby-value str">'U'</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">:unique</span>, <span class="ruby-value str">'C'</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">:compact</span>, } <span class="ruby-identifier">assert</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@single_options</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">+</span> <span class="ruby-ivar">@arg_options</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">==</span> <span class="ruby-ivar">@option_names</span>.<span class="ruby-identifier">length</span> (<span class="ruby-ivar">@single_options</span> <span class="ruby-operator">+</span> <span class="ruby-ivar">@arg_options</span>).<span class="ruby-identifier">each_byte</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">ch</span><span class="ruby-operator">|</span> <span class="ruby-identifier">assert</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@option_names</span>.<span class="ruby-identifier">key?</span>(<span class="ruby-identifier">ch</span>.<span class="ruby-identifier">chr</span>) <span class="ruby-keyword kw">end</span> <span class="ruby-keyword kw">end</span> </pre> </div> </div> </div> <h3 class="section-bar">Public Instance methods</h3> <div id="method-M000230" class="method-detail"> <a name="M000230"></a> <div class="method-heading"> <a href="#M000230" class="method-signature"> <span class="method-name">execute</span><span class="method-args">(argv=ARGV)</span> </a> </div> <div class="method-description"> <p><a class="source-toggle" href="#" onclick="toggleCode('M000230-source');return false;">[Source]</a></p> <div class="method-source-code" id="M000230-source"> <pre> <span class="ruby-comment cmt"># File erubis/main.rb, line 87</span> <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">execute</span>(<span class="ruby-identifier">argv</span>=<span class="ruby-constant">ARGV</span>) <span class="ruby-comment cmt">## parse command-line options</span> <span class="ruby-identifier">options</span>, <span class="ruby-identifier">properties</span> = <span class="ruby-identifier">parse_argv</span>(<span class="ruby-identifier">argv</span>, <span class="ruby-ivar">@single_options</span>, <span class="ruby-ivar">@arg_options</span>) <span class="ruby-identifier">filenames</span> = <span class="ruby-identifier">argv</span> <span class="ruby-identifier">options</span>[<span class="ruby-value str">'h'</span>] = <span class="ruby-keyword kw">true</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">properties</span>[<span class="ruby-identifier">:help</span>] <span class="ruby-identifier">opts</span> = <span class="ruby-constant">Object</span>.<span class="ruby-identifier">new</span> <span class="ruby-identifier">arr</span> = <span class="ruby-ivar">@option_names</span>.<span class="ruby-identifier">collect</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">ch</span>, <span class="ruby-identifier">name</span><span class="ruby-operator">|</span> <span class="ruby-node">"def #{name}; @#{name}; end\n"</span> } <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">instance_eval</span> <span class="ruby-identifier">arr</span>.<span class="ruby-identifier">join</span> <span class="ruby-identifier">options</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">ch</span>, <span class="ruby-identifier">val</span><span class="ruby-operator">|</span> <span class="ruby-identifier">name</span> = <span class="ruby-ivar">@option_names</span>[<span class="ruby-identifier">ch</span>] <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">instance_variable_set</span>(<span class="ruby-node">"@#{name}"</span>, <span class="ruby-identifier">val</span>) <span class="ruby-keyword kw">end</span> <span class="ruby-comment cmt">## help, version, enhancer list</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">help</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">version</span> <span class="ruby-identifier">puts</span> <span class="ruby-identifier">version</span>() <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">version</span> <span class="ruby-identifier">puts</span> <span class="ruby-identifier">usage</span>() <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">help</span> <span class="ruby-identifier">puts</span> <span class="ruby-identifier">show_properties</span>() <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">help</span> <span class="ruby-identifier">puts</span> <span class="ruby-identifier">show_enhancers</span>() <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">help</span> <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">end</span> <span class="ruby-comment cmt">## include path</span> <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">includes</span>.<span class="ruby-identifier">split</span>(<span class="ruby-regexp re">/,/</span>).<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">path</span><span class="ruby-operator">|</span> <span class="ruby-identifier">$:</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">path</span> <span class="ruby-keyword kw">end</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">includes</span> <span class="ruby-comment cmt">## require library</span> <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">requires</span>.<span class="ruby-identifier">split</span>(<span class="ruby-regexp re">/,/</span>).<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">library</span><span class="ruby-operator">|</span> <span class="ruby-identifier">require</span> <span class="ruby-identifier">library</span> <span class="ruby-keyword kw">end</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">requires</span> <span class="ruby-comment cmt">## action</span> <span class="ruby-identifier">action</span> = <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">action</span> <span class="ruby-identifier">action</span> <span class="ruby-operator">||=</span> <span class="ruby-value str">'syntax'</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">syntax</span> <span class="ruby-identifier">action</span> <span class="ruby-operator">||=</span> <span class="ruby-value str">'convert'</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">source</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">notext</span> <span class="ruby-comment cmt">## lang</span> <span class="ruby-identifier">lang</span> = <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">lang</span> <span class="ruby-operator">||</span> <span class="ruby-value str">'ruby'</span> <span class="ruby-identifier">action</span> <span class="ruby-operator">||=</span> <span class="ruby-value str">'convert'</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">lang</span> <span class="ruby-comment cmt">## class name of Eruby</span> <span class="ruby-comment cmt">#classname = opts.class</span> <span class="ruby-identifier">classname</span> = <span class="ruby-keyword kw">nil</span> <span class="ruby-identifier">klass</span> = <span class="ruby-identifier">get_classobj</span>(<span class="ruby-identifier">classname</span>, <span class="ruby-identifier">lang</span>, <span class="ruby-identifier">properties</span>[<span class="ruby-identifier">:pi</span>]) <span class="ruby-comment cmt">## kanji code</span> <span class="ruby-identifier">$KCODE</span> = <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">kanji</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">kanji</span> <span class="ruby-comment cmt">## read context values from yaml file</span> <span class="ruby-identifier">datafiles</span> = <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">datafiles</span> <span class="ruby-identifier">context</span> = <span class="ruby-identifier">load_datafiles</span>(<span class="ruby-identifier">datafiles</span>, <span class="ruby-identifier">opts</span>) <span class="ruby-comment cmt">## parse context data</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">context</span> <span class="ruby-identifier">context</span> = <span class="ruby-identifier">parse_context_data</span>(<span class="ruby-identifier">opts</span>.<span class="ruby-identifier">context</span>, <span class="ruby-identifier">opts</span>) <span class="ruby-keyword kw">end</span> <span class="ruby-comment cmt">## properties for engine</span> <span class="ruby-identifier">properties</span>[<span class="ruby-identifier">:escape</span>] = <span class="ruby-keyword kw">true</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">escape</span> <span class="ruby-operator">&&</span> <span class="ruby-operator">!</span><span class="ruby-identifier">properties</span>.<span class="ruby-identifier">key?</span>(<span class="ruby-identifier">:escape</span>) <span class="ruby-identifier">properties</span>[<span class="ruby-identifier">:pattern</span>] = <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">pattern</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">pattern</span> <span class="ruby-comment cmt">#properties[:trim] = false if opts.notrim</span> <span class="ruby-identifier">properties</span>[<span class="ruby-identifier">:preamble</span>] = <span class="ruby-identifier">properties</span>[<span class="ruby-identifier">:postamble</span>] = <span class="ruby-keyword kw">false</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">bodyonly</span> <span class="ruby-identifier">properties</span>[<span class="ruby-identifier">:pi</span>] = <span class="ruby-keyword kw">nil</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">properties</span>[<span class="ruby-identifier">:pi</span>] <span class="ruby-operator">==</span> <span class="ruby-keyword kw">true</span> <span class="ruby-comment cmt">## create engine and extend enhancers</span> <span class="ruby-identifier">engine</span> = <span class="ruby-identifier">klass</span>.<span class="ruby-identifier">new</span>(<span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">properties</span>) <span class="ruby-identifier">enhancers</span> = <span class="ruby-identifier">get_enhancers</span>(<span class="ruby-identifier">opts</span>.<span class="ruby-identifier">enhancers</span>) <span class="ruby-comment cmt">#enhancers.push(Erubis::EscapeEnhancer) if opts.escape</span> <span class="ruby-identifier">enhancers</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">enhancer</span><span class="ruby-operator">|</span> <span class="ruby-identifier">engine</span>.<span class="ruby-identifier">extend</span>(<span class="ruby-identifier">enhancer</span>) <span class="ruby-identifier">engine</span>.<span class="ruby-identifier">bipattern</span> = <span class="ruby-identifier">properties</span>[<span class="ruby-identifier">:bipattern</span>] <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">enhancer</span> <span class="ruby-operator">==</span> <span class="ruby-constant">Erubis</span><span class="ruby-operator">::</span><span class="ruby-constant">BiPatternEnhancer</span> <span class="ruby-keyword kw">end</span> <span class="ruby-comment cmt">## no-text</span> <span class="ruby-identifier">engine</span>.<span class="ruby-identifier">extend</span>(<span class="ruby-constant">Erubis</span><span class="ruby-operator">::</span><span class="ruby-constant">NoTextEnhancer</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">notext</span> <span class="ruby-comment cmt">## convert and execute</span> <span class="ruby-identifier">val</span> = <span class="ruby-keyword kw">nil</span> <span class="ruby-identifier">msg</span> = <span class="ruby-value str">"Syntax OK\n"</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">filenames</span> <span class="ruby-operator">&&</span> <span class="ruby-operator">!</span><span class="ruby-identifier">filenames</span>.<span class="ruby-identifier">empty?</span> <span class="ruby-identifier">filenames</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">filename</span><span class="ruby-operator">|</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">file?</span>(<span class="ruby-identifier">filename</span>) <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">raise</span> <span class="ruby-constant">CommandOptionError</span>.<span class="ruby-identifier">new</span>(<span class="ruby-node">"#{filename}: file not found."</span>) <span class="ruby-identifier">engine</span>.<span class="ruby-identifier">filename</span> = <span class="ruby-identifier">filename</span> <span class="ruby-identifier">engine</span>.<span class="ruby-identifier">convert!</span>(<span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">filename</span>)) <span class="ruby-identifier">val</span> = <span class="ruby-identifier">do_action</span>(<span class="ruby-identifier">action</span>, <span class="ruby-identifier">engine</span>, <span class="ruby-identifier">context</span>, <span class="ruby-identifier">filename</span>, <span class="ruby-identifier">opts</span>) <span class="ruby-identifier">msg</span> = <span class="ruby-keyword kw">nil</span> <span class="ruby-keyword kw">if</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">engine</span>.<span class="ruby-identifier">filename</span> = <span class="ruby-identifier">filename</span> = <span class="ruby-value str">'(stdin)'</span> <span class="ruby-identifier">engine</span>.<span class="ruby-identifier">convert!</span>(<span class="ruby-identifier">$stdin</span>.<span class="ruby-identifier">read</span>()) <span class="ruby-identifier">val</span> = <span class="ruby-identifier">do_action</span>(<span class="ruby-identifier">action</span>, <span class="ruby-identifier">engine</span>, <span class="ruby-identifier">context</span>, <span class="ruby-identifier">filename</span>, <span class="ruby-identifier">opts</span>) <span class="ruby-identifier">msg</span> = <span class="ruby-keyword kw">nil</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">val</span> <span class="ruby-keyword kw">end</span> <span class="ruby-identifier">print</span> <span class="ruby-identifier">msg</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">action</span> <span class="ruby-operator">==</span> <span class="ruby-value str">'syntax'</span> <span class="ruby-operator">&&</span> <span class="ruby-identifier">msg</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>