oxymoron 1.0.6 → 1.0.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 15e5bb8616cbe619a7882f56676964ee6cbb8152
4
- data.tar.gz: e397b26b8484342b3c12be317a3c0753d19a8a78
3
+ metadata.gz: a501cb321c5f88c00919bf2d430b892db77d5210
4
+ data.tar.gz: 43e60ce4f5a9217672155d15046134cb7d8f53ff
5
5
  SHA512:
6
- metadata.gz: dae32170556468155fc670b6cef06b333c4bfe8e073381c81654825dfe7ffd0de160466ec5c2521462787697029728393a4cf66af0cc1bfcf3a2078a574b9696
7
- data.tar.gz: c80cfa564daa7a0e3716ff231b3419b14bfec914d9ea5013352c95bd5c069e08d8b4f2a946477c22c655d22fb0946f2f0ba9b0067e8a0a1ac20ee04959bef6ac
6
+ metadata.gz: 74b1cb5f30f5ccfae633998c1223838d7614ceab09cafa4171c23df0c129a2e414f71e058e030ce9c121faa12a648e1ac4493eb3f9b411a0b98ffc629253b56c
7
+ data.tar.gz: e51323b78e8a8f7992795f9a89388dcdc25bd8abd45f4bf1b3e75244c21abfaef584d47baadf0bc0ae73013a5316202b3edc6ae49c914bce71b816a2061e7a57
data/README.md CHANGED
@@ -1,339 +1,12 @@
1
1
  # Oxymoron
2
-
3
- [Example application](https://github.com/storuky/oxymoron_app)
4
-
5
- [Basic forum based on Oxymoron](https://github.com/storuky/forum)
6
- ##Setup
7
-
8
- Add it to your Gemfile:
9
-
10
2
  ```
11
3
  gem 'oxymoron'
12
4
  ```
13
5
 
14
- ## Basic settings (Asset Pipeline)
15
-
16
- Add dependencies to your application.js and application.css
17
-
18
- **application.js**
19
- ```
20
- /*
21
- = require oxymoron/angular
22
- = require oxymoron/angular-resource
23
- = require oxymoron/angular-cookies
24
- = require oxymoron/angular-ui-router
25
- = require oxymoron/ng-notify
26
- = require oxymoron
27
- */
28
- ```
29
-
30
- **application.css**
31
- ```
32
- /*
33
- *= require oxymoron/ng-notify
34
- */
35
- ```
36
-
37
- ## Advanced settings
38
-
39
-
40
- **config/initializers/oxymoron.rb**
41
- ```
42
- Oxymoron::Config.setup do |c|
43
- # change path for generated oxymoron.js
44
- c.oxymoron_js_path = Rails.root.join('app', 'assets', 'javascripts', 'public')
45
-
46
- # Change form builder. By default used OxymoronFormBuilder
47
- c.form_builder = MyFormBuilder
48
-
49
- # Disabled rewrite form_for method in ActionView::FormHelper. In this case use helpers oxymoron_form_for and oxymoron_field_for
50
- c.rewrite_form_for = false
51
- end
52
- ```
53
-
54
- ##Usage
55
-
56
- Next, you need to inject required modules 'oxymoron' and 'ui.router'
57
-
58
- **application.js**
59
- ```
60
- angular.module('app', ['ui.router', 'oxymoron'])
61
- ```
62
-
63
- Create file routes.js, which will contain the application SPA-routings. Method $stateProvider.rails() transform routes.rb to Angular UI Router states.
64
-
65
- **routes.js**
66
- ```
67
- angular.module('app')
68
- .config(['$stateProvider', function ($stateProvider) {
69
- $stateProvider.rails()
70
- }])
71
- ```
72
-
73
- Disable layouts for all ajax query:
74
-
75
- **app/controllers/application_controller.rb**
76
- ```
77
- class ApplicationController < ActionController::Base
78
- layout proc {
79
- if request.xhr?
80
- false
81
- else
82
- index
83
- 'application' # or other layout
84
- end
85
- }
86
-
87
- private
88
- def index
89
- # In the production mode write this string into initializers/oxymoron.rb
90
- ActionView::Base.default_form_builder = OxymoronBuilder
91
- end
92
- end
93
- ```
94
-
95
- Edit your layout with ui-view notation:
96
-
97
- **app/views/layouts/application**
98
- ```
99
- = yield
100
- ```
101
- to
102
- ```
103
- ui-view
104
- ```
105
- or for SEO-friendly
106
- ```
107
- ui-view
108
- div[ng-non-bindable]
109
- = yield
110
- ```
111
-
112
-
113
- All controllers methods must be wrapped with respond_to
114
-
115
- **Example:**
116
- ```
117
- class PostsController < ActiveRecord::Base
118
- before_action :set_post, only: [:show, :update, :destroy]
6
+ [Read the docs](http://storuky.github.io/oxymoron/)
119
7
 
120
- def index
121
- respond_to do |format|
122
- format.html
123
- format.json {
124
- @posts = Post.all
125
- render json: @posts
126
- }
127
- end
128
- end
129
-
130
- def show
131
- respond_to do |format|
132
- format.html
133
- format.json {
134
- render json: @post
135
- }
136
- end
137
- end
138
-
139
- def new
140
- end
141
-
142
- def edit
143
- end
144
-
145
- def create
146
- respond_to do |format|
147
- format.json {
148
- @post = Post.new post_params
149
- if @post.save
150
- render json: {post: @post, msg: "Post successfully created", redirect_to: "posts_path"}
151
- else
152
- render json: {errors: @post.errors, msg: @post.errors.full_messages.join(', ')}, status: 422
153
- end
154
- }
155
- end
156
- end
8
+ **Oxymoron** is a new approach to build the architecture of SPA-applications. This gem makes a strong connection between server and client side. It is a fully complete framework based on [AngularJS](https://angularjs.org/) and [Ruby on Rails](https://github.com/rails/rails).
157
9
 
158
- def update
159
- respond_to do |format|
160
- format.json {
161
- if @post.update(post_params)
162
- render json: {post: @post, msg: "Post successfully updated", redirect_to: "posts_path"}
163
- else
164
- render json: {errors: @post.errors, msg: @post.errors.full_messages.join(', ')}, status: 422
165
- end
166
- }
167
- end
168
- end
169
-
170
- def destroy
171
- respond_to do |format|
172
- format.json {
173
- @post.destroy
174
- render json: {msg: "Post successfully deleted"}
175
- }
176
- end
177
- end
178
-
179
- private
180
- def set_post
181
- @post = Post.find(params[:id])
182
- end
183
-
184
- def post_params
185
- params.require(:post).permit(:title, :description, :author)
186
- end
187
- end
188
- ```
189
-
190
- Oxymoron add some functionality for your AngularJS application. You can use *factory* whose name matches the name of your resources routes.rb. Do not forget to inject it, when it's required.
191
- In our case it is Post resource.
192
-
193
- ```
194
- Post.query() // => GET /posts.json
195
- Post.get({id: id}) // => GET /posts/:id.json
196
- Post.new() // => GET /posts/new.json
197
- Post.edit({id: id}) // => GET /posts/:id/edit.json
198
- Post.create({post: post}) // => POST /posts.json
199
- Post.update({id: id, post: post}) // => PUT /posts/:id.json
200
- Post.destroy({id: id}) // => DELETE /posts/:id.json
201
- ```
202
-
203
- Add AngularJS-controller "PostsCtrl"
204
-
205
- **Example:**
206
-
207
- ```
208
- angular.module('app')
209
- .controller('PostsCtrl', ['Post', 'action', function (Post, action) {
210
- var ctrl = this;
211
-
212
- // Called only on '/posts'
213
- action('index', function(){
214
- ctrl.posts = Post.query();
215
- });
216
-
217
- // Called only for '/posts/:id'
218
- action('show', function (params){
219
- ctrl.post = Post.get({id: params.id});
220
- });
221
-
222
- // Called only on '/posts/new'
223
- action('new', function(){
224
- ctrl.post = Post.new();
225
- ctrl.save = Post.create;
226
- });
227
-
228
- // Called only for '/posts/:id/edit'
229
- action('edit', function (params){
230
- ctrl.post = Post.edit({id: params.id});
231
- ctrl.save = Post.update;
232
- })
233
-
234
- // Called only for '/posts/:id/edit' or '/posts/new'
235
- action(['edit', 'new'], function(){
236
- //
237
- })
238
-
239
- // Called only for your custom resource method. For example: '/posts/some_method'
240
- action('some_method', function(){
241
- //
242
- })
243
-
244
- // etc
245
- }])
246
- ```
247
-
248
- ##Example Views
249
- **posts/index.html.slim**
250
-
251
- ```
252
- h1 Posts
253
-
254
- input type="text" ng-model="search"
255
-
256
- table
257
- thead
258
- tr
259
- th Date
260
- th Title
261
- th Author
262
- tbody
263
- tr ng-repeat="post in ctrl.posts | filter:search"
264
- td
265
- | {{post.created_at | date:"dd.MM.yyyy"}}
266
- td
267
- | {{post.title}}
268
- td
269
- | {{post.author}}
270
- ```
271
-
272
- **posts/show.html.slim**
273
- ```
274
- dl
275
- dl Date
276
- dd
277
- | {{ctrl.post.created_at | date:"dd.MM.yyyy"}}
278
- dl Title
279
- dd
280
- | {{ctrl.post.title}}
281
- dl author
282
- dd
283
- | {{ctrl.post.author}}
284
- ```
285
-
286
- **posts/new.html.slim**
287
- ```
288
- h1 New post
289
-
290
- = render 'form'
291
- ```
292
-
293
- **posts/edit.html.slim**
294
- ```
295
- h1 Edit post
296
-
297
- = render 'form'
298
- ```
299
-
300
- **posts/_form.html.slim**
301
- ```
302
- = form_for Post.new do |f|
303
- div
304
- = f.label :title
305
- = f.text_field :title
306
- div
307
- = f.label :description
308
- = f.text_area :description
309
-
310
- = f.submit "Save"
311
-
312
- ```
313
-
314
- Use *ui-sref* insted of link_to helper
315
- ```
316
- a ui-sref="posts_path" All posts
317
- a ui-sref="new_post_path" New post
318
- a ui-sref="edit_post_path({id: id})" Edit post
319
- a ui-sref="post_path({id: id})" Show
320
- ```
321
-
322
- ##Routes
323
- In window you can find *Routes* variable, which contains all routes of your app (such as JsRoutes).
324
-
325
- **Example**
326
- ```
327
- Routes.posts_path() //=> '/posts'
328
- Routes.post_path({id: 1}) //=> '/posts/1'
329
- Routes.post_path({id: 1, format: "json"}) //=> '/posts/1.json'
330
- Routes.posts_url() //=> 'http://localhost:3000/posts'
331
- ```
332
- If your expect that your controller method return an array, you must mark this routes with *is_array* property. If you do not, it throw an exception from angular.
333
- ```
334
- resources :posts do
335
- get 'my', is_array: true
336
- end
337
- ```
10
+ You can greatly accelerate the development of your applications with it. But not only that! The speed of your application will accelerate at times.
338
11
 
339
- Happy coding :)
12
+ This gem contains the Angular Resources and UI Router States which are **automatically generated** from the Rails routes (from routes.rb). It also includes all the necessary configs and the most useful services and directives.
@@ -48,7 +48,6 @@ angular.module("oxymoron.config.states", [])
48
48
 
49
49
  return Routes['<%= key %>_path'](params);
50
50
  },
51
- reloadOnSearch: true,
52
51
  controller: '<%= value[:controller]%>',
53
52
  resolve: {
54
53
  action: ['$stateParams', function ($stateParams) {
@@ -1,3 +1,3 @@
1
1
  module Oxymoron
2
- VERSION = "1.0.6"
2
+ VERSION = "1.0.7"
3
3
  end
data/lib/oxymoron.rb CHANGED
@@ -34,14 +34,16 @@ module Oxymoron
34
34
  def set_states route
35
35
  if route.verb.match("GET")
36
36
  path = route.path.spec.to_s.gsub('(.:format)', '')
37
- url_matcher = "'#{path}'"
37
+ ui_params = (route.defaults[:ui_params] || []).join("&")
38
+ ui_params = ui_params.present? ? "?#{ui_params}" : ""
39
+ url_matcher = "'#{path}#{ui_params}'"
38
40
 
39
41
  route.path.required_names.each do |required_name|
40
42
  if requirement = route.requirements[required_name.to_sym]
41
43
  if requirement.is_a? Regexp
42
44
  requirement = requirement.to_s[7..-2]
43
45
  end
44
- url_matcher = path.gsub(':'+required_name, "{#{required_name}:(?:#{requirement})}")
46
+ url_matcher = path.gsub(':'+required_name, "{#{required_name}:(?:#{requirement})}#{ui_params}")
45
47
  url_matcher = "$urlMatcherFactoryProvider.compile(\"#{url_matcher}\")"
46
48
  end
47
49
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oxymoron
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kononenko Paul
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-04 00:00:00.000000000 Z
11
+ date: 2016-09-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print