Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 373
- Log:
Initial import of Radiant 0.9.1, which is now packaged as a gem. This is an
import of the tagged 0.9.1 source checked out from GitHub, which isn't quite
the same as the gem distribution - but it doesn't seem to be available in an
archived form and the installed gem already has modifications, so this is
the closest I can get.
- Author:
- rool
- Date:
- Mon Mar 21 13:40:05 +0000 2011
- Size:
- 4315 Bytes
1 | module Sass::Tree |
2 | # A static node reprenting a CSS property. |
3 | # |
4 | # @see Sass::Tree |
5 | class PropNode < Node |
6 | # The name of the property. |
7 | # |
8 | # @return [String] |
9 | attr_accessor :name |
10 | |
11 | # The value of the property, |
12 | # either a plain string or a SassScript parse tree. |
13 | # |
14 | # @return [String, Script::Node] |
15 | attr_accessor :value |
16 | |
17 | # @param name [String] See \{#name} |
18 | # @param value [String] See \{#value} |
19 | # @param prop_syntax [Symbol] `:new` if this property uses `a: b`-style syntax, |
20 | # `:old` if it uses `:a b`-style syntax |
21 | def initialize(name, value, prop_syntax) |
22 | @name = name |
23 | @value = value |
24 | @prop_syntax = prop_syntax |
25 | super() |
26 | end |
27 | |
28 | # Compares the names and values of two properties. |
29 | # |
30 | # @param other [Object] The object to compare with |
31 | # @return [Boolean] Whether or not this node and the other object |
32 | # are the same |
33 | def ==(other) |
34 | self.class == other.class && name == other.name && value == other.value && super |
35 | end |
36 | |
37 | # Computes the CSS for the property. |
38 | # |
39 | # @param tabs [Fixnum] The level of indentation for the CSS |
40 | # @param parent_name [String] The name of the parent property (e.g. `text`) or nil |
41 | # @return [String] The resulting CSS |
42 | # @raise [Sass::SyntaxError] if the property uses invalid syntax |
43 | def to_s(tabs, parent_name = nil) |
44 | if @options[:property_syntax] == :old && @prop_syntax == :new |
45 | raise Sass::SyntaxError.new("Illegal property syntax: can't use new syntax when :property_syntax => :old is set.", @line) |
46 | elsif @options[:property_syntax] == :new && @prop_syntax == :old |
47 | raise Sass::SyntaxError.new("Illegal property syntax: can't use old syntax when :property_syntax => :new is set.", @line) |
48 | end |
49 | |
50 | if value[-1] == ?; |
51 | raise Sass::SyntaxError.new("Invalid property: #{declaration.dump} (no \";\" required at end-of-line).", @line) |
52 | end |
53 | real_name = name |
54 | real_name = "#{parent_name}-#{real_name}" if parent_name |
55 | |
56 | if value.empty? && children.empty? |
57 | message = "Invalid property: #{declaration.dump} (no value)." + |
58 | pseudo_class_selector_message |
59 | raise Sass::SyntaxError.new(message, @line) |
60 | end |
61 | |
62 | join_string = case style |
63 | when :compact; ' ' |
64 | when :compressed; '' |
65 | else "\n" |
66 | end |
67 | spaces = ' ' * (tabs - 1) |
68 | to_return = '' |
69 | if !value.empty? |
70 | to_return << "#{spaces}#{real_name}:#{style == :compressed ? '' : ' '}#{value};#{join_string}" |
71 | end |
72 | |
73 | children.each do |kid| |
74 | next if kid.invisible? |
75 | to_return << kid.to_s(tabs, real_name) << join_string |
76 | end |
77 | |
78 | (style == :compressed && parent_name) ? to_return : to_return[0...-1] |
79 | end |
80 | |
81 | # Returns a appropriate message indicating how to escape pseudo-class selectors. |
82 | # This only applies for old-style properties with no value, |
83 | # so returns the empty string if this is new-style. |
84 | # |
85 | # @return [String] The message |
86 | def pseudo_class_selector_message |
87 | return "" if @prop_syntax == :new || !value.empty? |
88 | "\nIf #{declaration.dump} should be a selector, use \"\\#{declaration}\" instead." |
89 | end |
90 | |
91 | protected |
92 | |
93 | # Runs any SassScript that may be embedded in the property. |
94 | # |
95 | # @param environment [Sass::Environment] The lexical environment containing |
96 | # variable and mixin values |
97 | def perform!(environment) |
98 | @name = interpolate(@name, environment) |
99 | @value = @value.is_a?(String) ? interpolate(@value, environment) : @value.perform(environment).to_s |
100 | super |
101 | end |
102 | |
103 | # Returns an error message if the given child node is invalid, |
104 | # and false otherwise. |
105 | # |
106 | # {PropNode} only allows other {PropNode}s and {CommentNode}s as children. |
107 | # @param child [Tree::Node] A potential child node |
108 | # @return [String] An error message if the child is invalid, or nil otherwise |
109 | def invalid_child?(child) |
110 | if !child.is_a?(PropNode) && !child.is_a?(CommentNode) |
111 | "Illegal nesting: Only properties may be nested beneath properties." |
112 | end |
113 | end |
114 | |
115 | private |
116 | |
117 | def declaration |
118 | (@prop_syntax == :new ? "#{name}: #{value}" : ":#{name} #{value}").strip |
119 | end |
120 | end |
121 | end |