1
0
Fork 0
mirror of https://github.com/haml/haml.git synced 2022-11-09 12:33:31 -05:00

[Sass] Add an @extend node that registers extends.

This commit is contained in:
Nathan Weizenbaum 2010-02-22 01:18:08 -08:00
parent 0deee6016c
commit 0377b7252c
5 changed files with 51 additions and 2 deletions

View file

@ -9,6 +9,7 @@ require 'sass/tree/directive_node'
require 'sass/tree/variable_node'
require 'sass/tree/mixin_def_node'
require 'sass/tree/mixin_node'
require 'sass/tree/extend_node'
require 'sass/tree/if_node'
require 'sass/tree/while_node'
require 'sass/tree/for_node'

View file

@ -0,0 +1,22 @@
require 'sass/tree/node'
module Sass::Tree
class ExtendNode < Node
def initialize(selector)
@selector = selector
super()
end
protected
def perform!(environment)
@resolved_selector = run_interp(@selector, environment)
super
end
def _cssize(extends, parent)
extends[@resolved_selector] ||= []
extends[@resolved_selector] += parent.resolved_rules
end
end
end

View file

@ -22,6 +22,18 @@ module Sass::Tree
protected
# Returns an error message if the given child node is invalid,
# and false otherwise.
#
# {ExtendNode}s are valid within {MixinNode}s.
#
# @param child [Tree::Node] A potential child node
# @return [Boolean, String] Whether or not the child node is valid,
# as well as the error message to display if it is invalid
def invalid_child?(child)
super unless child.is_a?(ExtendNode)
end
def to_src(tabs, opts, fmt)
args = '(' + @args.map {|a| a.to_sass}.join(", ") + ')' unless @args.empty?
"#{' ' * tabs}#{fmt == :sass ? '+' : '@include '}#{@name}#{args}#{semi fmt}\n"

View file

@ -328,8 +328,8 @@ module Sass
# Returns an error message if the given child node is invalid,
# and false otherwise.
#
# By default, all child nodes except those only allowed at root level
# ({Tree::MixinDefNode}, {Tree::ImportNode}) are valid.
# By default, all child nodes except those only allowed under specific nodes
# ({Tree::MixinDefNode}, {Tree::ImportNode}, {Tree::ExtendNode}) are valid.
# This is expected to be overriden by subclasses
# for which some children are invalid.
#
@ -342,6 +342,8 @@ module Sass
"Mixins may only be defined at the root of a document."
when Tree::ImportNode
"Import directives may only be used at the root of a document."
when Tree::ExtendNode
"Extend directives may only be used within rules."
end
end

View file

@ -235,6 +235,18 @@ module Sass::Tree
super
end
# Returns an error message if the given child node is invalid,
# and false otherwise.
#
# {ExtendNode}s are valid within {RuleNode}s.
#
# @param child [Tree::Node] A potential child node
# @return [Boolean, String] Whether or not the child node is valid,
# as well as the error message to display if it is invalid
def invalid_child?(child)
super unless child.is_a?(ExtendNode)
end
private
def resolve_parent_refs(super_rules)