class Stylus::Rails::StylusTemplate

Constants

EXCLUDED_EXTENSIONS

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/stylus/tilt/rails.rb, line 12
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/stylus/tilt/rails.rb, line 38
def assets_hash(scope)
  @assets_hash ||= scope.environment.each_logical_path.each_with_object({ :url => '', :path => '' }) do |logical_path, assets_hash|
    extensions = EXCLUDED_EXTENSIONS.join('|')
    unless File.extname(logical_path) =~ Regexp.new("^(\.(#{extensions})|)$")
      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/stylus/tilt/rails.rb, line 22
      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