Project

deas-nm

0.0
No commit activity in last 3 years
No release in over 3 years
Deas template engine for Nm templates
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.16.3

Runtime

~> 0.43.4
~> 0.5.4
 Project Readme

Deas::Nm

Deas template engine for rendering Nm templates

Usage

Register the engine:

require 'deas'
require 'deas-nm'

Deas.configure do |c|

  c.template_source "/path/to/templates" do |s|
    s.engine 'nm', Deas::Nm::TemplateEngine
  end

end

Add .nm to any template files in your template source path. Deas will render their content using Nm when they are rendered.

Serialization

Nm doesn't serialize the objects it renders - it just returns them. However, Deas expects serialized body content. By default, the rendered objects are not serialized.

To serialize the rendered objects, specify a serializer when registering:

# this uses Oj to serialize to JSON (for example)
c.template_source "/path/to/templates" do |s|
  s.engine('nm', Deas::Nm::TemplateEngine, {
    'serializer' => proc{ |obj, template_name| Oj.dump(obj, :mode => :strict) }
  })
end

The template name is passed to any serializer proc. This can be helpful if choosing how to serialize is conditonal upon the template name. For example:

c.template_source "/path/to/templates" do |s|
  s.engine('nm', Deas::Nm::TemplateEngine, {
    'serializer' => proc do |obj, template_name|
      if File.extname(template_name) == '.json'
        Oj.dump(obj, :mode => :strict)
      else
        # serialize some other way?
      end
    end
  })
end

Notes

Nm doesn't allow overriding the template scope but instead allows you to pass in data that binds to the template scope as local methods. By default, the view handler will be bound to Nm's scope via the view method in templates. If you want to change this, provide a 'handler_local' option when registering:

c.template_source "/path/to/templates" do |s|
  s.engine 'nm', Deas::Nm::TemplateEngine, 'handler_local' => 'view_handler'
end

Nm doesn't cache templates by default. To enable caching, pass a 'cache' option when registering:

  c.template_source "/path/to/templates" do |s|
    s.engine 'nm', Deas::Nm::TemplateEngine, 'cache' => true
  end

Installation

Add this line to your application's Gemfile:

gem 'deas-nm'

And then execute:

$ bundle

Or install it yourself as:

$ gem install deas-nm

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request