Skip to content
Permalink
Browse files

Added a :interpolate_constants option

  • Loading branch information...
matehat
matehat committed Nov 10, 2009
1 parent 8860b7f commit d735656f746b3bd20429c61bd362dbc402c9fb3e
Showing with 19 additions and 6 deletions.
  1. +5 −0 lib/sprockets/preprocessor.rb
  2. +7 −4 lib/sprockets/secretary.rb
  3. +2 −0 lib/sprockets/source_file.rb
  4. +5 −2 lib/sprockets/source_line.rb
@@ -13,6 +13,7 @@ def initialize(environment, options = {})
def require(source_file)
return if source_files.include?(source_file)
source_files << source_file
source_file.interpolate_constants = interpolate_constants?

source_file.each_source_line do |source_line|
if source_line.require?
@@ -51,6 +52,10 @@ def strip_comments?
options[:strip_comments] != false
end

def interpolate_constants?
options[:interpolate_constants] != false
end

def pathname_from(source_line)
pathname = send(pathname_finder_from(source_line), source_line)
raise_load_error_for(source_line) unless pathname
@@ -5,9 +5,10 @@ class Secretary
:load_path => [],
:source_files => [],
:expand_paths => true,
:strip_comments => true
:strip_comments => true,
:interpolate_constants => true
}

attr_reader :environment, :preprocessor

def initialize(options = {})
@@ -17,8 +18,10 @@ def initialize(options = {})
def reset!(options = @options)
@options = DEFAULT_OPTIONS.merge(options)
@environment = Sprockets::Environment.new(@options[:root])
@preprocessor = Sprockets::Preprocessor.new(@environment, :strip_comments => @options[:strip_comments])

@preprocessor = Sprockets::Preprocessor.new(@environment,
:strip_comments => @options[:strip_comments],
:interpolate_constants => @options[:interpolate_constants])

add_load_locations(@options[:load_path])
add_source_files(@options[:source_files])
end
@@ -1,10 +1,12 @@
module Sprockets
class SourceFile
attr_reader :environment, :pathname
attr_accessor :interpolate_constants

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

def source_lines
@@ -7,7 +7,7 @@ def initialize(source_file, line, number)
@line = line
@number = number
end

def comment
@comment ||= line[/^\s*\/\/(.*)/, 1]
end
@@ -58,12 +58,15 @@ def inspect

def to_s(constants = source_file.environment.constants)
result = line.chomp
interpolate_constants!(result, constants)
interpolate_constants!(result, constants) if interpolate_constants?
strip_trailing_whitespace!(result)
result + $/
end

protected
def interpolate_constants?
source_file.interpolate_constants != false
end
def interpolate_constants!(result, constants)
result.gsub!(/<%=(.*?)%>/) do
constant = $1.strip

0 comments on commit d735656

Please sign in to comment.
You can’t perform that action at this time.