Skip to content

Instantly share code, notes, and snippets.

@foxyblocks
Created April 13, 2015 07:31
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 foxyblocks/93456c9fae8e1f671875 to your computer and use it in GitHub Desktop.
Save foxyblocks/93456c9fae8e1f671875 to your computer and use it in GitHub Desktop.
PROPS = %w{
appearance
align-content
align-items
backface-visibility
background-size
border-radius
box-orient
box-shadow
box-sizing
flex-direction
flex-flow
flex-grow
flex-shrink
flex-wrap
flex
justify-content
perspective
text-shadow
transform
transition
transition-duration
transition-property
transition-timing-function
}
PATTERN = /\+(?<prop>#{PROPS.join('|')})\(\s*(?<value>\S+.+\S+|\S+)\s*\)/
REPLACEMENT = "\\k<prop>: \\k<value>"
# These rules are so simple as the other ones
EXCEPTIONS = {
'translateX' => "transform: translateX(\\k<value>)",
'translateY' => "transform: translateY(\\k<value>)",
'translateZ' => "transform: translateZ(\\k<value>)",
'rotate' => "transform: rotate(\\k<value>)",
'scale' => "transform: scale(\\k<value>)"
}
# get all the files
sass_files = Dir["app/assets/stylesheets/**/*.sass"]
sass_files.each do |file_name|
# load the text
text = File.read(file_name)
# replace the basic rules
new_contents = text.gsub(PATTERN, REPLACEMENT)
#replace the exceptional rules
EXCEPTIONS.each do |prop, replacement|
pattern = /\+(?<prop>#{prop})\(\s*(?<value>\S+.+\S+|\S+)\s*\)/
new_contents = new_contents.gsub(pattern, replacement)
end
File.open(file_name, "w") {|file| file.puts new_contents }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment