class Stylus::Rails::StylusTemplate
Public Instance Methods
evaluate(scope, locals, &block)
click to toggle source
Internal: Appends stylus mixin for asset_url and asset_path support
Calls superclass method
Tilt::StylusTemplate#evaluate
# File lib/epuber-stylus/tilt/rails.rb, line 11 def evaluate(scope, locals, &block) @data = build_mixin_body(scope) + data super end
Protected Instance Methods
assets_hash(scope)
click to toggle source
Internal: Construct Hash with absolute/relative paths in stylus syntax.
Returns string representations of hash in Stylus
syntax
# File lib/epuber-stylus/tilt/rails.rb, line 37 def assets_hash(scope) @assets_hash ||= scope.environment.each_logical_path.each_with_object({ :url => '', :path => '' }) do |logical_path, assets_hash| unless File.extname(logical_path) =~ /^(\.(css|js)|)$/ path_to_asset = scope.path_to_asset(logical_path) assets_hash[:url] << "('#{logical_path}' url(\"#{path_to_asset}\")) " assets_hash[:path] << "('#{logical_path}' \"#{path_to_asset}\") " end end end
build_mixin_body(scope)
click to toggle source
Internal: Builds body of a mixin
Returns string representation of a mixin with asset helper functions
# File lib/epuber-stylus/tilt/rails.rb, line 21 def build_mixin_body(scope) @mixin_body ||= if assets_hash(scope).values.all? {|value| value != '' } <<-STYL asset-url(key) return pair[1] if pair[0] == key for pair in #{assets_hash(scope)[:url]} () asset-path(key) return pair[1] if pair[0] == key for pair in #{assets_hash(scope)[:path]} () STYL else '' end end