https://github.com/felipeelias/erb-view
Simple wrapper around ERB that lets you create class based views.
https://github.com/felipeelias/erb-view
erb ruby template
Last synced: 4 months ago
JSON representation
Simple wrapper around ERB that lets you create class based views.
- Host: GitHub
- URL: https://github.com/felipeelias/erb-view
- Owner: felipeelias
- License: mit
- Created: 2017-02-05T13:09:13.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2023-10-30T04:11:08.000Z (over 2 years ago)
- Last Synced: 2025-02-06T16:57:35.795Z (over 1 year ago)
- Topics: erb, ruby, template
- Language: Ruby
- Size: 25.4 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# [Erb::View](https://felipeelias.github.io/erb-view)
[](https://github.com/felipeelias/erb-view/actions/workflows/ci.yml)
[](https://badge.fury.io/rb/erb-view)
Simple wrapper around ERB that lets you create class based views.
## Installation
Add this line to your application's Gemfile:
```ruby
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
```ruby
Erb.root = 'lib/templates'
```
And then define your class.
```ruby
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`
```html
<%= title %>
Hello <%= name %>!
```
And use it in your code
```ruby
view = IndexView.new
view.render(name: 'World')
```
The result will be
```html
Index Page
Hello World!
```
## Development
```sh
$ 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](http://opensource.org/licenses/MIT).