pinkman 0.9.1.9 → 0.9.1.10

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: 28b5e2aee68bfcbb2e5df9fa35c8eaa336de6ad2
4
- data.tar.gz: c66a229e145856407ab7c2e1b27cc9b2cecdfa0d
3
+ metadata.gz: f316922107a3535edc3a1ea9dc9a93d251ef031b
4
+ data.tar.gz: f41cf712bbe140b9c8a672bbd59599f4643eb5e2
5
5
  SHA512:
6
- metadata.gz: 16e3a2e863e14057b5aae53642d74e2c6f3e012c809d2fb28b3fbfe3616809a530a6e9ea3de749ce91f64e117890adb3cb6562df1f30cc0e2fbf5358edbf921e
7
- data.tar.gz: 8504a6a5a5d04c221df84d4d7d55baf4c3eb5d6fc27b1d82cee8637a34166e91d026a2aa5a9bcbaf8dc5f16edf53307b02ae2a39dc3c8a6e2af549f2505e7403
6
+ metadata.gz: ab8c4c332254a397fffbd7583039bbcbf5eac6285bace521c5b7ccec6246b033626bcb797b504b0202374f5b30eb7e2b021ef145043fc30b5f12c68f1ba2706c
7
+ data.tar.gz: 4120498837285cb74c6316b65eac0ac2cac155dba03f984132f10b0fb4d2e850e93df7686bd89fdcb905454dca2ef1bf6451551b059c0de85c43ac90f770525a
@@ -1,4 +1,3 @@
1
- //= require pinkman_base/handlebars
2
1
  //= require pinkman_base/tools
3
2
  //= require pinkman_base/pinkman
4
3
  //= require pinkman_base/mixins
@@ -331,7 +331,6 @@ class window.PinkmanCollection extends window.PinkmanCommon
331
331
  else
332
332
  return false
333
333
 
334
-
335
334
  # --- Ajax related --- #
336
335
 
337
336
  # Desc: Fetch records from API_URL
@@ -359,37 +358,44 @@ class window.PinkmanCollection extends window.PinkmanCommon
359
358
  # request: get /api/API_URL/
360
359
  fetchFromUrl: (options) ->
361
360
  if options? and typeof options == 'object' and options.url?
361
+ @emptyResponse = null
362
362
  @fetchingFrom = options.url
363
363
  Pinkman.ajax.get
364
364
  url: Pinkman.json2url(options.url,options.params)
365
365
  complete: (response) =>
366
- if response.errors? or response.error?
367
- [@errors, @error] = [response.errors, response.error]
368
- if response.errors? then (throw new Error('Oh no... I could not fetch your records, bitch. (jk... about the "bitch" part)')) else (throw new Error(response.error))
369
- return false
370
- else
366
+ if response?
367
+ [@errors, @error] = [response.errors, response.error] if response.errors? or response.error?
368
+
369
+ # separate recent when this collection is already populated
370
+ if @any()
371
+ @_recent = new this.constructor
372
+ @_recent.fetchFromArray(response)
373
+
371
374
  @fetchFromArray(response).emptyResponse = response.length == 0
372
- options.callback(this) if options.callback? and typeof options.callback == 'function'
375
+
376
+ @emptyResponse = true unless response?
377
+ options.callback(this) if options.callback? and typeof options.callback == 'function'
373
378
  return(this)
374
379
 
375
380
  # Desc: Fetch next records from last fetched URL or main API_URl
376
381
  # request: get /api/API_URL/?offset="COLLECTION_SIZE"&limit=n
377
382
  # in rails: api::controller#index
378
383
  fetchMore: (n=10,callback='') ->
379
- if @fetchingFrom?
380
- @fetchFromUrl
381
- url: @fetchingFrom
382
- params:
383
- limit: n
384
- offset: @count()
385
- callback: callback
386
- else
387
- @fetchFromUrl
388
- url: @api()
389
- params:
390
- limit: n
391
- offset: @count()
392
- callback: callback
384
+ unless @emptyResponse
385
+ if @fetchingFrom?
386
+ @fetchFromUrl
387
+ url: @fetchingFrom
388
+ params:
389
+ limit: n
390
+ offset: @count()
391
+ callback: callback
392
+ else
393
+ @fetchFromUrl
394
+ url: @api()
395
+ params:
396
+ limit: n
397
+ offset: @count()
398
+ callback: callback
393
399
 
394
400
  # Desc: Fetch next n records from a action
395
401
  # request: get /api/API_URL/:action/?offset="COLLECTION_SIZE"&limit=n
@@ -403,6 +409,6 @@ class window.PinkmanCollection extends window.PinkmanCommon
403
409
  # assume models to have a Model.search("YOUR_QUERY") method.
404
410
  search: (query,callback='') ->
405
411
  @removeAll()
406
- @fetchFromUrl { url: @api(), params: {query: query}, callback: callback }
412
+ @fetchFromUrl { url: @api() + 'search', params: {query: query}, callback: callback }
407
413
 
408
414
  window.Pinkman.collection = window.PinkmanCollection
@@ -58,8 +58,24 @@ class window.PinkmanCommon
58
58
  opts = {object: this, target: options, template: options + '-template'}
59
59
  Pinkman.render opts
60
60
 
61
- reRender: () ->
62
- Pinkman.reRender this
61
+ reRender: (callback='') ->
62
+ Pinkman.reRender(this)
63
+ callback(this) if typeof callback == 'function'
64
+ return this
65
+
66
+
67
+ append: (options) ->
68
+ if options? and typeof options == 'object' and options.template? and options.target?
69
+ newOptions = new Object
70
+ for k,v of options
71
+ newOptions[k] = v if k != 'target' and k != 'callback'
72
+ newOptions.reRender = no
73
+ target = options.target
74
+ newOptions.object = this
75
+ newOptions.callback = (object,content) ->
76
+ $('#'+target).append(content)
77
+ options.callback(object,content) if options.callback? and typeof options.callback == 'function'
78
+ Pinkman.render(newOptions)
63
79
 
64
80
  watch: () ->
65
81
  @_watching = yes
@@ -74,13 +74,13 @@ class window.Pinkman
74
74
  dataType: 'json'
75
75
  data: options.data
76
76
  ajax.done (response) =>
77
- if response.errors?
77
+ if response? and response.errors?
78
78
  options.error(this) if options.error? and typeof options.error == 'function'
79
- return(false)
80
79
  else
81
80
  options.success(response) if options.success? and typeof options.success == 'function'
82
- options.complete(response) if options.complete? and typeof options.complete == 'function'
83
- return(true)
81
+
82
+ options.complete(response) if options.complete? and typeof options.complete == 'function'
83
+ return(true)
84
84
  else
85
85
  return false
86
86
 
@@ -3,80 +3,91 @@ Pinkman.templates = new Pinkman.collection
3
3
  Pinkman.template_engine = '<%= Pinkman.configuration.js_template_engine %>'
4
4
 
5
5
  Pinkman.template_engines =
6
- handlebars: (options) ->
7
- if options? and options.template? and $('#' + options.template).length
8
- if Pinkman.templates.include(template: options.template, engine: Pinkman.template_engine)
9
- template = Pinkman.templates.get(template: options.template, engine: Pinkman.template_engine)
10
- else
11
- template = new Pinkman.object(template: options.template, engine: Pinkman.template_engine)
12
- template.handlebars = Handlebars.compile $('#' + options.template).html()
13
- Pinkman.templates.push(template)
14
-
15
- options.object = options.context if options.context?
16
- options.object = new Object unless options.object? and typeof options.object == 'object'
17
- content = template.handlebars(options.object)
18
-
19
-
20
- if options.target?
21
- $('#' + options.target).html(content)
22
- $('#' + options.target).attr('data-pinkey',options.object.pinkey) if options.object? and typeof options.object == 'object' and options.object.isPink
23
-
24
- options.callback(options.object,content) if options.callback? and typeof options.callback == 'function'
25
- return(content)
26
6
 
27
- hogan: (options) ->
7
+ handlebars: (template,html) ->
8
+ if Handlebars?
9
+ template.handlebars = Handlebars.compile(html)
10
+ template.render = (context) ->
11
+ @handlebars(context)
12
+ template
13
+ else
14
+
15
+
16
+ hogan: (template,html) ->
17
+ if Hogan?
18
+ template.hogan = Hogan.compile(html)
19
+ template.render = (context) ->
20
+ @hogan.render(context)
21
+ template
22
+ else
23
+
24
+
25
+ markup: (template,html) ->
26
+ if Mark?
27
+ template.render = (context) -> Mark.up(html,context)
28
+ template
29
+ else
30
+
31
+ template: (options) ->
32
+ if Pinkman.templates.include(template: options.template, engine: options.engine)
33
+ template = Pinkman.templates.get(template: options.template, engine: options.engine)
34
+ else
35
+ template = new Pinkman.object(template: options.template, engine: options.engine)
36
+ @compile(options.engine, template, $('#' + options.template).html())
37
+ Pinkman.templates.push(template)
38
+ return(template)
39
+
40
+ context: (options) ->
41
+ options.object = options.context if options.context?
42
+ options.object = new Object unless options.object? and typeof options.object == 'object'
43
+ return(options.object)
44
+
45
+ compile: (engine, template, html) ->
46
+ e = Pinkman.template_engines[engine]
47
+ e(template,html)
48
+ template
49
+
50
+ renderOntarget: (options,content) ->
51
+ if options.target?
52
+ $('#' + options.target).html(content)
53
+ $('#' + options.target).attr('data-pinkey',options.object.pinkey) if options.object? and typeof options.object == 'object' and options.object.isPink
54
+
55
+ # checks and sync select options with the pinkman object
56
+ $("##{options.target} select").each (i,el) ->
57
+ obj = Pinkman.get($(el).data('pinkey'))
58
+ $(el).find("option[value='#{obj[$(el).attr('name')]}']").attr('selected','selected')
59
+
60
+ render: (options) ->
61
+ # 1 check if template exists
28
62
  if options? and options.template? and $('#' + options.template).length
29
- if Pinkman.templates.include(template: options.template, engine: Pinkman.template_engine)
30
- template = Pinkman.templates.get(template: options.template, engine: Pinkman.template_engine)
31
- else
32
- template = new Pinkman.object(template: options.template, engine: Pinkman.template_engine)
33
- template.hogan = Hogan.compile $('#' + options.template).html()
34
- Pinkman.templates.push(template)
35
63
 
36
- options.object = options.context if options.context?
37
- options.object = new Object unless options.object? and typeof options.object == 'object'
38
- content = template.hogan.render(options.object)
64
+ # 2 check if compiled template exists. Create one otherwise.
65
+ template = @template(options)
39
66
 
40
- if options.target?
41
- $('#' + options.target).html(content)
42
- $('#' + options.target).attr('data-pinkey',options.object.pinkey) if options.object? and typeof options.object == 'object' and options.object.isPink
67
+ # 3 render template within the context
68
+ content = template.render(@context(options))
43
69
 
44
- options.callback(options.object,content) if options.callback? and typeof options.callback == 'function'
45
- return(content)
46
-
47
- markup: (options) ->
48
- if options? and options.template? and $('#' + options.template).length
49
- if Pinkman.templates.include(template: options.template, engine: Pinkman.template_engine)
50
- template = Pinkman.templates.get(template: options.template, engine: Pinkman.template_engine)
51
- else
52
- template = new Pinkman.object(template: options.template, engine: Pinkman.template_engine)
53
- template.markup = (args...) -> Mark.up(args...)
54
- Pinkman.templates.push(template)
55
-
56
- options.object = options.context if options.context?
57
- options.object = new Object unless options.object? and typeof options.object == 'object'
58
- content = template.markup($('#'+options.template).html(),options.object)
59
-
60
- if options.target?
61
- $('#' + options.target).html(content)
62
- $('#' + options.target).attr('data-pinkey',options.object.pinkey) if options.object? and typeof options.object == 'object' and options.object.isPink
70
+ # 4 insert html on target
71
+ @renderOntarget(options,content)
63
72
 
73
+ # 5 callback function
64
74
  options.callback(options.object,content) if options.callback? and typeof options.callback == 'function'
65
75
  return(content)
66
76
 
67
77
  Pinkman.render = (options) ->
68
78
  options.reRender = true unless options.reRender? and options.reRender == false
69
79
  options.collectionReRender = true unless options.collectionReRender? and options.collectionReRender == false
70
-
71
- engine = Pinkman.template_engines[Pinkman.template_engine]
72
- content = engine(options)
80
+ options.engine = Pinkman.template_engine unless options.engine? and options.engine != ''
81
+ Pinkman.template_engines.render(options)
73
82
  options.object.queue(options) if options.reRender and options.object? and options.object.isPink
74
83
 
75
84
  Pinkman.reRender = (object) ->
76
85
  if object.renderQueue?
77
- engine = Pinkman.template_engines[Pinkman.template_engine]
78
- engine(options) for options in object.renderQueue.collection
79
- Pinkman.reRender(collection) for collection in object.collections.collection if object.collections? and options.collectionReRender
86
+ collectionReRender = false
87
+ for options in object.renderQueue.collection
88
+ Pinkman.template_engines.render(options)
89
+ collectionReRender = true if options.collectionReRender
90
+ collection.reRender() for collection in object.collections.collection if collectionReRender and object.collections?
80
91
  object.renderQueue.any()
81
92
  else
82
93
  true
@@ -0,0 +1,2 @@
1
+ //= require pinkman/engines/handlebars
2
+ //= require pinkman
@@ -0,0 +1,2 @@
1
+ //= require pinkman/engines/hogan
2
+ //= require pinkman
@@ -0,0 +1,2 @@
1
+ //= require pinkman/engines/markup
2
+ //= require pinkman
@@ -1,14 +1,8 @@
1
1
  class Api::<%= controller_name %> < ApiController
2
2
 
3
- before_action :current_scope
4
3
  before_action :permissions
5
4
  before_action :set_objects
6
5
 
7
- # To do: define the current scope the way you want
8
- def current_scope
9
- :all
10
- end
11
-
12
6
  # get api/<%= api_name %>
13
7
  def index
14
8
  <%= collection_name %> = <%= active_record_model_name %>.limit(params[:limit]).offset(params[:offset])
@@ -48,7 +42,6 @@ class Api::<%= controller_name %> < ApiController
48
42
  end
49
43
  end
50
44
 
51
-
52
45
  # delete api/<%= api_name %>/:id
53
46
  def destroy
54
47
  @<%= instance_name %>.destroy
@@ -6,5 +6,15 @@ class ApiController < ApplicationController
6
6
  params[:limit] = 20 if params[:limit].blank?
7
7
  params[:offset] = 0 if params[:offset].blank?
8
8
  end
9
+
10
+ # To do: define the current scope the way you want
11
+ # Example:
12
+ # def current_scope
13
+ # current_user.admin? ? :admin : :public
14
+ # end
15
+ def current_scope
16
+ :public
17
+ end
18
+
9
19
 
10
20
  end
@@ -27,7 +27,7 @@ module Pinkman
27
27
  end
28
28
 
29
29
  def can_read? attribute
30
- read.include?(:all) or read.include?(attribute.to_sym)
30
+ read.include?(:all) or read.include?(attribute.to_sym) or attribute == :error or attribute == :errors
31
31
  end
32
32
 
33
33
  def can_write? attribute
@@ -1,3 +1,3 @@
1
1
  module Pinkman
2
- VERSION = "0.9.1.9"
2
+ VERSION = "0.9.1.10"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pinkman
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1.9
4
+ version: 0.9.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Agilso Oliveira
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-26 00:00:00.000000000 Z
11
+ date: 2017-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -179,18 +179,21 @@ files:
179
179
  - README.md
180
180
  - Rakefile
181
181
  - app/assets/javascripts/pinkman.js
182
+ - app/assets/javascripts/pinkman/engines/handlebars.js
183
+ - app/assets/javascripts/pinkman/engines/hogan.js
184
+ - app/assets/javascripts/pinkman/engines/markup.js
182
185
  - app/assets/javascripts/pinkman_base/collection.coffee
183
186
  - app/assets/javascripts/pinkman_base/common.coffee
184
187
  - app/assets/javascripts/pinkman_base/controller.coffee
185
188
  - app/assets/javascripts/pinkman_base/glue.coffee
186
- - app/assets/javascripts/pinkman_base/handlebars.js
187
- - app/assets/javascripts/pinkman_base/hogan.js
188
- - app/assets/javascripts/pinkman_base/markup.js
189
189
  - app/assets/javascripts/pinkman_base/mixins.coffee
190
190
  - app/assets/javascripts/pinkman_base/object.js.coffee.erb
191
191
  - app/assets/javascripts/pinkman_base/pinkman.coffee
192
192
  - app/assets/javascripts/pinkman_base/render.coffee.erb
193
193
  - app/assets/javascripts/pinkman_base/tools.coffee
194
+ - app/assets/javascripts/pinkman_with_handlebars.js
195
+ - app/assets/javascripts/pinkman_with_hogan.js
196
+ - app/assets/javascripts/pinkman_with_markup.js
194
197
  - app/helpers/pinkman_helper.rb
195
198
  - bin/console
196
199
  - bin/setup