Module: Sass::Script::Functions

Defined in:
lib/sass/script/functions/dashy.rb

Instance Method Summary collapse

Instance Method Details

#is_wildcard(value) ⇒ Object

Defined directly on Functions so we can use declare.



22
23
24
# File 'lib/sass/script/functions/dashy.rb', line 22

def is_wildcard value
  '*' == value.to_s
end

#list_of(*lists) ⇒ Object



269
270
271
272
273
274
275
276
277
278
279
280
281
282
# File 'lib/sass/script/functions/dashy.rb', line 269

def list_of *lists
  Sass::Script::Value::List.new lists.map { |list|
    list                                 = list.to_a
    number                               = list.first
    first, second, operator, *rest, last = list.map &:value
    this                                 = first
    delta                                = second - first
    case operator
    when "_"  then [].tap { |list| while this <= last; list << this; this += delta; end }
    when "__" then [].tap { |list| while this <  last; list << this; this += delta; end }
    else list
    end.map { |value| Sass::Script::Value::Number.new value, number.numerator_units, number.denominator_units }
  }.flatten, :comma
end

#select(*selectors) ⇒ Object



26
27
28
29
# File 'lib/sass/script/functions/dashy.rb', line 26

def select *selectors
  this = select_identifier ""
  select_as this, *selectors
end

#select_adjacent_even_siblings(limit, *selectors) ⇒ Object



183
184
185
186
187
188
# File 'lib/sass/script/functions/dashy.rb', line 183

def select_adjacent_even_siblings limit, *selectors
  selectors.push select_identifier '*' if selectors.empty?
  selectors = selectors.first if 1 == selectors.length
  selectors = (0 .. limit.value).select { |i| 0 == i % 2 }.map { |i| select select_identifier(" + * " * i + " + "),  *selectors }
  select_either *selectors
end

#select_adjacent_odd_siblings(limit, *selectors) ⇒ Object



168
169
170
171
172
173
# File 'lib/sass/script/functions/dashy.rb', line 168

def select_adjacent_odd_siblings limit, *selectors
  selectors.push select_identifier '*' if selectors.empty?
  selectors = selectors.first if 1 == selectors.length
  selectors = (0 .. limit.value).select { |i| 1 == i % 2 }.map { |i| select select_identifier(" + * " * i + " + "),  *selectors }
  select_either *selectors
end

#select_adjacent_siblings(selector = select_any) ⇒ Object



84
85
86
87
# File 'lib/sass/script/functions/dashy.rb', line 84

def select_adjacent_siblings selector = select_any
  adjacent_siblings = select_identifier "+"
  select adjacent_siblings, selector
end

#select_anyObject



206
207
208
# File 'lib/sass/script/functions/dashy.rb', line 206

def select_any
  select_identifier "*"
end

#select_arguments(namespace, *name_value_pairs) ⇒ Object



240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
# File 'lib/sass/script/functions/dashy.rb', line 240

def select_arguments namespace, *name_value_pairs
  inputs = name_value_pairs.map { |name_value_pair|
    name, value = name_value_pair.to_a
    select select_identifier('input:checked'), select_attribute('form',  namespace),
                                               select_attribute('name',  name),
                                               select_attribute('value', value)
  }
  select_as_general_siblings *inputs

  # $form: select-class($form);

  # $left:  select($input select-general-siblings($form));
  # $right: select($form select-class($name $value));

  # @return select-either($left, $right);
end

#select_as(separator, *selectors) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/sass/script/functions/dashy.rb', line 32

def select_as separator, *selectors
  unquote   = method :unquote
  separator = separator.value
  selectors = selectors.first if 1 == selectors.length
  selectors = selectors.to_a.map { |selector| selector.to_a.map &unquote }
  selectors = selectors.shift.product *selectors
  Sass::Script::Value::List.new selectors.map! { |selector|
   # selector = selector.reject &method(:is_wildcard) unless 1 == selector.length && is_wildcard(selector.first)
    selector = selector.join separator
    selector.gsub! /(?<=[\w\-\]])\*/, ''  # Remove any wildcards after any words or attributes.
    selector.gsub! /\*(?=[\w\.\#\[])/, '' # Remove any wildcards before any tags, classes, ids or attributes.
    select_identifier selector
  }, :comma
end

#select_as_adjacent_siblings(*selectors) ⇒ Object



60
61
62
63
# File 'lib/sass/script/functions/dashy.rb', line 60

def select_as_adjacent_siblings *selectors
  adjacent_siblings = select_identifier "+"
  select_as adjacent_siblings, *selectors
end

#select_as_children(*selectors) ⇒ Object



54
55
56
57
# File 'lib/sass/script/functions/dashy.rb', line 54

def select_as_children *selectors
  children = select_identifier ">"
  select_as children, *selectors
end

#select_as_descendants(*selectors) ⇒ Object



48
49
50
51
# File 'lib/sass/script/functions/dashy.rb', line 48

def select_as_descendants *selectors
  descendants = select_identifier " "
  select_as descendants, *selectors
end

#select_as_general_siblings(*selectors) ⇒ Object



66
67
68
69
# File 'lib/sass/script/functions/dashy.rb', line 66

def select_as_general_siblings *selectors
  general_siblings = select_identifier "~"
  select_as general_siblings, *selectors
end

#select_attribute(attribute, *selectors) ⇒ Object



103
104
105
106
107
# File 'lib/sass/script/functions/dashy.rb', line 103

def select_attribute attribute, *selectors
  selectors = selectors.first if 1 == selectors.length
  selectors = selectors.to_a.map { |selector| select_string "[#{ attribute }=\'#{ select_escaped! selector }\']" }
  Sass::Script::Value::List.new selectors, :comma
end

#select_attribute_prefix(attribute, *selectors) ⇒ Object



109
110
111
112
113
114
115
116
117
118
# File 'lib/sass/script/functions/dashy.rb', line 109

def select_attribute_prefix attribute, *selectors
  selectors = selectors.first if 1 == selectors.length
  selectors = selectors.to_a.map { |selector|
    [
      (select_string "[#{ attribute }^=\'#{  select_escaped! selector }\']"),
      (select_string "[#{ attribute }*=\' #{ select_escaped! selector }\']")
    ]
  }
  Sass::Script::Value::List.new selectors.flatten, :comma
end

#select_attribute_suffix(attribute, *selectors) ⇒ Object



120
121
122
123
124
125
126
127
128
129
# File 'lib/sass/script/functions/dashy.rb', line 120

def select_attribute_suffix attribute, *selectors
  selectors = selectors.first if 1 == selectors.length
  selectors = selectors.to_a.map { |selector|
    [
      (select_string "[#{ attribute }$=\'#{ select_escaped! selector }\']"),
      (select_string "[#{ attribute }*=\'#{ select_escaped! selector } \']")
    ]
  }
  Sass::Script::Value::List.new selectors.flatten, :comma
end

#select_children(selector = select_any) ⇒ Object



78
79
80
81
# File 'lib/sass/script/functions/dashy.rb', line 78

def select_children selector = select_any
  children = select_identifier ">"
  select children, selector
end

#select_class(selector) ⇒ Object



141
142
143
144
145
146
# File 'lib/sass/script/functions/dashy.rb', line 141

def select_class selector
  selectors = selector.to_a.map &:to_a
  selectors = selectors.shift.product *selectors
  selectors.map! { |selector| select_identifier "." + select_escaped!(selector.to_a.map { |s| s.to_s(quote: :none).gsub(/(?<!\\)(?=[.\$\%\/\?\!])/, "\\") }.join "-") }
  Sass::Script::Value::List.new selectors, :comma
end

#select_class_prefix(*selectors) ⇒ Object



131
132
133
134
# File 'lib/sass/script/functions/dashy.rb', line 131

def select_class_prefix *selectors
  attribute = select_identifier "class"
  select_attribute_prefix attribute, *selectors
end

#select_class_suffix(*selectors) ⇒ Object



136
137
138
139
# File 'lib/sass/script/functions/dashy.rb', line 136

def select_class_suffix *selectors
  attribute = select_identifier "class"
  select_attribute_suffix attribute, *selectors
end

#select_classes(*selectors) ⇒ Object



148
149
150
# File 'lib/sass/script/functions/dashy.rb', line 148

def select_classes *selectors
  select_either *(selectors.map! &(method :select_class))
end

#select_descendants(selector = select_any) ⇒ Object



72
73
74
75
# File 'lib/sass/script/functions/dashy.rb', line 72

def select_descendants selector = select_any
  descendants = select_identifier " "
  select descendants, selector
end

#select_either(*selectors) ⇒ Object



96
97
98
99
100
# File 'lib/sass/script/functions/dashy.rb', line 96

def select_either *selectors
  selectors = selectors.first if 1 == selectors.length
  selectors = selectors.map &:to_a
  Sass::Script::Value::List.new selectors.flatten, :comma
end

#select_escaped!(thing) ⇒ Object



218
219
220
221
222
223
224
225
226
227
228
229
230
# File 'lib/sass/script/functions/dashy.rb', line 218

def select_escaped! thing
  thing.tap { |t|
    case thing

    when Sass::Script::Value::String
      select_escaped! t.value

    when String
      t.gsub! /(?<!\\)(?=[\=\$\%\/\?\!\.])/, "\\"

    end
  }
end

#select_escaped_identifier(selector) ⇒ Object



236
237
238
# File 'lib/sass/script/functions/dashy.rb', line 236

def select_escaped_identifier selector
  select_escaped! select_identifier selector
end

#select_escaped_string(selector) ⇒ Object



232
233
234
# File 'lib/sass/script/functions/dashy.rb', line 232

def select_escaped_string selector
  select_escaped! select_string selector
end

#select_even_children(limit, *selectors) ⇒ Object



194
195
196
# File 'lib/sass/script/functions/dashy.rb', line 194

def select_even_children limit, *selectors
  select_children select_even_siblings(limit, *selectors)
end

#select_even_siblings(limit, *selectors) ⇒ Object



190
191
192
# File 'lib/sass/script/functions/dashy.rb', line 190

def select_even_siblings limit, *selectors
  select select_first_sibling, select_adjacent_even_siblings(limit, *selectors)
end

#select_first_childObject



198
199
200
# File 'lib/sass/script/functions/dashy.rb', line 198

def select_first_child
  select_children select_first_sibling
end

#select_first_siblingObject



202
203
204
# File 'lib/sass/script/functions/dashy.rb', line 202

def select_first_sibling
  select_identifier ":first_child"
end

#select_general_siblings(selector = select_any) ⇒ Object



90
91
92
93
# File 'lib/sass/script/functions/dashy.rb', line 90

def select_general_siblings selector = select_any
  general_siblings = select_identifier "~"
  select general_siblings, selector
end

#select_identifier(selector) ⇒ Object



214
215
216
# File 'lib/sass/script/functions/dashy.rb', line 214

def select_identifier selector
  Sass::Script::Value::String.new selector.to_s, :selector
end

#select_lists(*selectors) ⇒ Object



257
258
259
# File 'lib/sass/script/functions/dashy.rb', line 257

def select_lists *selectors
  select_either select_ordered_lists(*selectors), select_unordered_lists(*selectors)
end

#select_odd_children(limit, *selectors) ⇒ Object



179
180
181
# File 'lib/sass/script/functions/dashy.rb', line 179

def select_odd_children limit, *selectors
  select_children select_odd_siblings(limit, *selectors)
end

#select_odd_siblings(limit, *selectors) ⇒ Object



175
176
177
# File 'lib/sass/script/functions/dashy.rb', line 175

def select_odd_siblings limit, *selectors
  select_either select_first_sibling, select(select_first_sibling, select_adjacent_odd_siblings(limit, *selectors))
end

#select_ordered_lists(*selectors) ⇒ Object



261
262
263
# File 'lib/sass/script/functions/dashy.rb', line 261

def select_ordered_lists *selectors
  select select_identifier('ol'), *selectors
end

#select_pseudoclass(selector) ⇒ Object



152
153
154
# File 'lib/sass/script/functions/dashy.rb', line 152

def select_pseudoclass selector
  select_identifier ":" + (selector.to_a.join "-")
end

#select_pseudoclasses(*selectors) ⇒ Object



156
157
158
# File 'lib/sass/script/functions/dashy.rb', line 156

def select_pseudoclasses *selectors
  select_either *(selectors.map! &(method :select_pseudoclass))
end

#select_quasiclass(selector) ⇒ Object



160
161
162
# File 'lib/sass/script/functions/dashy.rb', line 160

def select_quasiclass selector
  select_either select_class(selector), select_pseudoclass(selector)
end

#select_quasiclasses(*selectors) ⇒ Object



164
165
166
# File 'lib/sass/script/functions/dashy.rb', line 164

def select_quasiclasses *selectors
  select_either *(selectors.map! &(method :select_quasiclass))
end

#select_string(selector) ⇒ Object



210
211
212
# File 'lib/sass/script/functions/dashy.rb', line 210

def select_string selector
  Sass::Script::Value::String.new selector.to_s, :string
end

#select_unordered_lists(*selectors) ⇒ Object



265
266
267
# File 'lib/sass/script/functions/dashy.rb', line 265

def select_unordered_lists *selectors
  select select_identifier('ul'), *selectors
end