Module: Compass::Core::SassExtensions::Functions::Lists
- Included in:
- Sass::Script::Functions
- Defined in:
- lib/compass/core/sass_extensions/functions/lists.rb
Instance Method Summary collapse
-
#_compass_list(arg) ⇒ Object
Returns a list object from a value that was passed.
-
#_compass_list_size(list) ⇒ Object
Returns the size of the list.
-
#_compass_nth(list, place) ⇒ Object
Get the nth value from a list.
-
#_compass_slice(list, start_index, end_index = nil) ⇒ Object
slice a sublist from a list.
-
#_compass_space_list(list) ⇒ Object
If the argument is a list, it will return a new list that is space delimited Otherwise it returns a new, single element, space-delimited list.
-
#blank(obj) ⇒ Object
Returns true when the object is false, an empty string, or an empty list.
-
#compact(*args) ⇒ Object
Returns a new list after removing any non-true values.
-
#first_value_of(list) ⇒ Object
returns the first value of a space delimited list.
-
#reject(list, *values) ⇒ Object
removes the given values from the list.
Instance Method Details
#_compass_list(arg) ⇒ Object
Returns a list object from a value that was passed. This can be used to unpack a space separated list that got turned into a string by sass before it was passed to a mixin.
43 44 45 46 47 48 49 |
# File 'lib/compass/core/sass_extensions/functions/lists.rb', line 43 def _compass_list(arg) if arg.is_a?(Sass::Script::Value::List) list(arg.value.dup, arg.separator) else list(arg, :space) end end |
#_compass_list_size(list) ⇒ Object
Returns the size of the list.
62 63 64 65 |
# File 'lib/compass/core/sass_extensions/functions/lists.rb', line 62 def _compass_list_size(list) assert_list list number(list.value.size) end |
#_compass_nth(list, place) ⇒ Object
Get the nth value from a list
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/compass/core/sass_extensions/functions/lists.rb', line 29 def _compass_nth(list, place) assert_type list, :List if place.value == "first" list.value.first elsif place.value == "last" list.value.last else list.value[place.value - 1] end end |
#_compass_slice(list, start_index, end_index = nil) ⇒ Object
slice a sublist from a list
68 69 70 71 72 73 74 75 |
# File 'lib/compass/core/sass_extensions/functions/lists.rb', line 68 def _compass_slice(list, start_index, end_index = nil) end_index ||= number(-1) start_index = start_index.value end_index = end_index.value start_index -= 1 unless start_index < 0 end_index -= 1 unless end_index < 0 list(list.values[start_index..end_index], list.separator) end |
#_compass_space_list(list) ⇒ Object
If the argument is a list, it will return a new list that is space delimited Otherwise it returns a new, single element, space-delimited list.
53 54 55 56 57 58 59 |
# File 'lib/compass/core/sass_extensions/functions/lists.rb', line 53 def _compass_space_list(list) if list.is_a?(Sass::Script::Value::List) list(list.value.dup, :space) else list(list, :space) end end |
#blank(obj) ⇒ Object
Returns true when the object is false, an empty string, or an empty list
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/compass/core/sass_extensions/functions/lists.rb', line 4 def blank(obj) case obj when Sass::Script::Value::Bool, Sass::Script::Value::Null bool(!obj.to_bool) when Sass::Script::Value::String bool(obj.value.strip.size == 0) when Sass::Script::Value::List bool(obj.value.size == 0 || obj.value.all?{|el| blank(el).to_bool}) else bool(false) end end |
#compact(*args) ⇒ Object
Returns a new list after removing any non-true values
18 19 20 21 22 23 24 25 26 |
# File 'lib/compass/core/sass_extensions/functions/lists.rb', line 18 def compact(*args) sep = :comma if args.size == 1 && args.first.is_a?(Sass::Script::Value::List) list = args.first args = list.value sep = list.separator end list(args.reject{|a| !a.to_bool}, sep) end |
#first_value_of(list) ⇒ Object
returns the first value of a space delimited list.
83 84 85 86 87 88 89 90 91 92 |
# File 'lib/compass/core/sass_extensions/functions/lists.rb', line 83 def first_value_of(list) if list.is_a?(Sass::Script::Value::String) r = list.value.split(/\s+/).first list.type == :identifier ? identifier(r) : quoted_string(r) elsif list.is_a?(Sass::Script::Value::List) list.value.first else list end end |
#reject(list, *values) ⇒ Object
removes the given values from the list.
78 79 80 |
# File 'lib/compass/core/sass_extensions/functions/lists.rb', line 78 def reject(list, *values) list(list.value.reject{|v| values.any?{|o| v == o}}, list.separator) end |