Class: Rodbot::Generator
- Inherits:
-
Object
- Object
- Rodbot::Generator
- Defined in:
- lib/rodbot/generator.rb
Overview
Generators for new bots, deployments and such
All files inside the templates_path
are honoured provided they match the GLOB. Files with the extension “.gerb” are parsed like ERB files, however, GERB tags must use square brackets.
ERB: <%= 'foobar' %>
GERB: [%= 'foobar' %]
It’s therefore possible to generate ERB files such as index.erb.gerb
.
Helpers available in GERB templates have to be defined in Helpers.
Defined Under Namespace
Classes: Helpers
Constant Summary collapse
- GLOB =
Glob to filter relevant template files
"**/{*,.ruby-version*,.gitignore,.keep}"
- TAG_COLORS =
Colors used by
info
to color part of the output { create: :green }.freeze
Instance Method Summary collapse
-
#display ⇒ Object
Print the interpolated template to STDOUT.
-
#initialize(templates_path) ⇒ Generator
constructor
A new instance of Generator.
-
#write(directory) ⇒ Object
Write the interpolated template to directory.
Constructor Details
Instance Method Details
#display ⇒ Object
Print the interpolated template to STDOUT
40 41 42 43 44 45 |
# File 'lib/rodbot/generator.rb', line 40 def display puts each_template_path do |template_path, target_path, content| puts "### #{target_path} ###", (content || template_path.read), nil end end |
#write(directory) ⇒ Object
Write the interpolated template to directory
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/rodbot/generator.rb', line 50 def write(directory) fail(Rodbot::GeneratorError, "cowardly refusing to write to existing #{directory}") if directory.exist? each_template_path do |template_path, target_path, content| absolute_target_path = directory.join(target_path) absolute_target_path.dirname.mkpath puts tag(:create, target_path) if content absolute_target_path.write(content) else FileUtils.copy(template_path, absolute_target_path) end end end |