Sha256: 73309017b04098ab271584e5e1acffe73b37be1bc96440d16af2e144a893c385

Contents?: true

Size: 849 Bytes

Versions: 10

Compression:

Stored size: 849 Bytes

Contents

require 'erb'
require 'find'

module ModuleSync
  module Renderer

    class ForgeModuleFile
      def initialize(configs= {})
        @configs = configs
      end
    end

    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

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

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

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

  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
modulesync-0.6.1 lib/modulesync/renderer.rb
modulesync-0.6.0 lib/modulesync/renderer.rb
modulesync-0.5.0 lib/modulesync/renderer.rb
modulesync-0.4.0 lib/modulesync/renderer.rb
modulesync-0.3.0 lib/modulesync/renderer.rb
modulesync-0.2.0 lib/modulesync/renderer.rb
modulesync-0.1.0 lib/modulesync/renderer.rb
modulesync-0.0.3 lib/modulesync/renderer.rb
modulesync-0.0.2 lib/modulesync/renderer.rb
modulesync-0.0.1 lib/modulesync/renderer.rb