css re-formatter

0 views
Skip to first unread message

nonnax

unread,
Jul 11, 2008, 12:58:58 AM7/11/08
to Philippine Ruby Users Group (PRUG/PhRUG)
csspretty.rb

ARGF.readlines('}').each do |line|
puts line.strip.chomp.tap{|ln| ln.gsub!(/\s+/,' ')}.tap{|ln|
ln.gsub!(/\{(.+)\}/) do |m|
"{"<<$1.strip.split(/;/).map{|e| "\n\t%s" %
e.strip}.join(";")<<";"<<"\n}"
end
}
end

# run this as a text filter csspretty.rb style.css > newstyle.css

Keith Bennett

unread,
Jul 14, 2008, 9:43:37 AM7/14/08
to Philippine Ruby Users Group (PRUG/PhRUG)
nonnax -

What's "tap"?:

csspretty.rb:2: undefined method `tap' for #<String:0x21fb4c>
(NoMethodError)

Thanks,
Keith

mikong

unread,
Jul 14, 2008, 11:40:07 PM7/14/08
to Philippine Ruby Users Group (PRUG/PhRUG)
You could install the ruby facets gem. Or you could implement the tap
method itself (from facets):

def tap(&b)
if block_given?
b.arity == 1 ? yield(self) : instance_eval(&b)
end
self
end

In the facets gem, they implemented that in the Kernel module.

And here's an article on "tap": http://www.infoq.com/news/2008/02/tap-method-ruby19

nonnax

unread,
Jul 15, 2008, 12:31:17 AM7/15/08
to Philippine Ruby Users Group (PRUG/PhRUG)
Object#tap is also implemented in ruby 1.8.7

checkout http://svn.ruby-lang.org/repos/ruby/tags/v1_8_7_preview1/NEWS

Chris

unread,
Jul 15, 2008, 10:48:37 PM7/15/08
to Philippine Ruby Users Group (PRUG/PhRUG)
this deserves a pastie. :)

nonnax

unread,
Jul 16, 2008, 12:06:55 AM7/16/08
to Philippine Ruby Users Group (PRUG/PhRUG)
Reply all
Reply to author
Forward
0 new messages