joosy 1.2.0.alpha.13 → 1.2.0.alpha.14

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: 86784de6b810fdda417c04e5f2a32be2f50cdf20
4
- data.tar.gz: 807001da677b51db11ad5cf032ee1be57b70bc13
3
+ metadata.gz: e7efe3701ce2f216a6e1733e322573234cd19737
4
+ data.tar.gz: c41874a7bd7ce743e6f4c8232d5bad56acd4d8df
5
5
  SHA512:
6
- metadata.gz: ca1a9f7eb9081e2cf6cac92401a4dc5daf15fa29cec19091441b85b774302b86f97104801fc252cf11bcfcafd464b0b3ce2db26b12d219d530c9cd184ee24008
7
- data.tar.gz: 4dfd4f85e19997aa299ea7eadc2b59980d9cc93728b718deaccc00e1c8da62adca862ee0fef36ba485d4657c23aa003c4ae98f9092fd298de3708e4275e19c7d
6
+ metadata.gz: 3ac1bc38b42830cda852e9b46ff543d499d9057c7e290bc58b9d01b0995e5eb31604b05e8187f8dd87bbe37cf6de4dd659d95f4ba2baa29cc013a29cf2fbf1d7
7
+ data.tar.gz: 44265f5626c425a31c5ddcec40be293538a0b75e7d8d7f63a4b8ac92c116d3ee19d50befa8634c9c86a166b4457043d6cc6d747917b9549864ec726f23134d77
data/bower.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "joosy",
3
- "version": "1.2.0-alpha.13",
3
+ "version": "1.2.0-alpha.14",
4
4
  "main": "lib/joosy.js",
5
5
  "ignore": [
6
6
  "bin",
data/lib/joosy.js CHANGED
@@ -171,19 +171,24 @@ Joosy.Application = {
171
171
  Controls: {},
172
172
  loading: true,
173
173
  identity: true,
174
- debug: false,
175
174
  debounceForms: false,
175
+ config: {
176
+ debug: false,
177
+ router: {
178
+ html5: false,
179
+ base: '/'
180
+ }
181
+ },
176
182
  initialize: function(name, selector, options) {
177
- var key, value;
178
183
  this.name = name;
179
184
  this.selector = selector;
180
185
  if (options == null) {
181
186
  options = {};
182
187
  }
183
- for (key in options) {
184
- value = options[key];
185
- this[key] = value;
188
+ if (window.JoosyEnvironment != null) {
189
+ this.mergeConfig(window.JoosyEnvironment);
186
190
  }
191
+ this.mergeConfig(options);
187
192
  this.templater = new Joosy.Templaters.RailsJST(this.name);
188
193
  Joosy.Router.__setupRoutes();
189
194
  this.sandboxSelector = Joosy.uuid();
@@ -202,6 +207,19 @@ Joosy.Application = {
202
207
  if (!attempt.halted) {
203
208
  return this.page = attempt;
204
209
  }
210
+ },
211
+ mergeConfig: function(options) {
212
+ var key, value, _results;
213
+ _results = [];
214
+ for (key in options) {
215
+ value = options[key];
216
+ if (Object.isObject(this.config[key])) {
217
+ _results.push(Object.merge(this.config[key], value));
218
+ } else {
219
+ _results.push(this.config[key] = value);
220
+ }
221
+ }
222
+ return _results;
205
223
  }
206
224
  };
207
225
 
@@ -324,7 +342,7 @@ Joosy.Modules.Log = {
324
342
  debug: function() {
325
343
  var args;
326
344
  args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
327
- if (!Joosy.Application.debug) {
345
+ if (!Joosy.Application.config.debug) {
328
346
  return;
329
347
  }
330
348
  return this.log.apply(this, args);
@@ -332,7 +350,7 @@ Joosy.Modules.Log = {
332
350
  debugAs: function() {
333
351
  var args, context, string;
334
352
  context = arguments[0], string = arguments[1], args = 3 <= arguments.length ? __slice.call(arguments, 2) : [];
335
- if (!Joosy.Application.debug) {
353
+ if (!Joosy.Application.config.debug) {
336
354
  return;
337
355
  }
338
356
  context = Joosy.Module.__className(context) || 'unknown context';
@@ -3303,9 +3321,9 @@ Joosy.Router = {
3303
3321
  if (!history.pushState) {
3304
3322
  this.__ignoreRequest = to;
3305
3323
  location.hash = path;
3306
- return setTimeout(function() {
3324
+ return setTimeout((function() {
3307
3325
  return _this.__ignoreRequest = false;
3308
- }, 2);
3326
+ }), 0);
3309
3327
  } else {
3310
3328
  return history[options.replaceState ? 'replaceState' : 'pushState']({}, '', '#' + path);
3311
3329
  }
data/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "keywords": [
5
5
  "joosy"
6
6
  ],
7
- "version": "1.2.0-alpha.13",
7
+ "version": "1.2.0-alpha.14",
8
8
  "author": "Boris Staal <boris@staal.io>",
9
9
  "bin": {
10
10
  "joosy": "bin/joosy"
@@ -8,13 +8,14 @@ describe "Joosy.Application", ->
8
8
  Joosy.Router.__setupRoutes.restore()
9
9
 
10
10
  it "should initialize", ->
11
- Joosy.Application.initialize 'app', '#application'
11
+ Joosy.Application.initialize 'app', '#application', router: {foo: 'bar'}
12
12
  expect(Joosy.Application.page).toBeUndefined()
13
13
  expect(Joosy.Application.selector).toEqual '#application'
14
14
  expect(Joosy.Application.sandboxSelector).toMatch /#[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}/
15
15
  expect($(Joosy.Application.sandboxSelector).length).toEqual 1
16
16
  expect(Joosy.Router.__setupRoutes.callCount).toEqual 1
17
17
  expect(Joosy.Application.name).toEqual 'app'
18
+ expect(Joosy.Application.config.router.foo).toEqual 'bar'
18
19
 
19
20
  it "should set container", ->
20
21
  expect(Joosy.Application.content()).toEqual $('#application')
@@ -1,7 +1,7 @@
1
1
  describe "Joosy", ->
2
2
 
3
3
  it "should properly initialize", ->
4
- expect(Joosy.Application.debug).toBeFalsy()
4
+ expect(Joosy.Application.config.debug).toBeFalsy()
5
5
  expect(Joosy.Modules).toBeDefined()
6
6
  expect(Joosy.Resource).toBeDefined()
7
7
 
@@ -9,7 +9,7 @@ describe "Joosy.Modules.Log", ->
9
9
  @box.log 'message', 'appendix'
10
10
 
11
11
  it "should log debug messages into console", ->
12
- Joosy.Application.debug = true
12
+ Joosy.Application.config.debug = true
13
13
  @box.debug 'debug message'
14
- Joosy.Application.debug = false
14
+ Joosy.Application.config.debug = false
15
15
  @box.debug 'unseen debug message'
@@ -7,20 +7,21 @@ describe "Joosy.Router", ->
7
7
  section: sinon.spy()
8
8
  wildcard: sinon.spy()
9
9
 
10
- map = Object.extended
11
- '/': spies.root
12
- '/page': TestPage
13
- '/section':
14
- '/page/:id': spies.section
15
- '/page2/:more': TestPage
16
- 404: spies.wildcard
10
+ map =
11
+ Object.extended
12
+ '/': spies.root
13
+ '/page': TestPage
14
+ '/section':
15
+ '/page/:id': spies.section
16
+ '/page2/:more': TestPage
17
+ 404: spies.wildcard
17
18
 
18
19
  beforeEach ->
19
20
  Joosy.Router.reset()
20
21
  Joosy.Router.prefix = '!'
21
22
 
22
23
  afterEach ->
23
- $(window).unbind 'hashchange'
24
+ $(window).off 'hashchange'
24
25
 
25
26
  it "should map", ->
26
27
  Joosy.Router.map map
@@ -124,7 +125,6 @@ describe "Joosy.Router", ->
124
125
  expect(location.hash).toEqual "#!test"
125
126
  Joosy.Router.navigate ''
126
127
  expect(location.hash).toEqual '#!'
127
- location.hash = ''
128
128
 
129
129
  it "should restrict urls", ->
130
130
  sinon.stub Joosy.Router, '__respondRoute'
@@ -12,9 +12,14 @@ Joosy.Application =
12
12
 
13
13
  loading: true
14
14
  identity: true
15
- debug: false
16
15
  debounceForms: false
17
16
 
17
+ config:
18
+ debug: false
19
+ router:
20
+ html5: false
21
+ base: '/'
22
+
18
23
  #
19
24
  # Starts Joosy application by binding to element and bootstraping routes
20
25
  #
@@ -23,7 +28,9 @@ Joosy.Application =
23
28
  # @param [Object] options
24
29
  #
25
30
  initialize: (@name, @selector, options={}) ->
26
- @[key] = value for key, value of options
31
+ @mergeConfig(window.JoosyEnvironment) if window.JoosyEnvironment?
32
+ @mergeConfig(options)
33
+
27
34
  @templater = new Joosy.Templaters.RailsJST @name
28
35
 
29
36
  Joosy.Router.__setupRoutes()
@@ -52,4 +59,11 @@ Joosy.Application =
52
59
  #
53
60
  setCurrentPage: (page, params) ->
54
61
  attempt = new page(params, @page)
55
- @page = attempt unless attempt.halted
62
+ @page = attempt unless attempt.halted
63
+
64
+ mergeConfig: (options) ->
65
+ for key, value of options
66
+ if Object.isObject @config[key]
67
+ Object.merge @config[key], value
68
+ else
69
+ @config[key] = value
@@ -21,7 +21,7 @@ Joosy.Modules.Log =
21
21
  # Runs `log` if debug is active
22
22
  #
23
23
  debug: (args...) ->
24
- return unless Joosy.Application.debug
24
+ return unless Joosy.Application.config.debug
25
25
  @log args...
26
26
 
27
27
  #
@@ -31,6 +31,6 @@ Joosy.Modules.Log =
31
31
  # @param [String] string Message to log
32
32
  #
33
33
  debugAs: (context, string, args...) ->
34
- return unless Joosy.Application.debug
34
+ return unless Joosy.Application.config.debug
35
35
  context = Joosy.Module.__className(context) || 'unknown context'
36
36
  @debug "#{context}> #{string}", args...
@@ -98,9 +98,7 @@ Joosy.Router =
98
98
  if !history.pushState
99
99
  @__ignoreRequest = to
100
100
  location.hash = path
101
- setTimeout =>
102
- @__ignoreRequest = false
103
- , 2 # jQuery.hashchange checks hash changing every 1ms
101
+ setTimeout (=> @__ignoreRequest = false), 0
104
102
  else
105
103
  history[if options.replaceState then 'replaceState' else 'pushState'] {}, '', '#'+path
106
104
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: joosy
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0.alpha.13
4
+ version: 1.2.0.alpha.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Boris Staal