Sha256: 49cf3c8d9792415845e8dc61583d6cd15a4f361fb08899618f3f0758f520dd06

Contents?: true

Size: 1.77 KB

Versions: 86

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.first =~ /:in `(block in )?(#{name}|perform)'$/
        raise Sass::SyntaxError.new("#{e.message} for `#{name}'")
      end
    end
  end
end

Version data entries

86 entries across 86 versions & 4 rubygems

Version Path
drnic-haml-2.3.1 lib/sass/script/funcall.rb
middleman-0.10.17 vendor/gems/gems/haml-2.2.13/lib/sass/script/funcall.rb
middleman-0.10.16 vendor/gems/gems/haml-2.2.13/lib/sass/script/funcall.rb
middleman-0.10.15 vendor/gems/gems/haml-2.2.13/lib/sass/script/funcall.rb
middleman-0.10.14 vendor/gems/gems/haml-2.2.13/lib/sass/script/funcall.rb
haml-edge-2.3.80 lib/sass/script/funcall.rb
haml-edge-2.3.79 lib/sass/script/funcall.rb
haml-edge-2.3.78 lib/sass/script/funcall.rb
haml-2.2.13 lib/sass/script/funcall.rb
haml-edge-2.3.77 lib/sass/script/funcall.rb
haml-edge-2.3.76 lib/sass/script/funcall.rb
haml-edge-2.3.75 lib/sass/script/funcall.rb
haml-2.2.12 lib/sass/script/funcall.rb
haml-edge-2.3.74 lib/sass/script/funcall.rb
haml-edge-2.3.73 lib/sass/script/funcall.rb
haml-2.2.11 lib/sass/script/funcall.rb
haml-edge-2.3.72 lib/sass/script/funcall.rb
haml-edge-2.3.71 lib/sass/script/funcall.rb
haml-edge-2.3.70 lib/sass/script/funcall.rb
haml-edge-2.3.69 lib/sass/script/funcall.rb