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 +4 -4
- data/app/assets/javascripts/pinkman.js +0 -1
- data/app/assets/javascripts/{pinkman_base → pinkman/engines}/handlebars.js +0 -0
- data/app/assets/javascripts/{pinkman_base → pinkman/engines}/hogan.js +0 -0
- data/app/assets/javascripts/{pinkman_base → pinkman/engines}/markup.js +0 -0
- data/app/assets/javascripts/pinkman_base/collection.coffee +28 -22
- data/app/assets/javascripts/pinkman_base/common.coffee +18 -2
- data/app/assets/javascripts/pinkman_base/pinkman.coffee +4 -4
- data/app/assets/javascripts/pinkman_base/render.coffee.erb +69 -58
- data/app/assets/javascripts/pinkman_with_handlebars.js +2 -0
- data/app/assets/javascripts/pinkman_with_hogan.js +2 -0
- data/app/assets/javascripts/pinkman_with_markup.js +2 -0
- data/lib/generators/pinkman/templates/api.rb.erb +0 -7
- data/lib/generators/pinkman/templates/api_controller.rb +10 -0
- data/lib/pinkman/serializer/scope.rb +1 -1
- data/lib/pinkman/version.rb +1 -1
- metadata +8 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f316922107a3535edc3a1ea9dc9a93d251ef031b
|
4
|
+
data.tar.gz: f41cf712bbe140b9c8a672bbd59599f4643eb5e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab8c4c332254a397fffbd7583039bbcbf5eac6285bace521c5b7ccec6246b033626bcb797b504b0202374f5b30eb7e2b021ef145043fc30b5f12c68f1ba2706c
|
7
|
+
data.tar.gz: 4120498837285cb74c6316b65eac0ac2cac155dba03f984132f10b0fb4d2e850e93df7686bd89fdcb905454dca2ef1bf6451551b059c0de85c43ac90f770525a
|
File without changes
|
File without changes
|
File without changes
|
@@ -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
|
367
|
-
[@errors, @error] = [response.errors, response.error]
|
368
|
-
|
369
|
-
|
370
|
-
|
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
|
-
|
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
|
-
|
380
|
-
@
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
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
|
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
|
-
|
83
|
-
|
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
|
-
|
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
|
-
|
37
|
-
|
38
|
-
content = template.hogan.render(options.object)
|
64
|
+
# 2 check if compiled template exists. Create one otherwise.
|
65
|
+
template = @template(options)
|
39
66
|
|
40
|
-
|
41
|
-
|
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
|
-
|
45
|
-
|
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
|
-
|
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
|
-
|
78
|
-
|
79
|
-
|
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
|
@@ -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
|
data/lib/pinkman/version.rb
CHANGED
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.
|
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-
|
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
|