Permalink
Browse files

Add Processor for Google Stylesheets

  • Loading branch information...
1 parent 6a13edf commit 9a280df989ebee1b0a4d08a7cedb3b8c15bacbec @guilleiguaran committed Nov 13, 2011
View
@@ -1,6 +1,6 @@
# Closure Sprockets
-Sprockets preprocessor for Google's [Closure tools](http://code.google.com/closure/) + Closure-templates (soy) compiler.
+Sprockets preprocessor for Google's [Closure tools](http://code.google.com/closure/) + Closure-templates (soy) compiler + Closure stylesheets (gss) compiler.
## Integrating with Rails 3
@@ -14,6 +14,9 @@ The gem ships with a Railtie which will automatically register a Closure preproc
- [Download the latest version](http://code.google.com/closure/library/docs/gettingstarted.html) of closure library from Google and put it in `vendor/assets`
- Write some closure code!
+
+### Javascripts
+
```js
// in one of your javascript files
goog.require('goog.dom');
@@ -44,6 +47,43 @@ goog.dom.appendChild(document.body, soy);
That's it! Point your browser at your page and you should have a hello world greeting from Google Closure, preprocessed by the Rails 3 Asset Pipeline and without any external Python dependencies or dynamic Javascript loading.
+
+### Stylesheets
+
+You can use also [closure stylesheets](http://code.google.com/p/closure-stylesheets/) in .gss files
+
+```css
+/** style.gss **/
+
+@def BG_COLOR rgb(235, 239, 249);
+
+@def DIALOG_BORDER_COLOR rgb(107, 144, 218);
+@def DIALOG_BG_COLOR BG_COLOR;
+
+body {
+ background-color: BG_COLOR;
+}
+
+.dialog {
+ background-color: DIALOG_BG_COLOR;
+ border: 1px solid DIALOG_BORDER_COLOR;
+}
+```
+
+GSS files will be compiled automatically to CSS:
+
+```css
+body {
+ background-color: #ebeff9;
+}
+.dialog {
+ background-color: #ebeff9;
+ border: 1px solid #6b90da;
+}
+```
+
+
+
## Optional configuration
If you decided to put your `closure-library` directory somewhere other than `vendor/assets`, then you'll have to update your environment config with the right path:
@@ -76,4 +116,4 @@ If you are not using the closure compiler, then you may want to disable the dyna
### License
-(MIT License) - Copyright (c) 2011 Ilya Grigorik
+(MIT License) - Copyright (c) 2011 Ilya Grigorik
@@ -3,4 +3,5 @@
require "closure-sprockets/version"
require "closure-sprockets/directive_processor"
require "closure-sprockets/soy_processor"
+require "closure-sprockets/gss_processor"
require "closure-sprockets/railtie" if defined?(Rails)
@@ -0,0 +1,21 @@
+class GssTemplateProcessor < Tilt::Template
+ COMPILER_ROOT = File.expand_path(File.dirname(__FILE__))
+ COMPILER_JAR = File.join(COMPILER_ROOT, "/../jar/closure-stylesheets.jar")
+
+ self.default_mime_type = 'text/css'
+
+ def self.engine_initialized?; true; end
+ def initialize_engine; end
+ def prepare; end
+
+ def evaluate(context, locals, &block)
+ # not the prettiest way to do this, but it works, for now...
+ out = file.gsub(/gss$/, 'css')
+ `java -jar #{COMPILER_JAR} --output-file #{out} --pretty-print #{file}`
+
+ @output = IO.read(out)
+ File.delete(out)
+
+ @output
+ end
+end
@@ -9,6 +9,7 @@ class Railtie < Rails::Engine
app.assets.register_preprocessor 'application/javascript', ClosureDependenciesProcessor
app.assets.register_engine '.soy', SoyTemplateProcessor
+ app.assets.register_engine '.gss', GssTemplateProcessor
end
end
Binary file not shown.

0 comments on commit 9a280df

Please sign in to comment.