Skip to content

Commit

Permalink
Add Processor for Google Stylesheets
Browse files Browse the repository at this point in the history
  • Loading branch information
guilleiguaran committed Nov 21, 2011
1 parent 6a13edf commit 9a280df
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 2 deletions.
44 changes: 42 additions & 2 deletions README.md
@@ -1,6 +1,6 @@
# Closure Sprockets # 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 ## Integrating with Rails 3


Expand All @@ -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` - [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! - Write some closure code!



### Javascripts

```js ```js
// in one of your javascript files // in one of your javascript files
goog.require('goog.dom'); goog.require('goog.dom');
Expand Down Expand Up @@ -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. 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 ## 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: 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:
Expand Down Expand Up @@ -76,4 +116,4 @@ If you are not using the closure compiler, then you may want to disable the dyna


### License ### License


(MIT License) - Copyright (c) 2011 Ilya Grigorik (MIT License) - Copyright (c) 2011 Ilya Grigorik
1 change: 1 addition & 0 deletions lib/closure-sprockets.rb
Expand Up @@ -3,4 +3,5 @@
require "closure-sprockets/version" require "closure-sprockets/version"
require "closure-sprockets/directive_processor" require "closure-sprockets/directive_processor"
require "closure-sprockets/soy_processor" require "closure-sprockets/soy_processor"
require "closure-sprockets/gss_processor"
require "closure-sprockets/railtie" if defined?(Rails) require "closure-sprockets/railtie" if defined?(Rails)
21 changes: 21 additions & 0 deletions 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
1 change: 1 addition & 0 deletions lib/closure-sprockets/railtie.rb
Expand Up @@ -9,6 +9,7 @@ class Railtie < Rails::Engine


app.assets.register_preprocessor 'application/javascript', ClosureDependenciesProcessor app.assets.register_preprocessor 'application/javascript', ClosureDependenciesProcessor
app.assets.register_engine '.soy', SoyTemplateProcessor app.assets.register_engine '.soy', SoyTemplateProcessor
app.assets.register_engine '.gss', GssTemplateProcessor
end end


end end
Expand Down
Binary file added lib/jar/closure-stylesheets.jar
Binary file not shown.

0 comments on commit 9a280df

Please sign in to comment.