Permalink
Browse files

create rewrite rules and add it as json when pushing the app

  • Loading branch information...
Richard Metzler authored and quirkey committed Oct 29, 2010
1 parent c8e3138 commit 9cbb2a545dd2473df89708edd8425d094cc27eba
Showing with 28 additions and 0 deletions.
  1. +1 −0 lib/soca/cli.rb
  2. +2 −0 lib/soca/pusher.rb
  3. +8 −0 lib/soca/templates/rewrites.js.erb
  4. +4 −0 test/test_soca_cli.rb
  5. +5 −0 test/test_soca_pusher.rb
  6. +8 −0 test/testapp/rewrites.js
View
@@ -79,6 +79,7 @@ def generate(to = nil)
directory('db')
template('Jimfile')
template('index.html.erb', 'index.html')
+ template('rewrites.js.erb', 'rewrites.js')
@dir_mappings = {
"config.js" => "",
"index.html" => "_attachments/index.html",
View
@@ -138,6 +138,8 @@ def map_file(path, hash)
if base_path =~ /^_attachments/
hash['_attachments'] ||= {}
hash['_attachments'][base_path.gsub(/_attachments\//, '')] = make_attachment(path, file_data)
+ elsif base_path == 'rewrites.js'
+ hash['rewrites'] = JSON.parse(file_data)
else
parts = base_path.gsub(/^\//, '').gsub(/\.js$/, '').split('/')
current_hash = hash
@@ -0,0 +1,8 @@
+[
+ {
+ "from":"/",
+ "to":"index.html",
+ "method":"GET",
+ "query":{}
+ }
+]
View
@@ -57,6 +57,10 @@ class TestSocaCLI < Test::Unit::TestCase
assert_file(/\<html/, @new_app_dir, 'index.html')
end
+ should "generate a rewrites.js file" do
+ assert_file(/from/,@new_app_dir,'rewrites.js')
+ end
+
should "generate a css directory" do
assert_directory(@new_app_dir, 'css')
end
View
@@ -50,6 +50,11 @@ class TestSocaPusher < Test::Unit::TestCase
assert_match(/function/, @app_file['views']['recent']['map'])
assert @app_file['_attachments']['css/app.css']
end
+
+ should "include rewrites.js as json" do
+ assert @app_file['rewrites']
+ assert @app_file['rewrites'][0]['from']
+ end
end
context "push_url" do
View
@@ -0,0 +1,8 @@
+[
+ {
+ "from":"/",
+ "to":"index.html",
+ "method":"GET",
+ "query":{}
+ }
+]

0 comments on commit 9cbb2a5

Please sign in to comment.