A tool to check a template against a specification
Ruby
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
features
lib
test
.document
.gitignore
LICENSE
README.rdoc
Rakefile
VERSION
lazy_templatetester.gemspec

README.rdoc

LazyTemplatetester

Specification of Templates

It is based on the lazy_configtester gem and has the same requirements for a specification. Currently only mustache templates might be checked.

Examples:

Specifications:

spec = {
    :children => {
                    :data => true,
                    /^attr$/ => {
                      :rel => true
                    },
                    /^has_children$/ => {
                      :self => true
                    },
                    /^has_state$/ => {
                      :state => true
                    }
                  }
 }

here :children is obligatory as a subentry with an obligatory data placeholder, attr, has_children and has_state are optional, but if there is an attr, it should have a rel placeholder (same for has_children and self and has_state and state).

the following template would match the spec

<ul>
{{#children}}
  <li {{#has_state}}class=\"{{state}}\"{{/has_state}}>
    <a href={{#attr}}\"{{rel}}\"{{/attr}}>{{data}}</a>
    {{#has_children}}{{>self}}{{/has_children}}
  </li>
{{/children}}
</ul>

Validation:

In order to check if a template matches the spec, create an instance of LazyTemplatetester and call check on it:

LazyTemplatetester.new(spec).check_mustache(template).check_mustache(template2).check_mustache(template3)

or

LazyTemplatetester.new.check_mustache(template,spec)

You may check your spec as well:

LazyTemplatetester.new(spec)

or

LazyTemplatetester.new.check_spec(spec)

Before any template check the specification is checked anyway. In case of a specification error, it throws an LazySpecError, in case of a template error it throws an LazyTemplateError. If everything is fine, it returns itself to allow method chaining.

Note on Patches/Pull Requests

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don't break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)

  • Send me a pull request. Bonus points for topic branches.

Copyright

Copyright © 2010 Marc Rene Arns. See LICENSE for details.