Sha256: 3d4190bd850bbe80f8f2ddb0bd1abebc3b46c2de4e7d8b3484b0dfcbb79da5a1

Contents?: true

Size: 1.54 KB

Versions: 2

Compression:

Stored size: 1.54 KB

Contents

= Overview

== Example Neapolitan Document

Here is an example Neapolitan template, 'vanilla.np':

    output: vanilla.html

    --- erb rdoc

    = Yummy Vanilla

    Hi <%= name %>,

    I know you want some of that yummy stuff.

    --- coderay.ruby

      %{v a n i l l a}.each do |letter|
        puts "Give me a #{letter}!"
      end

      puts "What's that spell?"

    --- liquid html

    <quote>
      {{ yield }}
    </quote>

    --- textile

    |                | 2009 | 2010 |
    | Has Vanilla?   |  No  | Yes! |

    As you can see. It's all _fun_ and _games_ here.

== Loading the Library

Require the library.

    require 'neapolitan'

== Reading a Neapolitan File

To load our example template, we can either pass a +File+ object to the 
+Template+ initializer.

    path = "vanilla.np"

    template = Neapolitan::Template.new(File.new(path))

Or we can use the shortcut +file+ method.

    template = Neapolitan.file(path)

== Rendering Data Sources

Neapolitan uses Malt on the backend. Malt supports a three separate ways to pass
data into a template.

The most obvious data source is a Hash.

    data = {:name=>"Tom"}

    text = template.render(data).to_s

    text.assert =~ /Hi Tom/

Templates can also be rendered given a Binding.

    name = "Huck"

    text = template.render(binding).to_s

    text.assert =~ /Hi Huck/

Lastly, they can be rendered with the scope of any other type of Object,
including an instance of a Struct.

    scope = Struct.new(:name).new("Becky")

    text = template.render(scope).to_s

    text.assert =~ /Hi Becky/

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
neapolitan-0.4.1 demo/01_overview.rdoc
neapolitan-0.4.0 demo/01_overview.rdoc