secret
Created

  • Download Gist
application.js
JavaScript
1 2 3 4 5 6
goog.require('goog.dom');
 
function sayHi() {
var newHeader = goog.dom.createDom('h1', {'style': 'background-color:#EEE'}, 'Hello world!');
goog.dom.appendChild(document.body, newHeader);
}
closure.rb
Ruby
1 2 3 4 5 6 7 8 9
# initializer
 
require 'klosure-tilt'
 
path = File.expand_path("../../../app/assets/javascripts/closure-library/closure", __FILE__)
p [:closure_lib_path, path]
 
Rails.application.assets.append_path path
Rails.application.assets.register_preprocessor 'application/javascript', ClosureDependenciesProcessor
klosure-tilt.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
require 'tilt'
 
class ClosureDependenciesProcessor < Tilt::Template
def prepare; end
 
def evaluate(context, locals, &block)
p [:CALCDEPS_START]
p [:data, data]
 
context.require_asset 'goog/base'
 
data.lines.each do |line|
if line =~ /goog\.require\s*\(\s*[\'\"]([^\)]+)[\'\"]\s*\)/
goog, mod, sub = $1.split(".")
sub ||= mod
mod, sub = mod.downcase, sub.downcase
dep = [goog, mod, sub].join("/")
 
p [:require_asset, dep]
context.require_asset(dep)
end
end
 
data
end
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.