magic_lamp 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (24) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +43 -5
  3. data/VERSION +1 -1
  4. data/app/assets/javascripts/magic_lamp/genie.js +24 -8
  5. data/spec/dummy/log/development.log +14358 -0
  6. data/spec/dummy/log/test.log +7745 -0
  7. data/spec/dummy/tmp/cache/assets/development/sprockets/09bc89d8ac4ccacfcf2f4db466e7735f +0 -0
  8. data/spec/dummy/tmp/cache/assets/development/sprockets/18650d8ff9b0a83b32e55b58917ec791 +0 -0
  9. data/spec/dummy/tmp/cache/assets/development/sprockets/2ccef21649a61deac2c84f622753b77b +0 -0
  10. data/spec/dummy/tmp/cache/assets/development/sprockets/5bbf09297502a156801e9c65f4bd3db7 +0 -0
  11. data/spec/dummy/tmp/cache/assets/development/sprockets/759e97d6d411bc4cef7055a778e1bef3 +0 -0
  12. data/spec/dummy/tmp/cache/assets/development/sprockets/88fe64427f1fff8e41ca8ad0170da88a +0 -0
  13. data/spec/dummy/tmp/cache/assets/development/sprockets/8ed4b4f20fb65446181984e6df7d7c9b +0 -0
  14. data/spec/dummy/tmp/cache/assets/development/sprockets/96210dc070e479fcee862294afe5efc1 +0 -0
  15. data/spec/dummy/tmp/cache/assets/development/sprockets/972b6b0bb1fc0b1123077b4b2f4394bd +0 -0
  16. data/spec/dummy/tmp/cache/assets/development/sprockets/bfa154e8a12acdbc85028ad8130d9043 +0 -0
  17. data/spec/dummy/tmp/cache/assets/development/sprockets/cf573b52d944e8aea7f1dc03f9be9b2c +0 -0
  18. data/spec/dummy/tmp/cache/assets/development/sprockets/d98de652252dc6ae11b5b6db5588705b +0 -0
  19. data/spec/dummy/tmp/cache/assets/development/sprockets/f0aa53eb377a5d7cc83657ef33b02d25 +0 -0
  20. data/spec/dummy/tmp/cache/assets/development/sprockets/f5d1b7d2ec1c89dc32cc982b43502dc8 +0 -0
  21. data/spec/dummy/tmp/cache/assets/development/sprockets/f6256b2e4e609981d9eb420aae5bef46 +0 -0
  22. data/spec/javascripts/genie_spec.js +45 -17
  23. data/spec/javascripts/magic_lamp_spec.js +5 -0
  24. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 33f3da2cbb34f6a6ae52a955a4516f951c5d3a8b
4
- data.tar.gz: b955aa9d5410e195680a5fd5962fb0d9002741c5
3
+ metadata.gz: 69a906c254a61fe279023604c38c637f7df43548
4
+ data.tar.gz: 2ca061e786370cc9e820c336a3745ad7bf2394a8
5
5
  SHA512:
6
- metadata.gz: b65b5d21aa49f2f0cbf879123f256f7fee69a72a5652205d73e918000283a1e9d74918eb22ecd453b3abcbce2f8d15b00bbc953762b0cc70703bedeab8ea2a3f
7
- data.tar.gz: 9fdecee1b3990996c8b30ffd555598c7cbf66900b1d4bdb08ee2314c6951d2ed25a38cdc00149601c967d2dd8b53dedfd2e044ba409c046e73abc888d230f86e
6
+ metadata.gz: 7cc19bac382666dddd5334cc2155a2ef794991920372dcddbb3b6917fa9fe9b352096b31a6f9e8df809e7830abc3c4a188e5949f513d0c287ab7969d94962632
7
+ data.tar.gz: 0b6eaefe2022618da21240a2b98966b3ff271cc03f33a222563081fe1dc2585e6774b17663dc7eb37d8bed77956b2e49f92a9c7be1c139fdc6fdb4e491caa7f9
data/README.md CHANGED
@@ -119,6 +119,33 @@ Then you can go nuts testing your JavaScript against your actual template. If yo
119
119
  one request for your templates, simply call [`MagicLamp.preload();`](#preload) in your `spec_helper.js` to
120
120
  populate Magic Lamp's cache.
121
121
 
122
+ ### Loading multiple templates
123
+
124
+ Just pass more fixture names to `MagicLamp.load` and it will load them all. For example:
125
+ ```js
126
+ beforeEach(function() {
127
+ MagicLamp.load("orders/sidebar", "orders/form");
128
+ });
129
+ ```
130
+
131
+ with a sidebar template/partial that looks like this:
132
+ ```html
133
+ <div class="sidebar content">Links!</div>
134
+ ```
135
+
136
+ and a form template/partial that looks like this:
137
+ ```html
138
+ <div class="form content">Inputs!</div>
139
+ ```
140
+
141
+ will yield:
142
+ ```html
143
+ <div class="magic-lamp">
144
+ <div class="sidebar content">Links!</div>
145
+ <div class="form content">Inputs!</div>
146
+ </div>
147
+ ```
148
+
122
149
  ### A few more examples
123
150
  Here we're specifying which controller should render the template via the arguments hash
124
151
  to `fixture`. This gives us access to helper methods in the `fixture` block
@@ -367,11 +394,10 @@ Example:
367
394
  });
368
395
  ```
369
396
  ### load
370
- Call `MagicLamp.load` to load a fixture. It requires the name of the fixture and the fixture
371
- will be loaded into a `div` with a class of `magic-lamp`. It will destroy the previous fixture
372
- container if present so you never end up with duplicate fixture containers or end up with
373
- dom elements from previous loads. It will hit the network only on the first request for a given
374
- fixture. If you never want `load` to hit the network, call `MagicLamp.preload()` before your specs.
397
+ Call `MagicLamp.load` to load a fixture. It requires the name of the fixture and which will be loaded into a `div` with a class of `magic-lamp`. It will destroy the previous fixture container if present so you never end up with duplicate fixture containers or end up with dom elements from previous loads. It will hit the network only on the first request for a given
398
+ fixture. If you never want `load` to hit the network, call [`MagicLamp.preload()`](#preload) before your specs.
399
+
400
+ You can load multiple fixtures into the dom at the same time by simply passing more arguments to `load`.
375
401
 
376
402
  The call to get your template is completely synchronous.
377
403
 
@@ -380,6 +406,12 @@ Example:
380
406
  beforeEach(function() {
381
407
  MagicLamp.load("orders/foo");
382
408
  });
409
+
410
+ // or if you wanted multiple fixtures...
411
+
412
+ beforeEach(function() {
413
+ MagicLamp.load("orders/foo", "orders/bar", "orders/foo", "orders/baz");
414
+ });
383
415
  ```
384
416
  ### preload
385
417
  Call `MagicLamp.preload` to load all of your templates into MagicLamp's cache. This means you'll
@@ -460,6 +492,12 @@ MagicLamp.wishForMoreWishes => preload
460
492
  MagicLamp.polish => clean
461
493
  ```
462
494
 
495
+ ### Rake Tasks
496
+ ```
497
+ rake mlfn => rake magic_lamp:fixture_names
498
+ rake mll => rake magic_lamp:lint
499
+ ```
500
+
463
501
  Contributing
464
502
  ------------
465
503
  1. [Fork it](https://github.com/crismali/magic_lamp/fork)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.0
1
+ 1.3.0
@@ -8,10 +8,22 @@
8
8
 
9
9
  Genie.prototype = {
10
10
 
11
- load: function(path) {
11
+ load: function() {
12
12
  this.removeFixtureContainer();
13
- var fixture = this.cache[path];
14
13
  this.createFixtureContainer();
14
+ var fixture = '';
15
+ var context = this;
16
+
17
+ each(arguments, function(path) {
18
+ fixture += context.retrieveFixture(path);
19
+ });
20
+
21
+ this.fixtureContainer.innerHTML = fixture;
22
+ this.appendFixtureContainer();
23
+ },
24
+
25
+ retrieveFixture: function(path) {
26
+ var fixture = this.cache[path];
15
27
 
16
28
  if (!fixture && this.cacheOnly) {
17
29
  throw new Error('The fixture "' + path + '" was not preloaded. Is the fixture registered? Call `MagicLamp.fixtureNames()` to see what is registered.');
@@ -19,9 +31,7 @@
19
31
  var xhr = this.xhrRequest(getPath() + '/' + path);
20
32
  this.cache[path] = fixture = xhr.responseText;
21
33
  }
22
-
23
- this.fixtureContainer.innerHTML = fixture;
24
- this.appendFixtureContainer();
34
+ return fixture;
25
35
  },
26
36
 
27
37
  preload: function() {
@@ -39,9 +49,9 @@
39
49
  }
40
50
  }
41
51
  var sortedNames = names.sort();
42
- for (var i = 0; i < sortedNames.length; i++) {
43
- console.log(sortedNames[i]);
44
- };
52
+ each(sortedNames, function(name) {
53
+ console.log(name);
54
+ });
45
55
 
46
56
  return sortedNames;
47
57
  },
@@ -97,6 +107,12 @@
97
107
  parentNode && parentNode.removeChild(node);
98
108
  }
99
109
 
110
+ function each(collection, callback) {
111
+ for (var i = 0; i < collection.length; i++) {
112
+ callback(collection[i]);
113
+ };
114
+ }
115
+
100
116
  function newXhr() {
101
117
  var xhr;
102
118
  if (window.XMLHttpRequest) { // Mozilla, Safari, ...