224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
|
# File 'lib/css_dryer/processor.rb', line 224
def act_on(input)
if @state.eql? 'flow'
case input
when %r{/[*]}
@state = 'reading_comments'
act_on input
when /^[^,]*$/
@output << input
when /,.*;\s*$/
@output << input
when /@media/
@output << input
when /,/
@state = 'reading_selectors'
@selectors = []
@styles = []
act_on input
end
return
elsif @state.eql? 'reading_comments'
@output << input.gsub(',', ' ')
if input =~ %r{[*]/}
@state = 'flow'
end
return
elsif @state.eql? 'reading_selectors'
if input !~ /[{]/
@selectors << (input)
else
@selectors << ($`)
@state = 'reading_styles'
act_on input
end
return
elsif @state.eql? 'reading_styles'
case input
when /\A[^{}]*\Z/
@styles << input
when /\A[^,]*[{](.*)[}]/
@styles << (@depth == 0 ? $1 : input)
when /[{](.*)[}]/
@styles << $1
when /[{][^}]*\Z/
@styles << input unless @depth == 0
@depth += 1
when /[^{]*[}]/
@depth -= 1
@styles << input unless @depth == 0
end
if @depth == 0 && input =~ /[}]/
@selectors.flatten.each { |selector|
@output << "#{selector} {\n"
@styles.each { |style| @output << "#{@indent}#{style.chomp.strip}\n" }
@output << "}\n"
}
@state = 'flow'
end
return
end
end
|