Stencil is a small framework to generate very reusable and testable views. Each stencil class has its own methods and template file. It's inspired by Erector to allow for inheritance and encapsulation without losing the convenience of template files.
Add this line to your application's Gemfile:
gem 'stencil', git: "git://github.com/cohitre/stencil.git"
And then execute:
$ bundle
# app/stencils/user_information_stencil.rb
class UserInformationStencil < Stencil::Base
template "user_information_stencil"
needs :user
optional size: :small
def big?
@size == :big
end
def small?
@size == :small
end
def name
@user.name
end
end
# app/stencils/user_information_stencil.html.erb
<div class="user <%= "user-big" if big? %>">
<strong><%= name %></strong>
</div>
- #user_profile.haml
:ruby
# initialize your stencil instance
user_profile = UserInformationStencil.new(user: current_user, size: :big)
= user_profile.render
If you're using Rails, Stencil will look in app/stencils
for
templates to be used with it (.erb
or .haml
files).
- Fork it
- 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