Sha256: dcfcca4f4c89dfb65bdf196ef075ec781cd941c4286557fc3ea4769a5fff99a1

Contents?: true

Size: 1.22 KB

Versions: 28

Compression:

Stored size: 1.22 KB

Contents

module Sprout::Generator

  class FileManifest < Manifest
    attr_accessor :template
    attr_accessor :templates

    def create
      content = resolve_template
      
      File.open path, 'w+' do |file|
        file.write content
      end
      say "Created file:      #{path}"
      true
    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 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

28 entries across 28 versions & 1 rubygems

Version Path
sprout-1.1.3.pre lib/sprout/generator/file_manifest.rb
sprout-1.1.2.pre lib/sprout/generator/file_manifest.rb
sprout-1.0.35.pre lib/sprout/generator/file_manifest.rb
sprout-1.0.32.pre lib/sprout/generator/file_manifest.rb
sprout-1.0.31.pre lib/sprout/generator/file_manifest.rb
sprout-1.0.29.pre lib/sprout/generator/file_manifest.rb
sprout-1.0.26.pre lib/sprout/generator/file_manifest.rb
sprout-1.0.25.pre lib/sprout/generator/file_manifest.rb
sprout-1.0.24.pre lib/sprout/generator/file_manifest.rb
sprout-1.0.23.pre lib/sprout/generator/file_manifest.rb
sprout-1.0.22.pre lib/sprout/generator/file_manifest.rb
sprout-1.0.20.pre lib/sprout/generator/file_manifest.rb
sprout-1.0.19.pre lib/sprout/generator/file_manifest.rb
sprout-1.0.18.pre lib/sprout/generator/file_manifest.rb
sprout-1.0.17.pre lib/sprout/generator/file_manifest.rb
sprout-1.0.16.pre lib/sprout/generator/file_manifest.rb
sprout-1.0.15.pre lib/sprout/generator/file_manifest.rb
sprout-1.0.14.pre lib/sprout/generator/file_manifest.rb
sprout-1.0.13.pre lib/sprout/generator/file_manifest.rb
sprout-1.0.11.pre lib/sprout/generator/file_manifest.rb