Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #14 from postmodern/cleanup

Cleanup
  • Loading branch information...
commit 68d548d09e68b66a439030cf55b4f25d718facae 2 parents 43e9423 + ad88276
@igrigorik authored
View
2  closure-sprockets.gemspec
@@ -1,6 +1,6 @@
# -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
-require "closure-sprockets/version"
+require "closure/sprockets/version"
Gem::Specification.new do |s|
s.name = "closure-sprockets"
View
10 lib/closure-sprockets.rb
@@ -1,7 +1,7 @@
require "tilt"
-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)
+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
28 lib/closure-sprockets/directive_processor.rb
@@ -1,28 +0,0 @@
-require "sprockets/directive_processor"
-
-class ClosureDirectiveProcessor < Sprockets::DirectiveProcessor
- def process_require_closure_directive(path)
- # Locate python script that helps us to calculate deps
- # cmd = File.expand_path "../bin/build/closurebuilder.py", File.dirname(__FILE__)
-
- # Use old one script, coz it could calculate deps much easier for begginers without any project's namespaces
- cmd = File.expand_path "../bin/calcdeps.py", File.dirname(__FILE__)
-
- # Get only application lookup paths
- context.environment.paths.each do |p|
- # cmd << " --root=#{p}" # for closurebuilder.py script
- cmd << " --path=#{p}"
- end
-
- # closurebuilder.py needs some input files to start deps searching
- file_pathname = context.resolve path
- cmd << " --input=#{file_pathname}"
-
- # Read stdout result and split it by strings
- # results = `#{cmd}`.split "\n" # for closurebuilder.py script
- results = `#{cmd} --output_mode=list`.split "\n"
-
- # Finally require calculated assets
- results.each{|asset| context.require_asset asset };
- end
-end
View
21 lib/closure-sprockets/gss_processor.rb
@@ -1,21 +0,0 @@
-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
15 lib/closure-sprockets/railtie.rb
@@ -1,15 +0,0 @@
-module ClosureProcessor
- class Railtie < Rails::Engine
- initializer :setup_closure do |app|
- # For developing purposes, Sprockets used to cache a lot even when server restarted
- # app.assets.cache = false
-
- app.assets.unregister_preprocessor 'application/javascript', Sprockets::DirectiveProcessor
- app.assets.register_preprocessor 'application/javascript', ClosureDirectiveProcessor
-
- app.assets.register_engine '.soy', SoyTemplateProcessor
- app.assets.register_engine '.gss', GssTemplateProcessor
- end
-
- end
-end
View
23 lib/closure-sprockets/soy_processor.rb
@@ -1,23 +0,0 @@
-class SoyTemplateProcessor < Tilt::Template
- COMPILER_ROOT = File.expand_path(File.dirname(__FILE__))
- COMPILER_JAR = File.join(COMPILER_ROOT, "/../jar/SoyToJsSrcCompiler.jar")
-
- self.default_mime_type = 'application/javascript'
-
- def self.engine_initialized?; true; end
- def initialize_engine; end
- def prepare; end
-
- def evaluate(context, locals, &block)
- context.require_asset 'soyutils'
-
- # not the prettiest way to do this, but it works, for now...
- out = file.gsub(/soy$/, 'soyjs')
- `java -jar #{COMPILER_JAR} --outputPathFormat #{out} #{file}`
-
- @output = IO.read(out)
- File.delete(out)
-
- @output
- end
-end
View
36 lib/closure/sprockets/directive_processor.rb
@@ -0,0 +1,36 @@
+require "sprockets/directive_processor"
+
+require 'shellwords'
+
+module Closure
+ module Sprockets
+ class DirectiveProcessor < ::Sprockets::DirectiveProcessor
+ CALCDEPS_PY = File.expand_path("../bin/calcdeps.py", File.dirname(__FILE__))
+
+ def process_require_closure_directive(path)
+ # Locate python script that helps us to calculate deps
+ # cmd = File.expand_path "../bin/build/closurebuilder.py", File.dirname(__FILE__)
+
+ # Use old one script, coz it could calculate deps much easier for begginers without any project's namespaces
+ cmd = CALCDEPS_PY.shellescape
+
+ # Get only application lookup paths
+ context.environment.paths.each do |p|
+ # cmd << " --root=#{p}" # for closurebuilder.py script
+ cmd << " --path=#{p.shellescape}"
+ end
+
+ # closurebuilder.py needs some input files to start deps searching
+ file_pathname = context.resolve path
+ cmd << " --input=#{file_pathname.shellescape}"
+
+ # Read stdout result and split it by strings
+ # results = `#{cmd}`.split "\n" # for closurebuilder.py script
+ results = `#{cmd} --output_mode=list`.split "\n"
+
+ # Finally require calculated assets
+ results.each{|asset| context.require_asset asset };
+ end
+ end
+ end
+end
View
27 lib/closure/sprockets/gss_processor.rb
@@ -0,0 +1,27 @@
+require 'shellwords'
+
+module Closure
+ module Sprockets
+ 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.shellescape} --output-file #{out.shellescape} --pretty-print #{file.shellescape}`
+
+ @output = IO.read(out)
+ File.delete(out)
+
+ @output
+ end
+ end
+ end
+end
View
17 lib/closure/sprockets/railtie.rb
@@ -0,0 +1,17 @@
+module Closure
+ module Sprockets
+ class Railtie < Rails::Engine
+ initializer :setup_closure do |app|
+ # For developing purposes, Sprockets used to cache a lot even when server restarted
+ # app.assets.cache = false
+
+ app.assets.unregister_preprocessor 'application/javascript', Sprockets::DirectiveProcessor
+ app.assets.register_preprocessor 'application/javascript', DirectiveProcessor
+
+ app.assets.register_engine '.soy', SoyTemplateProcessor
+ app.assets.register_engine '.gss', GssTemplateProcessor
+ end
+
+ end
+ end
+end
View
29 lib/closure/sprockets/soy_processor.rb
@@ -0,0 +1,29 @@
+require 'shellwords'
+
+module Closure
+ module Sprockets
+ class SoyTemplateProcessor < Tilt::Template
+ COMPILER_ROOT = File.expand_path(File.dirname(__FILE__))
+ COMPILER_JAR = File.join(COMPILER_ROOT, "/../jar/SoyToJsSrcCompiler.jar")
+
+ self.default_mime_type = 'application/javascript'
+
+ def self.engine_initialized?; true; end
+ def initialize_engine; end
+ def prepare; end
+
+ def evaluate(context, locals, &block)
+ context.require_asset 'soyutils'
+
+ # not the prettiest way to do this, but it works, for now...
+ out = file.gsub(/soy$/, 'soyjs')
+ `java -jar #{COMPILER_JAR.shellescape} --outputPathFormat #{out.shellescape} #{file.shellescape}`
+
+ @output = IO.read(out)
+ File.delete(out)
+
+ @output
+ end
+ end
+ end
+end
View
0  lib/closure-sprockets/version.rb → lib/closure/sprockets/version.rb
File renamed without changes
Please sign in to comment.
Something went wrong with that request. Please try again.