Sha256: d4b441965e66bd2aff2a7b1757f8bd7d155ff16a243c85ca4010302301b218c2

Contents?: true

Size: 1.77 KB

Versions: 24

Compression:

Stored size: 1.77 KB

Contents

require File.join(File.dirname(__FILE__), 'functions')
module Sass
  module Script
    # A SassScript parse node representing a function call.
    #
    # A function call either calls one of the functions in {Script::Functions},
    # or if no function with the given name exists
    # it returns a string representation of the function call.
    class Funcall < Node
      # The name of the function.
      #
      # @return [String]
      attr_reader :name

      # The arguments to the function.
      #
      # @return [Array<Script::Node>]
      attr_reader :args

      # @param name [String] See \{#name}
      # @param name [Array<Script::Node>] See \{#args}
      def initialize(name, args)
        @name = name
        @args = args
      end

      # @return [String] A string representation of the function call
      def inspect
        "#{name}(#{args.map {|a| a.inspect}.join(', ')})"
      end

      # Evaluates the function call.
      #
      # @param environment [Sass::Environment] The environment in which to evaluate the SassScript
      # @return [Literal] The SassScript object that is the value of the function call
      # @raise [Sass::SyntaxError] if the function call raises an ArgumentError
      def perform(environment)
        args = self.args.map {|a| a.perform(environment)}
        unless Haml::Util.has?(:public_instance_method, Functions, name) && name !~ /^__/
          return Script::String.new("#{name}(#{args.map {|a| a.perform(environment)}.join(', ')})")
        end

        return Functions::EvaluationContext.new(environment.options).send(name, *args)
      rescue ArgumentError => e
        raise e unless e.backtrace.any? {|t| t =~ /:in `(block in )?(#{name}|perform)'$/}
        raise Sass::SyntaxError.new("#{e.message} for `#{name}'")
      end
    end
  end
end

Version data entries

24 entries across 23 versions & 6 rubygems

Version Path
radiantcms-couchrest_model-0.1.4 vendor/plugins/haml/lib/sass/script/funcall.rb
radiant-0.9.1 vendor/plugins/haml/lib/sass/script/funcall.rb
haml-2.2.24 lib/sass/script/funcall.rb
radiant-0.9.0.rc2 vendor/plugins/haml/lib/sass/script/funcall.rb
haml-2.2.23 lib/sass/script/funcall.rb
haml-2.2.22 lib/sass/script/funcall.rb
haml-2.2.21 lib/sass/script/funcall.rb
haml-2.2.20 lib/sass/script/funcall.rb
haml-2.2.19 lib/sass/script/funcall.rb
haml-2.2.18 lib/sass/script/funcall.rb
middleman-0.13.1 lib/middleman/vendor/gems/ruby/1.9.1/gems/haml-2.2.17/lib/sass/script/funcall.rb
middleman-0.13.1 lib/middleman/vendor/gems/ruby/1.8/gems/haml-2.2.17/lib/sass/script/funcall.rb
haml-2.2.17 lib/sass/script/funcall.rb
middleman-0.12.2 lib/middleman/vendor/gems/gems/haml-2.2.16/lib/sass/script/funcall.rb
simple-templater-0.0.1.4 gems/gems/haml-2.2.16/lib/sass/script/funcall.rb
haml-2.2.16 lib/sass/script/funcall.rb
middleman-0.12.1 lib/middleman/vendor/gems/gems/haml-2.2.15/lib/sass/script/funcall.rb
middleman-0.12.0.pre3 lib/middleman/vendor/gems/gems/haml-2.2.15/lib/sass/script/funcall.rb
middleman-0.12.0.pre2 lib/middleman/vendor/gems/gems/haml-2.2.15/lib/sass/script/funcall.rb
haml-2.2.15 lib/sass/script/funcall.rb