Sha256: 9b94b1ea3ee522dad0a1c2af9124bf6938ab0318e8acb6331f09be98f6704d48

Contents?: true

Size: 1.02 KB

Versions: 2

Compression:

Stored size: 1.02 KB

Contents

module Sprockets
  class SourceLine
    attr_reader :source_file, :line, :number

    def initialize(source_file, line, number)
      @source_file = source_file
      @line = line
      @number = number
    end
    
    def comment
      @comment ||= line[/^\s*\/\/(.*)/, 1]
    end

    def comment?
      !!comment
    end

    def begins_multiline_comment?
      line =~ /^\s*\/\*\*(.*)/
    end

    def closes_multiline_comment?
      line =~ /^(.*)*\*\*\/\s*/
    end

    def require
      @require ||= (comment || "")[/^=\s+require\s+(\"(.*?)\"|<(.*?)>)\s*$/, 1]
    end
    
    def require?
      !!require
    end
    
    def inspect
      "line #@number of #{@source_file.pathname}"
    end
    
    def to_s(constants = source_file.environment.constants)
      line.chomp.gsub(/<%=(.*?)%>/) do
        constant = $1.strip
        if value = constants[constant]
          value
        else
          raise UndefinedConstantError, "couldn't find constant `#{constant}' in #{inspect}"
        end
      end + $/
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sstephenson-sprockets-0.3.0 lib/sprockets/source_line.rb
sstephenson-sprockets-0.4.0 lib/sprockets/source_line.rb