Sha256: d1ed3f67f820657f9bd590ebcee902cd67299bb38a2bc2223c6f16bd61328c18

Contents?: true

Size: 1.13 KB

Versions: 3

Compression:

Stored size: 1.13 KB

Contents

module Sprockets
  class SourceFile
    attr_reader :environment, :pathname

    def initialize(environment, pathname)
      @environment = environment
      @pathname = pathname
    end

    def source_lines
      @lines ||= begin
        lines = []

        comments = []
        File.open(pathname.absolute_location) do |file|
          file.each do |line|
            lines << line = SourceLine.new(self, line, file.lineno)

            if line.begins_pdoc_comment? || comments.any?
              comments << line
            end

            if line.ends_multiline_comment?
              if line.ends_pdoc_comment?
                comments.each { |l| l.comment! }
              end
              comments.clear
            end
          end
        end

        lines
      end
    end

    def each_source_line(&block)
      source_lines.each(&block)
    end

    def find(location, kind = :file)
      pathname.parent_pathname.find(location, kind)
    end
    
    def ==(source_file)
      pathname == source_file.pathname
    end
    
    def mtime
      File.mtime(pathname.absolute_location)
    rescue Errno::ENOENT
      0
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sprockets-1.0.0 lib/sprockets/source_file.rb
sprockets-1.0.1 lib/sprockets/source_file.rb
sprockets-0.9.1 lib/sprockets/source_file.rb