Sha256: faf52410e3f25cfbc2c033fcea45e379acb47420d964d12f2557f77657cd0a6d

Contents?: true

Size: 945 Bytes

Versions: 4

Compression:

Stored size: 945 Bytes

Contents

$jsl_import_regex= /\/\*jsl:import\s+([^\*]*)\*\//

class JslDependencyFilter < Filter
  
  def handles_file(file)
    return ["js"].include?(file.content_type)
  end
  
  def preprocess_content(file, content)

    content= content.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= Project.current.find_file($1)
          if (dependency)
            file.add_dependency dependency
          else
            file.error "Missing import file: #{$1}", line_num
          end
        end
        
        # replace jsl import with empty string
        ""

      }
      
    }
    
    content.join("\n")
  end
  
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
distil-0.10.4 lib/filters/jsl-dependency-filter.rb
distil-0.10.3 lib/filters/jsl-dependency-filter.rb
distil-0.10.1 lib/filters/jsl-dependency-filter.rb
distil-0.10.0 lib/filters/jsl-dependency-filter.rb