No commit activity in last 3 years
No release in over 3 years
Inline templates for Rails controllers with Arbre-like DSL
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
>= 0
>= 2

Runtime

 Project Readme

Inline Templates

Inline Templates allow you to write HTML markup in your controllers just like arbre, but without its inherent incompatibilities. All helpers - Rails builtin, provided by other gems and yours - are available out of box.

For example:

@inline_html = rit do
  ~ form_for(:session) do |f|
    ~ div(class: "fields") do
      ~ div(class: "field") do
        ~ f.label(:email, 'E-Mail')
        ~ f.text_field(:email)
      end
      ~ div(class: "field") do
        ~ f.label(:password, 'Password')
        ~ f.password_field(:password)
      end
    end

    ~ div(class: "actions") do
      ~ f.submit
    end
  end
end

Plain strings (i.e. not helpers output or variable values) should be escaped by t or h helper before passing them to ~ for output. t should be used for text and h should be used for HTML.

Inline Templates can also be used in views. It handles .rit files with same syntax.

Installation

Add this line to your application's Gemfile:

gem 'inline_templates'

And then execute:

$ bundle

Or install it yourself as:

$ gem install inline_templates

Usage

In Rails controllers:

class TestController < ApplicationController
  include InlineMarkup::Helpers

  def test
    @inline_html = rit(:list => [ 'a', 'b', 'c' ]) do
      ~ ul do
        list.each do |item|
          ~ li(item)
        end
      end
    end

Standalone:

view = ActionView::Base.new context, assigns, controller, formats
inline_html = InlineTemplates.render view, details, locals do
  ~ t('foo')
end

Contributing

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