Project

erbh

0.0
Low commit activity in last 3 years
No release in over a year
Simple ERB helper.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

 Project Readme

ERBh

Simple ERB helper.

test

Installation

Add this line to your application's Gemfile:

gem 'erbh'

And then execute:

$ bundle

Or install it yourself as:

$ gem install erbh

Usage

require 'erbh'
include ERBh

erbh('<%= @foo %>, <%= @bar %>', foo: 100, bar: 'zoo')
#=> "100, zoo"

erbh(<<-EOS, {foo: 1..3}, trim_mode: '%')
% @foo.each do |i|
<%= i %>
% end
EOS
#=> "1\n2\n3\n"

Define helper method

require 'erbh'
include ERBh

ERBh.define_method(:concat) {|a, b| a + b }

erbh('<%= concat @foo, @bar %>', foo: 'a', bar: 'b')
#=> "ab"

ERBh.define_method(:chomp) do |obj|
  if obj.nil?
    @_erbout.sub!(/,\s*\z/, '')
    ''
  else
    obj
  end
end

erbh('100, <%= chomp @foo %>', foo: nil)
#=> "100"