Project

erb-view

0.0
No release in over 3 years
Low commit activity in last 3 years
Simple wrapper around ERB that lets you create class based views
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 5.0
~> 12.3
 Project Readme

Erb::View

Build Status Gem Version Code Climate security

Simple wrapper around ERB that lets you create class based views.

Installation

Add this line to your application's Gemfile:

gem 'erb-view'

And then execute:

$ bundle

Or install it yourself as:

$ gem install erb-view

Usage

Erb::View lets you create reusable class based views. Start with a configuring the template directory

Erb.root = 'lib/templates'

And then define your class.

class IndexView
  include Erb::View

  # Reads a file named `index.erb` from the `root` specified
  template :index

  # This method is available on the ERB context
  def title
    'Index Page'
  end
end

In the root defined, create a file named index.erb

<h1><%= title %></h1>
<p>Hello <%= name %>!</p>

And use it in your code

view = IndexView.new
view.render(name: 'World')

The result will be

<h1>Index Page</h1>
<p>Hello World!</p>

Development

$ git clone git@github.com:felipeelias/erb-view.git
$ cd erb-view
$ bin/setup
$ rake test

You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/felipeelias/erb-view.

License

The gem is available as open source under the terms of the MIT License.