A basic implementation of replacing inline {{variables}} with values. Inspired by Shopify's Liquid
Add this line to your application's Gemfile:
gem 'parsable'
And then execute:
$ bundle
Or install it yourself as:
$ gem install parsable
context = Parsable::Context.new
context.system_store('email', 'name', 'Bert') # top level for pre-defined variables
Parsable.crunch(\
:string => %(my+{{email.name}}@email.com), :context => context
)
#=> [email protected]
context = Parsable::Context.new
context.custom_store('email', '[email protected]') # scoped to "custom" for user-entered variables
context.read('custom', 'email')
#=> '[email protected]'
Parsable.crunch(\
:string => %({{custom.email}} is my email!), :context => context
)
#=> [email protected] is my email!
Parsable.crunch(:string => "{{random.hex}} {{random.integer}}")
# "6e53a6dbab3a8e9b0eb9d467463c8a46 1392849191"
# note: {{random.integer}} is implemented by Time.now.to_i, so not really random at all.
Parsable.crunch(:string => "{{date.today}} {{date.year}} {{time.now}}")
# "2014-02-19 2014 2014-02-19 17:35:35 -0500"
- Fork it ( http://github.com//parsable/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request