Project

erbb

0.0
No commit activity in last 3 years
No release in over 3 years
ERB with Blocks
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 1.16
~> 10.0
~> 3.0
 Project Readme

Build Status

ERBB

ERBB is ERB, with the additional ability to name blocks and save the output of rendering those blocks separately. It works exactly like ERB, with some additional methods.

Installation

Add this line to your application's Gemfile:

gem 'erbb'

And then execute:

$ bundle

Or install it yourself as:

$ gem install erbb

Usage

ERBB is built on top of ERB. It implements a #named_block method in templates which tells the parser to save the rendered contents of the block. In every other way, ERBB is used the same way as ERB.

First, set up your erb template and instantiate.

template = <<~TEMPLATE
             some text
             <% named_block :foo do %>
             some text in the named block
             <% end %>
             some more text
           TEMPLATE

erbb = ERBB.new(template)

Then call #result to get the rendered output

result = erbb.result(binding)
=> "some text\nsome text in the named block\nsome more text\n"

The result is a string-like object that has a #named_blocks method that returns the rendered contents of all the named blocks in the template.

result.named_blocks
=> {:foo=>"some text in the named block\n"}

Also, for convenience, the result delegates method calls to #named_blocks if they don't collide with String methods

result.foo
=> "some text in the named block\n"

That's pretty much it. Use it like ERB.

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/josh-lauer/erbb.

License

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