Last active
May 6, 2017 14:05
-
-
Save PragmaticEd/4acbf70cd4f2962aa0a1fc269a76bf34 to your computer and use it in GitHub Desktop.
Generate bootstrap-like padding & margin classes
This file contains hidden or 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
| minify = true | |
| px_steps = 2 | |
| min_px = 0 | |
| max_px = 200 | |
| # ---------------------------------------------------------------------------------------- | |
| margin_css = '' | |
| padding_css = '' | |
| arr = ([0] + (min_px..max_px).step(px_steps).to_a + [max_px]).uniq # make sure min and max are included | |
| arr.each do |i| | |
| margin_css << ".m-#{i} {margin: #{i}px !important;}" + "\n" | |
| margin_css << ".mt-#{i} {margin-top: #{i}px !important;}" + "\n" | |
| margin_css << ".mb-#{i} {margin-bottom: #{i}px !important;}" + "\n" | |
| margin_css << ".mr-#{i} {margin-right: #{i}px !important;}" + "\n" | |
| margin_css << ".ml-#{i} {margin-left: #{i}px !important;}" + "\n" | |
| padding_css << ".p-#{i} {padding: #{i}px !important;}" + "\n" | |
| padding_css << ".pt-#{i} {padding-top: #{i}px !important;}" + "\n" | |
| padding_css << ".pb-#{i} {padding-bottom: #{i}px !important;}" + "\n" | |
| padding_css << ".pr-#{i} {padding-right: #{i}px !important;}" + "\n" | |
| padding_css << ".pl-#{i} {padding-left: #{i}px !important;}" + "\n" | |
| end | |
| css = '' | |
| css << "/*\n" | |
| css << " Generated by: PragmaticEd (https://gist.github.com/PragmaticEd/4acbf70cd4f2962aa0a1fc269a76bf34)\n\n" | |
| css << " bootstrap-like margin & padding styles, where number represents pixels.\n" | |
| css << " Usage: {m/p}{t/b/r/l}-{px}\n" | |
| css << " Example: mt-#{min_px}\n" | |
| css << " Available pixes are from #{min_px} to #{max_px} with step of #{px_steps}, so: " + arr.first(5).join(', ') + ' .. ' + arr.last(5).join(', ') + "\n" | |
| css << "*/\n\n" | |
| margin_css = margin_css.gsub(' 0px', ' 0') | |
| padding_css = padding_css.gsub(' 0px', ' 0') | |
| if minify | |
| css << margin_css.gsub("\n", '').gsub(' ', '') | |
| css << "\n" | |
| css << padding_css.gsub("\n", '').gsub(' ', '') | |
| else | |
| css << margin_css | |
| css << "\n\n" | |
| css << padding_css | |
| end | |
| css << "\n\n" # Blank space at the end | |
| open('css-spaces.css', 'w+') { |f| f.write(css) } | |
| puts "Saved to 'css-spaces.css'" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment