lib/sprockets/helpers.rb in sprockets-helpers-1.0.0 vs lib/sprockets/helpers.rb in sprockets-helpers-1.0.1
- old
+ new
@@ -16,10 +16,17 @@
attr_accessor :digest
# When true, expand assets.
attr_accessor :expand
+ # When true, force debug mode
+ # :debug => true equals
+ # :expand => true
+ # :digest => false
+ # :manifest => false
+ attr_accessor :debug
+
# Set the Sprockets environment to search for assets.
# This defaults to the context's #environment method.
attr_accessor :environment
# The manifest file used for lookup
@@ -112,11 +119,11 @@
#
def asset_path(source, options = {})
uri = URI.parse(source)
return source if uri.absolute?
- if options[:debug]
+ if Helpers.debug || options[:debug]
options[:manifest] = false
options[:digest] = false
options[:asset_host] = false
end
@@ -134,16 +141,20 @@
end
alias_method :path_to_asset, :asset_path
def asset_tag(source, options = {}, &block)
raise ::ArgumentError, 'block missing' unless block
- options = { :expand => Helpers.expand }.merge(options)
- path = asset_path source, options
- if options[:expand] && path.respond_to?(:map)
- return path.map(&block).join()
+ options = { :expand => Helpers.debug || Helpers.expand, :debug => Helpers.debug }.merge(options)
+
+ path = asset_path(source, options)
+ output = if options[:expand] && path.respond_to?(:map)
+ path.map(&block).join("\n")
else
yield path
end
+
+ output = output.html_safe if output.respond_to?(:html_safe)
+ output
end
def javascript_tag(source, options = {})
options = Helpers.default_path_options[:javascript_path].merge(options)
asset_tag(source, options) do |path|