transponder 0.9.6 → 0.10.1
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 +79 -1
- data/lib/generators/transponder/presenter/presenter_generator.rb +1 -1
- data/lib/generators/transponder/service/service_generator.rb +1 -1
- data/lib/transponder/transmission.rb +9 -1
- data/lib/transponder/version.rb +1 -1
- data/spec/generators/transponder/presenter/presenter_generator_spec.rb +2 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69e800aadd79761edb7b30a93705f016fa497f3a
|
4
|
+
data.tar.gz: 5467cc1f66292a39995a430178e4cb2449903aad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb061a9b5718d74fa268f0efe3b698f30134219d7716a2d999dc2acc7195798fe17b084a90fd711f98931c0c40bc158eaeacd654727c30db5c3a06c318e56be2
|
7
|
+
data.tar.gz: fd04bc611910918122a116ff60eff355844e5c057b63c1902dd9a8b496020d5e4574625835ff328f82a1c64aadeb5153f81ae871e83e6ac1f72a68c71c6d780c
|
data/README.md
CHANGED
@@ -98,9 +98,87 @@ In the presenter you can do pretty much anything you want to your response befor
|
|
98
98
|
|
99
99
|
Testing is also much easier as now you've shifted the responsibility of the client side behavior to the client. We have more documentation coming on how to test your presenters.
|
100
100
|
|
101
|
+
## Services
|
102
|
+
|
103
|
+
Services are meant to be an easy way to manage functionality of a widget on a page. What does this mean?
|
104
|
+
|
105
|
+
Generally we will have elements on the page that do more than just display information, they have to listen to some even like a mouse click or a tap and then act on that. They may have 1 simple functionality or multiple functions Services are a way to manage that.
|
106
|
+
|
107
|
+
Services are designed to be idempotent. You can run a service on a page repeatedly and it will not apply to the widgets that already have the same service applied. This can be very useful when working with pages that use pjax / turbolinks / single page apps etc...
|
108
|
+
|
109
|
+
### Service Generator
|
110
|
+
|
111
|
+
To generate a service simply type
|
112
|
+
|
113
|
+
```
|
114
|
+
rails g transponder:service contacts_search
|
115
|
+
```
|
116
|
+
|
117
|
+
In our `initializers/manifest.coffee` file we have something like this
|
118
|
+
|
119
|
+
```coffee
|
120
|
+
Application.services_manifest = ->
|
121
|
+
$('body').trigger 'application:services:contacts_search'
|
122
|
+
```
|
123
|
+
|
124
|
+
Basically we want to trigger this service on the page. Since we're using 'body' as the element the service will run on every page. If we apply a class to the html ```<body>``` tag to something like this in our application layout file ```<body class="<%= controller_name %> <%= action_name %>"``` we can trigger specific services on specific pages.
|
125
|
+
|
126
|
+
For example if we're on the controller index page and we want to trigger the contacts search only when we're on that page we can do something like this
|
127
|
+
```coffee
|
128
|
+
Application.services_manifest = ->
|
129
|
+
$('body.contacts.index').trigger 'application:services:contacts_search'
|
130
|
+
```
|
131
|
+
This gives us very fine grained control as to which services should run on which pages.
|
132
|
+
|
133
|
+
We have this in our erb some where on our page
|
134
|
+
|
135
|
+
```html
|
136
|
+
<%= form_tag contacts_path, class: 'navbar-form navbar-left contacts_search', remote: true do %>
|
137
|
+
<div class='form-group'>
|
138
|
+
<%= text_field_tag :query, nil,class: 'form-control', placeholder: "Search for someone", id: 'search-field' %>
|
139
|
+
</div>
|
140
|
+
<% end %>
|
141
|
+
```
|
142
|
+
which renders down to
|
143
|
+
```html
|
144
|
+
<form accept-charset="UTF-8" action="/contacts" class="navbar-form navbar-left contacts_search contacts_search_active" data-remote="true" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓"></div>
|
145
|
+
<div class="form-group">
|
146
|
+
<input class="form-control" id="search-field" name="query" placeholder="Search for someone" type="text">
|
147
|
+
</div>
|
148
|
+
</form>
|
149
|
+
```
|
150
|
+
The service will detect the element on the page with the matching class to the ```serviceName:``` and apply the behavior to those elements.
|
151
|
+
|
152
|
+
```coffee
|
153
|
+
class Application.Services.ContactsSearch extends Transponder.Service
|
154
|
+
serviceName: 'contacts_search'
|
155
|
+
module: 'application'
|
156
|
+
|
157
|
+
init: ->
|
158
|
+
@element.on 'keyup', "#search-field", @submitSearch
|
159
|
+
|
160
|
+
search: _.debounce ( (e) ->
|
161
|
+
field = @element.find('#search-field')
|
162
|
+
$.ajax
|
163
|
+
url: @element.prop('action')
|
164
|
+
dataType: 'script'
|
165
|
+
data:
|
166
|
+
query: field.val()
|
167
|
+
), 600
|
168
|
+
|
169
|
+
submitSearch: (field) =>
|
170
|
+
@search(field)
|
171
|
+
|
172
|
+
serve: ->
|
173
|
+
@init()
|
174
|
+
```
|
175
|
+
|
101
176
|
## Example App
|
102
177
|
|
103
|
-
|
178
|
+
The code above is taken from the example app [Kontax](http://kontax.herokuapp.com)
|
179
|
+
|
180
|
+
You can review the Kontax app for a full picture of how all the pieces fit together.
|
181
|
+
|
104
182
|
+ [kontax on heroku](http://kontax.herokuapp.com)
|
105
183
|
+ [kontax on github](http://github.com/xpdr/kontax)
|
106
184
|
|
@@ -13,7 +13,7 @@ module Transponder
|
|
13
13
|
|
14
14
|
def xms_error_hash(object, message, action, module_name)
|
15
15
|
{
|
16
|
-
errors: (message || object.errors ),
|
16
|
+
errors: (message || xms_error_partial || object.errors ),
|
17
17
|
controller: controller_name,
|
18
18
|
action: (action || action_name),
|
19
19
|
model_name: object.class.name.downcase,
|
@@ -22,6 +22,14 @@ module Transponder
|
|
22
22
|
}
|
23
23
|
end
|
24
24
|
|
25
|
+
def xms_error_partial(module_name: nil, action: nil, controller: nil)
|
26
|
+
render_to_string [(module_name || xms_module_name),
|
27
|
+
(controller || controller_name), 'errors',
|
28
|
+
(action || action_name)].join('/'), layout: false
|
29
|
+
rescue ActionView::MissingTemplate
|
30
|
+
nil
|
31
|
+
end
|
32
|
+
|
25
33
|
def xms_error object, message: nil, action: nil, module_name: nil
|
26
34
|
render json: xms_error_hash(object, message, action, module_name),
|
27
35
|
status: :unprocessable_entity
|
data/lib/transponder/version.rb
CHANGED
@@ -24,12 +24,12 @@ describe Transponder::Generators::PresenterGenerator do
|
|
24
24
|
|
25
25
|
describe "comments_presenter.coffee" do
|
26
26
|
it { should exist }
|
27
|
-
it { should contain /Application.Presenters.
|
27
|
+
it { should contain /Application.Presenters.CommentsPresenter/ }
|
28
28
|
end
|
29
29
|
|
30
30
|
describe "initializers/boot.coffee" do
|
31
31
|
subject { file('app/assets/javascripts/application/initializers/boot.coffee') }
|
32
|
-
it { should contain /Application.Presenters.
|
32
|
+
it { should contain /Application.Presenters.CommentsPresenter()/ }
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: transponder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zack Siri
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: coffee-rails
|
@@ -95,7 +95,7 @@ files:
|
|
95
95
|
- spec/javascripts/transponder/presenters/examples_presenter_test.coffee
|
96
96
|
- spec/javascripts/transponder/services/calculate_test.coffee
|
97
97
|
- spec/spec_helper.rb
|
98
|
-
homepage: http://github.
|
98
|
+
homepage: http://xpdr.github.io/transponder
|
99
99
|
licenses:
|
100
100
|
- MIT
|
101
101
|
metadata: {}
|