pinkman 0.9.8.2 → 0.9.9

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: 8a4c207e261eb4c62383ac4a7e7069ca70024f7c
4
- data.tar.gz: 0bbc015f3849349e210c007a683f1e3f5bcd6373
3
+ metadata.gz: df7295f0731183847a15dd00281daf106ffff34d
4
+ data.tar.gz: 0aca39dd1ab281a14c2b9f0bf9cd593873414eeb
5
5
  SHA512:
6
- metadata.gz: a0eec236e80927bef711a9b2be9f139dd751151b53fc62d3e71d4e2bcb440881af5204c7b934f21ec555430ffc485983f3e4ba5c835c40390befde51eedabfe0
7
- data.tar.gz: 73a09bdeed967df13e7a309d20524d9e306c31c62beaa6d52ed2163549fded7a3afa5cd4ebfad3e5a95897709ba8b0df5c4c746587b9d159fcffbad27b936b7a
6
+ metadata.gz: 8b619cbcf5625f3b969d10792f2b7a260fb295776995bb3b74bcc270c878c22097e069364ed121e81d337ce9b73cbb2458b1e9b19fc2c2cb409c4975dfcab7fd
7
+ data.tar.gz: 4fc5c39c776ba02e7ade7470b073118696f8a3f323a4a885a2fca3bedf0b389cbfe359a13140bbc6b01dd1f0d4497a38c6f6360da529c056b657252da93852c3
@@ -5,8 +5,8 @@
5
5
  //= require pinkman_base/object
6
6
  //= require pinkman_base/collection
7
7
  //= require pinkman_base/render
8
+ //= require pinkman_base/css_and_config
8
9
  //= require pinkman_base/controller
9
10
  //= require pinkman_base/state
10
11
  //= require pinkman_base/router
11
- //= require pinkman_base/css
12
12
  //= require pinkman_base/cable
@@ -1,9 +1,10 @@
1
1
  class window.PinkmanCommon
2
2
 
3
3
  constructor: (attributesObject) ->
4
+ @_listening = true
4
5
  @initialize(attributesObject) if attributesObject?
5
6
 
6
- @privateAttributes = ['isPink','isObject','isCollection','pinkey','config','pinkmanType','collections','renderQueue']
7
+ @privateAttributes = ['isPink','isObject','isCollection','pinkey','config','pinkmanType','collections','renderQueue','_listening']
7
8
 
8
9
  @mixin: (args...) ->
9
10
  Pinkman.mixin(args...)
@@ -46,8 +47,18 @@ class window.PinkmanCommon
46
47
  if attr? and value?
47
48
  this[attr] = value
48
49
  callback(this) if typeof callback == 'function'
49
- @reRender() if @_watching
50
+ @sync(attr) if @_listening
50
51
  return this
52
+
53
+ sync: (attribute) ->
54
+ if attribute? and attribute!=''
55
+ Pinkman.sync(this, attribute, this[attribute])
56
+ else
57
+ Pinkman.sync(this, k, v) for k, v of @attributes()
58
+ true
59
+
60
+ stop: ->
61
+ @_listening = no
51
62
 
52
63
  # Desc: sets the attribute as undefined (destroy attribute)
53
64
  unset: (attr,callback) ->
@@ -98,9 +109,6 @@ class window.PinkmanCommon
98
109
  template: options + '-template'
99
110
  target: options
100
111
 
101
- watch: () ->
102
- @_watching = yes
103
-
104
112
  queue: (options) ->
105
113
  options.id = options.template
106
114
  @renderQueue = new PinkmanCollection unless @renderQueue?
@@ -4,4 +4,5 @@ Pinkman.css = (selector,property,value) ->
4
4
 
5
5
  $(document).ready ->
6
6
  unless $('style#pinkman-css-injector').length
7
- $('body').append('<style id="pinkman-css-injector" type="text/css"></style>')
7
+ $('body').append('<style id="pinkman-css-injector" type="text/css">pink{display: inline; margin: 0; padding: 0; color: inherit; background-color: inherit; font: inherit;}</style>')
8
+ document.createElement('pink') if document.createElement?
@@ -22,6 +22,9 @@ class window.Pinkman
22
22
 
23
23
  @isString: (str) ->
24
24
  str? and typeof str == 'string'
25
+
26
+ @isPrintable: (value) ->
27
+ @isString(value) or @isNumber(value)
25
28
 
26
29
  # --- tools and facilities
27
30
 
@@ -33,9 +33,32 @@ Pinkman.template_engines =
33
33
  template = Pinkman.templates.get(template: options.template, engine: options.engine)
34
34
  else
35
35
  template = new Pinkman.object(template: options.template, engine: options.engine)
36
- @compile(options.engine, template, $('#' + options.template).html())
36
+ @compile(options.engine, template, @templateAdapter($('#' + options.template).html()))
37
37
  Pinkman.templates.push(template)
38
38
  return(template)
39
+
40
+
41
+ # attrAdapterHelper: helper for templateAdapter
42
+ # Helps formating the pink tag.
43
+ # The pink tag is a custom html tag. Pinkman uses it for binding an object and for updating the rendered html automatically everytime that attribute is changed.
44
+ # Used in the replace function below. Take a look.
45
+ attrAdapterHelper: (match,$1,$2,$3) ->
46
+ # console.log 'lol'
47
+ array = $2.split('.')
48
+ attr = array.pop()
49
+ array.push('pinkey')
50
+ pinkey = array.join('.')
51
+ "#{$1}<pink data-pinkey=\"{{ #{pinkey} }}\" data-attribute=\"#{attr}\">{{ #{$2} }}</pink>#{$3}"
52
+
53
+ # changes templates html to insert binders so pinkman can make realtime updates
54
+ templateAdapter: (templateBody) ->
55
+ if templateBody? and templateBody != ''
56
+ syncRegex = /([^'"]){{(?!\.)(?:\s)*([\w\d.]+)(?:\s)*}}([^'"])/gm
57
+ content = templateBody.replace(syncRegex,@attrAdapterHelper)
58
+ escapeSyncingRegex = /{{\./gm
59
+ content.replace(escapeSyncingRegex,'{{')
60
+ else
61
+ ''
39
62
 
40
63
  context: (options) ->
41
64
  options.object = options.context if options.context?
@@ -81,6 +104,23 @@ Pinkman.template_engines =
81
104
  options.callback(options.object,content) if options.callback? and typeof options.callback == 'function'
82
105
  return(content)
83
106
 
107
+ # Pinkman sync:
108
+
109
+ # what it does: finds every ocorrence of a given attribute
110
+ # of an object in the html rendered and updates its value.
111
+
112
+ # input: obj, attribute, value(opcional)
113
+ # output: updates html
114
+ Pinkman.__syncing = new Object
115
+
116
+ Pinkman.sync = (obj,attribute,value) ->
117
+ if typeof obj == 'object' and obj.pinkey? and obj[attribute]? and Pinkman.isPrintable(obj[attribute])
118
+ # clearTimeout(Pinkman.__syncing[attribute]) if Pinkman.__syncing[attribute]?
119
+ # Pinkman.__syncing[attribute] = sleep 0.5, ->
120
+ value = obj[attribute] unless value? and value != ''
121
+ $("pink[data-pinkey='#{obj.pinkey}'][data-attribute='#{attribute}']").html(value)
122
+
123
+
84
124
  Pinkman.render = (options) ->
85
125
  options.reRender = true unless options.reRender? and options.reRender == false
86
126
  options.collectionReRender = true unless options.collectionReRender? and options.collectionReRender == false
@@ -9,7 +9,7 @@ module PinkmanHelper
9
9
  def textarea hash, *args
10
10
  name = hash[:name]
11
11
  content_tag('textarea',hash.merge(data: {pinkey: pinkey, action: name}, value: write(name)), *args) do
12
- raw(write(name))
12
+ write_and_escape_sync('name')
13
13
  end
14
14
  end
15
15
 
@@ -32,10 +32,14 @@ module PinkmanHelper
32
32
  def write string
33
33
  raw("{{#{string}}}")
34
34
  end
35
-
36
- def w *args
37
- write(*args)
35
+ alias w write
36
+
37
+
38
+
39
+ def write_and_escape_sync string
40
+ raw("{{.#{string}}}")
38
41
  end
42
+ alias _w write_and_escape_sync
39
43
 
40
44
  def pinkey
41
45
  w('pinkey')
@@ -1,3 +1,3 @@
1
1
  module Pinkman
2
- VERSION = "0.9.8.2"
2
+ VERSION = "0.9.9"
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.8.2
4
+ version: 0.9.9
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-11-17 00:00:00.000000000 Z
11
+ date: 2017-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -186,10 +186,10 @@ files:
186
186
  - app/assets/javascripts/pinkman_base/collection.coffee
187
187
  - app/assets/javascripts/pinkman_base/common.coffee
188
188
  - app/assets/javascripts/pinkman_base/controller.coffee
189
- - app/assets/javascripts/pinkman_base/css.coffee
189
+ - app/assets/javascripts/pinkman_base/css_and_config.coffee
190
190
  - app/assets/javascripts/pinkman_base/glue.coffee
191
191
  - app/assets/javascripts/pinkman_base/mixins.coffee
192
- - app/assets/javascripts/pinkman_base/object.js.coffee.erb
192
+ - app/assets/javascripts/pinkman_base/object.coffee.erb
193
193
  - app/assets/javascripts/pinkman_base/pinkman.coffee
194
194
  - app/assets/javascripts/pinkman_base/render.coffee.erb
195
195
  - app/assets/javascripts/pinkman_base/router.coffee