Templatable
Templatable is CLI tool that generate ruby-source-code using ERB template.
Installation
Add this line to your application's Gemfile:
gem 'templatable'
And then execute:
$ bundle
Or install it yourself as:
$ gem install templatable
Usage
before execute
templatable use 'templatable module' that is provided by 'tbpgr_utils' gem.
so, you must install 'tbpgr_utils' gem(=>0.0.5), before use this gem.
generate Templatablefile
- templatable init
output Templatablefile
# encoding: utf-8
# output_fullpath
# output_fullpath is required
# output_fullpath allow only String
# output_fullpath's default value => "output_fullpath"
output_fullpath "output_fullpath"
# class_name
# class_name is required
# class_name allow only String
# class_name's default value => "class_name"
class_name "class_name"
TEMPLATE ="TODO: set your template(ERB format)\n"
# template
# template is required
# template allow only String
# template's default value => "TODO: set your template(ERB format)"
template TEMPLATE
# placeholders
# placeholders is required
# placeholders allow only String-Array
# placeholders's default value => []
placeholders []
edit Templatablefile manually
# encoding: utf-8
output_fullpath "./sample_use.rb"
class_name "sample_use"
TEMPLATE ="line1:<%=param1%>\nline2:<%=param2%>\n"
template TEMPLATE
placeholders ["param1", "param2"]
generate templatable class
- templatable execute
sample_use.rb
# encoding: utf-8
require 'templatable'
class SampleUse
include Templatable
template "line1:<%=placeholders[:param1]%>\nline2:<%=placeholders[:param2]%>\n EOS\n\n def manufactured_param1\n # TODO: implement your logic\n end\n\n def manufactured_param2\n # TODO: implement your logic\n end\nend\n"
edit your logic
sample_use.rb
require 'templatable'
class SampleUse
include Templatable
template "line1:<%=placeholders[:param1]%>\nline2:<%=placeholders[:param2]%>\n EOS\n\n def manufactured_param1\n \"ret1-\#{@materials}\"\n end\n\n def manufactured_param2\n \"ret2-\#{@materials}\"\n end\nend\n"
use your class
puts SampleUse.new("input").result
output
line1:ret1-input
line2:ret2-input
Notes
- Templatable output code use 'tbpgr_utils' gem(=>0.0.5).
- if you want to generate RSpec-spec for this class, use 'rspec_piccolo' gem.
History
- version 0.0.1 : first release.
Contributing
- 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