Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add Processor for Google Stylesheets

  • Loading branch information...
commit 9a280df989ebee1b0a4d08a7cedb3b8c15bacbec 1 parent 6a13edf
Guillermo Iguaran authored
44 README.md
Source Rendered
... ... @@ -1,6 +1,6 @@
1 1 # Closure Sprockets
2 2
3   -Sprockets preprocessor for Google's [Closure tools](http://code.google.com/closure/) + Closure-templates (soy) compiler.
  3 +Sprockets preprocessor for Google's [Closure tools](http://code.google.com/closure/) + Closure-templates (soy) compiler + Closure stylesheets (gss) compiler.
4 4
5 5 ## Integrating with Rails 3
6 6
@@ -14,6 +14,9 @@ The gem ships with a Railtie which will automatically register a Closure preproc
14 14 - [Download the latest version](http://code.google.com/closure/library/docs/gettingstarted.html) of closure library from Google and put it in `vendor/assets`
15 15 - Write some closure code!
16 16
  17 +
  18 +### Javascripts
  19 +
17 20 ```js
18 21 // in one of your javascript files
19 22 goog.require('goog.dom');
@@ -44,6 +47,43 @@ goog.dom.appendChild(document.body, soy);
44 47
45 48 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.
46 49
  50 +
  51 +### Stylesheets
  52 +
  53 +You can use also [closure stylesheets](http://code.google.com/p/closure-stylesheets/) in .gss files
  54 +
  55 +```css
  56 +/** style.gss **/
  57 +
  58 +@def BG_COLOR rgb(235, 239, 249);
  59 +
  60 +@def DIALOG_BORDER_COLOR rgb(107, 144, 218);
  61 +@def DIALOG_BG_COLOR BG_COLOR;
  62 +
  63 +body {
  64 + background-color: BG_COLOR;
  65 +}
  66 +
  67 +.dialog {
  68 + background-color: DIALOG_BG_COLOR;
  69 + border: 1px solid DIALOG_BORDER_COLOR;
  70 +}
  71 +```
  72 +
  73 +GSS files will be compiled automatically to CSS:
  74 +
  75 +```css
  76 +body {
  77 + background-color: #ebeff9;
  78 +}
  79 +.dialog {
  80 + background-color: #ebeff9;
  81 + border: 1px solid #6b90da;
  82 +}
  83 +```
  84 +
  85 +
  86 +
47 87 ## Optional configuration
48 88
49 89 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
76 116
77 117 ### License
78 118
79   -(MIT License) - Copyright (c) 2011 Ilya Grigorik
  119 +(MIT License) - Copyright (c) 2011 Ilya Grigorik
1  lib/closure-sprockets.rb
@@ -3,4 +3,5 @@
3 3 require "closure-sprockets/version"
4 4 require "closure-sprockets/directive_processor"
5 5 require "closure-sprockets/soy_processor"
  6 +require "closure-sprockets/gss_processor"
6 7 require "closure-sprockets/railtie" if defined?(Rails)
21 lib/closure-sprockets/gss_processor.rb
... ... @@ -0,0 +1,21 @@
  1 +class GssTemplateProcessor < Tilt::Template
  2 + COMPILER_ROOT = File.expand_path(File.dirname(__FILE__))
  3 + COMPILER_JAR = File.join(COMPILER_ROOT, "/../jar/closure-stylesheets.jar")
  4 +
  5 + self.default_mime_type = 'text/css'
  6 +
  7 + def self.engine_initialized?; true; end
  8 + def initialize_engine; end
  9 + def prepare; end
  10 +
  11 + def evaluate(context, locals, &block)
  12 + # not the prettiest way to do this, but it works, for now...
  13 + out = file.gsub(/gss$/, 'css')
  14 + `java -jar #{COMPILER_JAR} --output-file #{out} --pretty-print #{file}`
  15 +
  16 + @output = IO.read(out)
  17 + File.delete(out)
  18 +
  19 + @output
  20 + end
  21 +end
1  lib/closure-sprockets/railtie.rb
@@ -9,6 +9,7 @@ class Railtie < Rails::Engine
9 9
10 10 app.assets.register_preprocessor 'application/javascript', ClosureDependenciesProcessor
11 11 app.assets.register_engine '.soy', SoyTemplateProcessor
  12 + app.assets.register_engine '.gss', GssTemplateProcessor
12 13 end
13 14
14 15 end
BIN  lib/jar/closure-stylesheets.jar
Binary file not shown

0 comments on commit 9a280df

Please sign in to comment.
Something went wrong with that request. Please try again.