Permalink
Browse files

fixing filename generation for camelcased apps

  • Loading branch information...
Ryan Fitzgerald
Ryan Fitzgerald committed Aug 8, 2011
1 parent 104adfd commit f13375c9a59748b630501b804bcbd141119847c8
@@ -14,7 +14,7 @@ class InstallGenerator < Rails::Generators::Base
def inject_backbone
inject_into_file "app/assets/javascripts/application.js", :before => "//= require_tree" do
- "//= require underscore\n//= require backbone\n//= require backbone_rails_sync\n//= require backbone_datalink\n//= require backbone/#{js_app_name}\n"
+ "//= require underscore\n//= require backbone\n//= require backbone_rails_sync\n//= require backbone_datalink\n//= require backbone/#{application_name.underscore}\n"
end
end
@@ -26,7 +26,7 @@ def create_dir_layout
end
def create_app_file
- template "app.coffee", "app/assets/javascripts/backbone/#{js_app_name}.js.coffee"
+ template "app.coffee", "app/assets/javascripts/backbone/#{application_name.underscore}.js.coffee"
end
end
@@ -4,7 +4,7 @@
#= require_tree ./views
#= require_tree ./routers
-window.<%= application_name.camelize %> =
+window.<%= js_app_name %> =
Models: {}
Collections: {}
Routers: {}
@@ -7,7 +7,7 @@ def backbone_path
end
def model_namespace
- [application_name.camelize, "Models", class_name].join(".")
+ [js_app_name, "Models", class_name].join(".")
end
def singular_model_name
@@ -19,23 +19,23 @@ def plural_model_name
end
def collection_namespace
- [application_name.camelize, "Collections", plural_name.camelize].join(".")
+ [js_app_name, "Collections", plural_name.camelize].join(".")
end
def view_namespace
- [application_name.camelize, "Views", plural_name.camelize].join(".")
+ [js_app_name, "Views", plural_name.camelize].join(".")
end
def router_namespace
- [application_name.camelize, "Routers", plural_name.camelize].join(".")
+ [js_app_name, "Routers", plural_name.camelize].join(".")
end
def jst(action)
"backbone/templates/#{plural_name}/#{action}"
end
def js_app_name
- uncapitalize application_name.camelize
+ application_name.camelize
end
def application_name
@@ -21,6 +21,20 @@ def setup
assert_file "#{backbone_path}/dummy.js.coffee", /window\.Dummy/
end
+ test "Assert application coffeescript file is created for two word application name" do
+ Rails.application.class.stubs(:name).returns("FooBar::Application")
+ run_generator
+
+ assert_file "#{backbone_path}/foo_bar.js.coffee", /window\.FooBar/
+ end
+
+ test "Assert application require is properly setup for two word application name" do
+ Rails.application.class.stubs(:name).returns("FooBar::Application")
+ run_generator
+
+ assert_file "app/assets/javascripts/application.js", /require backbone\/foo_bar/
+ end
+
test "Assert backbone directory structure is created" do
run_generator

0 comments on commit f13375c

Please sign in to comment.