Parse placeholders in strings
Ruby
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
spec
.gitignore
Gemfile
LICENSE
README.rdoc
Rakefile
king_placeholder.gemspec

README.rdoc

KingPlaceholder

This gem was extraced from SalesKing where it handles placeholders substitution for user supplied email-, text- and export- templates.

Define the available methods in your class

class User
  include KingPlaceholder
  has_many :comments
  has_placeholders :firstname
end
class Comment
  include KingPlaceholder
  has_placeholders :text
end

Use placeholder names in square brackets:

@user.expand_placeholders("Hello [user.first_name]")
=> Hello Schorsch

It can also handle relations and collections

@user.expand_placeholders("[comments][text][/comments]")
=> All comment texts

@user.expand_placeholders("[comments.1.text]")
=> First comment text

TODO

This gems still relies on king_views with king_format, for money, date formatting. We will outsource king_format into its own gem and remove more SalesKing internal dependencies.

Installation

Add this line to your application's Gemfile:

gem 'king_placeholder'

And then execute:

$ bundle

Or install it yourself as:

$ gem install king_placeholder

Usage

See specs

Contributing

  1. Fork it

  2. Create your feature branch (`git checkout -b my-new-feature`)

  3. Commit your changes (`git commit -am 'Added some feature'`)

  4. Push to the branch (`git push origin my-new-feature`)

  5. Create new Pull Request