transponder 0.9.6 → 0.10.1

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: 6feff04c3e1786bc152beb0e5750d59c2979bf45
4
- data.tar.gz: 992b7431c2c704371e50ff763047354b12293a97
3
+ metadata.gz: 69e800aadd79761edb7b30a93705f016fa497f3a
4
+ data.tar.gz: 5467cc1f66292a39995a430178e4cb2449903aad
5
5
  SHA512:
6
- metadata.gz: dd203125d52101183f4fcf6edac72fe46c40e64510be5a1fddbdbf2d9e8dba2e601282a305a2378bde6cbed06954a089197eb110beb55d96e120bbc76033504f
7
- data.tar.gz: 3ab315529d479230a206e4c9bce68b548fe059e5da9340f6b355e8b8edead1a8169188732518fb964b79a2cfe13496f7638a3dfba5a9c25626243c7d1aebf5fd
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
- Here is a link to a more typical example with a controller / presenter that is more fleshed out. [Presenters: Typical Example](https://github.com/xpdr/transponder/wiki/Presenters:-Typical-Example). The code in the link is the controller / presenter code for this app here
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
 
@@ -11,7 +11,7 @@ module Transponder
11
11
  end
12
12
 
13
13
  def presenter_class_name
14
- "#{options[:module_name].camelize}.Presenters.#{file_name.classify}Presenter"
14
+ "#{options[:module_name].camelize}.Presenters.#{file_name.camelize}Presenter"
15
15
  end
16
16
 
17
17
  def add_presenter_to_boot
@@ -12,7 +12,7 @@ module Transponder
12
12
 
13
13
 
14
14
  def service_class_name
15
- "#{options[:module_name].camelize}.Services.#{file_name.classify}"
15
+ "#{options[:module_name].camelize}.Services.#{file_name.camelize}"
16
16
  end
17
17
 
18
18
  def add_service_to_boot
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Transponder
2
- VERSION = "0.9.6"
2
+ VERSION = "0.10.1"
3
3
  end
@@ -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.CommentPresenter/ }
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.CommentPresenter()/ }
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.9.6
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-05 00:00:00.000000000 Z
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.com/artellectual/transponder
98
+ homepage: http://xpdr.github.io/transponder
99
99
  licenses:
100
100
  - MIT
101
101
  metadata: {}