Sha256: 83f97bbf10d24a933e5491bed2f4d2a719d7bb095bee85f61f57c33555803fbf
Contents?: true
Size: 1.56 KB
Versions: 11
Compression:
Stored size: 1.56 KB
Contents
module Sprout::Generator class FileManifest < Manifest attr_accessor :template attr_accessor :templates def create content = resolve_template if File.exists?(path) if generator.force write_file path, content say "Replaced file: #{path}" true else say "Skipped file: #{path}" false end else write_file path, content say "Created file: #{path}" true end end def destroy if !File.exists?(path) say "Skipped remove missing file: #{path}" return true end expected_content = resolve_template actual_content = File.read path if generator.force || actual_content == expected_content FileUtils.rm path say "Removed file: #{path}" true else say "Skipped remove file: #{path}" false end end protected def write_file path, content File.open path, 'w+' do |file| file.write content end end def resolve_template read_source end def read_source templates.each do |template_path| path = File.join template_path, source_name if File.exists?(path) return File.read path end end raise Sprout::Errors::MissingTemplateError.new "Could not find template (#{source_name}) in any of the following paths:\n\n (#{templates.inspect})\n\n" end def source_name template || File.basename(path) end end end
Version data entries
11 entries across 11 versions & 1 rubygems