Skip to content

Loading…

Add Processor for Google Stylesheets #3

Merged
merged 1 commit into from

3 participants

@guilleiguaran
Collaborator

No description provided.

@igrigorik igrigorik merged commit f6906dc into igrigorik:master
@igrigorik
Owner

Great stuff, thanks!

@igrigorik
Owner

Hmm, it seems like I'm getting the following exception post this merge:

Compiled /git/closure-sprockets/vendor/assets/javascripts/soyutils.js  (7ms)  (pid 35250)
Error compiling asset application.js:
Sprockets::CircularDependencyError: /git/klosure/vendor/assets/closure-library/closure/goog/base.js has already been required

Have you run into this?

@guilleiguaran
Collaborator

Actually, I got it before of the merge, looks like it was caused by something changed in the last versions of Sprockets 2.0.x

@igrigorik
Owner

Ah, well then. :-)

Well, I think that's our cue then to resolve #5. I think the error its throwing is perfectly valid.. Instead of the naive implementation, we need to do the proper deps graph as done by the calcdeps.py

http://code.google.com/p/closure-library/source/browse/trunk/closure/bin/calcdeps.py

@lypanov

Without calcdeps many things don't work anyway. One of the reasons I'm now using clojurescript instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 21, 2011
  1. @guilleiguaran
View
44 README.md
@@ -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
View
1 lib/closure-sprockets.rb
@@ -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)
View
21 lib/closure-sprockets/gss_processor.rb
@@ -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
View
1 lib/closure-sprockets/railtie.rb
@@ -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
View
BIN lib/jar/closure-stylesheets.jar
Binary file not shown.
Something went wrong with that request. Please try again.