pinkman 0.9.9.9.11 → 1.0.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 +4 -4
- data/README.md +1 -1
- data/app/assets/javascripts/pinkman_base/cache.coffee +12 -2
- data/app/assets/javascripts/pinkman_base/collection.coffee +85 -70
- data/app/assets/javascripts/pinkman_base/common.coffee +31 -2
- data/app/assets/javascripts/pinkman_base/controller.coffee +42 -28
- data/app/assets/javascripts/pinkman_base/object.coffee.erb +21 -12
- data/app/assets/javascripts/pinkman_base/pinkman.coffee +50 -2
- data/app/assets/javascripts/pinkman_base/render.coffee.erb +26 -3
- data/app/assets/javascripts/pinkman_base/router.coffee +91 -38
- data/lib/generators/pinkman/install_generator.rb +4 -3
- data/lib/generators/pinkman/templates/api.rb.erb +14 -14
- data/lib/generators/pinkman/templates/api_controller.rb +17 -26
- data/lib/generators/pinkman/templates/initializer.rb.erb +5 -1
- data/lib/pinkman/form_helper/form_helpers.rb +7 -1
- data/lib/pinkman/serializer/base.rb +5 -1
- data/lib/pinkman/serializer/scope.rb +16 -2
- data/lib/pinkman/version.rb +1 -1
- data/lib/pinkman/views_helpers/form_helper.rb +7 -3
- data/lib/pinkman/views_helpers/template_helper.rb +14 -6
- data/lib/pinkman/views_helpers/writer_helper.rb +3 -2
- data/lib/pinkman/views_helpers.rb +2 -2
- data/lib/pinkman.rb +22 -18
- metadata +3 -3
@@ -1,37 +1,50 @@
|
|
1
1
|
class window.PinkmanPath extends Pinkman.object
|
2
2
|
|
3
3
|
constructor: (url) ->
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
i = 0
|
15
|
-
s = 0
|
16
|
-
d = 0
|
17
|
-
for l in a
|
18
|
-
i = i + 1
|
19
|
-
obj = new Pinkman.object({entry: l, index: i})
|
20
|
-
if /:/.test(l[0])
|
21
|
-
d = d + 1
|
22
|
-
obj.set('dynamic',yes)
|
23
|
-
obj.set('static',no)
|
24
|
-
@dynamic.push(obj)
|
25
|
-
else
|
26
|
-
s = s + 1
|
27
|
-
obj.set('dynamic',no)
|
28
|
-
obj.set('static',yes)
|
29
|
-
@static.push(obj)
|
30
|
-
@levels.push(obj)
|
4
|
+
if PinkmanCache.has("p-path-#{url}")
|
5
|
+
return(PinkmanCache.get("p-path-#{url}"))
|
6
|
+
else
|
7
|
+
# setting params
|
8
|
+
paramsRegex = /\?.*/
|
9
|
+
if paramsRegex.test(url)
|
10
|
+
paramsString = /\?(.*)/.exec(url)[1]
|
11
|
+
@query = JSON.parse('{"' + decodeURI(paramsString).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g,'":"') + '"}')
|
12
|
+
url = url.replace("?#{paramsString}", '')
|
13
|
+
|
31
14
|
|
32
|
-
@
|
33
|
-
@
|
34
|
-
@
|
15
|
+
@levels = new Pinkman.collection
|
16
|
+
@static = new Pinkman.collection
|
17
|
+
@dynamic = new Pinkman.collection
|
18
|
+
@params = new Object
|
19
|
+
super()
|
20
|
+
if Pinkman.isString(url)
|
21
|
+
url = url.replace(window.location.origin,'') if PinkmanPath.isInternal(url)
|
22
|
+
|
23
|
+
|
24
|
+
a = url.split('/')
|
25
|
+
a.shift() if a[0] == ''
|
26
|
+
a.pop() if a[a.length-1] == ''
|
27
|
+
i = 0
|
28
|
+
s = 0
|
29
|
+
d = 0
|
30
|
+
for l in a
|
31
|
+
i = i + 1
|
32
|
+
obj = new Pinkman.object({entry: l, index: i})
|
33
|
+
if /:/.test(l[0])
|
34
|
+
d = d + 1
|
35
|
+
obj.set('dynamic',yes)
|
36
|
+
obj.set('static',no)
|
37
|
+
@dynamic.push(obj)
|
38
|
+
else
|
39
|
+
s = s + 1
|
40
|
+
obj.set('dynamic',no)
|
41
|
+
obj.set('static',yes)
|
42
|
+
@static.push(obj)
|
43
|
+
@levels.push(obj)
|
44
|
+
@set('depth',i)
|
45
|
+
@set('staticDepth',s)
|
46
|
+
@set('dynamicDepth',d)
|
47
|
+
PinkmanCache.cache("p-path-#{url}",this)
|
35
48
|
|
36
49
|
@depth: (url) ->
|
37
50
|
a = url.split('/')
|
@@ -54,18 +67,25 @@ class window.PinkmanPath extends Pinkman.object
|
|
54
67
|
@levels.last()
|
55
68
|
|
56
69
|
match: (path) ->
|
70
|
+
# console.log "PinkmanPath#match - path arg: #{path}"
|
57
71
|
path = new PinkmanPath(path) if Pinkman.isString(path)
|
58
72
|
if PinkmanPath.isInstance(path) and path.depth == @depth
|
73
|
+
# console.log 'tentou'
|
59
74
|
match = true
|
60
75
|
@static.each (level) ->
|
61
|
-
|
76
|
+
if level.entry != path.level(level.index).entry
|
77
|
+
# console.log level.entry
|
78
|
+
# console.log path.level(level.index).entry
|
79
|
+
match = false
|
62
80
|
return(match)
|
63
81
|
else
|
64
82
|
false
|
65
83
|
|
66
84
|
matchParams: (path) ->
|
67
85
|
@dynamic.each (level) ->
|
68
|
-
|
86
|
+
# console.log level
|
87
|
+
# console.log path
|
88
|
+
path.params[level.entry.replace(/:/g,"")] = path.level(level.index).entry.replace(/[#?].*/,'')
|
69
89
|
|
70
90
|
deduceControllerName: ->
|
71
91
|
@static.extract('entry').join('-').replace(/[\/_]/g,'-').replace(/^-/,'')
|
@@ -100,13 +120,20 @@ class window.PinkmanRouteMatcher extends Pinkman.object
|
|
100
120
|
|
101
121
|
findRouteFor: (url) ->
|
102
122
|
url = url.replace(window.location.origin,'') if PinkmanPath.isInternal(url)
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
.
|
123
|
+
# console.log 'tentando achar route'
|
124
|
+
# console.log(url)
|
125
|
+
if PinkmanCache.has("p-router-#{url}")
|
126
|
+
PinkmanCache.get("p-router-#{url}")
|
127
|
+
else
|
128
|
+
r = Pinkman.routes
|
129
|
+
.select(depth: PinkmanPath.depth(url))
|
130
|
+
.select((candidate) -> candidate.path.match(url))
|
131
|
+
.sortBy('staticDepth','desc').first()
|
132
|
+
return(PinkmanCache.cache("p-router-#{url}", r))
|
107
133
|
|
108
134
|
setup: (route,url) ->
|
109
135
|
if route? and url?
|
136
|
+
# console.log "PinkmanRouterMatcher#setup - url arg: #{url}"
|
110
137
|
urlPath = new PinkmanPath(url)
|
111
138
|
route.path.matchParams(urlPath)
|
112
139
|
@set('url',url)
|
@@ -124,7 +151,7 @@ class window.PinkmanRouteMatcher extends Pinkman.object
|
|
124
151
|
params: ->
|
125
152
|
# console.log @path
|
126
153
|
# console.log @path.params
|
127
|
-
@path.params
|
154
|
+
Pinkman.mergeObjects(@path.params, @path.query)
|
128
155
|
|
129
156
|
|
130
157
|
# every route defined turn into a object of this class: PinkmanRoute
|
@@ -246,14 +273,19 @@ class window.PinkmanRouter
|
|
246
273
|
if r? and r
|
247
274
|
# console.log r
|
248
275
|
r.options = options
|
276
|
+
@_config.beforeRender(r) if $p.isFunction(@_config.beforeRender)
|
249
277
|
if @_config.transition? and typeof @_config.transition == 'function'
|
250
278
|
@_config.transition =>
|
251
279
|
@render(r,callback)
|
252
280
|
else
|
253
281
|
@render(r,callback)
|
254
282
|
else
|
283
|
+
# console.log 'route not found'
|
255
284
|
false
|
256
285
|
|
286
|
+
@path: ->
|
287
|
+
window.location.pathname
|
288
|
+
|
257
289
|
# Goes to a path
|
258
290
|
@visit: (path) ->
|
259
291
|
@activate path, ->
|
@@ -287,12 +319,26 @@ class window.PinkmanRouter
|
|
287
319
|
@back: ->
|
288
320
|
window.history.back() if window.history?
|
289
321
|
|
322
|
+
@refresh: ->
|
323
|
+
@go(@path())
|
324
|
+
|
325
|
+
@reload: ->
|
326
|
+
window.location.reload()
|
327
|
+
|
328
|
+
@paramsObject: ->
|
329
|
+
regex = /\?(.*)/
|
330
|
+
if regex.test(window.location.href)
|
331
|
+
paramsString = regex.exec(window.location.href)[1]
|
332
|
+
JSON.parse('{"' + decodeURI(paramsString).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g,'":"') + '"}')
|
333
|
+
else
|
334
|
+
return new Object
|
335
|
+
|
290
336
|
@start: ->
|
291
337
|
Pinkman.ready =>
|
292
338
|
Pinkman.router = this
|
293
339
|
App.router = this
|
294
340
|
window.$r = App.router
|
295
|
-
@activate(window.location.
|
341
|
+
@activate(window.location.href)
|
296
342
|
$('body').on 'click', 'a:not([data-pinkman="false"],[target="blank"],[target="_blank"])', (ev) =>
|
297
343
|
ev.preventDefault()
|
298
344
|
path = ev.currentTarget.href
|
@@ -304,6 +350,12 @@ class window.PinkmanRouter
|
|
304
350
|
namespaced._namespace = if @_namespace then ("#{@_namespace}/#{namespace}") else namespace
|
305
351
|
rules(namespaced) if typeof rules == 'function'
|
306
352
|
|
353
|
+
scope: (scope, rules) ->
|
354
|
+
scope = scope.replace(/^\//,'')
|
355
|
+
scoped = new @constructor()
|
356
|
+
scoped._scope = if @_scope then ("#{@_scope}/#{scope}") else scope
|
357
|
+
rules(scoped) if typeof rules == 'function'
|
358
|
+
|
307
359
|
resources: (resourceName) ->
|
308
360
|
|
309
361
|
# controllerPrefix = if @_namespace then @_namespace.replace(/\//,'-') + '-' else ''
|
@@ -325,6 +377,7 @@ class window.PinkmanRouter
|
|
325
377
|
if Pinkman.isString(path)
|
326
378
|
path = path.replace(/^\//,'')
|
327
379
|
path = "/#{@_namespace}/" + path if @_namespace
|
380
|
+
path = "/#{@_scope}/" + path if @_scope
|
328
381
|
p = new PinkmanPath(path)
|
329
382
|
route = new PinkmanRoute
|
330
383
|
route.set('id',path)
|
@@ -45,9 +45,10 @@ module Pinkman
|
|
45
45
|
generate 'pinkman:initializer'
|
46
46
|
end
|
47
47
|
|
48
|
-
|
49
|
-
|
50
|
-
|
48
|
+
# # TO DO < pinkman channel
|
49
|
+
# def create_pinkman_channel
|
50
|
+
# generate 'pinkman:pinkman_channel'
|
51
|
+
# end
|
51
52
|
|
52
53
|
def install_hello_world_controller
|
53
54
|
copy_file "hello.controller.coffee.erb", Rails.root.join('app','assets','javascripts','pinkman','app','controllers','hello.coffee')
|
@@ -1,23 +1,23 @@
|
|
1
1
|
class Api::<%= controller_name %> < ApiController
|
2
2
|
|
3
|
+
before_action :verify_permissions
|
3
4
|
before_action :set_objects
|
4
|
-
before_action :permissions
|
5
5
|
|
6
6
|
# get api/<%= api_name %>
|
7
7
|
def index
|
8
|
-
<%= collection_name %> = <%= active_record_model_name %>.limit(
|
9
|
-
render json: <%= collection_name %>.json(
|
8
|
+
<%= collection_name %> = <%= active_record_model_name %>.limit(current_limit).offset(current_offset)
|
9
|
+
render json: <%= collection_name %>.json(requested_scope)
|
10
10
|
end
|
11
11
|
|
12
12
|
# get api/<%= api_name %>/:id
|
13
13
|
def show
|
14
|
-
render json: @<%= instance_name %>.json(
|
14
|
+
render json: @<%= instance_name %>.json(requested_scope)
|
15
15
|
end
|
16
16
|
|
17
17
|
# get api/<%= api_name %>/get
|
18
18
|
def get
|
19
19
|
<%= collection_name %> = <%= active_record_model_name %>.get(handle_query_param)
|
20
|
-
render json: <%= collection_name %>.json(
|
20
|
+
render json: <%= collection_name %>.json(requested_scope)
|
21
21
|
end
|
22
22
|
|
23
23
|
# --- TO DO: Revise this ---
|
@@ -33,8 +33,8 @@ class Api::<%= controller_name %> < ApiController
|
|
33
33
|
# get api/<%= api_name %>/search/:query
|
34
34
|
def search
|
35
35
|
if params[:query].present?
|
36
|
-
<%= collection_name %> = <%= active_record_model_name %>.search(params[:query]).limit(
|
37
|
-
render json: <%= collection_name %>.json(
|
36
|
+
<%= collection_name %> = <%= active_record_model_name %>.search(params[:query]).limit(current_limit).offset(current_offset)
|
37
|
+
render json: <%= collection_name %>.json(requested_scope)
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
@@ -42,28 +42,28 @@ class Api::<%= controller_name %> < ApiController
|
|
42
42
|
def create
|
43
43
|
@<%= instance_name %>.assign_attributes <%= params_method_name %>
|
44
44
|
@<%= instance_name %>.save
|
45
|
-
render json: @<%= instance_name %>.json(
|
45
|
+
render json: @<%= instance_name %>.json(requested_scope)
|
46
46
|
end
|
47
47
|
|
48
48
|
# put/patch api/<%= api_name %>/:id
|
49
49
|
def update
|
50
50
|
@<%= instance_name %>.update <%= params_method_name %>
|
51
|
-
render json: @<%= instance_name %>.json(
|
51
|
+
render json: @<%= instance_name %>.json(requested_scope)
|
52
52
|
end
|
53
53
|
|
54
54
|
# delete api/<%= api_name %>/:id
|
55
55
|
def destroy
|
56
56
|
@<%= instance_name %>.destroy
|
57
|
-
render json: @<%= instance_name %>.json(
|
57
|
+
render json: @<%= instance_name %>.json(requested_scope)
|
58
58
|
end
|
59
59
|
|
60
60
|
protected
|
61
61
|
|
62
62
|
# --- begin permissions --- #
|
63
63
|
|
64
|
-
def
|
65
|
-
unless <%= serializer_name %>.scope(
|
66
|
-
render json: {
|
64
|
+
def verify_permissions
|
65
|
+
unless requested_scope.in?(allowed_scopes) and <%= serializer_name %>.scope(requested_scope).can_access? action_name
|
66
|
+
render json: {error: 'Unauthorized'}, status: :unauthorized
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
@@ -79,7 +79,7 @@ class Api::<%= controller_name %> < ApiController
|
|
79
79
|
|
80
80
|
def <%= params_method_name %>
|
81
81
|
if params['pink_obj']
|
82
|
-
params["pink_obj"].keep_if {|k,v| <%= serializer_name %>.scope(
|
82
|
+
params["pink_obj"].keep_if {|k,v| <%= serializer_name %>.scope(requested_scope).can_write?(k)}
|
83
83
|
params["pink_obj"].permit!
|
84
84
|
else
|
85
85
|
{}
|
@@ -1,15 +1,23 @@
|
|
1
1
|
class ApiController < ApplicationController
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
params[:limit]
|
7
|
-
|
3
|
+
def current_limit
|
4
|
+
# default: 20
|
5
|
+
# max: 200
|
6
|
+
[(params[:limit] || 10).to_i, 100].min
|
7
|
+
end
|
8
|
+
|
9
|
+
def current_offset
|
10
|
+
params[:offset] || 0
|
11
|
+
end
|
12
|
+
|
13
|
+
# TO DO: allowed_scopes
|
14
|
+
# This method should return array of allowed scopes based on current user info.
|
15
|
+
def allowed_scopes
|
16
|
+
[:public]
|
8
17
|
end
|
9
18
|
|
10
|
-
|
11
|
-
|
12
|
-
:public
|
19
|
+
def requested_scope
|
20
|
+
begin params[:scope].to_sym rescue :public end
|
13
21
|
end
|
14
22
|
|
15
23
|
# You can define it according to the current user and his permissions
|
@@ -20,26 +28,9 @@ class ApiController < ApplicationController
|
|
20
28
|
# * *
|
21
29
|
# * Never pass params[:scope] directly to serializers. *
|
22
30
|
# * params[:scope] must to be whitelisted if you are going to allow/use it. *
|
23
|
-
# * See examples bellow. *
|
24
31
|
# * *
|
25
|
-
|
26
|
-
|
27
|
-
# --- Examples
|
32
|
+
# *****************************************************************************************
|
28
33
|
|
29
|
-
# Example 1:
|
30
|
-
# def current_scope
|
31
|
-
# current_user.admin? ? :admin : :public
|
32
|
-
# end
|
33
|
-
|
34
|
-
# Example 2:
|
35
|
-
# def current_scope
|
36
|
-
# params[:scope].in?(['public','user_allowed','vip']) ? params[:scope].to_sym : :public
|
37
|
-
# end
|
38
|
-
|
39
|
-
# Example 3:
|
40
|
-
# def current_scope
|
41
|
-
# your_custom_scope_verification_method?(params[:scope]) ? params[:scope].to_sym : :public
|
42
|
-
# end
|
43
34
|
|
44
35
|
# --- Settings scope in client
|
45
36
|
|
@@ -1,6 +1,10 @@
|
|
1
1
|
Pinkman.setup do |config|
|
2
2
|
|
3
|
+
# Whenever a given scope is not defined, use this one instead.
|
4
|
+
config.scope_fallback = :public
|
5
|
+
# Comment the line above to raise an error everytime a scope is not found.
|
6
|
+
|
3
7
|
# Choose between: handlebars, hogan, markup
|
4
|
-
config.js_template_engine =
|
8
|
+
config.js_template_engine = :hogan
|
5
9
|
|
6
10
|
end
|
@@ -15,7 +15,11 @@ module Pinkman
|
|
15
15
|
|
16
16
|
define_helper :text do |attr_name,label=nil,html_attributes={}|
|
17
17
|
label ||= attr_name.titleize
|
18
|
+
|
18
19
|
error_for_name = html_attributes.delete(:error_for) || attr_name
|
20
|
+
error_prepend = html_attributes.delete(:error_prepend)
|
21
|
+
error_for_name = error_prepend + error_for_name if error_prepend
|
22
|
+
|
19
23
|
render partial: 'pinkman/pinkman/form_textarea', locals: {attr_name: attr_name, label: label, error_for_name: error_for_name, textarea_options: {name: attr_name}.merge(html_attributes) }
|
20
24
|
end
|
21
25
|
|
@@ -40,6 +44,8 @@ module Pinkman
|
|
40
44
|
obligatory = true if obligatory.nil?
|
41
45
|
label ||= attr_name.titleize
|
42
46
|
error_for_name = html_attributes.delete(:error_for) || attr_name
|
47
|
+
error_prepend = html_attributes.delete(:error_prepend)
|
48
|
+
error_for_name = error_prepend + error_for_name if error_prepend
|
43
49
|
render partial: 'pinkman/pinkman/form_select', locals: {attr_name: attr_name, label: label, error_for_name: error_for_name, options_hash: options_hash, html_attributes: html_attributes, placeholder: placeholder, obligatory: obligatory}
|
44
50
|
end
|
45
51
|
|
@@ -52,7 +58,7 @@ module Pinkman
|
|
52
58
|
end
|
53
59
|
|
54
60
|
define_helper :money do |attr_name,label=nil,html_attributes={}|
|
55
|
-
p.input_helper attr_name, label, html_attributes.merge(type: 'number',
|
61
|
+
p.input_helper attr_name, label, html_attributes.merge(type: 'number', step: '0.01')
|
56
62
|
end
|
57
63
|
|
58
64
|
end
|
@@ -26,8 +26,10 @@ module Pinkman
|
|
26
26
|
else
|
27
27
|
if @scopes[name.to_sym]
|
28
28
|
@scopes[name.to_sym]
|
29
|
+
elsif Pinkman.configuration.scope_fallback and @scopes[Pinkman.configuration.scope_fallback]
|
30
|
+
@scopes[Pinkman.configuration.scope_fallback]
|
29
31
|
else
|
30
|
-
raise
|
32
|
+
raise(ArgumentError, (Pinkman.configuration.scope_fallback ? ("Scope '#{name}' and fallback scope '#{Pinkman.configuration.scope_fallback}' were not found in #{self.to_s}.") : ("Scope '#{name}' not found in #{self.to_s}.") ))
|
31
33
|
end
|
32
34
|
end
|
33
35
|
end
|
@@ -85,6 +87,8 @@ module Pinkman
|
|
85
87
|
model.column_names.each {|attribute| hash[attribute] = object.send(attribute) } if include_all && model && model.methods.include?(:column_names)
|
86
88
|
pinkmanscope.read.each {|attribute| hash[attribute] = send(attribute) if self.methods.include?(attribute)}
|
87
89
|
pinkmanscope.read.each {|attribute| hash[attribute] ||= object.send(attribute) if object.methods.include?(attribute)}
|
90
|
+
pinkmanscope.read_ghost.each {|attribute| begin hash[attribute] ||= object.send(attribute) rescue nil end }
|
91
|
+
hash[:destroyed] = true if object.destroyed?
|
88
92
|
hash[:errors] = self.class.format_errors(errors) if errors.present? and errors.any?
|
89
93
|
hash
|
90
94
|
end
|
@@ -7,12 +7,26 @@ module Pinkman
|
|
7
7
|
end
|
8
8
|
|
9
9
|
attr_accessor :read, :write, :access, :serializer
|
10
|
+
|
11
|
+
def read_ghost
|
12
|
+
@read_ghost || []
|
13
|
+
end
|
14
|
+
|
15
|
+
def read_ghost= value
|
16
|
+
@read_ghost = value
|
17
|
+
end
|
10
18
|
|
11
19
|
def read_attributes *args
|
12
20
|
self.read = args
|
13
21
|
self.read = [] unless args.first
|
14
22
|
read
|
15
23
|
end
|
24
|
+
|
25
|
+
def read_ghost_attributes *args
|
26
|
+
self.read_ghost = args
|
27
|
+
self.read_ghost = [] unless args.first
|
28
|
+
read_ghost
|
29
|
+
end
|
16
30
|
|
17
31
|
def write_attributes *args
|
18
32
|
self.write = args
|
@@ -27,7 +41,7 @@ module Pinkman
|
|
27
41
|
end
|
28
42
|
|
29
43
|
def can_read? attribute
|
30
|
-
read.include?(:all) or read.include?(attribute.to_sym) or attribute.to_sym == :error or attribute.to_sym == :errors
|
44
|
+
read.include?(:all) or read.include?(attribute.to_sym) or attribute.to_sym == :error or attribute.to_sym == :errors or read_ghost.include?(attribute.to_sym)
|
31
45
|
end
|
32
46
|
|
33
47
|
def can_write? attribute
|
@@ -39,7 +53,7 @@ module Pinkman
|
|
39
53
|
end
|
40
54
|
|
41
55
|
def can_read
|
42
|
-
read
|
56
|
+
read + read_ghost
|
43
57
|
end
|
44
58
|
|
45
59
|
def can_write
|
data/lib/pinkman/version.rb
CHANGED
@@ -9,6 +9,10 @@ module Pinkman
|
|
9
9
|
define_helper :input_helper do |attr_name,label=nil,options={}|
|
10
10
|
label ||= attr_name.titleize
|
11
11
|
error_for_name = options.delete(:error_for) || attr_name
|
12
|
+
|
13
|
+
error_prepend = options.delete(:error_prepend)
|
14
|
+
error_for_name = error_prepend + error_for_name if error_prepend
|
15
|
+
|
12
16
|
render partial: 'pinkman/pinkman/form_input', locals: {attr_name: attr_name, label: label, error_for_name: error_for_name, html_attributes: options.merge(name: attr_name)}
|
13
17
|
end
|
14
18
|
|
@@ -28,8 +32,8 @@ module Pinkman
|
|
28
32
|
end
|
29
33
|
|
30
34
|
define_helper :textarea do |hash|
|
31
|
-
content_tag('textarea',hash.merge(data: {pinkey: p.pinkey, action: hash[:name]}, value: p.
|
32
|
-
p.
|
35
|
+
content_tag('textarea',hash.merge(data: {pinkey: p.pinkey, action: hash[:name]}, value: p.w(hash[:name]))) do
|
36
|
+
p.w(hash[:name])
|
33
37
|
end
|
34
38
|
end
|
35
39
|
|
@@ -61,7 +65,7 @@ module Pinkman
|
|
61
65
|
end
|
62
66
|
|
63
67
|
define_helper :first_error do
|
64
|
-
p.
|
68
|
+
p.w('firstError')
|
65
69
|
end
|
66
70
|
|
67
71
|
end
|
@@ -32,17 +32,25 @@ module Pinkman
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
define_helper :partial do |path,
|
35
|
+
define_helper :partial do |path, opts_or_block=nil|
|
36
36
|
# definition mode
|
37
37
|
name = path.to_s
|
38
38
|
id = (/(?:-template)$/ =~ name) ? name : (name + '-template')
|
39
|
-
if
|
40
|
-
|
39
|
+
if opts_or_block.is_a?(Proc)
|
40
|
+
block = opts_or_block
|
41
|
+
content_tag('script',{id: id, type: 'text/p-partial', class: 'p'}, &block)
|
41
42
|
# rendering template partial mode
|
42
43
|
else
|
43
|
-
|
44
|
-
|
45
|
-
|
44
|
+
opts = opts_or_block if opts_or_block.is_a?(Hash)
|
45
|
+
div = opts && opts[:div]
|
46
|
+
div ? raw("<div id='#{id.sub(/(-template)$/,'')}'>{{ partial(#{id}) }}</div>") : raw("{{ partial(#{id}) }}")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# wrap and insert partial = imprint
|
51
|
+
define_helper :imprint do |path|
|
52
|
+
p.wrap_in path do
|
53
|
+
p.partial path
|
46
54
|
end
|
47
55
|
end
|
48
56
|
|
@@ -7,12 +7,13 @@ module Pinkman
|
|
7
7
|
extend Pinkman::BaseHelper
|
8
8
|
|
9
9
|
define_helper :write do |string|
|
10
|
-
raw "{{ #{string} }}"
|
10
|
+
raw "{{. #{string} }}"
|
11
11
|
end
|
12
12
|
define_helper_alias :w, :write
|
13
13
|
|
14
14
|
define_helper :write_and_escape_sync do |string|
|
15
|
-
|
15
|
+
ActiveSupport::Deprecation.warn('"p._w" deprecated. Use "p.w" instead.')
|
16
|
+
p.write(string)
|
16
17
|
end
|
17
18
|
define_helper_alias :_w, :write_and_escape_sync
|
18
19
|
|
@@ -64,8 +64,8 @@ end
|
|
64
64
|
# as procs. So...
|
65
65
|
|
66
66
|
# Use:
|
67
|
-
#
|
67
|
+
# define_helper :method_name do |one, two, block=nil|
|
68
68
|
|
69
69
|
# DONT't use:
|
70
|
-
#
|
70
|
+
# define_helper :method_name do |one, two, &block|
|
71
71
|
# (this won't work)
|
data/lib/pinkman.rb
CHANGED
@@ -9,7 +9,7 @@ require 'pinkman/broadcaster'
|
|
9
9
|
|
10
10
|
module Pinkman
|
11
11
|
|
12
|
-
@@configuration = OpenStruct.new
|
12
|
+
@@configuration = OpenStruct.new(js_template_engine: 'handlebars')
|
13
13
|
|
14
14
|
def self.root
|
15
15
|
Pathname.new(File.dirname(__FILE__)).join('..')
|
@@ -26,7 +26,7 @@ module Pinkman
|
|
26
26
|
class Engine < ::Rails::Engine
|
27
27
|
config.after_initialize do
|
28
28
|
Rails.application.routes.append do
|
29
|
-
mount
|
29
|
+
mount(Pinkman::Engine => '/')
|
30
30
|
end
|
31
31
|
|
32
32
|
module ApplicationHelper
|
@@ -34,7 +34,7 @@ module Pinkman
|
|
34
34
|
end
|
35
35
|
|
36
36
|
if defined? Slim
|
37
|
-
Slim::Engine.set_options
|
37
|
+
Slim::Engine.set_options(attr_list_delims: {'(' => ')', '[' => ']'})
|
38
38
|
end
|
39
39
|
|
40
40
|
# Extending ActiveRecord
|
@@ -68,13 +68,13 @@ module Pinkman
|
|
68
68
|
|
69
69
|
# Active Record Relation: json
|
70
70
|
ActiveRecord::Relation.class_eval do
|
71
|
-
def json scope_name, params_hash = {}
|
72
|
-
serialize_for(scope_name,params_hash).to_json
|
71
|
+
def json scope_name=:public, params_hash = {}
|
72
|
+
serialize_for(scope_name, params_hash).to_json
|
73
73
|
end
|
74
74
|
|
75
75
|
def json_for *args, &block
|
76
76
|
ActiveSupport::Deprecation.warn('"json_for" deprecated. Use "json" instead.')
|
77
|
-
json(*args
|
77
|
+
json(*args, &block)
|
78
78
|
end
|
79
79
|
|
80
80
|
def serialize_for scope_name, params_hash = {}
|
@@ -85,13 +85,13 @@ module Pinkman
|
|
85
85
|
end
|
86
86
|
|
87
87
|
Array.class_eval do
|
88
|
-
def json scope_name, params_hash = {}
|
89
|
-
serialize_for(scope_name,params_hash).to_json
|
88
|
+
def json scope_name=:public, params_hash = {}
|
89
|
+
serialize_for(scope_name, params_hash).to_json
|
90
90
|
end
|
91
91
|
|
92
92
|
def json_for *args, &block
|
93
93
|
ActiveSupport::Deprecation.warn('"json_for" deprecated. Use "json" instead.')
|
94
|
-
json(*args
|
94
|
+
json(*args, &block)
|
95
95
|
end
|
96
96
|
|
97
97
|
def serialize_for scope_name, params_hash = {}
|
@@ -108,24 +108,28 @@ module Pinkman
|
|
108
108
|
self.class.serializer.new(self,options)
|
109
109
|
end
|
110
110
|
|
111
|
-
def json scope_name, params_hash={}
|
112
|
-
serialize_for(scope_name,params_hash).to_json
|
111
|
+
def json scope_name=:public, params_hash={}
|
112
|
+
serialize_for(scope_name, params_hash).to_json
|
113
113
|
end
|
114
114
|
|
115
115
|
def json_for *args, &block
|
116
116
|
ActiveSupport::Deprecation.warn('"json_for" deprecated. Use "json" instead.')
|
117
|
-
json(*args
|
117
|
+
json(*args, &block)
|
118
118
|
end
|
119
119
|
|
120
|
-
def has_json_key? key, scope
|
121
|
-
json_version
|
122
|
-
json_version.has_key?(key.to_s) and json_version[key.to_s].present?
|
120
|
+
def has_json_key? key, scope=:public, options={}
|
121
|
+
json_version(scope, options).has_key?(key.to_s) and json_version(scope, options)[key.to_s].present?
|
123
122
|
end
|
124
123
|
|
125
|
-
def
|
126
|
-
JSON.parse(json(
|
124
|
+
def json_version *args
|
125
|
+
JSON.parse(json(*args))
|
127
126
|
end
|
128
|
-
|
127
|
+
alias json_hash json_version
|
128
|
+
|
129
|
+
def json_key key, scope=:public, options={}
|
130
|
+
json_version(scope, options)[key.to_s]
|
131
|
+
end
|
132
|
+
|
129
133
|
end
|
130
134
|
end
|
131
135
|
|