Created
June 16, 2009 07:34
-
-
Save liquidz/130588 to your computer and use it in GitHub Desktop.
rcss.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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