Sha256: 723c08e2ad19459ac3520fe99d8978c523fa75d9cc02a5e0f6d19271cf69da8a

Contents?: true

Size: 1.77 KB

Versions: 7

Compression:

Stored size: 1.77 KB

Contents

# 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:
```ruby
@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:
```ruby
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:
```ruby
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

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
inline_templates-1.0.0 README.md
inline_templates-0.0.6 README.md
inline_templates-0.0.5 README.md
inline_templates-0.0.4 README.md
inline_templates-0.0.3 README.md
inline_templates-0.0.2 README.md
inline_templates-0.0.1 README.md