Module: Sass::Script::Value::Helpers
- Included in:
- Functions::EvaluationContext
- Defined in:
- /Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/value/helpers.rb
Overview
Provides helper functions for creating sass values from within ruby methods.
Constant Summary
Instance Method Summary (collapse)
- - (Sass::Script::Value::Bool) bool(value)
Construct a Sass Boolean.
- - (Boolean) calc?(literal)
Returns true when the literal is a string containing a calc().
- - (Sass::Script::Value::Color) hex_color(value, alpha = nil)
Construct a Sass Color from a hex color string.
- - (Sass::Script::Value::Color) hsl_color(hue, saturation, lightness, alpha = nil)
Construct a Sass Color from hsl values.
- - list(*elements)
- - (Sass::Script::Value::Map) map(hash)
Construct a Sass map.
- - (Sass::Script::Value::Null) null
Create a sass null value.
- - (Sass::Script::Value::Number) number(number, unit_string = nil)
Construct a Sass Number from a ruby number.
- - (Sass::Selector::Sequence) parse_complex_selector(value, name = nil, allow_parent_ref = false)
Parses a user-provided complex selector.
- - (Sass::Selector::SimpleSequence) parse_compound_selector(value, name = nil, allow_parent_ref = false)
Parses a user-provided compound selector.
- - (Sass::Selector::CommaSequence) parse_selector(value, name = nil, allow_parent_ref = false)
Parses a user-provided selector.
- - (Sass::Script::Value::String) quoted_string(str)
Create a quoted string.
- - (Sass::Script::Value::Color) rgb_color(red, green, blue, alpha = nil)
Construct a Sass Color from rgb values.
- - (Sass::Script::Value::String) unquoted_string(str) (also: #identifier)
Create an unquoted string.
Instance Method Details
- (Sass::Script::Value::Bool) bool(value)
Construct a Sass Boolean.
11 12 13 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/value/helpers.rb', line 11
def bool(value)
Bool.new(value)
end |
- (Boolean) calc?(literal)
Returns true when the literal is a string containing a calc()
203 204 205 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/value/helpers.rb', line 203
def calc?(literal)
literal.is_a?(Sass::Script::Value::String) && literal.value =~ /calc\(/
end |
- (Sass::Script::Value::Color) hex_color(value, alpha = nil)
Construct a Sass Color from a hex color string.
21 22 23 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/value/helpers.rb', line 21
def hex_color(value, alpha = nil)
Color.from_hex(value, alpha)
end |
- (Sass::Script::Value::Color) hsl_color(hue, saturation, lightness, alpha = nil)
Construct a Sass Color from hsl values.
36 37 38 39 40 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/value/helpers.rb', line 36
def hsl_color(hue, saturation, lightness, alpha = nil)
attrs = {:hue => hue, :saturation => saturation, :lightness => lightness}
attrs[:alpha] = alpha if alpha
Color.new(attrs)
end |
- (Sass::Script::Value::List) list(*elements, separator) - (Sass::Script::Value::List) list(array, separator)
82 83 84 85 86 87 88 89 90 91 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/value/helpers.rb', line 82
def list(*elements)
unless elements.last.is_a?(Symbol)
raise ArgumentError.new("A list type of :space or :comma must be specified.")
end
separator = elements.pop
if elements.size == 1 && elements.first.is_a?(Array)
elements = elements.first
end
Sass::Script::Value::List.new(elements, separator)
end |
- (Sass::Script::Value::Map) map(hash)
Construct a Sass map.
98 99 100 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/value/helpers.rb', line 98
def map(hash)
Map.new(hash)
end |
- (Sass::Script::Value::Null) null
Create a sass null value.
105 106 107 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/value/helpers.rb', line 105
def null
Sass::Script::Value::Null.new
end |
- (Sass::Script::Value::Number) number(number, unit_string = nil)
Construct a Sass Number from a ruby number.
67 68 69 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/value/helpers.rb', line 67
def number(number, unit_string = nil)
Number.new(number, *parse_unit_string(unit_string))
end |
- (Sass::Selector::Sequence) parse_complex_selector(value, name = nil, allow_parent_ref = false)
Parses a user-provided complex selector.
A complex selector can contain combinators but cannot contain commas.
163 164 165 166 167 168 169 170 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/value/helpers.rb', line 163
def parse_complex_selector(value, name = nil, allow_parent_ref = false)
selector = parse_selector(value, name, allow_parent_ref)
return seq if selector.members.length == 1
err = "#{value.inspect} is not a complex selector"
err = "$#{name.to_s.tr('_', '-')}: #{err}" if name
raise ArgumentError.new(err)
end |
- (Sass::Selector::SimpleSequence) parse_compound_selector(value, name = nil, allow_parent_ref = false)
Parses a user-provided compound selector.
A compound selector cannot contain combinators or commas.
184 185 186 187 188 189 190 191 192 193 194 195 196 197 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/value/helpers.rb', line 184
def parse_compound_selector(value, name = nil, allow_parent_ref = false)
assert_type value, :String, name
selector = parse_selector(value, name, allow_parent_ref)
seq = selector.members.first
sseq = seq.members.first
if selector.members.length == 1 && seq.members.length == 1 &&
sseq.is_a?(Sass::Selector::SimpleSequence)
return sseq
end
err = "#{value.inspect} is not a compound selector"
err = "$#{name.to_s.tr('_', '-')}: #{err}" if name
raise ArgumentError.new(err)
end |
- (Sass::Selector::CommaSequence) parse_selector(value, name = nil, allow_parent_ref = false)
Parses a user-provided selector.
138 139 140 141 142 143 144 145 146 147 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/value/helpers.rb', line 138
def parse_selector(value, name = nil, allow_parent_ref = false)
str = normalize_selector(value, name)
begin
Sass::SCSS::StaticParser.new(str, nil, nil, 1, 1, allow_parent_ref).parse_selector
rescue Sass::SyntaxError => e
err = "#{value.inspect} is not a valid selector: #{e}"
err = "$#{name.to_s.tr('_', '-')}: #{err}" if name
raise ArgumentError.new(err)
end
end |
- (Sass::Script::Value::String) quoted_string(str)
Create a quoted string.
113 114 115 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/value/helpers.rb', line 113
def quoted_string(str)
Sass::Script::String.new(str, :string)
end |
- (Sass::Script::Value::Color) rgb_color(red, green, blue, alpha = nil)
Construct a Sass Color from rgb values.
50 51 52 53 54 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/value/helpers.rb', line 50
def rgb_color(red, green, blue, alpha = nil)
attrs = {:red => red, :green => green, :blue => blue}
attrs[:alpha] = alpha if alpha
Color.new(attrs)
end |
- (Sass::Script::Value::String) unquoted_string(str) Also known as: identifier
Create an unquoted string.
121 122 123 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/value/helpers.rb', line 121
def unquoted_string(str)
Sass::Script::String.new(str, :identifier)
end |