Skip to content

Commit

Permalink
Rename @children to @content.
Browse files Browse the repository at this point in the history
  • Loading branch information
chriseppstein committed Sep 13, 2011
1 parent 98e6d18 commit b0d560d
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 54 deletions.
10 changes: 5 additions & 5 deletions doc-src/SASS_CHANGELOG.md
Expand Up @@ -5,12 +5,12 @@

## 3.2.0 (Unreleased)

* A mixin include can now accept a block of styles ({file:SASS_REFERENCE.md#mixin-children Reference Documentation}).
The style block will be passed to the mixin and can be placed at the point @children is used. E.g.:
* A mixin include can now accept a block of content ({file:SASS_REFERENCE.md#mixin-content Reference Documentation}).
The style block will be passed to the mixin and can be placed at the point @content is used. E.g.:

@mixin iphone {
@media only screen and (max-width: 480px) {
@children;
@content;
}
}
Expand All @@ -22,7 +22,7 @@

=iphone
@media only screen and (max-width: 480px)
@children
@content
+iphone
body
Expand All @@ -35,7 +35,7 @@
}

Note that the contents passed to the mixin are evaluated in the scope they are used,
not the scope of the mixin. {file:SASS_REFERENCE.md#variable_scope_and_style_blocks More on variable scoping.}
not the scope of the mixin. {file:SASS_REFERENCE.md#variable_scope_and_content_blocks More on variable scoping.}

## `:any` Support

Expand Down
16 changes: 8 additions & 8 deletions doc-src/SASS_REFERENCE.md
Expand Up @@ -1812,17 +1812,17 @@ providing many arguments without becoming difficult to call.
Named arguments can be passed in any order, and arguments with default values can be omitted.
Since the named arguments are variable names, underscores and dashes can be used interchangeably.

### Passing Style Blocks to a Mixin {#mixin-children}
### Passing Content Blocks to a Mixin {#mixin-content}

It is possible to pass a block of styles to the mixin for placement within the styles included by
the mixin. The styles will appear at the location of any `@children` directives found within the mixin. This makes is possible to define abstractions relating to the construction of
the mixin. The styles will appear at the location of any `@content` directives found within the mixin. This makes is possible to define abstractions relating to the construction of
selectors and directives.

For example:

@mixin apply-to-ie6-only {
* html {
@children;
@content;
}
}
@include apply-to-ie6-only {
Expand All @@ -1841,24 +1841,24 @@ The same mixins can be done in the `.sass` shorthand syntax:

=apply-to-ie6-only
* html
@children
@content

+apply-to-ie6-only
#logo
background-image: url(/logo.gif)

**Note:** when the `@children` directive is specified more than once or in a loop, the style block will be duplicated with each invocation.
**Note:** when the `@content` directive is specified more than once or in a loop, the style block will be duplicated with each invocation.

#### Variable Scope and Style Blocks
#### Variable Scope and Content Blocks

The block of styles passed to a mixin are evaluated in the scope where the block is defined,
The block of content passed to a mixin are evaluated in the scope where the block is defined,
not in the scope of the mixin. This means that variables local to the mixin **cannot** be used
within the passed style block and variables will resolve to the global value:

$color: white;
@mixin colors($color: blue) {
background-color: $color;
@children;
@content;
border-color: $color;
}
.colors {
Expand Down
20 changes: 10 additions & 10 deletions lib/sass/engine.rb
Expand Up @@ -12,7 +12,7 @@
require 'sass/tree/variable_node'
require 'sass/tree/mixin_def_node'
require 'sass/tree/mixin_node'
require 'sass/tree/children_node'
require 'sass/tree/content_node'
require 'sass/tree/function_node'
require 'sass/tree/return_node'
require 'sass/tree/extend_node'
Expand Down Expand Up @@ -63,7 +63,7 @@ module Sass
class Callable < Struct.new(:name, :args, :environment, :tree)
def accepts_style_block?
if @accepts_style_block.nil?
@accepts_style_block = Sass::Tree::Visitors::Grep.visit(self) {|n| n.is_a?(Tree::ChildrenNode) }.any?
@accepts_style_block = Sass::Tree::Visitors::Grep.visit(self) {|n| n.is_a?(Tree::ContentNode) }.any?
end
@accepts_style_block
end
Expand Down Expand Up @@ -632,8 +632,8 @@ def parse_directive(parent, line, root)
parse_import(line, value)
elsif directive == "mixin"
parse_mixin_definition(line)
elsif directive == "children"
parse_children_directive(line)
elsif directive == "content"
parse_content_directive(line)
elsif directive == "include"
parse_mixin_include(line, root)
elsif directive == "function"
Expand Down Expand Up @@ -798,13 +798,13 @@ def parse_mixin_definition(line)
Tree::MixinDefNode.new(name, args)
end

CHILDREN_RE = /^(?:@children)\s*(.+)?$/
def parse_children_directive(line)
trailing = line.text.scan(CHILDREN_RE).first.first
raise SyntaxError.new("Invalid children directive. Trailing characters found: \"#{trailing}\".") unless trailing.nil?
raise SyntaxError.new("Illegal nesting: Nothing may be nested beneath @children directives.",
CONTENT_RE = /^(?:@content)\s*(.+)?$/
def parse_content_directive(line)
trailing = line.text.scan(CONTENT_RE).first.first
raise SyntaxError.new("Invalid content directive. Trailing characters found: \"#{trailing}\".") unless trailing.nil?
raise SyntaxError.new("Illegal nesting: Nothing may be nested beneath @content directives.",
:line => line.index + 1) unless line.children.empty?
Tree::ChildrenNode.new
Tree::ContentNode.new
end

MIXIN_INCLUDE_RE = /^(?:\+|@include)\s*(#{Sass::SCSS::RX::IDENT})(.*)$/
Expand Down
6 changes: 3 additions & 3 deletions lib/sass/scss/parser.rb
Expand Up @@ -101,7 +101,7 @@ def process_comment(text, node)
end

DIRECTIVES = Set[:mixin, :include, :function, :return, :debug, :warn, :for,
:each, :while, :if, :else, :extend, :import, :media, :charset, :children]
:each, :while, :if, :else, :extend, :import, :media, :charset, :content]

def directive
return unless tok(/@/)
Expand Down Expand Up @@ -151,9 +151,9 @@ def include_directive
end
end

def children_directive
def content_directive
ss
node(Sass::Tree::ChildrenNode.new)
node(Sass::Tree::ContentNode.new)
end

def function_directive
Expand Down
@@ -1,9 +1,9 @@
module Sass
module Tree
# A node representing the placement within a mixin of the include statement's children.
# A node representing the placement within a mixin of the include statement's content.
#
# @see Sass::Tree
class ChildrenNode < Node
class ContentNode < Node
end
end
end
4 changes: 2 additions & 2 deletions lib/sass/tree/visitors/check_nesting.rb
Expand Up @@ -58,9 +58,9 @@ def visit_mixindef(node)
@inside_mixindef = false
end

def visit_children(node)
def visit_content(node)
unless @inside_mixindef
raise Sass::SyntaxError, "@children may only be used within a mixin."
raise Sass::SyntaxError, "@content may only be used within a mixin."
end
rescue Sass::SyntaxError => e
e.modify_backtrace(:filename => node.filename, :line => node.line)
Expand Down
4 changes: 2 additions & 2 deletions lib/sass/tree/visitors/convert.rb
Expand Up @@ -178,8 +178,8 @@ def visit_mixin(node)
"#{tab_str}#{@format == :sass ? '+' : '@include '}#{dasherize(node.name)}#{arglist}#{node.children.any? ? yield : semi}\n"
end

def visit_children(node)
"#{tab_str}@children#{semi}\n"
def visit_content(node)
"#{tab_str}@content#{semi}\n"
end

def visit_prop(node)
Expand Down
10 changes: 5 additions & 5 deletions lib/sass/tree/visitors/perform.rb
Expand Up @@ -163,15 +163,15 @@ def visit_mixindef(node)
def visit_mixin(node)
handle_include_loop!(node) if @environment.mixins_in_use.include?(node.name)

@current_mixin_children, old_mixin_children = node.children, @current_mixin_children
@current_mixin_content, old_mixin_content = node.children, @current_mixin_content
@current_mixin_env, old_mixin_env = @environment, @current_mixin_env
original_env = @environment
original_env.push_frame(:filename => node.filename, :line => node.line)
original_env.prepare_frame(:mixin => node.name)
raise Sass::SyntaxError.new("Undefined mixin '#{node.name}'.") unless mixin = @environment.mixin(node.name)

if node.children.any? && !mixin.accepts_style_block?
raise Sass::SyntaxError, %Q{Mixin "#{node.name}" does not accept a style block.}
raise Sass::SyntaxError, %Q{Mixin "#{node.name}" does not accept a content block.}
end

passed_args = node.args.dup
Expand Down Expand Up @@ -213,13 +213,13 @@ def visit_mixin(node)
raise e
ensure
original_env.pop_frame if original_env
@current_mixin_children = old_mixin_children
@current_mixin_content = old_mixin_content
@current_mixin_env = old_mixin_env
end

def visit_children(node)
def visit_content(node)
with_environment(@current_mixin_env) do
(@current_mixin_children || []).map{|c| visit(c.dup) }
(@current_mixin_content || []).map{|c| visit(c.dup) }
end
end

Expand Down
4 changes: 2 additions & 2 deletions test/sass/conversion_test.rb
Expand Up @@ -1159,7 +1159,7 @@ def test_children_conversion
=context($class, $color: red)
.\#{$class}
background-color: $color
@children
@content
border-color: $color
+context(parent)
Expand All @@ -1171,7 +1171,7 @@ def test_children_conversion
@mixin context($class, $color: red) {
.\#{$class} {
background-color: $color;
@children;
@content;
border-color: $color; } }
@include context(parent) {
Expand Down
26 changes: 13 additions & 13 deletions test/sass/engine_test.rb
Expand Up @@ -141,10 +141,10 @@ class SassEngineTest < Test::Unit::TestCase
"@mixin foo\n @extend .bar\n@include foo" => ["Extend directives may only be used within rules.", 2],
"foo\n &a\n b: c" => ["Invalid CSS after \"&\": expected \"{\", was \"a\"\n\n\"a\" may only be used at the beginning of a selector.", 2],
"foo\n &1\n b: c" => ["Invalid CSS after \"&\": expected \"{\", was \"1\"\n\n\"1\" may only be used at the beginning of a selector.", 2],
"=foo\n @children error" => "Invalid children directive. Trailing characters found: \"error\".",
"=foo\n @children\n b: c" => "Illegal nesting: Nothing may be nested beneath @children directives.",
"@children" => '@children may only be used within a mixin.',
"=simple\n .simple\n color: red\n+simple\n color: blue" => ['Mixin "simple" does not accept a style block.', 4],
"=foo\n @content error" => "Invalid content directive. Trailing characters found: \"error\".",
"=foo\n @content\n b: c" => "Illegal nesting: Nothing may be nested beneath @content directives.",
"@content" => '@content may only be used within a mixin.',
"=simple\n .simple\n color: red\n+simple\n color: blue" => ['Mixin "simple" does not accept a content block.', 4],

# Regression tests
"a\n b:\n c\n d" => ["Illegal nesting: Only properties may be nested beneath properties.", 3],
Expand Down Expand Up @@ -2479,7 +2479,7 @@ def test_changing_precision
end
end

def test_children
def test_content
assert_equal <<CSS, render(<<SASS)
.children {
background-color: red;
Expand All @@ -2490,14 +2490,14 @@ def test_children
=context($class, $color: red)
.\#{$class}
background-color: $color
@children
@content
border-color: $color
+context(children)
color: $color
SASS
end

def test_selector_in_children
def test_selector_in_content
assert_equal <<CSS, render(<<SASS)
.parent {
background-color: red;
Expand All @@ -2509,15 +2509,15 @@ def test_selector_in_children
=context($class, $color: red)
.\#{$class}
background-color: $color
@children
@content
border-color: $color
+context(parent)
.children
color: $color
SASS
end

def test_using_parent_mixin_in_children
def test_using_parent_mixin_in_content
assert_equal <<CSS, render(<<SASS)
.parent {
background-color: red;
Expand All @@ -2531,15 +2531,15 @@ def test_using_parent_mixin_in_children
=context($class, $color: red)
.\#{$class}
background-color: $color
@children
@content
border-color: $color
+context(parent)
+context(child, $color: yellow)
color: $color
SASS
end

def test_children_more_than_once
def test_content_more_than_once
assert_equal <<CSS, render(<<SASS)
.once {
color: blue; }
Expand All @@ -2550,9 +2550,9 @@ def test_children_more_than_once
$color: blue
=context($class, $color: red)
.once
@children
@content
.twice
@children
@content
+context(parent)
color: $color
SASS
Expand Down
4 changes: 2 additions & 2 deletions test/sass/scss/scss_test.rb
Expand Up @@ -1244,7 +1244,7 @@ def test_multiline_var
SCSS
end

def test_mixin_children
def test_mixin_content
assert_equal <<CSS, render(<<SASS)
.parent {
background-color: red;
Expand All @@ -1258,7 +1258,7 @@ def test_mixin_children
@mixin context($class, $color: red) {
.\#{$class} {
background-color: $color;
@children;
@content;
border-color: $color;
}
}
Expand Down

0 comments on commit b0d560d

Please sign in to comment.