Skip to content

Instantly share code, notes, and snippets.

@clockworkpc
Last active June 12, 2017 05:03
Show Gist options
  • Save clockworkpc/c14b75987eb78bddd4c8241e6c67799c to your computer and use it in GitHub Desktop.
Save clockworkpc/c14b75987eb78bddd4c8241e6c67799c to your computer and use it in GitHub Desktop.
Convert HTML Classes to CSS
html_file = ARGV[0]
css_file = "app/assets/stylesheets/css_output.css"
class_array = Array.new
open_html_file = File.readlines(html_file)
open_css_file = File.open(css_file, "w+")
open_html_file.each do |line|
search_string = /class="[a-z]*"/
if line.match?(search_string)
nugget = line[search_string]
class_name = nugget[7..-2]
class_array.push(class_name)
end
end
class_array.uniq!
class_array.sort!
class_array.each do |item|
css_conversion = "\n." + item + "{\n\t\n}"
open_css_file.write(css_conversion)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment