public
Rubygem
Description: a humane, eval-safe templating system using Hpricot
Clone URL: git://github.com/mattly/hpreserve.git
Click here to lend your support to: hpreserve and make a donation at www.pledgie.com !
mattly (author)
Mon May 12 14:22:54 -0700 2008
commit  8b4863a478a377bc02fd320c88e2a3a02a486078
tree    b33925c6b3d0eb476565cf5393e09118ea3a4e1f
parent  d7151d861874f0d198e6bc59b1952f121f1e33d9
name age message
file .autotest Sat Mar 22 01:52:53 -0700 2008 autotest for lib/* [Matt Lyon]
file .gitignore Thu Apr 03 15:46:20 -0700 2008 ignore the bugs.yaml~ backup [mattly]
file History.txt Sat Mar 22 01:52:42 -0700 2008 initial parser and variable stack [Matt Lyon]
file License.txt Sun May 04 01:23:25 -0700 2008 capitalize my last name fool [mattly]
file Manifest.txt Thu Mar 27 16:55:20 -0700 2008 readme update, also allows us to build a gem now [Matt Lyon]
file README.txt Tue May 06 01:56:29 -0700 2008 update readme [mattly]
file Rakefile Wed Mar 26 21:41:51 -0700 2008 rake actually runs now [Matt Lyon]
file bugs.yaml Tue May 06 01:45:18 -0700 2008 ditz [mattly]
directory config/ Sun May 04 01:24:00 -0700 2008 we're not doing this on rubyforge, like, evar. ... [mattly]
directory lib/ Mon May 12 14:22:54 -0700 2008 and the filter knows about the parsers variable... [mattly]
directory script/ Sat Mar 22 01:52:42 -0700 2008 initial parser and variable stack [Matt Lyon]
file setup.rb Sat Mar 22 01:52:42 -0700 2008 initial parser and variable stack [Matt Lyon]
directory spec/ Mon May 12 14:22:54 -0700 2008 and the filter knows about the parsers variable... [mattly]
directory tasks/ Sat Mar 22 01:52:42 -0700 2008 initial parser and variable stack [Matt Lyon]
directory website/ Sat Mar 22 01:52:42 -0700 2008 initial parser and variable stack [Matt Lyon]
README.txt
= Hpreserve

* mailto:matt@flowerpowered.com

== DESCRIPTION:

Hpreserve is a humane, eval-safe template system built atop the Hpricot DOM
manipulation library. Its primary goal is to not require an interpreter to preview
a design in a browser. The designer provides their own sample data which is replaced
by the template parser at runtime.

Unlike similar DOM-replacement libraries lilu and Amrita, Hpreserve does not rely
on matching dom-ids to variable names, recognizing that dom_ids often have semantic
meaning in their own right. Rather, templates are driven by custom attributes on 
DOM elements that are removed at runtime.

== FEATURES/PROBLEMS:

* Content Replacement: elements with a "content" attribute will have their contents
  replaced with the equivalent variable. Namespaced variables are available to the
  template using '.' to separate the namespaces.

* Content Replacement with Collections: if the variable for an element's content
  attribute returns an Array, the element's first child node will be used as a 
  template for iterating over the content of the array. While iterating, the current
  item in the array is made available as a variable specified by the parent element's
  "local" attribute:
  
  <ul content='album.songs' local='song'><li content='song.name'>Song Name</li></ul>
  
  TODO: Currently, no attempt is made to prevent this local context variable naame 
  from clobbering an equivalent variable name elsewhere in the variable namespace.

* Partial Includes: Since this huge productivity booster can be replicated in 
  Textmate (and presumably other decent html editors), elements with an "include"
  tag have their content replaced by the given variable. You may provide a default 'root'
  in the variable namespace with "include_base=". Variable substitution is performed
  on the given value, and a default is available:
  
  <div include='{section.name}_sidebar | sidebar'></div>
  
  This would render f.e. 'blog_sidebar' if 'section.name' resolved to 'blog'. If this
  value returns empty (that is, there is no 'blog_sidebar') it will render the default
  'sidebar' instead.

* Filters: given by an element's "filter" attribute and specified using a syntax 
  similar to the "style" attribute in HTML, filters operate on the node itself, 
  either modifying the element's contents or altering the element's properties. Filter
  directives are separated by semi-colons, they may be given arguments after a colon, and
  multiple arguments are separated by commas:
  
  <a filter='capitalize; link_to: {thing.link}; truncate: 30, ...'>text</a> 
  
* Planned Features include more sophisticated controls for iterating over an array
  variable, and methods for escaping html entities in variables, including an option
  to do this automatically.

== SYNOPSIS:

template = File.open('example.html')
variables = {'name' => 'value'}
Hpreserve::Parser.render(template, variables)

== REQUIREMENTS:

* Hpricot

== LICENSE:

Copyright (c) 2008 Matt Lyon

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.