Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Rename @children to @content.

  • Loading branch information...
commit b0d560d185fddfa492481f0d6304029c93d7459f 1 parent 98e6d18
@chriseppstein chriseppstein authored
View
10 doc-src/SASS_CHANGELOG.md
@@ -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;
}
}
@@ -22,7 +22,7 @@
=iphone
@media only screen and (max-width: 480px)
- @children
+ @content
+iphone
body
@@ -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
View
16 doc-src/SASS_REFERENCE.md
@@ -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 {
@@ -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 {
View
20 lib/sass/engine.rb
@@ -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'
@@ -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
@@ -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"
@@ -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})(.*)$/
View
6 lib/sass/scss/parser.rb
@@ -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(/@/)
@@ -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
View
4 lib/sass/tree/children_node.rb → lib/sass/tree/content_node.rb
@@ -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
View
4 lib/sass/tree/visitors/check_nesting.rb
@@ -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)
View
4 lib/sass/tree/visitors/convert.rb
@@ -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)
View
10 lib/sass/tree/visitors/perform.rb
@@ -163,7 +163,7 @@ 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)
@@ -171,7 +171,7 @@ def visit_mixin(node)
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
@@ -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
View
4 test/sass/conversion_test.rb
@@ -1159,7 +1159,7 @@ def test_children_conversion
=context($class, $color: red)
.\#{$class}
background-color: $color
- @children
+ @content
border-color: $color
+context(parent)
@@ -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) {
View
26 test/sass/engine_test.rb
@@ -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],
@@ -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;
@@ -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;
@@ -2509,7 +2509,7 @@ def test_selector_in_children
=context($class, $color: red)
.\#{$class}
background-color: $color
- @children
+ @content
border-color: $color
+context(parent)
.children
@@ -2517,7 +2517,7 @@ def test_selector_in_children
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;
@@ -2531,7 +2531,7 @@ 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)
@@ -2539,7 +2539,7 @@ def test_using_parent_mixin_in_children
SASS
end
- def test_children_more_than_once
+ def test_content_more_than_once
assert_equal <<CSS, render(<<SASS)
.once {
color: blue; }
@@ -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
View
4 test/sass/scss/scss_test.rb
@@ -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;
@@ -1258,7 +1258,7 @@ def test_mixin_children
@mixin context($class, $color: red) {
.\#{$class} {
background-color: $color;
- @children;
+ @content;
border-color: $color;
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.