Sha256: 13c50ea25f46ec7f61d005d897c5a8dc98da10aa437c2e948e2557701b49f766

Contents?: true

Size: 1.33 KB

Versions: 1

Compression:

Stored size: 1.33 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 comment!
      @comment = line
    end

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

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

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

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

    def require
      @require ||= (comment || "")[/^=\s+require\s+(\"(.*?)\"|<(.*?)>)\s*$/, 1]
    end
    
    def require?
      !!require
    end
    
    def provide
      @provide ||= (comment || "")[/^=\s+provide\s+\"(.*?)\"\s*$/, 1]
    end
    
    def provide?
      !!provide
    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

1 entries across 1 versions & 1 rubygems

Version Path
sprockets-0.9.1 lib/sprockets/source_line.rb