2010-01-22 19:41:08 +00:00
|
|
|
require 'sass'
|
2010-01-21 19:54:47 +00:00
|
|
|
module Sass
|
|
|
|
module Tree
|
2012-03-13 16:21:05 +00:00
|
|
|
class RuleNode
|
|
|
|
attr_accessor :comment unless method_defined? :comment
|
|
|
|
def identifier
|
|
|
|
@identifier ||= begin
|
|
|
|
id = name.gsub(/[^a-zA-Z]+/,"-").downcase
|
|
|
|
id = id[1..-1] if id[0..0] == "-"
|
|
|
|
id = id[0..-2] if id[-1..-1] == "-"
|
|
|
|
id
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def name
|
|
|
|
@name ||= rule.map{|part| Sass::Script::Node === part ? "\#{#{part.to_sass}}" : part}.join('')
|
|
|
|
end
|
|
|
|
end
|
2010-01-21 19:54:47 +00:00
|
|
|
class VariableNode < Node
|
|
|
|
attr_accessor :name unless method_defined? :name
|
2010-01-24 03:48:25 +00:00
|
|
|
attr_accessor :expr unless method_defined? :expr
|
|
|
|
attr_accessor :guarded unless method_defined? :guarded
|
|
|
|
attr_accessor :comment unless method_defined? :comment
|
2010-01-21 19:54:47 +00:00
|
|
|
end
|
2010-01-23 09:06:54 +00:00
|
|
|
class DebugNode < Node
|
|
|
|
def to_sass
|
|
|
|
""
|
|
|
|
end
|
|
|
|
end
|
|
|
|
class MixinNode < Node
|
|
|
|
attr_accessor :name unless method_defined? :name
|
|
|
|
attr_accessor :args unless method_defined? :args
|
|
|
|
end
|
2010-01-24 03:48:25 +00:00
|
|
|
class VariableNode < Node
|
|
|
|
attr_accessor :comment unless method_defined? :comment
|
2010-01-28 08:01:23 +00:00
|
|
|
end
|
2011-01-02 20:34:16 +00:00
|
|
|
module HasSignature
|
|
|
|
def sass_signature(format = :text)
|
|
|
|
"#{name}#{arglist_to_sass(format)}"
|
2010-01-23 09:06:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2010-03-29 06:06:56 +00:00
|
|
|
def arglist_to_sass(format = :text)
|
2010-01-25 00:02:53 +00:00
|
|
|
if args && args.any?
|
2010-03-29 06:06:56 +00:00
|
|
|
"(#{args.map{|a| arg_to_sass(a, format)}.join(", ")})"
|
2010-01-23 09:06:54 +00:00
|
|
|
else
|
|
|
|
""
|
|
|
|
end
|
|
|
|
end
|
2010-03-29 06:06:56 +00:00
|
|
|
def arg_to_sass(arg, format = :text)
|
2010-01-23 09:06:54 +00:00
|
|
|
name, default_value = arg
|
2010-03-29 06:06:56 +00:00
|
|
|
sass_str = ""
|
|
|
|
if format == :html
|
|
|
|
ddv = %Q{ data-default-value="#{h(default_value.to_sass)}"} if default_value
|
2010-04-12 09:46:33 +00:00
|
|
|
sass_str = %Q{<span class="arg"#{ddv}>#{name.to_sass}</span>}
|
2010-03-29 06:06:56 +00:00
|
|
|
else
|
2010-04-12 09:46:33 +00:00
|
|
|
sass_str = "#{name.to_sass}"
|
2010-03-29 06:06:56 +00:00
|
|
|
if default_value
|
|
|
|
sass_str << " = "
|
|
|
|
sass_str << default_value.to_sass
|
|
|
|
end
|
2010-01-23 09:06:54 +00:00
|
|
|
end
|
|
|
|
sass_str
|
|
|
|
end
|
2010-01-21 19:54:47 +00:00
|
|
|
end
|
2011-01-02 20:34:16 +00:00
|
|
|
class MixinDefNode < Node
|
|
|
|
attr_accessor :name unless method_defined? :name
|
|
|
|
attr_accessor :args unless method_defined? :args
|
|
|
|
attr_accessor :comment unless method_defined? :comment
|
|
|
|
unless included_modules.include?(HasSignature)
|
|
|
|
include HasSignature
|
|
|
|
alias sass_signature_without_prefix sass_signature
|
|
|
|
def sass_signature(mode = :definition, format = :text)
|
|
|
|
prefix = case mode
|
|
|
|
when :definition
|
|
|
|
"="
|
|
|
|
when :include
|
|
|
|
"+"
|
|
|
|
end
|
|
|
|
"#{prefix}#{sass_signature_without_prefix(format)}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
class FunctionNode < Node
|
|
|
|
attr_accessor :name unless method_defined? :name
|
|
|
|
attr_accessor :args unless method_defined? :args
|
|
|
|
attr_accessor :comment unless method_defined? :comment
|
|
|
|
include HasSignature unless included_modules.include?(HasSignature)
|
|
|
|
end
|
2010-01-22 19:40:56 +00:00
|
|
|
class ImportNode < RootNode
|
2010-01-21 19:54:47 +00:00
|
|
|
attr_accessor :imported_filename unless method_defined? :imported_filename
|
|
|
|
end
|
2010-01-22 19:40:56 +00:00
|
|
|
class CommentNode < Node
|
2010-11-13 05:45:24 +00:00
|
|
|
unless defined?(PRE_COMMENT)
|
|
|
|
PRE_COMMENT = %r{(^ */*\**(\s*\|)?( |$))}
|
|
|
|
end
|
|
|
|
unless defined?(POST_COMMENT)
|
|
|
|
POST_COMMENT = %r{ *\*/$}
|
|
|
|
end
|
2010-03-16 23:39:56 +00:00
|
|
|
def self.clean(docstring)
|
|
|
|
docstring.gsub(/@doc off(.*?)@doc on/m, '')
|
|
|
|
end
|
2010-01-22 19:40:56 +00:00
|
|
|
def docstring
|
2011-10-16 19:42:38 +00:00
|
|
|
v = value
|
|
|
|
v = v.join("\n") if v.respond_to?(:join)
|
|
|
|
v.gsub(PRE_COMMENT, '').gsub(POST_COMMENT, '')
|
2010-01-22 19:40:56 +00:00
|
|
|
end
|
2010-01-23 09:06:54 +00:00
|
|
|
def doc
|
|
|
|
if value == "@doc off"
|
|
|
|
false
|
|
|
|
elsif value == "@doc on"
|
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|
2010-01-22 19:40:56 +00:00
|
|
|
end
|
2010-01-21 19:54:47 +00:00
|
|
|
end
|
2010-01-24 03:48:25 +00:00
|
|
|
module Script
|
2010-01-24 09:34:05 +00:00
|
|
|
class Color < Literal
|
2010-04-12 09:46:33 +00:00
|
|
|
def to_sass(options = {})
|
|
|
|
if options[:format] == :html
|
2010-01-24 09:34:05 +00:00
|
|
|
%Q{<span class="color">#{to_s}</span>}
|
|
|
|
else
|
|
|
|
to_s
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2010-01-24 03:48:25 +00:00
|
|
|
end
|
2010-01-30 20:37:25 +00:00
|
|
|
end
|