Class: Sprockets::SourceLine
- Inherits:
-
Object
- Object
- Sprockets::SourceLine
- Defined in:
- lib/sprockets/source_line.rb
Instance Attribute Summary collapse
-
#line ⇒ Object
readonly
Returns the value of attribute line.
-
#number ⇒ Object
readonly
Returns the value of attribute number.
-
#source_file ⇒ Object
readonly
Returns the value of attribute source_file.
Instance Method Summary collapse
- #begins_multiline_comment? ⇒ Boolean
- #closes_multiline_comment? ⇒ Boolean
- #comment ⇒ Object
- #comment? ⇒ Boolean
-
#initialize(source_file, line, number) ⇒ SourceLine
constructor
A new instance of SourceLine.
- #inspect ⇒ Object
- #provide ⇒ Object
- #provide? ⇒ Boolean
- #require ⇒ Object
- #require? ⇒ Boolean
- #to_s(constants = source_file.environment.constants) ⇒ Object
Constructor Details
#initialize(source_file, line, number) ⇒ SourceLine
Returns a new instance of SourceLine.
5 6 7 8 9 |
# File 'lib/sprockets/source_line.rb', line 5 def initialize(source_file, line, number) @source_file = source_file @line = line @number = number end |
Instance Attribute Details
#line ⇒ Object (readonly)
Returns the value of attribute line.
3 4 5 |
# File 'lib/sprockets/source_line.rb', line 3 def line @line end |
#number ⇒ Object (readonly)
Returns the value of attribute number.
3 4 5 |
# File 'lib/sprockets/source_line.rb', line 3 def number @number end |
#source_file ⇒ Object (readonly)
Returns the value of attribute source_file.
3 4 5 |
# File 'lib/sprockets/source_line.rb', line 3 def source_file @source_file end |
Instance Method Details
#begins_multiline_comment? ⇒ Boolean
19 20 21 |
# File 'lib/sprockets/source_line.rb', line 19 def begins_multiline_comment? line =~ /^\s*\/\*\*(.*)/ end |
#closes_multiline_comment? ⇒ Boolean
23 24 25 |
# File 'lib/sprockets/source_line.rb', line 23 def closes_multiline_comment? line =~ /^(.*)*\*\*\/\s*/ end |
#comment ⇒ Object
11 12 13 |
# File 'lib/sprockets/source_line.rb', line 11 def comment @comment ||= line[/^\s*\/\/(.*)/, 1] end |
#comment? ⇒ Boolean
15 16 17 |
# File 'lib/sprockets/source_line.rb', line 15 def comment? !!comment end |
#inspect ⇒ Object
43 44 45 |
# File 'lib/sprockets/source_line.rb', line 43 def inspect "line #@number of #{@source_file.pathname}" end |
#provide ⇒ Object
35 36 37 |
# File 'lib/sprockets/source_line.rb', line 35 def provide @provide ||= (comment || "")[/^=\s+provide\s+\"(.*?)\"\s*$/, 1] end |
#provide? ⇒ Boolean
39 40 41 |
# File 'lib/sprockets/source_line.rb', line 39 def provide? !!provide end |
#require ⇒ Object
27 28 29 |
# File 'lib/sprockets/source_line.rb', line 27 def require @require ||= (comment || "")[/^=\s+require\s+(\"(.*?)\"|<(.*?)>)\s*$/, 1] end |
#require? ⇒ Boolean
31 32 33 |
# File 'lib/sprockets/source_line.rb', line 31 def require? !!require end |
#to_s(constants = source_file.environment.constants) ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/sprockets/source_line.rb', line 47 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 |