Class: StaticShellTemplates::Template

Inherits:
Object
  • Object
show all
Defined in:
lib/static_shell_templates.rb

Constant Summary collapse

OPENING =
'#template: '
CLOSING =
'#template:end'

Instance Method Summary collapse

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

#includesObject



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

#replaceObject



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