-
-
Save igrigorik/9a72dc99931429c4f8f8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
goog.require('goog.dom'); | |
function sayHi() { | |
var newHeader = goog.dom.createDom('h1', {'style': 'background-color:#EEE'}, 'Hello world!'); | |
goog.dom.appendChild(document.body, newHeader); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment