Skip to content

Instantly share code, notes, and snippets.

@liquidz
Created June 16, 2009 07:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liquidz/130588 to your computer and use it in GitHub Desktop.
Save liquidz/130588 to your computer and use it in GitHub Desktop.
rcss.rb
# rcss.rb
class Array
def map
self.each_index do |i|
self[i] = yield(self[i])
end
end
end
def escape_quote(str)
str.gsub("\"", "\\\"").gsub("'", "\\'")
end
def delete_tab(str)
str.gsub(/^\t+/, "").gsub(/\t+$/, "")
end
# =main
lambda {
return if ARGV.length == 0
File.open(ARGV[0]) do |fp|
result = Array.new
codes = fp.read.split("{%").map do |x|
x.split("%}")
end.flatten
codes.each_index do |i|
if i % 2 == 0
codes[i].split(/[\r\n]+/).each do |line_origin|
line = delete_tab(line_origin)
next if line == "" or /\/\*#.+#\*\// =~ line
result.push "puts \"#{escape_quote(line)}\""
end
else
result.push codes[i].strip
end
end
eval result.join("\n")
end
}[]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment