Created
November 11, 2011 22:07
-
-
Save axiixc/1359472 to your computer and use it in GitHub Desktop.
A quick-and-dirty CSS generator. Basically takes a file an does some text replacements, but allows you to use constants and blocks in your css.
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
--- | |
:definitions: | |
MAIN_BG: white | |
MAIN_TEXT_COLOR: black | |
MAIN_LINK_COLOR: black | |
MAIN_LINK_HIGHLIGHT_COLOR: "#FF0" | |
:partials: | |
MASTHEAD_GRADIENT: | | |
background: rgb(40,40,40); | |
background: -moz-linear-gradient(top, rgba(40,40,40,1) 0%, rgba(25,25,25,1) 100%); | |
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(40,40,40,1)), color-stop(100%,rgba(25,25,25,1))); | |
background: -webkit-linear-gradient(top, rgba(40,40,40,1) 0%,rgba(25,25,25,1) 100%); | |
background: -o-linear-gradient(top, rgba(40,40,40,1) 0%,rgba(25,25,25,1) 100%); | |
background: -ms-linear-gradient(top, rgba(40,40,40,1) 0%,rgba(25,25,25,1) 100%); | |
background: linear-gradient(top, rgba(40,40,40,1) 0%,rgba(25,25,25,1) 100%); | |
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#282828', endColorstr='#191919',GradientType=0 ); |
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
.body { | |
background: MAIN_BG; | |
color: MAIN_TEXT_COLOR; | |
} | |
.masthead { | |
<MASTHEAD_GRADIENT> | |
} |
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
#!/usr/bin/ruby | |
require 'yaml' | |
CONFIG_FILE = 'config.yaml' | |
if !File.exists? CONFIG_FILE | |
IO.write(CONFIG_FILE, { | |
:partials => { 'PARTIAL' => 'PARTIAL' }, | |
:definitions => { 'DEFINITION' => 'DEFINITION' } | |
}.to_yaml) | |
puts "No config file found, created `config.yaml`" | |
end | |
input_file = ARGV[0] | |
input_file ||= 'style.css' | |
output_file = ARGV[1] | |
output_file ||= File.join Dir.pwd, File.basename(input_file, '.css') + '-gen.css' | |
last_modified = { | |
:css => nil, | |
:config => nil | |
} | |
loop do | |
current_modified = { | |
:css => File.mtime(input_file), | |
:config => File.mtime(CONFIG_FILE) | |
} | |
if last_modified != current_modified | |
last_modified = current_modified | |
css = IO.read input_file | |
config = YAML.load_file CONFIG_FILE | |
# Due to gsub order, partials can contain constants, and will | |
# have them replaced correctly! | |
config[:partials].each { |k,v| css.gsub! "<#{k}>", v } | |
config[:definitions].each { |k,v| css.gsub! k, v } | |
File.open(output_file, 'w') { |f| f.write css } | |
puts "Update!" | |
end | |
sleep 0.2 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment