Skip to content

Instantly share code, notes, and snippets.

@bwillis
Last active December 25, 2015 00:49
Show Gist options
  • Save bwillis/6891032 to your computer and use it in GitHub Desktop.
Save bwillis/6891032 to your computer and use it in GitHub Desktop.
Convert camel case variables to hyphen case. This was useful when upgrading from Bootstrap 2 to 3.

Pass the filename or pipe the contents of the file into the script.

#> ./camel-to-hyphen-case.rb path/to/file.scss > converted_file.scss
#!/usr/bin/env ruby
ARGF.each_line do |line|
fixed = line.gsub(/\$([a-z]+[A-Z]{1}[a-zA-Z]+)/) do |v|
v.gsub(/([A-Z]{1})/) do |m|
"-#{m.downcase}"
end
end
begin
$stdout.puts fixed
rescue Errno::EPIPE
exit(74)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment