# Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com # All files in this distribution are subject to the terms of the Ruby license. require 'ramaze/template/ezamar/engine' # This applies a morphing-replace for the template. # # To use the functionality of Morpher you will need to have hpricot # installed, you will get one error in case you don't and the method # will be replaced by a stub that simply returns the template. # # The method first checks if you use any morphers and just skips # the step if you don't, this should give quite some speedup for # smaller templates that don't use this functionality at all. # the check works by searching the morphs with appended '=' # in the template. There may be a few cases where this won't work # since we cannot make any assumptions on the format. # # If you want to turn this functionality off, either remove Morpher # from: # Ramaze::Template::Ezamar.trait[:transform_pipeline] # or do: # Ramaze::Morpher.trait[:morphs] = {} # # The latter is a tad slower, but i mention the possibility in case you # find good use for it. # # You can add your own morphers in Ramaze::Morpher.trait[:morphs] # # For Example: # # Morpher.trait[:morphs]['if'] = '%content' # # Now, assuming that some tag in your template is 'x' # # %morph stands for the name of your morph: 'if' # %expression is the stuff you write in the attribute: '@foo' # %content is the tag without the attribute (and all inside): 'x' class Ezamar::Morpher # Use this trait to define your custom morphs. trait :morphs => { 'if' => '%content', 'unless' => '%content', 'for' => '%content', 'each' => '%content', 'times' => '%content', } # Since the functionality is best explained by examples, here they come. # # Example: # # if: #