Parsable Code Climate Build Status

A basic implementation of replacing inline {variables} with values. Inspired by Shopify's Liquid

Installation

Add this line to your application's Gemfile:

gem 'parsable'

And then execute:

$ bundle

Or install it yourself as:

$ gem install parsable

Usage

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!

Pre-defined

  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"

Contributing

  1. Fork it ( http://github.com//parsable/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request