Nes

 view release on metacpan or  search on metacpan

share/examples/tutorial/index.html  view on Meta::CPAN


<ul>

	<li><a href="#name">NAME</a></li>
	<li><a href="#install_nes">Install Nes</a></li>
	<li><a href="#create_work_space_for_tutorial">Create Work Space for Tutorial</a></li>
	<li><a href="#create_first_nes_template">Create first Nes Template</a></li>
	<li><a href="#includes_and_object">Includes and Object</a></li>
	<li><a href="#nes_environment_variables">Nes Environment Variables</a></li>
	<li><a href="#conditional_replacement">Conditional Replacement</a></li>
	<li><a href="#data_tables">Data Tables</a></li>
	<li><a href="#plugins">Plugins</a></li>
	<li><a href="#forms">Forms</a></li>
	<li><a href="#author">AUTHOR</a></li>
	<li><a href="#version">VERSION</a></li>
	<li><a href="#copyright">COPYRIGHT</a></li>
	<li><a href="#license">LICENSE</a></li>
	<li><a href="#disclaimer">DISCLAIMER</a></li>
	<li><a href="#see_also">SEE ALSO</a></li>
</ul>

<hr name="index" />
</div>
<!-- INDEX END -->

<p>
</p>
<h1><a name="name">NAME</a></h1>
<p>Nes::Tutorial - Step by Step Nes Tutorial.</p>
<p>
</p>
<hr />
<h1><a name="install_nes">Install Nes</a></h1>
<p>See: README file</p>
<p>
</p>
<hr />
<h1><a name="create_work_space_for_tutorial">Create Work Space for Tutorial</a></h1>
<p>We assume you already have installed and enabled Nes for cgi-bin.</p>
<p>According to its distribution its web root directory could be in 
/var/www/html, /var/www/htdocs, etc.</p>
<p>For this tutorial we will assume that your web root directory is
/var/www, change it throughout the tutorial if needed.</p>
<p>Create a working directory on your web root directory with the 
name nes_tutorial</p>
<pre>
    mkdir /var/www/nes_tutorial</pre>
<p>The next step is to set this directory to make it possible executing 
Nes templates, is done with the shell command:</p>
<pre>
    set_nes_site</pre>
<p>Configured:</p>
<pre>
    set_nes_site --dir_cfg=/var/www/nes_tutorial</pre>
<p>With this we have created a file .htaccess with the configuration
because Nes templates can execute in this directory.</p>
<p>The .nes.cfg file serve to configure Nes and also for your own
Perl script or application. There is a value that needs to be changed,
otherwise Nes release a warning:</p>
<pre>
    private_key</pre>
<p>It is a password used to encrypt data such as cookies, so it is very 
important to give a value to private_key.</p>
<p>Create a file in /var/www/nes_tutorial with the name .nes.cfg, with the
following content.</p>
<p>/var/www/nes_tutorial/.nes.cfg:</p>
<pre>
    private_key      = ChangeIt
    nes_tutorial_var = test variable</pre>
<p>Change 'changeit' with the password you want. And with this 
nes_tutorial is ready to work.</p>
<p>
</p>
<hr />
<h1><a name="create_first_nes_template">Create first Nes Template</a></h1>
<p>Nes templates have the extension .nhtml, any file with this extension, 
in nes_tutorial directory, will be treated as a Nes template.</p>
<p>Create a file named 'nes_01.nhtml' in 'nes_tutorial' with following 
contents:</p>
<pre>
    &lt;html&gt;
      &lt;head&gt;
        &lt;title&gt;Nes Tutorial&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
      &lt;b&gt;Hello Nes Tutorial&lt;/b&gt;
      &lt;/body&gt;
    &lt;/html&gt;</pre>
<p>To show it works:</p>
<pre>
    <a href="./nes_01.nhtml">http://yousite/nes_tutorial/nes_01.nhtml</a></pre>
<p>* Change 'yousite' with your domain or 'localhost'</p>
<p>'nes_01.nhtml' has no special feature, is only HTML. To include dynamic
content, must tell Nes to run a script for this template.</p>
<p>We therefore need a Perl script. Creates a file named 'script_02.pl' 
in 'nes_tutorial' with the following contents:</p>
<pre>
    #!/usr/bin/perl</pre>
<pre>
    use Nes;
    my $nes = Nes::Singleton-&gt;new();</pre>
<pre>
    $nes-&gt;out();</pre>
<pre>
    1;</pre>
<p>It is very important that Nes scripts returns 1, or displays an error. 
Another feature is that you do not need permission of execution to run
the script, unless you want run the script and not the template.</p>
<p>Now we tell the template that our script is 'script_02.pl' with
the Tag '{: NES 1.0 ( 'script_02.pl' ) :}'</p>
<p>Therefore we create a new template with the name 'nes_02.nhtml' and
the following contents:</p>
<pre>
    {: NES 1.0 ( 'script_02.pl' ) :}
    &lt;html&gt;
      &lt;head&gt;
        &lt;title&gt;Nes Tutorial&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
      &lt;b&gt;Hello Nes Tutorial&lt;/b&gt;
      &lt;/body&gt;
    &lt;/html&gt;</pre>
<p>When we do:</p>
<pre>
    <a href="./nes_02.nhtml">http://yousite/nes_tutorial/nes_02.nhtml</a></pre>
<p>Nes load and run script_02.pl</p>
<p>But our template continues without doing anything special, we will create
another script with the name 'script_03.pl' with the following contents:</p>



( run in 1.759 second using v1.01-cache-2.11-cpan-39bf76dae61 )