kindred 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +58 -6
- data/app/assets/javascripts/models/active_page.coffee +12 -6
- data/app/assets/javascripts/models/base.coffee +2 -0
- data/app/helpers/template_helper.rb +2 -6
- data/kindred-0.0.1.gem +0 -0
- data/lib/kindred/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e03bccd44f384512d021142b9c05e55432834f2
|
4
|
+
data.tar.gz: 7a82f21f14b9fcfed70848620ae80e0505da041d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 76f08bed0689360d3765562774575bf006593e162499eb2ce5e6284f58e95ab0060c4202e84c8e0acc4c4172f5706f0243353ea09e7839d5e842b833162146b6
|
7
|
+
data.tar.gz: 99e97908c9dccf760e01ab940da6d4fa5357b34af60f1a93375f26502f2ab07ce1a677c88c92ca2f6deb4e783f219c66a07bd2f884c6861c0b806340572fc52e
|
data/README.md
CHANGED
@@ -12,6 +12,7 @@ kindred
|
|
12
12
|
| Homepage | [http://mfpiccolo.github.io/kindred][homepage] |
|
13
13
|
| Documentation | [http://rdoc.info/github/mfpiccolo/kindred/frames][documentation] |
|
14
14
|
| Issues | [https://github.com/mfpiccolo/kindred/issues][issues] |
|
15
|
+
| Conversation | [![Gitter](https://badges.gitter.im/Join Chat.svg)](https://gitter.im/mfpiccolo/kindred?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
15
16
|
|
16
17
|
## Description
|
17
18
|
Kindred is an open source project that intends to optimize programmers happiness and productivity for client-heavy rails applications. Kindred aims to allow developers to create robust client side applications with minimal code while maintaining best practices and conventions.
|
@@ -38,12 +39,45 @@ Add `gem "kindred"` to gemfile
|
|
38
39
|
|
39
40
|
Add `//= require kindred` to application.js manifest
|
40
41
|
|
41
|
-
|
42
|
+
If you are using uglifier you may need to add the following to assets.rb:
|
42
43
|
|
43
44
|
```ruby
|
44
45
|
Rails.application.config.assets.js_compressor = Uglifier.new(mangle: false)
|
45
46
|
```
|
46
47
|
|
48
|
+
The following config needs to be abstracted to the gem or refactored but for now:
|
49
|
+
|
50
|
+
Add this configuration to application.html.erb:
|
51
|
+
|
52
|
+
```
|
53
|
+
<%= kindred_model_data %>
|
54
|
+
<%= content_for :kindred_script %>
|
55
|
+
<script type="text/javascript">
|
56
|
+
App.BaseUrl = '<%= "#{request.protocol}#{request.host_with_port}" %>';
|
57
|
+
</script>
|
58
|
+
```
|
59
|
+
|
60
|
+
In the controller that you will be rendering kindred models you need to add:
|
61
|
+
|
62
|
+
```
|
63
|
+
...
|
64
|
+
after_action :setup_kindred
|
65
|
+
|
66
|
+
helper_method :js
|
67
|
+
...
|
68
|
+
```
|
69
|
+
|
70
|
+
```
|
71
|
+
def setup_kindred
|
72
|
+
view_context.content_for :kindred_script do
|
73
|
+
js(js_class: "App.Template", function: "set_templates", args: @kindred_hash, rendered: true)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
```
|
77
|
+
|
78
|
+
One again, much of this configuration will be removed in the future but is neccesary at the moment.
|
79
|
+
|
80
|
+
|
47
81
|
## Demo
|
48
82
|
|
49
83
|
If you would like to see kindred in action check out [kindred-demo](https://kindred-demo.herokuapp.com/invoices/1/edit).
|
@@ -57,12 +91,12 @@ The `#template` method takes the following keyword arguments:
|
|
57
91
|
|
58
92
|
`collection:` Collection of json serializable ruby objects
|
59
93
|
|
60
|
-
`
|
94
|
+
`target_uuid:` String of the uuid for the data-target-uuid attribute wrapper
|
61
95
|
|
62
96
|
`&block` In the block pass html that will be used for that model
|
63
97
|
|
64
98
|
```HTML
|
65
|
-
<div
|
99
|
+
<div <%= target @invoice %>>
|
66
100
|
<%= template(collection: @line_items, target: "line-item", model: "line_item") do %>
|
67
101
|
<tr>
|
68
102
|
<td><%= k_text_field_tag(:line_item, :description) %></td>
|
@@ -85,13 +119,31 @@ You could then get access to the collection or the template by using those prope
|
|
85
119
|
|
86
120
|
`li_info.collection` would return the json collection
|
87
121
|
|
122
|
+
###Interpolation
|
123
|
+
Inside of templates, it is possible to interpolate dynamic data by using the {{}} syntax.
|
124
|
+
|
125
|
+
For example, you could interpolate the id of the line item by doing the following
|
126
|
+
```HTML
|
127
|
+
<div <%= target @invoice %>>
|
128
|
+
<%= template(collection: @line_items, target: "line-item", model: "line_item") do %>
|
129
|
+
<tr>
|
130
|
+
<td>{{line_item.id}}</td>
|
131
|
+
<td><%= k_text_field_tag(:line_item, :description) %></td>
|
132
|
+
<td><%= k_text_field_tag(:line_item, :qty) %></td>
|
133
|
+
<td><%= k_text_field_tag(:line_item, :price_cents) %></td>
|
134
|
+
<td><%= k_check_box_tag(:line_item, :complete) %></td>
|
135
|
+
</tr>
|
136
|
+
<% end %>
|
137
|
+
</div>
|
138
|
+
```
|
139
|
+
|
88
140
|
###Controllers
|
89
141
|
In kindred, javascript controllers are a client side augmentation of your ruby controllers. They are just client side code that gets run on page load.
|
90
142
|
|
91
143
|
```coffeescript
|
92
|
-
|
93
|
-
|
94
|
-
|
144
|
+
class this.InvoicesController
|
145
|
+
@edit: ->
|
146
|
+
console.log "Run this on invoice edit view"
|
95
147
|
```
|
96
148
|
|
97
149
|
To ensure that this code is run on the client side call the js method from your view or controller:
|
@@ -25,9 +25,10 @@ class App.ActivePage
|
|
25
25
|
if select.length
|
26
26
|
select.val(value)
|
27
27
|
|
28
|
-
|
29
|
-
if
|
30
|
-
|
28
|
+
display = $template.find("div[data-attr='" + key + "'], span[data-attr='" + key + "'], p[data-attr='" + key + "']")
|
29
|
+
if display.length
|
30
|
+
new_display = display.html(value)
|
31
|
+
display.replaceWith(new_display)
|
31
32
|
|
32
33
|
@_append_data_model_to_page()
|
33
34
|
|
@@ -40,6 +41,11 @@ class App.ActivePage
|
|
40
41
|
$.each @attributes, (attr, val) =>
|
41
42
|
$("[data-k-uuid='" + @uuid + "'][data-attr='" + attr + "']").val(val)
|
42
43
|
|
44
|
+
update_displays_on_page: ->
|
45
|
+
$.each @attributes, (attr, val) =>
|
46
|
+
# TODO make this work with span and p
|
47
|
+
$("div[data-k-uuid='" + @uuid + "'][data-attr='" + attr + "'], span[data-k-uuid='" + @uuid + "'][data-attr='" + attr + "'], p[data-k-uuid='" + @uuid + "'][data-attr='" + attr + "']").html(val)
|
48
|
+
|
43
49
|
dirty_from_page: ->
|
44
50
|
dirty = []
|
45
51
|
$.each $("input[data-k-uuid='" + @uuid + "'], select[data-k-uuid='" + @uuid + "']"), (i, input) =>
|
@@ -65,9 +71,9 @@ class App.ActivePage
|
|
65
71
|
else
|
66
72
|
@set $input.data("attr"), $input.val()
|
67
73
|
|
68
|
-
|
69
|
-
|
70
|
-
|
74
|
+
model_data = $("[data-kindred-model]").find("[data-k-uuid='" + @uuid + "']")
|
75
|
+
if !isNaN(parseFloat(model_data.data("id"))) && isFinite(model_data.data("id"))
|
76
|
+
@id = model_data.data("id")
|
71
77
|
|
72
78
|
$("select[data-k-uuid='" + @uuid + "']").each (i, select) =>
|
73
79
|
@set $(select).data("attr"), $(select).val()
|
@@ -101,7 +101,9 @@ class App.Base extends App.VirtualClass App.ActivePage, App.Setup
|
|
101
101
|
@assign_attributes(data)
|
102
102
|
@_clear_errors()
|
103
103
|
@_update_data_vals_on_page()
|
104
|
+
@update_vals_on_page()
|
104
105
|
@_setup_interpolated_vars()
|
106
|
+
@update_displays_on_page()
|
105
107
|
|
106
108
|
#overridable hook
|
107
109
|
after_save_error: (xhr) ->
|
@@ -1,10 +1,6 @@
|
|
1
1
|
module TemplateHelper
|
2
2
|
def template(model: nil, collection: nil, target_uuid: nil, &block)
|
3
|
-
model_name =
|
4
|
-
ActiveModel::Naming.singular(collection.first)
|
5
|
-
else
|
6
|
-
model
|
7
|
-
end
|
3
|
+
model_name = model
|
8
4
|
|
9
5
|
@kindred_hash ||= {}
|
10
6
|
@kindred_hash.merge!({
|
@@ -23,7 +19,7 @@ module TemplateHelper
|
|
23
19
|
end
|
24
20
|
|
25
21
|
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: k_try(object, :uuid), val:
|
22
|
+
content_tag(element, nil, options.merge({data: { attr: attribute, k_uuid: k_try(object, :uuid), val: object.try(attribute.to_sym)} }))
|
27
23
|
end
|
28
24
|
|
29
25
|
def k_hidden_field_tag(name, value=nil, object=nil, delegate_to=nil, options = {})
|
data/kindred-0.0.1.gem
ADDED
Binary file
|
data/lib/kindred/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kindred
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Piccolo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -91,6 +91,7 @@ files:
|
|
91
91
|
- app/assets/javascripts/utilities/uuid.coffee
|
92
92
|
- app/assets/javascripts/utilities/virtual_class.coffee
|
93
93
|
- app/helpers/template_helper.rb
|
94
|
+
- kindred-0.0.1.gem
|
94
95
|
- kindred.gemspec
|
95
96
|
- lib/kindred.rb
|
96
97
|
- lib/kindred/engine.rb
|
@@ -115,9 +116,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
115
116
|
version: '0'
|
116
117
|
requirements: []
|
117
118
|
rubyforge_project:
|
118
|
-
rubygems_version: 2.
|
119
|
+
rubygems_version: 2.4.3
|
119
120
|
signing_key:
|
120
121
|
specification_version: 4
|
121
122
|
summary: ''
|
122
123
|
test_files: []
|
123
|
-
has_rdoc:
|