public
Rubygem
Description: A XHTML templating engine written in Ruby based on so-called pipes
Homepage: http://ramaze.net
Clone URL: git://github.com/manveru/nagoro.git
Click here to lend your support to: nagoro and make a donation at www.pledgie.com !
nagoro /
name age message
file README.markdown Sun May 25 03:59:59 -0700 2008 correct firstname of Kashia [fabianbuch]
file Rakefile Thu Aug 14 00:06:34 -0700 2008 New specs in place [manveru]
file bench.rb Tue Dec 25 04:28:00 -0800 2007 Adding StringScanner wrapper, fastest and most ... [manveru]
directory bin/ Tue Dec 25 04:28:00 -0800 2007 Adding StringScanner wrapper, fastest and most ... [manveru]
directory doc/ Wed May 14 18:39:22 -0700 2008 Put /doc/README at /README.markdown [manveru]
directory example/ Fri Nov 30 05:09:00 -0800 2007 Major refactor for Pipe::Morpher, it's now call... [manveru]
directory lib/ Thu Aug 14 00:06:34 -0700 2008 New implementation in place [manveru]
file nagoro.gemspec Wed May 14 22:06:42 -0700 2008 Adding gemspec task and gemspec [manveru]
directory spec/ Thu Aug 14 00:06:34 -0700 2008 New specs in place [manveru]
README.markdown
       Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com

All files in this distribution are subject to the terms of the Ruby license.

About Nagoro

Nagoro is a templating engine for XHTML based on different parsing engines. It featues a modular code layout and is used in the Ramaze web framework.

Nagoro consists of a series of so-called pipes to produce valid ruby from the templates that are eventually evaluated with custom binding.

All functionality of Nagoro is carefully tested by a series of specs to avoid breakage and give a good overview of nagoros capabilities.

Features Overview

  • Pipes

    Pipes are pluggable subclasses of Nagoro::Pipe::Base or respond to ::process and the returned value should provide a #to_html method.

    • Element

    Elements are tags that correspond to classes.

    • Include

    Transforms <include href="file" /> tags, file is passed to Kernel::open and so you can even include remote locations if you require 'open-uri'

    • Instruction

    Instructions have a syntax of <?name instruction?>, most common is <?r code ?> to evaluate ruby code without outputting it.

    • Localization

    Not based on Pipe::Base, processes the template by a regular expression and substitutes keys with localized strings.

    • Morph

    Custom tag parameters like <div if="cond">condition is fulfilled</div>

  • Engines

    Nagoro utilizes different engines to accomplish template transformation, currently the "best" engine is hand-written using StringScanner.

    • StringScanner

    StringScanner is a part of Ruby standard library that provides lexical scanning operations on a String. It is mostly implemented in C, which makes it quite fast and efficient. Our implementation is not a strict XML/SGML parser and allows for arbitrary code inside the templates, this will be the engine you want to use most likely.

    • libxml-ruby

    These are the Ruby bindings for GNU/LibXML2, we are using the SaX2 interface. It should give you the best performance on large and standard conform documents, but it doesn't allow for arbitrary code inside the template as we have to feed it the document before doing any transformation or interpolation.

    • REXML

    REXML is a pure Ruby, XML 1.0 conforming, non-validating toolkit with an intuitive API. REXML passes 100% of the non-validating Oasis tests, and provides tree, stream, SAX2, pull, and lightweight APIs. REXML also includes a full XPath 1.0 implementation. Since Ruby 1.8, REXML is included in the standard Ruby distribution.

    REXML was used for the first implementations of Nagoro, but for performance reasons libxml and StringScanner were introduced later on. It here is mostly to give a third example of how to wrap an engine or to give an idea of how a document would behave if it was fed into libxml as both are strict parsers.

Installation

eaaa548e89decfe17f6b23ab22d48464

Add a file to your site_ruby named nagoro.rb the content should be:

  require '/path/to/git/repo/nagoro/lib/nagoro'
  • Get the latest version (from inside the nagoro directory)

    $ git pull

  • Recording a patch

    $ git commit -a

  • output your patches into a bundle ready to be mailed (compress it before sending to make sure it arrives in the way you sent it)

    $ git format-patch origin/HEAD $ tar -cjf ramaze_bundle.tar.bz2 *.patch

Getting started

See the installation section for how to install nagoro. After installation you can use nagoro in a couple of ways

  • CLI

    From commandline using the nagoro executable.

    $ nagoro yourfile.xhtml
    
  • In Ruby

    Using Nagoro::render_file

    nagoro = Nagoro.render_file('yourfile.xhtml')
    xhtml = nagoro.result(binding)
    puts xhtml
    

    Using Nagoro::render

    nagoro = Nagoro.render('<?r a = 42 ?>#{a * 42}')
    xhtml = nagoro.result(binding)
    puts xhtml
    

    Using Nagoro::render with filename, useful because it shows up in backtraces.

    nagoro = Nagoro.render('<?r a = 42 ?>#{a * 42}', :file => 'foo.xhtml')
    xhtml = nagoro.result(binding)
    puts xhtml
    

Examples

Examples can be found in the /example directory.

And thanks to...

This list is by no means a full listing of all these people, but I try to get a good coverage despite that.

  • Yukihiro Matsumoto a.k.a. matz

    For giving the world Ruby and bringing joy and passion back into programming.

  • Jim Weirich

    For Rake, which lifts off a lot of tasks from the shoulders of every developer using it.

  • George Moschovitis a.k.a. gmosx

    For the Nitro web framework. Its templating engine has been the inspiration for nagoro.

  • Jonathan Buch a.k.a. Kashia

    For the first implementation of the Localization mechanism which is mostly ported from Ramaze.

  • Sean Russell

    For REXML, it's one of the engines that drive nagoro.

  • Sean Chittenden and Wai-Sun Chia

    For libxml-ruby, it's one of the engines that drive nagoro.