Sha256: 69849c85822078d15272b85315f2eb84a98ec653c7b0c57bb2160400bf96db63

Contents?: true

Size: 1.07 KB

Versions: 10

Compression:

Stored size: 1.07 KB

Contents

module Distil

  JSL_IMPORT_REGEX= /\/\*jsl:import\s+([^\*]*)\*\//
  
  class JslDependencyTask < Task

    def handles_file(file)
      return ["js"].include?(file.content_type)
    end

    def include_file(file)
      return if !handles_file(file)

      content= target.get_content_for_file(file).split("\n")
    
      line_num=0
    
      content.each { |line|
      
        line_num+=1
      
        # handle dependencies
        line.gsub!(JSL_IMPORT_REGEX) { |match|

          import_file= File.expand_path(File.join(file.parent_folder, $1))
          if (File.exists?(import_file))
            file.add_dependency SourceFile.from_path(import_file)
          else
            dependency= target.find_file($1, file)
            if (dependency)
              file.add_dependency dependency
            else
              file.error "Missing import file: #{$1}", line_num
            end
          end
        
          # replace jsl import with empty string
          ""

        }
      
      }
    
      target.set_content_for_file(file, content.join("\n"))
    end
    
  end
  
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
distil-0.12.2 lib/distil/task/jsl-dependency-task.rb
distil-0.12.1 lib/distil/task/jsl-dependency-task.rb
distil-0.12.0 lib/distil/task/jsl-dependency-task.rb
distil-0.11.8 lib/distil/task/jsl-dependency-task.rb
distil-0.11.6 lib/distil/task/jsl-dependency-task.rb
distil-0.11.5 lib/distil/task/jsl-dependency-task.rb
distil-0.11.4 lib/distil/task/jsl-dependency-task.rb
distil-0.11.3 lib/distil/task/jsl-dependency-task.rb
distil-0.11.1 lib/distil/task/jsl-dependency-task.rb
distil-0.11.0 lib/distil/task/jsl-dependency-task.rb