kindred-rails 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 001c632a3e3afa77efdabc26f278a8310cead18f
4
- data.tar.gz: 8176a13a8a1c67394aec32709a65a9eeaa483000
3
+ metadata.gz: 70b4b26fde36e24f4ca148d09ba43fd89608f455
4
+ data.tar.gz: 754daf92c18e3e90d8d9fddc88d1658ce68c2667
5
5
  SHA512:
6
- metadata.gz: 5d59c0bb81d4b088324c0883972c814dc18702abc433d7d0c48491f78ac9d3be2e3e4a3b0d1f369219fb9adf2ff77936f9fd66e7718c387efe9e084590943dd5
7
- data.tar.gz: 56816c9a02796798a584dae5190f4724dc2710573ccc3216e55b92e8cc42f5dffea0d90c8a567fcddd98d26dfc72a0fadb6115d23c770a278e7bf18728ea3f73
6
+ metadata.gz: a0f55320b4fa985d782c755c8c1794939f8f9cbf317c0baa9e232ec6e5522b5d52a3e8e7da094fe7fae068d88330b2ab05242577efe708498cab5ab7b718c7c3
7
+ data.tar.gz: b28ac292c687ae619287454a7af09e6158a4269fe6ce8c17ad50a0d803d4f383f4c5a88afcd66aedc5bf3a1b0b0a12c2635de3890da8d3453daa9f9d66b2f9a7
data/README.md CHANGED
@@ -40,7 +40,7 @@ Add `//= require kindred` to application.js manifest
40
40
 
41
41
  ## Demo
42
42
 
43
- If you would like to see kindred in action check out [kindred-demo](https://kindred-demo.herokuapp.com/dashboard).
43
+ If you would like to see kindred in action check out [kindred-demo](https://kindred-demo.herokuapp.com/invoices/1/edit).
44
44
 
45
45
  ## Features
46
46
  ###Templates
@@ -14,6 +14,12 @@ class App.Base extends App.VirtualClass App.ActivePage, App.Setup
14
14
 
15
15
  data[@snake_name + "s"] = added_attrs
16
16
 
17
+ url_match = new RegExp(/{{([^{}]+)}}/g)
18
+ @route = @route.replace(url_match, (match, p1) =>
19
+ attribute = match.slice(2, - 2)
20
+ opts.add_data_to_each[attribute]
21
+ )
22
+
17
23
  # TODO REMOVE THIS AFTER WEBKIT BUG FIX. https://github.com/thoughtbot/capybara-webkit/issues/553
18
24
  # This conditonal is for testing but there is no easy fix at the moment.
19
25
  # Put passes through data. Patch dosn't.
@@ -22,7 +28,7 @@ class App.Base extends App.VirtualClass App.ActivePage, App.Setup
22
28
  method = 'PUT'
23
29
  else
24
30
  path = @route + "/save_all.json"
25
- method = 'PATCH'
31
+ method = 'PUT'
26
32
 
27
33
  $.ajax
28
34
  type: method
@@ -2,19 +2,16 @@ class App.Setup
2
2
  constructor: (@opts) ->
3
3
  @_set_name_properties()
4
4
  @_set_self()
5
- @route ||= App[@constructor.name].route
6
- @route ||= "/" + @snake_name + "s"
7
5
 
8
6
  @opts ||= {}
9
7
 
10
- if App[@constructor.name].relations?
11
- @_setup_relationships()
12
-
13
8
  @attributes = {}
14
9
  template = @opts.template || App[@constructor.name].template
15
10
 
16
11
  @_set_opts_to_attributes()
17
12
 
13
+ @_setup_route()
14
+
18
15
  @uuid = @opts.uuid || @attributes.uuid || App.UUID.generate()
19
16
  @id = @opts.id || @attributes.id
20
17
  @target_uuid = @opts.target_uuid || @attributes.target_uuid
@@ -27,10 +24,6 @@ class App.Setup
27
24
  @_build_attrs_template()
28
25
  @_setup_interpolated_vars()
29
26
 
30
- @has_many: (relation) ->
31
- @relations ||= []
32
- @relations.push({has_many: relation})
33
-
34
27
  @set_class_name: (class_name) ->
35
28
  @class_name = class_name
36
29
  @dash_name = @_get_dash_name(class_name)
@@ -49,26 +42,6 @@ class App.Setup
49
42
  "_" + $1.toLowerCase()
50
43
  under_str[1 .. under_str.length - 1]
51
44
 
52
- _setup_relationships: =>
53
- if App[@constructor.name].relations.length > 0
54
- $.each App[@constructor.name].relations, (i, relation) =>
55
- @[relation["has_many"]] = ->
56
- $.ajax
57
- type: "get"
58
- url: "/kindred.json"
59
- dataType: "json"
60
- data: {
61
- class_name: @class_name
62
- id: @id
63
- relation: relation["has_many"]
64
- }
65
- success: (data, textStatus, xhr) =>
66
- console.log "success"
67
- console.log data
68
- error: (xhr) =>
69
- console.log "error"
70
- console.log xhr
71
-
72
45
  _set_self: ->
73
46
  @_self = @
74
47
 
@@ -113,3 +86,12 @@ class App.Setup
113
86
  if @opts?
114
87
  $.each @opts, (key, val) =>
115
88
  @set key, val
89
+
90
+ _setup_route: =>
91
+ url_match = new RegExp(/{{([^{}]+)}}/g)
92
+ @route ||= App[@constructor.name].route
93
+ @route ||= "/" + @snake_name + "s"
94
+ @route = @route.replace(url_match, (match, p1) =>
95
+ attribute = match.slice(2, - 2)
96
+ @get(attribute)
97
+ )
@@ -19,27 +19,27 @@ module TemplateHelper
19
19
  end
20
20
 
21
21
  def target(object)
22
- "data-target data-target-uuid=" + object.try(:uuid).to_s
22
+ "data-target data-target-uuid=" + k_try(object, :uuid).to_s
23
23
  end
24
24
 
25
25
  def k_content_tag(element, attribute = nil, object = nil, content_or_options_with_block = nil, options = {}, escape = true, &block)
26
- content_tag(element, nil, options.merge({data: { attr: attribute, k_uuid: object.try(:uuid), val: ""} }))
26
+ content_tag(element, nil, options.merge({data: { attr: attribute, k_uuid: k_try(object, :uuid), val: ""} }))
27
27
  end
28
28
 
29
29
  def k_hidden_field_tag(name, value=nil, object=nil, delegate_to=nil, options = {})
30
- hidden_field_tag name, value, options.merge({data: { attr: name, k_uuid: object.try(:uuid), val: value } })
30
+ hidden_field_tag name, value, options.merge({data: { attr: name, k_uuid: k_try(object, :uuid), val: value } })
31
31
  end
32
32
 
33
33
  def k_text_field_tag(object, attribute, options={})
34
- text_field_tag attribute, nil, options.merge({data: { attr: attribute, k_uuid: object.try(:uuid), val: "" } })
34
+ text_field_tag attribute, nil, options.merge({data: { attr: attribute, k_uuid: k_try(object, :uuid), val: "" } })
35
35
  end
36
36
 
37
37
  def k_check_box_tag(object, name, value=nil, checked = false, options = {})
38
- check_box_tag name, value, checked, options.merge({data: { attr: name, k_uuid: object.try(:uuid), val: ""} })
38
+ check_box_tag name, value, checked, options.merge({data: { attr: name, k_uuid: k_try(object, :uuid), val: ""} })
39
39
  end
40
40
 
41
41
  def k_select_tag(object, name, option_tags = nil, options = {})
42
- select_tag name, option_tags, options.merge(data: { attr: name, k_uuid: object.try(:uuid), val: "" })
42
+ select_tag name, option_tags, options.merge(data: { attr: name, k_uuid: k_try(object, :uuid), val: "" })
43
43
  end
44
44
 
45
45
  def error_for(object, attribute)
@@ -50,4 +50,10 @@ module TemplateHelper
50
50
  "<div data-kindred-model style='display:none;'></div>".html_safe
51
51
  end
52
52
 
53
+ def k_try(object, method)
54
+ unless object.is_a?(Symbol)
55
+ object.try method
56
+ end
57
+ end
58
+
53
59
  end
@@ -1,5 +1,5 @@
1
1
  module Kindred
2
2
  module Rails
3
- VERSION = "0.0.4"
3
+ VERSION = "0.0.5"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kindred-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Piccolo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-22 00:00:00.000000000 Z
11
+ date: 2015-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails