#hello{
content: "hi there";
}
#goodbye {
content: "fare well";
}
into something more manageable (it will eventually be exported to XML because of how much IE sucks at everything I make.. there's a designer involved that I don't want getting flustered).
So it will probably get to this state at some point:
myHash = { :hello => "hi there", :goodbye => "fare well" }
I'm trying to do this the cool way with regex, but I've been stumped for the past hour or so. At this point I'm up to:
http://rubular.com/r/WKyWomf4Nm
or rather, /#(\w+)\S*/m but I'm having trouble working out the next part and how it will be implemented in my code exactly.
Here's the entirety of my code, btw, if anyone wants to see what's going on with this puzzle I wound up creating for myself. Basically there's some ajax on a webpage that, for IE < 9, it will send a query to the data.xml file that I have this script setup since it can't simply pull from the css as would be most preferable.
# The designer is adding the paragraph content into the
# CSS (top of partners grid) and this works great for all good
# browsers, but not IE windows XP, so you need to run this task
# whenever the lovely paragraphs change so the changes are reflected
# in pathetic browsers
#
CSS_LOCATION = "#{Rails.root}/public/stylesheets/grid.css"
END_OF_LINE_STRING = "/* End of Grid"
namespace :db do
desc "Converts the grid.css paragraph contents into xml for IE."
task :convert => :environment do
convert_paragraphs
end
end
def convert_paragraphs
css_file = get_css_file
data = parse_to_data(css_file)
puts css_file
end
def parse_to_data(file)
# create a hash for each id
my_data_hash = {}
# find an occurance of '#', then collect the string attached to it...
#
end
def get_css_file
css_file = File.open(CSS_LOCATION, "rb").read
css_file = cut_css_file(css_file)
css_file = remove_comments(css_file)
css_file = remove_empty_lines(css_file)
return css_file
end
def remove_empty_lines(file)
file = file.gsub /^\s*$\n/, ''
return file
end
def remove_comments(file)
file = file.gsub( /\/\*(...).*\*\//, "")
return file
end
def cut_css_file(file)
cut_point = file =~ /\/\* End of Grid/
file = file[0..cut_point-1]
return file
end

New Topic/Question
Reply




MultiQuote



|