class Composify::Template
Constants
- FILE_LIST
TODO: Make these work on windows?
Public Class Methods
new( file )
click to toggle source
# File lib/composify.rb, line 20 def initialize( file ) @file = file end
Public Instance Methods
destination()
click to toggle source
# File lib/composify.rb, line 24 def destination return @_destination ||= @file.gsub( /^\.\/templates\//, './' ).gsub(/\.erb/, '') end
result( bind )
click to toggle source
bind - the binding to use for ERB#result
# File lib/composify.rb, line 29 def result( bind ) ERB.new( File.read( File.expand_path( File.join("..", @file), __FILE__ ) ), nil, '-' ).result( bind ) end
write( bind, force: false )
click to toggle source
bind - the binding to use for ERB#result
# File lib/composify.rb, line 38 def write( bind, force: false ) if File.exists?( destination ) && !force STDERR.puts( "File already exists at #{destination}. Refusing to overwrite" ) return end if (dirname = File.dirname(destination)) != "." FileUtils.mkdir_p( dirname ) end puts "Attempting to write #{destination}" File.open( destination, "w" ) do |f| contents = result( bind ) f.write( contents ) end end