chef
https://github.com/opscode/chef
Ruby
A systems integration framework, built to bring the benefits of configuration management to your entire infrastructure.
Chef::Resource::Template#helper
Declares a helper method to be defined in the template context when
rendering.
=== Example:
==== Basic usage:
Given the following helper:
helper(:static_value) { "hello from helper" }
A template with the following code:
<%= static_value %>
Will render as;
hello from helper
==== Referencing Instance Variables:
Any instance variables available to the template can be referenced in
the method body. For example, you can simplify accessing app-specific
node attributes like this:
helper(:app) { @node[:my_app_attributes] }
And use it in a template like this:
<%= app[:listen_ports] %>
This is equivalent to the non-helper template code:
<%= @node[:my_app_attributes][:listen_ports] %>
==== Method Arguments:
Helper methods can also take arguments. The syntax available for
argument specification supports full syntax available for method
definition.
Continuing the above example of simplifying attribute access, we can
define a helper to look up app-specific attributes like this:
helper(:app) { |setting| @node[:my_app_attributes][setting] }
The template can then look up attributes like this:
<%= app(:listen_ports) %>Edit
git clone [email protected]:opscode/chef.git
cd chef
open lib/chef/resource/template.rb
Contribute
# Make a new branchgit checkout -b -your-name--update-docs-Chef--Resource--Template-helper-for-pr
# Commit to gitgit add lib/chef/resource/template.rbgit commit -m "better docs for Chef::Resource::Template#helper"
# Open pull requestgem install hub # on a mac you can `brew install hub`
hub fork
git push <your name> -your-name--update-docs-Chef--Resource--Template-helper-for-pr
hub pull-request
# Celebrate!