compass/doc-src/lib/stylesheets/sass_extensions.rb

97 lines
2.6 KiB
Ruby
Raw Normal View History

2010-01-22 19:41:08 +00:00
require 'sass'
module Sass
module Tree
class VariableNode < Node
attr_accessor :name unless method_defined? :name
attr_accessor :expr unless method_defined? :expr
attr_accessor :guarded unless method_defined? :guarded
attr_accessor :comment unless method_defined? :comment
end
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
class VariableNode < Node
attr_accessor :comment unless method_defined? :comment
2010-01-28 08:01:23 +00:00
end
class MixinDefNode < Node
attr_accessor :name unless method_defined? :name
attr_accessor :args unless method_defined? :args
2010-01-22 19:40:56 +00:00
attr_accessor :comment unless method_defined? :comment
2010-03-29 06:06:56 +00:00
def sass_signature(mode = :definition, format = :text)
prefix = case mode
when :definition
"="
when :include
"+"
end
2010-03-29 06:06:56 +00:00
"#{prefix}#{name}#{arglist_to_sass(format)}"
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(", ")})"
else
""
end
end
2010-03-29 06:06:56 +00:00
def arg_to_sass(arg, format = :text)
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
end
sass_str
end
end
2010-01-22 19:40:56 +00:00
class ImportNode < RootNode
attr_accessor :imported_filename unless method_defined? :imported_filename
end
2010-01-22 19:40:56 +00:00
class CommentNode < Node
unless defined?(PRE_COMMENT)
PRE_COMMENT = %r{(^ */*\**(\s*\|)?( |$))}
end
unless defined?(POST_COMMENT)
POST_COMMENT = %r{ *\*/$}
end
def self.clean(docstring)
docstring.gsub(/@doc off(.*?)@doc on/m, '')
end
2010-01-22 19:40:56 +00:00
def docstring
value.gsub(PRE_COMMENT, '').gsub(POST_COMMENT, '')
2010-01-22 19:40:56 +00:00
end
def doc
if value == "@doc off"
false
elsif value == "@doc on"
true
end
end
2010-01-22 19:40:56 +00:00
end
end
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
end
end