pinball_wizard 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 42cbebb8dd5c1c26041835f0bf8149703670e028
4
- data.tar.gz: d9222cff9a8711eaf7a1423ecc4f5a52cc383b6f
3
+ metadata.gz: 78d6696dbc0eb16536cecb49b6ca0b9afc6416e8
4
+ data.tar.gz: 5a931d205815ff4b35f562c7ac2d306ee7bdb096
5
5
  SHA512:
6
- metadata.gz: 473cb966be4e5ef8151fec9a9a8b49c76a810593f235478a3a69435f5c2ff4825490bff06d573aaf96ff2664ac94867536d8f147f5f7f46de106f4980b107881
7
- data.tar.gz: e910016832eb2bb49ffc292b6e2be0c308800fbf1c46a7371c2ba2c13182d6ae61bebad9a0978d10e7ae233fefb90e97ce1e5077ec0d11b723842348a54081ae
6
+ metadata.gz: b6c2b38b3675d9337810fb94a8e34b98fdb401fd939017b9b93eb4d8b4a7e0d118c1ac13213d9b9d297154569ac8586213b47558b943ba295807da8c2997ccc4
7
+ data.tar.gz: 9a5284f3b01f5427415c7090a547a74da5acfbe5f774e138a0ee85045a8a0d829d64b4167eb24509b4ab789728d00b5c8b68bc05e0778d95562aac9d24b7d8db
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ # v0.4.0
2
+ * [feature] Added `#activatePermanently('feature_name')` to
3
+ activate features across URLs. Stored in `localStorage`
4
+ * [feature] Added `#resetPermanent` which clears all permanent.
5
+ * [feature] Added `#permanent` which lists out features turned on.
6
+
7
+ [Compare v0.3.0..v0.4.0](https://github.com/primedia/pinball_wizard/compare/v0.3.0...v0.4.0)
8
+
1
9
  # v0.3.0
2
10
  * [feature] Automatically add and remove CSS class `.use-{feature-name}` to `<html>` as features are enabled and disabled.
3
11
  * [feature] Switch to karma for the test runner.
data/README.md CHANGED
@@ -29,7 +29,7 @@ A feature is simply a name and default state:
29
29
 
30
30
  ## Ruby
31
31
 
32
- Define your feature in (typically `config/initializers/pinball_wizard.rb`).
32
+ Define your feature (typically in `config/initializers/pinball_wizard.rb`).
33
33
 
34
34
  ```ruby
35
35
  PinballWizard::DSL.build do
@@ -41,7 +41,7 @@ PinballWizard::DSL.build do
41
41
  end
42
42
  ```
43
43
 
44
- You can also pass in a proc for situtations where active/inactive is conditional. Returning false with make the feature inactive.
44
+ You can also pass in a proc for situtations where active/inactive is conditional. Returning false will make the feature inactive.
45
45
 
46
46
  ```ruby
47
47
  PinballWizard::DSL.build do
@@ -113,9 +113,9 @@ define ['pinball_wizard'], (pinball) ->
113
113
 
114
114
  @after 'initialize', ->
115
115
  pinball.subscribe 'example',
116
- =>
116
+ ->
117
117
  # callback when activated. e.g. show it
118
- =>
118
+ ->
119
119
  # callback when deactivated. e.g. hide it.
120
120
 
121
121
  ```
@@ -131,7 +131,7 @@ define ['pinball_wizard'], (pinball) ->
131
131
  # Do something
132
132
  ```
133
133
 
134
- ## Activating and Testing Features
134
+ ## Activating Features for Testing (once)
135
135
 
136
136
  ### With a URL Param
137
137
  Add `pinball` to the URL (e.g. `?pinball=example_a,example_b`).
@@ -156,7 +156,25 @@ activated while debugging.
156
156
  ```javascript
157
157
  pinball.activate('example','source name');
158
158
  ```
159
+ ## Activating Features (permanently)
159
160
 
161
+ To turn on and keep a feature on, you can activate it permanently in the console. This is only for your browser's session.
162
+
163
+ ```javascript
164
+ pinball.activatePermanently('example')
165
+ ```
166
+
167
+ #### See a List of Permanent Features
168
+
169
+ ```javascript
170
+ pinball.permanent()
171
+ ```
172
+
173
+ #### Reset Permanent Features
174
+
175
+ ```javascript
176
+ pinball.resetPermanent()
177
+ ```
160
178
 
161
179
  ## JsConfig
162
180
  The application keeps a list of features and passes them in the JsConfig object (e.g. `window.ApartmentGuide`). These define what's available and activated on page load. AG is hooked up to PinballWizard to automatically be aware of these. No additional code is necessary.
data/dist/css_tagger.js CHANGED
@@ -1,13 +1,13 @@
1
1
  (function() {
2
2
  define(function() {
3
3
  return function(ele, pinballQueue, searchQuery) {
4
- var add, classNames, entry, feature, featureNames, matches, state, _i, _j, _len, _len1, _ref;
4
+ var add, classNames, entry, feature, featureNames, i, j, len, len1, matches, ref, state;
5
5
  classNames = [];
6
6
  add = function(name) {
7
7
  return classNames.push('use-' + name.split('_').join('-'));
8
8
  };
9
- for (_i = 0, _len = pinballQueue.length; _i < _len; _i++) {
10
- entry = pinballQueue[_i];
9
+ for (i = 0, len = pinballQueue.length; i < len; i++) {
10
+ entry = pinballQueue[i];
11
11
  if (!entry.length) {
12
12
  continue;
13
13
  }
@@ -16,9 +16,9 @@
16
16
  add(entry[1]);
17
17
  break;
18
18
  case 'add':
19
- _ref = entry[1];
20
- for (feature in _ref) {
21
- state = _ref[feature];
19
+ ref = entry[1];
20
+ for (feature in ref) {
21
+ state = ref[feature];
22
22
  if (state === 'active') {
23
23
  add(feature);
24
24
  }
@@ -28,8 +28,8 @@
28
28
  matches = searchQuery.match(/pinball=([a-z-_,]+)/i);
29
29
  if (matches && matches.length > 1) {
30
30
  featureNames = (matches[1] + '').split(',');
31
- for (_j = 0, _len1 = featureNames.length; _j < _len1; _j++) {
32
- feature = featureNames[_j];
31
+ for (j = 0, len1 = featureNames.length; j < len1; j++) {
32
+ feature = featureNames[j];
33
33
  add(feature);
34
34
  }
35
35
  }
@@ -1,55 +1,55 @@
1
1
  (function() {
2
2
  'use strict';
3
- var __slice = [].slice;
3
+ var slice = [].slice;
4
4
 
5
5
  define(function() {
6
- var activate, add, addCSSClassName, cssClassName, deactivate, debug, exports, features, get, isActive, logPrefix, push, removeCSSClassName, reset, showLog, state, subscribe, subscribers, update, urlValues, _buildSubscriber, _log, _notifySubscriberOnActivate, _notifySubscribersOnActivate, _notifySubscribersOnDeactivate, _urlValueMatches, _urlValues;
6
+ var _buildSubscriber, _log, _notifySubscriberOnActivate, _notifySubscribersOnActivate, _notifySubscribersOnDeactivate, _urlValueMatches, _urlValues, activate, activateAllPermanent, activatePermanently, add, addCSSClassName, appendPermanent, cssClassName, deactivate, debug, exports, features, get, isActive, logPrefix, permanent, push, removeCSSClassName, reset, resetPermanent, setPermanent, showLog, state, storage, subscribe, subscribers, update, urlValues;
7
7
  features = {};
8
8
  subscribers = {};
9
9
  showLog = false;
10
10
  logPrefix = '[PinballWizard]';
11
11
  _log = function() {
12
12
  var args, message;
13
- message = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
13
+ message = arguments[0], args = 2 <= arguments.length ? slice.call(arguments, 1) : [];
14
14
  if (showLog && window.console && window.console.log) {
15
- console.log.apply(console, ["" + logPrefix + " " + message].concat(__slice.call(args)));
15
+ console.log.apply(console, [logPrefix + " " + message].concat(slice.call(args)));
16
16
  }
17
17
  };
18
18
  _notifySubscribersOnActivate = function(name) {
19
- var subscriber, _i, _len, _ref, _results;
19
+ var i, len, ref, results, subscriber;
20
20
  if (subscribers[name] == null) {
21
21
  subscribers[name] = [];
22
22
  }
23
- _ref = subscribers[name];
24
- _results = [];
25
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
26
- subscriber = _ref[_i];
27
- _results.push(_notifySubscriberOnActivate(subscriber, name));
23
+ ref = subscribers[name];
24
+ results = [];
25
+ for (i = 0, len = ref.length; i < len; i++) {
26
+ subscriber = ref[i];
27
+ results.push(_notifySubscriberOnActivate(subscriber, name));
28
28
  }
29
- return _results;
29
+ return results;
30
30
  };
31
31
  _notifySubscriberOnActivate = function(subscriber, name) {
32
32
  _log('Notify subscriber that %s is active', name);
33
33
  return subscriber.onActivate();
34
34
  };
35
35
  _notifySubscribersOnDeactivate = function(name) {
36
- var subscriber, _i, _len, _ref, _results;
36
+ var i, len, ref, results, subscriber;
37
37
  if (subscribers[name] == null) {
38
38
  subscribers[name] = [];
39
39
  }
40
- _ref = subscribers[name];
41
- _results = [];
42
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
43
- subscriber = _ref[_i];
44
- _results.push(subscriber.onDeactivate());
40
+ ref = subscribers[name];
41
+ results = [];
42
+ for (i = 0, len = ref.length; i < len; i++) {
43
+ subscriber = ref[i];
44
+ results.push(subscriber.onDeactivate());
45
45
  }
46
- return _results;
46
+ return results;
47
47
  };
48
48
  _urlValueMatches = function(value) {
49
- var v, _i, _len, _ref;
50
- _ref = _urlValues();
51
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
52
- v = _ref[_i];
49
+ var i, len, ref, v;
50
+ ref = _urlValues();
51
+ for (i = 0, len = ref.length; i < len; i++) {
52
+ v = ref[i];
53
53
  if (value === v) {
54
54
  return true;
55
55
  }
@@ -57,14 +57,14 @@
57
57
  return false;
58
58
  };
59
59
  _urlValues = function(search) {
60
- var key, pair, pairs, value, _i, _len, _ref;
60
+ var i, key, len, pair, pairs, ref, value;
61
61
  if (search == null) {
62
62
  search = window.location.search;
63
63
  }
64
64
  pairs = search.substr(1).split('&');
65
- for (_i = 0, _len = pairs.length; _i < _len; _i++) {
66
- pair = pairs[_i];
67
- _ref = pair.split('='), key = _ref[0], value = _ref[1];
65
+ for (i = 0, len = pairs.length; i < len; i++) {
66
+ pair = pairs[i];
67
+ ref = pair.split('='), key = ref[0], value = ref[1];
68
68
  if (key === 'pinball' && (value != null)) {
69
69
  return value.split(',');
70
70
  }
@@ -99,21 +99,21 @@
99
99
  }
100
100
  };
101
101
  add = function(list) {
102
- var name, state, _results;
103
- _results = [];
102
+ var name, results, state;
103
+ results = [];
104
104
  for (name in list) {
105
105
  state = list[name];
106
106
  features[name] = state;
107
107
  _log("Added %s: %s.", name, state);
108
108
  if (isActive(name)) {
109
- _results.push(activate(name, "automatic. added as '" + state + "'"));
109
+ results.push(activate(name, "automatic. added as '" + state + "'"));
110
110
  } else if (_urlValueMatches(name, urlValues)) {
111
- _results.push(activate(name, 'URL'));
111
+ results.push(activate(name, 'URL'));
112
112
  } else {
113
- _results.push(void 0);
113
+ results.push(void 0);
114
114
  }
115
115
  }
116
- return _results;
116
+ return results;
117
117
  };
118
118
  get = function(name) {
119
119
  return features[name];
@@ -187,6 +187,36 @@
187
187
  method = params.shift();
188
188
  return this[method].apply(this, params);
189
189
  };
190
+ storage = window.localStorage;
191
+ setPermanent = function(value) {
192
+ return storage.setItem('pinball_wizard', JSON.stringify(value));
193
+ };
194
+ appendPermanent = function(name) {
195
+ var l;
196
+ l = permanent();
197
+ l.push(name);
198
+ return setPermanent(l);
199
+ };
200
+ permanent = function() {
201
+ return JSON.parse(storage.getItem('pinball_wizard') || "[]") || [];
202
+ };
203
+ activatePermanently = function(name) {
204
+ appendPermanent(name);
205
+ return activate(name, 'permanent');
206
+ };
207
+ resetPermanent = function() {
208
+ return setPermanent([]);
209
+ };
210
+ activateAllPermanent = function() {
211
+ var i, len, name, ref, results;
212
+ ref = permanent();
213
+ results = [];
214
+ for (i = 0, len = ref.length; i < len; i++) {
215
+ name = ref[i];
216
+ results.push(activate(name));
217
+ }
218
+ return results;
219
+ };
190
220
  state = function() {
191
221
  return features;
192
222
  };
@@ -210,7 +240,11 @@
210
240
  cssClassName: cssClassName,
211
241
  addCSSClassName: addCSSClassName,
212
242
  removeCSSClassName: removeCSSClassName,
213
- _urlValues: _urlValues
243
+ _urlValues: _urlValues,
244
+ activatePermanently: activatePermanently,
245
+ resetPermanent: resetPermanent,
246
+ permanent: permanent,
247
+ activateAllPermanent: activateAllPermanent
214
248
  };
215
249
  if (typeof window !== "undefined" && window !== null ? window.pinball : void 0) {
216
250
  if (_urlValueMatches('debug')) {
@@ -221,6 +255,7 @@
221
255
  }
222
256
  window.pinball = exports;
223
257
  }
258
+ activateAllPermanent();
224
259
  return exports;
225
260
  });
226
261
 
@@ -1,3 +1,3 @@
1
1
  module PinballWizard
2
- VERSION = '0.3.0'
2
+ VERSION = '0.4.0'
3
3
  end
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinball_wizard",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "pinball_wizard",
5
5
  "homepage": "https://github.com/primedia/pinball_wizard",
6
6
  "license": "MIT",
@@ -14,7 +14,7 @@
14
14
  "github": "https://github.com/primedia/pinball_wizard.git",
15
15
  "devDependencies": {
16
16
  "del": "^1.1.0",
17
- "gulp": "^3.8.10",
17
+ "gulp": "~3.8.10",
18
18
  "gulp-coffee": "^2.2.0",
19
19
  "gulp-sourcemaps": "~1.2.0",
20
20
  "gulp-util": "^3.0.1",
@@ -23,8 +23,7 @@
23
23
  "karma-cli": "0.0.4",
24
24
  "karma-chrome-launcher": "~0.1.7",
25
25
  "requirejs": "~2.1.15",
26
- "karma-requirejs": "~0.2.2",
27
- "gulp": "~3.8.10"
26
+ "karma-requirejs": "~0.2.2"
28
27
  },
29
28
  "scripts": {
30
29
  "compile": "gulp build",
@@ -120,6 +120,31 @@ define ->
120
120
  method = params.shift()
121
121
  @[method].apply(@, params)
122
122
 
123
+
124
+ storage = window.localStorage
125
+
126
+ setPermanent = (value) ->
127
+ storage.setItem('pinball_wizard', JSON.stringify(value))
128
+
129
+ appendPermanent = (name) ->
130
+ l = permanent()
131
+ l.push(name)
132
+ setPermanent l
133
+
134
+ permanent = ->
135
+ JSON.parse(storage.getItem('pinball_wizard') or "[]") or []
136
+
137
+ activatePermanently = (name) ->
138
+ appendPermanent(name)
139
+ activate(name, 'permanent')
140
+
141
+ resetPermanent = ->
142
+ setPermanent []
143
+
144
+ activateAllPermanent = ->
145
+ for name in permanent()
146
+ activate(name)
147
+
123
148
  state = ->
124
149
  features
125
150
 
@@ -145,6 +170,10 @@ define ->
145
170
  addCSSClassName
146
171
  removeCSSClassName
147
172
  _urlValues
173
+ activatePermanently
174
+ resetPermanent
175
+ permanent
176
+ activateAllPermanent
148
177
  }
149
178
 
150
179
  # Initialize
@@ -154,4 +183,6 @@ define ->
154
183
  exports.push window.pinball.shift()
155
184
  window.pinball = exports
156
185
 
186
+ activateAllPermanent()
187
+
157
188
  exports
@@ -266,3 +266,45 @@ define ['pinball_wizard'], (pinball) ->
266
266
  it 'works with other keys/values', ->
267
267
  urlParam = '?foo=bar&pinball=a,b&bar'
268
268
  expect(pinball._urlValues(urlParam)).toEqual(['a','b'])
269
+
270
+ describe '#activatePermanent', ->
271
+ beforeEach ->
272
+ pinball.add
273
+ my_feature: 'inactive'
274
+ pinball.activatePermanently('my_feature')
275
+
276
+ it 'adds it to the list of permanent', ->
277
+ expect(pinball.permanent()).toEqual(['my_feature'])
278
+
279
+ it 'activates the feature', ->
280
+ expect(pinball.isActive('my_feature')).toEqual(true)
281
+
282
+ describe '#permanent', ->
283
+ beforeEach ->
284
+ pinball.resetPermanent()
285
+ pinball.add
286
+ my_feature: 'inactive'
287
+
288
+ it 'is empty by default', ->
289
+ expect(pinball.permanent()).toEqual([])
290
+
291
+ it 'builds a list of those permanent', ->
292
+ pinball.activatePermanently('my_feature')
293
+ expect(pinball.permanent()).toEqual(['my_feature'])
294
+
295
+ it 'is empty after resetting', ->
296
+ pinball.activatePermanently('my_feature')
297
+ pinball.resetPermanent()
298
+ expect(pinball.permanent()).toEqual([])
299
+
300
+ describe '#activateAllPermanent', ->
301
+ beforeEach ->
302
+ pinball.resetPermanent()
303
+ pinball.add
304
+ my_feature: 'inactive'
305
+
306
+ it 'is active', ->
307
+ pinball.activatePermanently('my_feature')
308
+ pinball.deactivate 'my_feature'
309
+ pinball.activateAllPermanent()
310
+ expect(pinball.isActive('my_feature')).toEqual(true)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pinball_wizard
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Caleb Wright
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-01-14 00:00:00.000000000 Z
13
+ date: 2015-10-15 00:00:00.000000000 Z
14
14
  dependencies: []
15
15
  description: Build flippable features.
16
16
  email:
@@ -29,7 +29,6 @@ files:
29
29
  - Rakefile
30
30
  - bower.json
31
31
  - dist/css_tagger.js
32
- - dist/css_tagger.min.js
33
32
  - dist/pinball_wizard.js
34
33
  - gulpfile.js
35
34
  - karma.conf.js
@@ -74,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
73
  version: '0'
75
74
  requirements: []
76
75
  rubyforge_project:
77
- rubygems_version: 2.4.2
76
+ rubygems_version: 2.2.2
78
77
  signing_key:
79
78
  specification_version: 4
80
79
  summary: Lib to build flippable features.
@@ -1,3 +0,0 @@
1
- // Minified on http://closure-compiler.appspot.com/ using Advanced settings
2
-
3
- (function(g,d,e){var f,h,b,a,c,l,k;h=[];f=function(a){h.push("use-"+a.split("_").join("-"))};c=0;for(l=d.length;c<l;c++)if(b=d[c],b.length)switch(b[0]){case "activate":f(b[1]);break;case "add":for(a in k=b[1],k)b=k[a],"active"===b&&f(a)}if((a=e.match(/pinball=([a-z-_,]+)/i))&&1<a.length)for(d=(a[1]+"").split(","),e=0,c=d.length;e<c;e++)a=d[e],f(a);g&&(g.className+=" "+h.join(" "))})(document.documentElement,window.pinball,window.location.search);