Permalink
Browse files

fix calcdeps.py script for finding .js.erb and another variants of ex…

…tension, use finally deprecated script calcdeps.py instead of brand new closurebuilder.py for simplicity
  • Loading branch information...
1 parent 27470cc commit b7d89af15d6d3bac41722879a955918deab2bd70 @egorkhmelev egorkhmelev committed Feb 2, 2012
Showing with 14 additions and 6 deletions.
  1. +3 −1 lib/bin/calcdeps.py
  2. +9 −4 lib/closure-sprockets/directive_processor.rb
  3. +2 −1 lib/closure-sprockets/railtie.rb
View
@@ -45,6 +45,7 @@
prov_regex = re.compile('goog\.provide\s*\(\s*[\'\"]([^\)]+)[\'\"]\s*\)')
ns_regex = re.compile('^ns:((\w+\.)*(\w+))$')
version_regex = re.compile('[\.0-9]+')
+js_file_regex = re.compile(r'^.+\.js(\..*)?$')
def IsValidFile(ref):
@@ -54,7 +55,8 @@ def IsValidFile(ref):
def IsJsFile(ref):
"""Returns true if the provided reference is a Javascript file."""
- return ref.endswith('.js')
+ return js_file_regex.match(ref)
+ # return ref.endswith('.js')
def IsNamespace(ref):
@@ -1,19 +1,24 @@
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__)
+ # 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.select{ |p| p if p.include? context.environment.root }.each do |path|
- cmd << " --root=#{path}"
+ # cmd << " --root=#{path}" # for closurebuilder.py script
+ cmd << " --path=#{path}"
end
# closurebuilder.py needs some input files to start deps searching
file_pathname = context.resolve path
- cmd << " --input #{file_pathname}"
+ cmd << " --input=#{file_pathname}"
# Read stdout result and split it by strings
- results = `#{cmd}`.split "\n"
+ # results = `#{cmd}`.split "\n" # for closurebuilder.py script
+ results = `#{cmd} --output_mode=list`.split "\n"
# Finally require calculated deps
results.each{|dep| context.require_asset dep };
@@ -1,7 +1,8 @@
module ClosureProcessor
class Railtie < Rails::Engine
initializer :setup_closure do |app|
- app.assets.cache = false
+ # 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

0 comments on commit b7d89af

Please sign in to comment.