magic_carpet 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +202 -0
- data/README.md +232 -0
- data/Rakefile +15 -0
- data/app/assets/javascripts/magic_carpet/application.js +13 -0
- data/app/assets/javascripts/magic_carpet/magic_carpet.js +80 -0
- data/app/assets/stylesheets/magic_carpet/application.css +13 -0
- data/app/controllers/magic_carpet/application_controller.rb +4 -0
- data/app/controllers/magic_carpet/js_fixtures_controller.rb +110 -0
- data/app/helpers/magic_carpet/application_helper.rb +4 -0
- data/app/helpers/magic_carpet/js_fixtures_helper.rb +139 -0
- data/config/routes.rb +3 -0
- data/lib/magic_carpet/engine.rb +12 -0
- data/lib/magic_carpet/version.rb +3 -0
- data/lib/magic_carpet.rb +4 -0
- data/lib/tasks/magic_carpet_tasks.rake +4 -0
- data/spec/controllers/magic_carpet/js_fixtures_controller_spec.rb +275 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/javascripts/jquery-2.1.0.js +9111 -0
- data/spec/dummy/app/assets/javascripts/users.js +2 -0
- data/spec/dummy/app/assets/javascripts/wishes.js +2 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/assets/stylesheets/scaffold.css +56 -0
- data/spec/dummy/app/assets/stylesheets/users.css +4 -0
- data/spec/dummy/app/assets/stylesheets/wishes.css +4 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/controllers/users_controller.rb +58 -0
- data/spec/dummy/app/controllers/wishes_controller.rb +70 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/helpers/users_helper.rb +2 -0
- data/spec/dummy/app/helpers/wishes_helper.rb +2 -0
- data/spec/dummy/app/models/user.rb +3 -0
- data/spec/dummy/app/models/wish.rb +4 -0
- data/spec/dummy/app/views/layouts/application.html.erb +19 -0
- data/spec/dummy/app/views/layouts/other_layout.html.erb +15 -0
- data/spec/dummy/app/views/shared/_id_able.html.erb +5 -0
- data/spec/dummy/app/views/users/_form.html.erb +29 -0
- data/spec/dummy/app/views/users/edit.html.erb +6 -0
- data/spec/dummy/app/views/users/index.html.erb +31 -0
- data/spec/dummy/app/views/users/new.html.erb +5 -0
- data/spec/dummy/app/views/users/show.html.erb +19 -0
- data/spec/dummy/app/views/wishes/_form.html.erb +21 -0
- data/spec/dummy/app/views/wishes/_some_partial.html.erb +1 -0
- data/spec/dummy/app/views/wishes/_wish.html.erb +6 -0
- data/spec/dummy/app/views/wishes/_wish_list_item.html.erb +3 -0
- data/spec/dummy/app/views/wishes/edit.html.erb +6 -0
- data/spec/dummy/app/views/wishes/index.html.erb +22 -0
- data/spec/dummy/app/views/wishes/local_models.html.erb +3 -0
- data/spec/dummy/app/views/wishes/locals.html.erb +6 -0
- data/spec/dummy/app/views/wishes/new.html.erb +5 -0
- data/spec/dummy/app/views/wishes/numbers.html.erb +4 -0
- data/spec/dummy/app/views/wishes/plain.html.erb +1 -0
- data/spec/dummy/app/views/wishes/show.html.erb +9 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config/application.rb +28 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +29 -0
- data/spec/dummy/config/environments/production.rb +80 -0
- data/spec/dummy/config/environments/test.rb +36 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +12 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +9 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/20140201230228_create_wishes.rb +9 -0
- data/spec/dummy/db/migrate/20140201230247_create_users.rb +11 -0
- data/spec/dummy/db/migrate/20140208042514_associate_users_and_wishes.rb +5 -0
- data/spec/dummy/db/schema.rb +31 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +21112 -0
- data/spec/dummy/log/test.log +33634 -0
- data/spec/dummy/public/404.html +58 -0
- data/spec/dummy/public/422.html +58 -0
- data/spec/dummy/public/500.html +57 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/spec/javascripts/helpers/spec_helper.js +367 -0
- data/spec/dummy/spec/javascripts/magic_carpet_spec.js +314 -0
- data/spec/dummy/spec/javascripts/support/jasmine.yml +29 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/0743af5c3f490550c6a448f45e6889b4 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/0800f54ee19cf3cee10b956fa9786799 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/082245bc7cce1345893a81643f76284a +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/08b0d9573e11dc361c93563cec2a0106 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/09f277e17472af932cda6f7dd86ff943 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/0e3142f2ae2a0b8902383f65b86a5299 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/0f87038bb320b83592e071bff83e4195 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/10925724a66880466e7f3b4e158196cb +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/10fb651bf6e564ad505e391670c11a8d +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/12090b2e7e2e9ac2632e486d02ee346a +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/142047722c23a8e9a96c6355d224b67e +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/1b4c56479f40fe3f7fc8daf684f4f71c +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/1c3579416ea74586464f5969c6949d5d +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/1e259f0863fa6da47ded59eef77ac351 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/21d2c592e1570709ecd1208a030cfc66 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/220ab8240fd9e0712b64dd9ff515f5df +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/277a51802284d997817fcaca55211243 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/28c409c3bba590030a8074120aa781db +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/35906b4cd565b14db8ba786fc66c7eb3 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/371bf96e99717688ed7313a0c53f4212 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/388a1d725ffd01cc06a34d720ea97775 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/4050a4e5062ab95c9f32e9b6940821ea +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/442917e5b534e0e7ac0a3bac0c5299e7 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/45ccf991e042a7cf7abe52d1125eeae3 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/469198efe71fedae413489ff2fad66e4 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/4817f65b5fc5c2042e04af7eb83a4c99 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/497ff8927ce695e3febb3cdfd3e4a74e +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/510da110ae528e2d22533be39ff696c5 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/51202fde1d49c04c5d5588ca203b7b1e +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/55ea602f40a0ad2185e22964a16b4d42 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/596788b2d37e650dd4cf582b185f9d37 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/5c09faba4e454de97f078861e82db15c +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/5f1a0d05e77ca8b9a1fc2a47e17a8174 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/64de9e1fa2dd01768d6e85552dcdb18a +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/68c5fa1f98ca79274b1f6750d8611af5 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/6bcea01ea8389e9a2ee296904803a01c +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/6fc757c2c8329244ca95d6909865bbc2 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/7406b6e2ecfc7b024db7822fb753c796 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/744bda5bad4a3b9b9b244a4583fb6e29 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/786804147f5da16b37ef8932e422797c +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/793dc2ede21315a9eabfe2b0a0ff13d4 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/7b1c8fbfabc405ee6e5c8887095e6b43 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/7c2edc3a2733a7bc22c572af66983a2e +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/7cd1032c2c1fa8a02016ac207cd9c76f +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/7d4bf0f7a6d67ade27f05b9bbdfaa13f +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/809136388a8f6d7a862b20361fad205c +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/80ba335c5610df2a1defeab247d03cc9 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/817b43e6477d4059b9006261356b7147 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/81b537f4760199f4030b928268605909 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/83521bb0fd5da34426e16d8825eb314e +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/85b590662faa5956a7cb3a38390f16ca +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/8733ef9be8fb368ac9aa5b1ccbfce14c +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/87b209c0c9da28094a8d5581a21262c6 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/8931ae3296ab13e8eed90f434208887f +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/8cb4c1afbd9a270155d8cdd697a8b20d +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/8d1f1fbd708160b30af96a108fef6c0d +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/91ef1ca0ef363be62f4a38fb3fbc2291 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/9a25637a28779d7c49c40044188bd0e5 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/a0d10779d647db6ab1328734733a0e4d +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/a0e04aab47dc3631152c26632687f898 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/a74883b193a8e72f27cba5703a696a89 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/a839288628913e4533ef8cba740de1eb +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/a95ead461bd72142ffb3040f8cd7cfa0 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/ac47afc414ae67e366a330dc003edf1a +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/b1d1383958868d6f0e9e05c848682d70 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/b4ff5ac95c02b56ca97786b337f8b845 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/b718bc4e8c8146520d982e086897fe24 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/b848029d2fa6db3db28ccbce818b399b +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/ba05f15307eb6d2c7e31e50768867139 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/c1a8bdfcb2dca842a48acc85d3ff658a +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/c2eb6c5cabed0e6b333c035ac8400bbc +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/c3dbe303660d299b488648fc157fd32b +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/c45af704cb234484a8e1d0852f8fe0bc +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/c4868ba5188e0672b480e24d979224d0 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/caa2f86bb055636b69e292f2ae993914 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/ce4b669883cb8df0ccd1c6aca12e0434 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/cebc6db0bbb8120f430da3970b173d2f +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/d8a7bed1e7150777f59a9e107c1acaa8 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/db4f843f0e597f7ba079bec345a91d58 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/dd5a838f402c1f78ff0f6e43b3ce6624 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/dfd7187ca1d53815395570d20d933e13 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/e4092eb95487a855cb730373c97b8756 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/e41b3d9532b5ef87c246ef6eb88417ed +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/e8266bddb6510ce3a2bc5ae1469ab3f6 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/e86f67e739e4d85d5b8b1830b327ee67 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/efc1c13c84f6f8686ade375b47913c8d +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/f1e3cae1b4d4c1085b32f88d26fd1f89 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/f21b1a83f2c41f61ba73c424b057ee19 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/f25cc7f3223a9259336cb2dd38df220e +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/f56253b5f374fff1a33fbbc9881c9124 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/10fb651bf6e564ad505e391670c11a8d +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/142047722c23a8e9a96c6355d224b67e +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/371bf96e99717688ed7313a0c53f4212 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/4050a4e5062ab95c9f32e9b6940821ea +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/51202fde1d49c04c5d5588ca203b7b1e +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/596788b2d37e650dd4cf582b185f9d37 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/5f1a0d05e77ca8b9a1fc2a47e17a8174 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/6fc757c2c8329244ca95d6909865bbc2 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/81b537f4760199f4030b928268605909 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/87b209c0c9da28094a8d5581a21262c6 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/8cb4c1afbd9a270155d8cdd697a8b20d +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/f56253b5f374fff1a33fbbc9881c9124 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/spec/dummy/tmp/jasmine/assets/application.js +9132 -0
- data/spec/dummy/tmp/jasmine/assets/boot.js +204 -0
- data/spec/dummy/tmp/jasmine/assets/helpers/spec_helper.js +462 -0
- data/spec/dummy/tmp/jasmine/assets/jasmine-console-reporter.js +125 -0
- data/spec/dummy/tmp/jasmine/assets/jasmine-console-shims.js +31 -0
- data/spec/dummy/tmp/jasmine/assets/jasmine-html.js +360 -0
- data/spec/dummy/tmp/jasmine/assets/jasmine-specs.js +0 -0
- data/spec/dummy/tmp/jasmine/assets/jasmine.css +55 -0
- data/spec/dummy/tmp/jasmine/assets/jasmine.js +2403 -0
- data/spec/dummy/tmp/jasmine/assets/jquery-2.1.0.js +9112 -0
- data/spec/dummy/tmp/jasmine/assets/json2.js +479 -0
- data/spec/dummy/tmp/jasmine/assets/magic_carpet/application.js +95 -0
- data/spec/dummy/tmp/jasmine/assets/magic_carpet/magic_carpet.js +81 -0
- data/spec/dummy/tmp/jasmine/assets/magic_carpet_spec.js +317 -0
- data/spec/dummy/tmp/jasmine/assets/users.js +3 -0
- data/spec/dummy/tmp/jasmine/assets/wishes.js +3 -0
- data/spec/dummy/tmp/jasmine/runner.html +28 -0
- data/spec/dummy/tmp/pids/server.pid +1 -0
- data/spec/helpers/magic_carpet/js_fixtures_helper_spec.rb +249 -0
- data/spec/spec_helper.rb +14 -0
- metadata +590 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7b4f542fe84afd15b88006009e867c3fffea08f0
|
4
|
+
data.tar.gz: 427553d7e7c57a375b21400445d9575ae503c8cf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2671198a16ab43a33ba50816477bc7d0ce1a65bd9f27bf4d41d0f6289cfec88efcb226a2e001f1fef30f1af51ce2f0d1b1bc9ce762793edd09798233fd5a1550
|
7
|
+
data.tar.gz: 755209b1b90c3bfbf80c2b10135ebde4f8a0a935a0296395b0d7551a6f3f15e622fb07fddb5f2576747015d6fbf3b4c4cc9b651b25afbacd9573f20818ff38cb
|
data/LICENSE
ADDED
@@ -0,0 +1,202 @@
|
|
1
|
+
|
2
|
+
Apache License
|
3
|
+
Version 2.0, January 2004
|
4
|
+
http://www.apache.org/licenses/
|
5
|
+
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
7
|
+
|
8
|
+
1. Definitions.
|
9
|
+
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
12
|
+
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
14
|
+
the copyright owner that is granting the License.
|
15
|
+
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
17
|
+
other entities that control, are controlled by, or are under common
|
18
|
+
control with that entity. For the purposes of this definition,
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
20
|
+
direction or management of such entity, whether by contract or
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
23
|
+
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
25
|
+
exercising permissions granted by this License.
|
26
|
+
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
28
|
+
including but not limited to software source code, documentation
|
29
|
+
source, and configuration files.
|
30
|
+
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
32
|
+
transformation or translation of a Source form, including but
|
33
|
+
not limited to compiled object code, generated documentation,
|
34
|
+
and conversions to other media types.
|
35
|
+
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
37
|
+
Object form, made available under the License, as indicated by a
|
38
|
+
copyright notice that is included in or attached to the work
|
39
|
+
(an example is provided in the Appendix below).
|
40
|
+
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
47
|
+
the Work and Derivative Works thereof.
|
48
|
+
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
50
|
+
the original version of the Work and any modifications or additions
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
62
|
+
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
65
|
+
subsequently incorporated within the Work.
|
66
|
+
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
73
|
+
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
79
|
+
where such license applies only to those patent claims licensable
|
80
|
+
by such Contributor that are necessarily infringed by their
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
83
|
+
institute patent litigation against any entity (including a
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
86
|
+
or contributory patent infringement, then any patent licenses
|
87
|
+
granted to You under this License for that Work shall terminate
|
88
|
+
as of the date such litigation is filed.
|
89
|
+
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
92
|
+
modifications, and in Source or Object form, provided that You
|
93
|
+
meet the following conditions:
|
94
|
+
|
95
|
+
(a) You must give any other recipients of the Work or
|
96
|
+
Derivative Works a copy of this License; and
|
97
|
+
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
99
|
+
stating that You changed the files; and
|
100
|
+
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
103
|
+
attribution notices from the Source form of the Work,
|
104
|
+
excluding those notices that do not pertain to any part of
|
105
|
+
the Derivative Works; and
|
106
|
+
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
109
|
+
include a readable copy of the attribution notices contained
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
112
|
+
of the following places: within a NOTICE text file distributed
|
113
|
+
as part of the Derivative Works; within the Source form or
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
115
|
+
within a display generated by the Derivative Works, if and
|
116
|
+
wherever such third-party notices normally appear. The contents
|
117
|
+
of the NOTICE file are for informational purposes only and
|
118
|
+
do not modify the License. You may add Your own attribution
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
121
|
+
that such additional attribution notices cannot be construed
|
122
|
+
as modifying the License.
|
123
|
+
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
125
|
+
may provide additional or different license terms and conditions
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
129
|
+
the conditions stated in this License.
|
130
|
+
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
134
|
+
this License, without any additional terms or conditions.
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
136
|
+
the terms of any separate license agreement you may have executed
|
137
|
+
with Licensor regarding such Contributions.
|
138
|
+
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
141
|
+
except as required for reasonable and customary use in describing the
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
143
|
+
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
153
|
+
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
159
|
+
incidental, or consequential damages of any character arising as a
|
160
|
+
result of this License or out of the use or inability to use the
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
163
|
+
other commercial damages or losses), even if such Contributor
|
164
|
+
has been advised of the possibility of such damages.
|
165
|
+
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
169
|
+
or other liability obligations and/or rights consistent with this
|
170
|
+
License. However, in accepting such obligations, You may act only
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
175
|
+
of your accepting any such warranty or additional liability.
|
176
|
+
|
177
|
+
END OF TERMS AND CONDITIONS
|
178
|
+
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
180
|
+
|
181
|
+
To apply the Apache License to your work, attach the following
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
183
|
+
replaced with your own identifying information. (Don't include
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
185
|
+
comment syntax for the file format. We also recommend that a
|
186
|
+
file or class name and description of purpose be included on the
|
187
|
+
same "printed page" as the copyright notice for easier
|
188
|
+
identification within third-party archives.
|
189
|
+
|
190
|
+
Copyright 2014 Michael Crismali, Dayton Nolan
|
191
|
+
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
193
|
+
you may not use this file except in compliance with the License.
|
194
|
+
You may obtain a copy of the License at
|
195
|
+
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
197
|
+
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
201
|
+
See the License for the specific language governing permissions and
|
202
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,232 @@
|
|
1
|
+
Magic Carpet
|
2
|
+
===========
|
3
|
+
Magic Carpet takes your templates on a magical trip to your JavaScript tests.
|
4
|
+
|
5
|
+
This ensures that **if your templates change, your JavaScript tests will break too.** No more stubbed markup and clicking around in the browser to make sure your JavaScript works in "real life."
|
6
|
+
|
7
|
+
Magic Carpet can:
|
8
|
+
* render templates and partials in the context of any of your controllers
|
9
|
+
* set the state of any of those controllers (params, instance variables, etc)
|
10
|
+
* set local variables for the templates
|
11
|
+
* pretty much do whatever you want with your controller's `render` method
|
12
|
+
* append your templates to the DOM for you
|
13
|
+
* be synchronous or asynchronous
|
14
|
+
|
15
|
+
It also doesn't monkeypatch anything, so nothing weird will start happening during your Ruby tests or development.
|
16
|
+
|
17
|
+
## Installation
|
18
|
+
Add this line to your application's Gemfile (probably in the `test` and `development` groups):
|
19
|
+
|
20
|
+
gem "magic_carpet"
|
21
|
+
|
22
|
+
And then:
|
23
|
+
|
24
|
+
$ bundle
|
25
|
+
|
26
|
+
Or install it yourself like this:
|
27
|
+
|
28
|
+
$ gem install magic_carpet
|
29
|
+
|
30
|
+
## Setup
|
31
|
+
Add this to your `routes` file:
|
32
|
+
```ruby
|
33
|
+
# config/routes.rb
|
34
|
+
mount MagicCarpet::Engine => "/magic_carpet" if defined?(MagicCarpet)
|
35
|
+
```
|
36
|
+
### Pulling in the companion JavaScript
|
37
|
+
**Magic Carpet Js Dependencies:** [jQuery](https://jquery.org/) (only for `MagicCarpet.request`; also load order doesn't matter).
|
38
|
+
|
39
|
+
Anyway, you can throw this:
|
40
|
+
```javascript
|
41
|
+
//= require magic_carpet/magic_carpet
|
42
|
+
```
|
43
|
+
wherever the Asset Pipeline will pick up on it. If you're using [jasmine-rails](https://github.com/searls/jasmine-rails), you can put it at the top of any file in `spec/javascripts/helpers`. Or you can drop the [this file](https://github.com/daytonn/magic_carpet/blob/master/app/assets/javascripts/magic_carpet/magic_carpet.js) into wherever your test framework of choice will pick up on it.
|
44
|
+
### Without the companion JavaScript
|
45
|
+
Just make a `get` request to `/magic_carpet` with whatever paremeters you need to set the proper state on the controller to prepare the template.
|
46
|
+
## Usage
|
47
|
+
Just request the template you want with the specified state on the controller like so:
|
48
|
+
```javascript
|
49
|
+
MagicCarpet.request({
|
50
|
+
controller_name: "Wishes",
|
51
|
+
action_name: "index",
|
52
|
+
instance_variables: {
|
53
|
+
wishes: [
|
54
|
+
{ id: 1, model: "Wish", text: "more wishes" },
|
55
|
+
{ id: 2, model: "Wish", text: "more genies" },
|
56
|
+
{ id: 3, model: "Wish", text: "more wishes and genies" }
|
57
|
+
]
|
58
|
+
},
|
59
|
+
locals: {
|
60
|
+
truncate_text: "true"
|
61
|
+
}
|
62
|
+
});
|
63
|
+
```
|
64
|
+
Here we're just grabbing the `index` template from the `WishesController` and making sure that the `@wishes` is set to a collection of `Wish` objects so the template doesn't blow up when it's rendered. We're also setting a local variable called `truncate_text` to `true`. `action_name` and `template` are completely interchangeable:
|
65
|
+
```javascript
|
66
|
+
MagicCarpet.request({
|
67
|
+
controller_name: "Wishes",
|
68
|
+
template: "plain"
|
69
|
+
});
|
70
|
+
```
|
71
|
+
Also note that Magic Carpet never runs any controller actions or hits any of your routes. It just munges options and sets state before calling `render`.
|
72
|
+
|
73
|
+
You can also grab partials:
|
74
|
+
```javascript
|
75
|
+
MagicCarpet.request({
|
76
|
+
controller_name: "Wishes",
|
77
|
+
partial: "some_partial"
|
78
|
+
});
|
79
|
+
```
|
80
|
+
You can also have partial rendered with a collection and even pass it the `as` option (sometimes the as option is necessary):
|
81
|
+
```javascript
|
82
|
+
MagicCarpet.request({
|
83
|
+
controller_name: "Wishes",
|
84
|
+
partial: "wish",
|
85
|
+
collection: [
|
86
|
+
{ id: 1, model: "Wish", text: "wish text" },
|
87
|
+
{ id: 2, model: "Wish", text: "boring wish text" },
|
88
|
+
{ id: 3, model: "Wish", text: "last of the boring wish text" }
|
89
|
+
],
|
90
|
+
as: "wish"
|
91
|
+
});
|
92
|
+
```
|
93
|
+
Magic Carpet can also handle associations:
|
94
|
+
```javascript
|
95
|
+
MagicCarpet.request({
|
96
|
+
controller_name: "Wishes",
|
97
|
+
action_name: "show",
|
98
|
+
instance_variables: {
|
99
|
+
wish: {
|
100
|
+
id: 1,
|
101
|
+
model: "Wish",
|
102
|
+
text: "more wishes",
|
103
|
+
user: { id: 3, name: "Al" }
|
104
|
+
}
|
105
|
+
}
|
106
|
+
});
|
107
|
+
```
|
108
|
+
The type coercion is recursive, so feel free to nest associations and data structures as deeply as you like (although, if you need to do too much of that, your template might be a bit too complicated).
|
109
|
+
|
110
|
+
You can also set the `params`, `flash`, `session`, and `cookies` the template sees like so:
|
111
|
+
```javascript
|
112
|
+
MagicCarpet.request({
|
113
|
+
controller_name: "Wishes",
|
114
|
+
template: "upon_a_start",
|
115
|
+
flash: {
|
116
|
+
success: "Woohoo!"
|
117
|
+
},
|
118
|
+
cookies: {
|
119
|
+
user_id: 5
|
120
|
+
},
|
121
|
+
params: {
|
122
|
+
wish_id: 10
|
123
|
+
},
|
124
|
+
session: {
|
125
|
+
token: "TOP SECRET"
|
126
|
+
}
|
127
|
+
});
|
128
|
+
```
|
129
|
+
### Synchronous and Async
|
130
|
+
By default `MagicCarpet.request` is synchronous, but you can make it asynchronous by changing `MagicCarpet.asyc` to `true`. `MagicCarpet.asyncComplete` will be `true` when the request is finished.
|
131
|
+
### Your Template and the DOM
|
132
|
+
By default, `MagicCarpet` appends a div with an id of `magic-carpet` to the body of the page and puts the requested template in there. If you'd rather have your template put somewhere else, just change `MagicCarpet.sandbox` to the html node that you want to contain the template.
|
133
|
+
### Clean Up
|
134
|
+
You can empty the div that MagicCarpet puts templates in by calling `MagicCarpet.emptySandbox()`.
|
135
|
+
### Caching Responses
|
136
|
+
Magic Carpet will cache responses so if you request the same template the same way a bunch of times it will skip unnecessary extra calls to the server. If you want to empty the cache for whatever reason, just set `MagicCarpet.cache` to an empty object.
|
137
|
+
### All Options
|
138
|
+
Here's a list of all the options you can pass `MagicCarpet.request`:
|
139
|
+
* `controller_name`
|
140
|
+
* `action_name`
|
141
|
+
* `template`
|
142
|
+
* `partial`
|
143
|
+
* `locals`
|
144
|
+
* `instance_variables`
|
145
|
+
* `collection`
|
146
|
+
* `as`
|
147
|
+
* `params`
|
148
|
+
* `session`
|
149
|
+
* `flash`
|
150
|
+
* `cookies`
|
151
|
+
* `layout`
|
152
|
+
|
153
|
+
## Type Coercion
|
154
|
+
### Booleans and Nil
|
155
|
+
Booleans and `nil` can be coerced by simply sending a string of their name, ie `"true"`, `"false"`, and `"nil"`.
|
156
|
+
### "Models"
|
157
|
+
Models is in quotes above because the object doesn't necessarily need to be and ActiveRecord object or ActiveModel at all. Magic Carpet grabs the specified 'model' class and passes the rest of the hash into the model class's `new` method. Like this:
|
158
|
+
```javascript
|
159
|
+
// You send an object that looks like this:
|
160
|
+
{
|
161
|
+
model: "Wish",
|
162
|
+
id: 4,
|
163
|
+
text: "howdy",
|
164
|
+
some_other_attribute: "value"
|
165
|
+
}
|
166
|
+
```
|
167
|
+
And Magic Carpet essentially does this:
|
168
|
+
```ruby
|
169
|
+
Wish.new({
|
170
|
+
id: 4,
|
171
|
+
text: "howdy",
|
172
|
+
some_other_attribute: "value"
|
173
|
+
})
|
174
|
+
```
|
175
|
+
`OpenStruct` is a good candidate when you need a stubbed object.
|
176
|
+
### Numbers
|
177
|
+
If you need a number to actually _be_ a number (ie not a `String`), just tell Magic Carpet:
|
178
|
+
```javascript
|
179
|
+
// any of these
|
180
|
+
{ number: "5.5" }
|
181
|
+
{ number: 5.5 }
|
182
|
+
{
|
183
|
+
number: 5.5,
|
184
|
+
integer: true
|
185
|
+
}
|
186
|
+
// or these
|
187
|
+
{
|
188
|
+
number: 5.5,
|
189
|
+
integer: false // doesn't matter what's here, if the integer key is present, you get an integer.
|
190
|
+
}
|
191
|
+
// or these
|
192
|
+
{
|
193
|
+
number: 5.5,
|
194
|
+
integer: "anything"
|
195
|
+
}
|
196
|
+
```
|
197
|
+
Without the `integer` option, it will coerce the type via `to_f`, with the integer option present it will use `to_i`.
|
198
|
+
### Dates, Times, and DateTimes
|
199
|
+
`Dates`, `Times`, and `DateTimes` will all be parsed according to there respsective `parse` methods. Just use `date`, `time`, or `datetime` as a key that points to a parsable string (`MagicCarpet.request` will `toString()` whatever you give it, so raw `Date` objects or `moment` objects are fine too).
|
200
|
+
|
201
|
+
`Times` also have a `utc` option you can pass them (it doesn't matter what the key points to, its presence will trigger the behavior). It just calls `utc` on the `Time` object.
|
202
|
+
```javascript
|
203
|
+
// any of these
|
204
|
+
{ date: "Sat Apr 12 2014 20:44:24 GMT-0500 (CDT)" }
|
205
|
+
{ datetime: "Sat Apr 12 2014 20:44:24 GMT-0500 (CDT)" }
|
206
|
+
{
|
207
|
+
time: "Sat Apr 12 2014 20:44:24 GMT-0500 (CDT)",
|
208
|
+
utc: true
|
209
|
+
}
|
210
|
+
// or these
|
211
|
+
{ date: new Date() }
|
212
|
+
{ datetime: new Date() }
|
213
|
+
{
|
214
|
+
time: new Date(),
|
215
|
+
utc: false
|
216
|
+
}
|
217
|
+
// or these
|
218
|
+
{ date: moment() }
|
219
|
+
{ datetime: moment() }
|
220
|
+
{
|
221
|
+
time: moment(),
|
222
|
+
utc: "anything"
|
223
|
+
}
|
224
|
+
```
|
225
|
+
## Errors
|
226
|
+
MagicCarpet will throw descriptive errors in the JavaScript and in your server logs if something breaks in your template, if you've attempted to render a template that doesn't exist, you've sent an unparseable date string, or if something else goes wrong. If you read the errors it should be easy to figure out what's wrong. If it's not, create a new issue here or make a pull request.
|
227
|
+
## Contributing
|
228
|
+
1. Fork it
|
229
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
230
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
231
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
232
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
8
|
+
load 'rails/tasks/engine.rake'
|
9
|
+
Bundler::GemHelper.install_tasks
|
10
|
+
Dir[File.join(File.dirname(__FILE__), 'tasks/**/*.rake')].each {|f| load f }
|
11
|
+
require 'rspec/core'
|
12
|
+
require 'rspec/core/rake_task'
|
13
|
+
desc "Run all specs in spec directory (excluding plugin specs)"
|
14
|
+
RSpec::Core::RakeTask.new(:spec => 'app:db:test:prepare')
|
15
|
+
task :default => :spec
|
@@ -0,0 +1,13 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require magic_carpet/magic_carpet
|
@@ -0,0 +1,80 @@
|
|
1
|
+
(MagicCarpet = {
|
2
|
+
async: false,
|
3
|
+
asyncComplete: true,
|
4
|
+
cache: {},
|
5
|
+
|
6
|
+
initialize: function() {
|
7
|
+
this.bindAll();
|
8
|
+
this.cacheElements();
|
9
|
+
this.appendSandbox();
|
10
|
+
},
|
11
|
+
|
12
|
+
bindAll: function() {
|
13
|
+
for(var prop in this) {
|
14
|
+
if (typeof this[prop] === "function" && this.hasOwnProperty(prop))
|
15
|
+
this.bind(this, prop);
|
16
|
+
}
|
17
|
+
},
|
18
|
+
|
19
|
+
bind: function(context, methodName) {
|
20
|
+
var func = context[methodName];
|
21
|
+
context[methodName] = function() {
|
22
|
+
return func.apply(context, arguments);
|
23
|
+
};
|
24
|
+
},
|
25
|
+
|
26
|
+
cacheElements: function() {
|
27
|
+
this.sandbox = this.createSandbox();
|
28
|
+
},
|
29
|
+
|
30
|
+
createSandbox: function() {
|
31
|
+
var div = document.createElement("div");
|
32
|
+
div.setAttribute("id", "magic-carpet");
|
33
|
+
return div;
|
34
|
+
},
|
35
|
+
|
36
|
+
appendSandbox: function() {
|
37
|
+
document.body.appendChild(this.sandbox);
|
38
|
+
},
|
39
|
+
|
40
|
+
emptySandbox: function() {
|
41
|
+
this.sandbox.innerHTML = "";
|
42
|
+
},
|
43
|
+
|
44
|
+
request: function(data) {
|
45
|
+
var cachedMarkup = this.cache[$.param(data)];
|
46
|
+
if (cachedMarkup) {
|
47
|
+
this.sandbox.innerHTML = cachedMarkup;
|
48
|
+
} else {
|
49
|
+
this.fetch(data);
|
50
|
+
}
|
51
|
+
},
|
52
|
+
|
53
|
+
fetch: function(data) {
|
54
|
+
this.lastRequest = data;
|
55
|
+
this.asyncComplete = false;
|
56
|
+
$.ajax({
|
57
|
+
url: "/magic_carpet",
|
58
|
+
method: "get",
|
59
|
+
async: this.async,
|
60
|
+
data: data
|
61
|
+
})
|
62
|
+
.done(this.handleSuccess)
|
63
|
+
.fail(this.handleFailure)
|
64
|
+
.always(this.afterRequest);
|
65
|
+
},
|
66
|
+
|
67
|
+
handleSuccess: function(markup) {
|
68
|
+
var cacheKey = $.param(this.lastRequest);
|
69
|
+
this.cache[cacheKey] = markup;
|
70
|
+
this.request(this.lastRequest);
|
71
|
+
},
|
72
|
+
|
73
|
+
handleFailure: function(response) {
|
74
|
+
throw new Error(response.responseJSON.error);
|
75
|
+
},
|
76
|
+
|
77
|
+
afterRequest: function() {
|
78
|
+
this.asyncComplete = true;
|
79
|
+
}
|
80
|
+
}).initialize();
|
@@ -0,0 +1,13 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the top of the
|
9
|
+
* compiled file, but it's generally better to create a new file per style scope.
|
10
|
+
*
|
11
|
+
*= require_self
|
12
|
+
*= require_tree .
|
13
|
+
*/
|
@@ -0,0 +1,110 @@
|
|
1
|
+
require_dependency "magic_carpet/application_controller"
|
2
|
+
|
3
|
+
module MagicCarpet
|
4
|
+
class JsFixturesController < ApplicationController
|
5
|
+
include JsFixturesHelper
|
6
|
+
|
7
|
+
def index
|
8
|
+
render text: controller.render_to_string(*build_options)
|
9
|
+
end
|
10
|
+
|
11
|
+
rescue_from "NameError" do |exception|
|
12
|
+
message = name_error_message(exception)
|
13
|
+
log_error(exception, message)
|
14
|
+
render_error(message)
|
15
|
+
end
|
16
|
+
|
17
|
+
rescue_from "NoMethodError" do |exception|
|
18
|
+
line_info = exception.backtrace.find { |line| line.match(/app\/views\/.*\.html\./) }
|
19
|
+
message = "#{exception.class}: #{exception.message}\n#{line_info}"
|
20
|
+
log_error(exception, message)
|
21
|
+
render_error(message)
|
22
|
+
end
|
23
|
+
|
24
|
+
rescue_from "ArgumentError" do |exception|
|
25
|
+
log_error(exception)
|
26
|
+
render_error(exception.message)
|
27
|
+
end
|
28
|
+
|
29
|
+
rescue_from "ActionView::MissingTemplate" do |exception|
|
30
|
+
log_error(exception)
|
31
|
+
render_error(exception.message)
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def name_error_message(exception)
|
37
|
+
if exception.name
|
38
|
+
missing_variable_or_method = exception.message.split(" for ").first
|
39
|
+
"#{missing_variable_or_method} for '#{template_name}' template."
|
40
|
+
else
|
41
|
+
missing_constant = exception.message.split("::").last
|
42
|
+
"#{missing_constant} not found."
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def log_error(exception, message = exception.message)
|
47
|
+
message_with_backtrace = ([message] + exception.backtrace).join("\n\s\s\s\s")
|
48
|
+
logger.error(message_with_backtrace)
|
49
|
+
end
|
50
|
+
|
51
|
+
def render_error(message)
|
52
|
+
render json: { error: "Magic Carpet Error: #{message}" }, status: 400
|
53
|
+
end
|
54
|
+
|
55
|
+
def controller
|
56
|
+
@controller ||= create_controller
|
57
|
+
end
|
58
|
+
|
59
|
+
def create_controller
|
60
|
+
new_controller = self.class.const_get("#{params[:controller_name]}Controller").new
|
61
|
+
new_controller.request = ActionDispatch::TestRequest.new
|
62
|
+
set_instance_variables(new_controller) if params.key?(:instance_variables)
|
63
|
+
set_controller_hashes(new_controller)
|
64
|
+
new_controller
|
65
|
+
end
|
66
|
+
|
67
|
+
def set_instance_variables(controller_instance)
|
68
|
+
instance_variables_hash = hydrate(params[:instance_variables])
|
69
|
+
instance_variables_hash.each do |name, value|
|
70
|
+
controller_instance.instance_variable_set("@#{name}", value)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def set_controller_hashes(controller_instance)
|
75
|
+
[:flash, :params, :session, :cookies].each do |hash_name|
|
76
|
+
if params.key?(hash_name)
|
77
|
+
set_controller_hash(controller_instance.send(hash_name), hash_name)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def set_controller_hash(controller_hash, hash_name)
|
83
|
+
params[hash_name].each do |key, value|
|
84
|
+
controller_hash[key] = value
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def build_options
|
89
|
+
options = {}
|
90
|
+
options[:layout] = params.fetch(:layout, false)
|
91
|
+
options[:locals] = hydrate(params[:locals]) if params.key?(:locals)
|
92
|
+
if params.key?(:partial)
|
93
|
+
[partial_options(options)]
|
94
|
+
else
|
95
|
+
[template_name, options]
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def partial_options(options)
|
100
|
+
options[:partial] = params[:partial]
|
101
|
+
options[:collection] = hydrate(params[:collection]) if params.key?(:collection)
|
102
|
+
options[:as] = params[:as] if params.key?(:as)
|
103
|
+
options
|
104
|
+
end
|
105
|
+
|
106
|
+
def template_name
|
107
|
+
params.fetch(:template, params[:action_name].to_s)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|