Class: StaticShellTemplates::Template
- Inherits:
-
Object
- Object
- StaticShellTemplates::Template
- Defined in:
- lib/static_shell_templates.rb
Constant Summary collapse
- OPENING =
'#template: '- CLOSING =
'#template:end'
Instance Method Summary collapse
- #delete_end_end(content) ⇒ Object
- #includes ⇒ Object
-
#initialize(content, verbose: false) ⇒ Template
constructor
A new instance of Template.
- #replace ⇒ Object
Constructor Details
#initialize(content, verbose: false) ⇒ Template
Returns a new instance of Template.
10 11 12 13 14 |
# File 'lib/static_shell_templates.rb', line 10 def initialize(content, verbose: false) @content = content @logger = Logger.new(STDOUT) @verbose = verbose end |
Instance Method Details
#delete_end_end(content) ⇒ Object
22 23 24 |
# File 'lib/static_shell_templates.rb', line 22 def delete_end_end(content) content.gsub(/#{CLOSING}.*#{CLOSING}/m, CLOSING) end |
#includes ⇒ Object
26 27 28 29 30 |
# File 'lib/static_shell_templates.rb', line 26 def includes @content.scan(/#{OPENING}.*$/).map do |tpl| Include.new tpl, @logger end end |
#replace ⇒ Object
16 17 18 19 20 |
# File 'lib/static_shell_templates.rb', line 16 def replace delete_end_end(includes.reduce(@content) do |memo, inc| memo.gsub(inc.template, inc.output) end) end |