styx 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.md +46 -17
  2. data/lib/styx/helpers.rb +14 -6
  3. data/styx.gemspec +1 -1
  4. metadata +2 -2
data/README.md CHANGED
@@ -1,18 +1,24 @@
1
1
  Styx
2
2
  ========
3
3
 
4
- Bridge between Server (Rails) side and Client (JS) side divided into several modules:
4
+ Bridge between Server (Rails) side and Client (JS) side which is divided into several modules:
5
5
 
6
6
  * **Helpers**: set of helpers to support all other modules.
7
7
  * **Initializer**: organizes JS into bootstrap classes and allows you to pass data from controller/view.
8
- * **Forms**: remote validaton engine.
8
+ * **Forms**: remote validation engine.
9
9
 
10
10
 
11
11
  Installation
12
12
  ------------
13
13
 
14
- $ gem install styx
14
+ In your Gemfile, add this line:
15
15
 
16
+ gem 'styx'
17
+
18
+ In your assets application.js include appropriate libs:
19
+
20
+ //= require styx <- Helpers and Initializers
21
+ //= require styx.forms <- Forms
16
22
 
17
23
  Basic Usage
18
24
  ------------
@@ -32,10 +38,10 @@ Initializer
32
38
  ------------
33
39
 
34
40
  In common each controller in Rails comes with *app/assets/javascripts/controller_name.js.coffee*.
35
- Styx.Initializer allows you to separately define bootstrap logic for each Rails action and pass
36
- some data from server right in.
41
+ **Styx.Initializer** allows you to define bootstrap logic for each Rails action separately and
42
+ pass some data from server right into it.
37
43
 
38
- To enable initializers bootstrap, add *styx_initialize* line to your layout:
44
+ To enable initializers bootstrap, add *styx_initialize* call into your layout:
39
45
 
40
46
  ```erb
41
47
  <head>
@@ -87,7 +93,7 @@ Forms
87
93
  Forms assist *form_for @foo, :remote => true* to automate server response and UJS callbacks.
88
94
 
89
95
  If everything went smooth you can respond with URL for redirect or with JSON for your callback.
90
- If validation failed appropriate form fields will be wraped with native
96
+ If validation failed appropriate form fields will be wrapped in a native way:
91
97
 
92
98
  <div class="field_with_errors">
93
99
 
@@ -112,14 +118,14 @@ error_callback = function() {} // Form wasn't validated
112
118
  Forms.attach('#foo_form', success_callback, error_callback)
113
119
  ```
114
120
 
115
- Note that if success_callback was not given but server responded with some data, Styx.Forms will try
121
+ Note that if success_callback was not given but server responded with some data, **Styx.Forms** will try
116
122
  to evaluate it as URL and will try to redirect to it.
117
123
 
118
- Javascript part goes best with Styx.Initializers.
124
+ Javascript part goes best with **Styx.Initializers**.
119
125
 
120
126
  ### Server side
121
127
 
122
- In common you just want to store your form as model. Styx.Forms come with predefined helper for this:
128
+ In common you just want to store your form as a model. **Styx.Forms** come with a predefined helper for this:
123
129
 
124
130
  ```ruby
125
131
  # app/controllers/foos_controller.rb
@@ -133,18 +139,18 @@ def create
133
139
  end
134
140
  ```
135
141
 
136
- *response* parameter can either be passed as lambda{|x|}.
142
+ *response* parameter can also be passed as lambda{|x|}.
137
143
 
138
- ### What if form was invalid?
144
+ ### What if the form was invalid?
139
145
 
140
- First of all, *success_callback* and server-side block won't be called. *response* won't be return to JS.
141
- Validation errors for @entity will be returned instead. All invalid form fields will be wraped with
146
+ First of all, *success_callback* and server-side block wouldn't be called. *response* wouldn't be return to JS.
147
+ Instead validation errors for @entity will be returned. All invalid form fields will be wrapped with
142
148
 
143
149
  <div class="field_with_errors">
144
150
 
145
151
  ### Server side without models
146
152
 
147
- To work without models (i.e. to serve login form) you can use two helpers
153
+ You can use two helpers to work without models (i.e. to serve login form):
148
154
 
149
155
  ```ruby
150
156
  styx_form_respond_success(data)
@@ -154,5 +160,28 @@ To work without models (i.e. to serve login form) you can use two helpers
154
160
  styx_form_respond_failure(entity_name, fields) # fields = {'field_name' => 'error message'}
155
161
  ```
156
162
 
157
- To choose which fields have to be marked as invalid JS part will concatenate entity_name + field _name. So if
158
- you don't have entity, simply pass empty string as the first arg.
163
+ JS part will concatenate *entity_name* + *field_name* to locate which fields have to be marked as invalid.
164
+ So if you don't have entity, simply pass empty string as the first arg.
165
+
166
+ License
167
+ -------
168
+
169
+ Copyright (C) 2011 by Boris Staal <boris@roundlake.ru>
170
+
171
+ Permission is hereby granted, free of charge, to any person obtaining a copy
172
+ of this software and associated documentation files (the "Software"), to deal
173
+ in the Software without restriction, including without limitation the rights
174
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
175
+ copies of the Software, and to permit persons to whom the Software is
176
+ furnished to do so, subject to the following conditions:
177
+
178
+ The above copyright notice and this permission notice shall be included in
179
+ all copies or substantial portions of the Software.
180
+
181
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
182
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
183
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
184
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
185
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
186
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
187
+ THE SOFTWARE.
@@ -9,15 +9,23 @@ module Styx
9
9
 
10
10
  module InstanceMethods
11
11
  def this_page?(mask)
12
- mask = mask.split('#')
12
+ mask = [mask] unless mask.is_a?(Array)
13
13
 
14
- c = mask[0]
15
- a = mask[1]
14
+ flag = false
16
15
 
17
- flag = true
16
+ mask.each do |m|
17
+ m = m.to_s.split('#')
18
18
 
19
- flag = false if !c.blank? && c != controller_path
20
- flag = false if !a.blank? && a != action_name
19
+ c = m[0]
20
+ a = m[1]
21
+
22
+ f = true
23
+
24
+ f = false if !c.blank? && c != controller_name
25
+ f = false if !a.blank? && a != action_name
26
+
27
+ flag ||= f
28
+ end
21
29
 
22
30
  flag
23
31
  end
@@ -1,6 +1,6 @@
1
1
  SPEC = Gem::Specification.new do |s|
2
2
  s.name = "styx"
3
- s.version = "0.0.1"
3
+ s.version = "0.0.2"
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.summary = "Set of helpers to maintain bridge between Server (Rails) side and Client (JS) side"
6
6
  s.email = "boris@roundlake.ru"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: styx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-22 00:00:00.000000000 Z
12
+ date: 2011-12-02 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Set of helpers to maintain bridge between Server (Rails) side and Client
15
15
  (JS) side