lib/distil/source-file.rb in distil-0.14.0.d vs lib/distil/source-file.rb in distil-0.14.0.g

- old
+ new

@@ -1,21 +1,22 @@ require 'fileutils' module Distil class SourceFile - attr_reader :full_path, :project + attr_reader :full_path, :project, :dependencies attr_accessor :language, :is_asset class_attr :extension class_attr :content_type include ErrorReporter def initialize(filepath, project) @full_path= File.expand_path(filepath) @project= project + @dependencies=[] project.cache_file(self) end def warning(message, line=nil) super(message, self, line) @@ -26,19 +27,19 @@ end def output_path # SourceFiles get copied (or symlinked) into the output folder so that # their path is the same as that relative to the source folder - @output_path||= File.join(project.output_path, relative_path) + @output_path ||= File.join(project.output_path, relative_path) end def relative_path return @relative_path if @relative_path if full_path.starts_with?(project.output_path) @relative_path= Project.path_relative_to_folder(full_path, project.output_path) else - @relative_path=Project.path_relative_to_folder(full_path, project.source_folder) + @relative_path=Project.path_relative_to_folder(full_path, project.source_path) end end def path_relative_to(path) Project.path_relative_to_folder(full_path, path) @@ -86,14 +87,10 @@ def path_relative_to_folder(folder) Project.path_relative_to_folder(@full_path, folder) end - def dependencies - @dependencies||=[] - end - def add_dependency(file) return if @dependencies.include?(file) @dependencies << file end @@ -105,14 +102,14 @@ file.is_asset=true assets << file end def copy_to(folder, prefix) - file_path= self.file_path || relative_to_folder(prefix||"") - final_target_folder= File.join(folder, File.dirname(file_path)) + relative= path_relative_to_folder(prefix) + target_path= File.join(folder, relative) FileUtils.mkdir_p final_target_folder - FileUtils.cp self.full_path, final_target_folder - File.join(final_target_folder, File.basename(file_path)) + FileUtils.cp self.full_path, File.dirname(target_path) + target_path end end end