Module: ModuleSync::Renderer

Defined in:
lib/modulesync/renderer.rb

Defined Under Namespace

Classes: ForgeModuleFile

Class Method Summary collapse

Class Method Details

.build(from_erb_template) ⇒ Object


12
13
14
15
16
17
# File 'lib/modulesync/renderer.rb', line 12

def self.build(from_erb_template)
  erb_obj = ERB.new(File.read(from_erb_template), nil, '-')
  erb_obj.filename = from_erb_template.chomp('.erb')
  erb_obj.def_method(ForgeModuleFile, 'render()')
  erb_obj
end

.remove(file) ⇒ Object


19
20
21
# File 'lib/modulesync/renderer.rb', line 19

def self.remove(file)
  File.delete(file) if File.exist?(file)
end

.render(_template, configs = {}) ⇒ Object


23
24
25
# File 'lib/modulesync/renderer.rb', line 23

def self.render(_template, configs = {})
  ForgeModuleFile.new(configs).render
end

.sync(template, to_file) ⇒ Object


27
28
29
30
31
32
33
# File 'lib/modulesync/renderer.rb', line 27

def self.sync(template, to_file)
  path = to_file.rpartition('/').first
  FileUtils.mkdir_p(path) unless path.empty?
  File.open(to_file, 'w') do |file|
    file.write(template)
  end
end