Sha256: 1314e901cf0a94d098db1b1f3963a1a8d00de18bbc097b389b14b611d73bf669

Contents?: true

Size: 1.26 KB

Versions: 9

Compression:

Stored size: 1.26 KB

Contents

require 'sass'

module JsDuck
  module Css

    class Type
      # Given SASS expression node, determines its type.
      # When unknown, return nil.
      def detect(node)
        if LITERAL_TYPES[node.class]
          LITERAL_TYPES[node.class]
        elsif node.class == Sass::Script::Funcall && COLOR_FUNCTIONS[node.name]
          "color"
        else
          nil
        end
      end

      LITERAL_TYPES = {
        Sass::Script::Number => "number",
        Sass::Script::String => "string",
        Sass::Script::Color => "color",
        Sass::Script::Bool => "boolean",
        Sass::Script::List => "list",
      }

      COLOR_FUNCTIONS = {
        # CSS3 builtins
        "rgb" => true,
        "rgba" => true,
        "hsl" => true,
        "hsla" => true,
        # SASS builtins
        "mix" => true,
        "adjust-hue" => true,
        "lighten" => true,
        "darken" => true,
        "saturate" => true,
        "desaturate" => true,
        "grayscale" => true,
        "complement" => true,
        "invert" => true,
        "opacify" => true,
        "fade-in" => true,
        "transparentize" => true,
        "fade-out" => true,
        "adjust-color" => true,
        "scale-color" => true,
        "change-color" => true,
      }

    end

  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
jsduck-troopjs-0.0.10 lib/jsduck/css/type.rb
jsduck-troopjs-0.0.9 lib/jsduck/css/type.rb
jsduck-troopjs-0.0.8 lib/jsduck/css/type.rb
jsduck-troopjs-0.0.7 lib/jsduck/css/type.rb
jsduck-troopjs-0.0.5 lib/jsduck/css/type.rb
jsduck-troopjs-0.0.4 lib/jsduck/css/type.rb
jsduck-troopjs-0.0.3 lib/jsduck/css/type.rb
jsduck-troopjs-0.0.1 lib/jsduck/css/type.rb
jsduck-6.0.0beta lib/jsduck/css/type.rb