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:
- 5569 Bytes
1 | module Sass::Script |
2 | # The abstract superclass for SassScript objects. |
3 | # |
4 | # Many of these methods, especially the ones that correspond to SassScript operations, |
5 | # are designed to be overridden by subclasses which may change the semantics somewhat. |
6 | # The operations listed here are just the defaults. |
7 | class Literal < Node |
8 | require 'sass/script/string' |
9 | require 'sass/script/number' |
10 | require 'sass/script/color' |
11 | require 'sass/script/bool' |
12 | |
13 | # Returns the Ruby value of the literal. |
14 | # The type of this value varies based on the subclass. |
15 | # |
16 | # @return [Object] |
17 | attr_reader :value |
18 | |
19 | # Creates a new literal. |
20 | # |
21 | # @param value [Object] The object for \{#value} |
22 | def initialize(value = nil) |
23 | @value = value |
24 | end |
25 | |
26 | # Evaluates the literal. |
27 | # |
28 | # @param environment [Sass::Environment] The environment in which to evaluate the SassScript |
29 | # @return [Literal] This literal |
30 | def perform(environment) |
31 | self |
32 | end |
33 | |
34 | # The SassScript `and` operation. |
35 | # |
36 | # @param other [Literal] The right-hand side of the operator |
37 | # @return [Literal] The result of a logical and: |
38 | # `other` if this literal isn't a false {Bool}, |
39 | # and this literal otherwise |
40 | def and(other) |
41 | to_bool ? other : self |
42 | end |
43 | |
44 | # The SassScript `or` operation. |
45 | # |
46 | # @param other [Literal] The right-hand side of the operator |
47 | # @return [Literal] The result of the logical or: |
48 | # this literal if it isn't a false {Bool}, |
49 | # and `other` otherwise |
50 | def or(other) |
51 | to_bool ? self : other |
52 | end |
53 | |
54 | # The SassScript `==` operation. |
55 | # **Note that this returns a {Sass::Script::Bool} object, |
56 | # not a Ruby boolean**. |
57 | # |
58 | # @param other [Literal] The right-hand side of the operator |
59 | # @return [Bool] True if this literal is the same as the other, |
60 | # false otherwise |
61 | def eq(other) |
62 | Sass::Script::Bool.new(self.class == other.class && self.value == other.value) |
63 | end |
64 | |
65 | # The SassScript `!=` operation. |
66 | # **Note that this returns a {Sass::Script::Bool} object, |
67 | # not a Ruby boolean**. |
68 | # |
69 | # @param other [Literal] The right-hand side of the operator |
70 | # @return [Bool] False if this literal is the same as the other, |
71 | # true otherwise |
72 | def neq(other) |
73 | Sass::Script::Bool.new(!eq(other).to_bool) |
74 | end |
75 | |
76 | # The SassScript `==` operation. |
77 | # **Note that this returns a {Sass::Script::Bool} object, |
78 | # not a Ruby boolean**. |
79 | # |
80 | # @param other [Literal] The right-hand side of the operator |
81 | # @return [Bool] True if this literal is the same as the other, |
82 | # false otherwise |
83 | def unary_not |
84 | Sass::Script::Bool.new(!to_bool) |
85 | end |
86 | |
87 | # The SassScript default operation (e.g. `!a !b`, `"foo" "bar"`). |
88 | # |
89 | # @param other [Literal] The right-hand side of the operator |
90 | # @return [Script::String] A string containing both literals |
91 | # separated by a space |
92 | def concat(other) |
93 | Sass::Script::String.new("#{self.to_s} #{other.to_s}") |
94 | end |
95 | |
96 | # The SassScript `,` operation (e.g. `!a, !b`, `"foo", "bar"`). |
97 | # |
98 | # @param other [Literal] The right-hand side of the operator |
99 | # @return [Script::String] A string containing both literals |
100 | # separated by `", "` |
101 | def comma(other) |
102 | Sass::Script::String.new("#{self.to_s}, #{other.to_s}") |
103 | end |
104 | |
105 | # The SassScript `+` operation. |
106 | # |
107 | # @param other [Literal] The right-hand side of the operator |
108 | # @return [Script::String] A string containing both literals |
109 | # without any separation |
110 | def plus(other) |
111 | Sass::Script::String.new(self.to_s + other.to_s) |
112 | end |
113 | |
114 | # The SassScript `-` operation. |
115 | # |
116 | # @param other [Literal] The right-hand side of the operator |
117 | # @return [Script::String] A string containing both literals |
118 | # separated by `"-"` |
119 | def minus(other) |
120 | Sass::Script::String.new("#{self.to_s}-#{other.to_s}") |
121 | end |
122 | |
123 | # The SassScript `/` operation. |
124 | # |
125 | # @param other [Literal] The right-hand side of the operator |
126 | # @return [Script::String] A string containing both literals |
127 | # separated by `"/"` |
128 | def div(other) |
129 | Sass::Script::String.new("#{self.to_s}/#{other.to_s}") |
130 | end |
131 | |
132 | # The SassScript unary `-` operation (e.g. `-!a`). |
133 | # |
134 | # @param other [Literal] The right-hand side of the operator |
135 | # @return [Script::String] A string containing the literal |
136 | # preceded by `"-"` |
137 | def unary_minus |
138 | Sass::Script::String.new("-#{self.to_s}") |
139 | end |
140 | |
141 | # The SassScript unary `/` operation (e.g. `/!a`). |
142 | # |
143 | # @param other [Literal] The right-hand side of the operator |
144 | # @return [Script::String] A string containing the literal |
145 | # preceded by `"/"` |
146 | def unary_div |
147 | Sass::Script::String.new("/#{self.to_s}") |
148 | end |
149 | |
150 | # @return [String] A readable representation of the literal |
151 | def inspect |
152 | value.inspect |
153 | end |
154 | |
155 | # @return [Boolean] `true` (the Ruby boolean value) |
156 | def to_bool |
157 | true |
158 | end |
159 | |
160 | # Compares this object with another. |
161 | # |
162 | # @param other [Object] The object to compare with |
163 | # @return [Boolean] Whether or not this literal is equivalent to `other` |
164 | def ==(other) |
165 | eq(other).to_bool |
166 | end |
167 | |
168 | # @return [Fixnum] The integer value of this literal |
169 | # @raise [Sass::SyntaxError] if this literal isn't an integer |
170 | def to_i |
171 | raise Sass::SyntaxError.new("#{self.inspect} is not an integer.") |
172 | end |
173 | |
174 | # @raise [Sass::SyntaxError] if this literal isn't an integer |
175 | def assert_int!; to_i; end |
176 | end |
177 | end |