ng_on_rails 0.0.1.1 → 0.0.1.2
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 +51 -8
- data/app/helpers/ng_on_rails_helper.rb +4 -1
- data/lib/ng_on_rails/engine.rb +3 -0
- data/lib/ng_on_rails/version.rb +1 -1
- metadata +30 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf5e98c33661afb66786a5d04b5527ed082db98e
|
4
|
+
data.tar.gz: 77df1507938c1ccf493367b57a667fe285565d95
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7897c440eceb597afc38d6f698d818595bc24c1cf2169e62acfc898b56688e2842377f305256a11c8761729598a330b2bdb9b84cfad53023a1e8e7d9bc5bb7e9
|
7
|
+
data.tar.gz: 0c2bba831949cd6c300dfd0c352a36aa86cfcd60aaab2448751a0a0143b1b5c122cd3c617dd9feb8cd5e3c7dee74ee8d47bb37d6aa4528505b0461655125ec80
|
data/README.md
CHANGED
@@ -13,9 +13,39 @@ I am just getting started but this does function *as-is*. Some things left to d
|
|
13
13
|
* Create generators for controllers/services/(views?)
|
14
14
|
* (ViewHelper functions via shared service?)
|
15
15
|
|
16
|
-
Install it!
|
16
|
+
### Install it!
|
17
17
|
```
|
18
|
+
# Gemfile
|
18
19
|
gem 'ng_on_rails'
|
20
|
+
|
21
|
+
# your_app/app/assets/javascripts/application.js
|
22
|
+
//
|
23
|
+
//= require angular
|
24
|
+
//= require angular-resource
|
25
|
+
//= require angular-animate
|
26
|
+
//= require angular-sanitize
|
27
|
+
//= require ng_on_rails
|
28
|
+
//= require_tree .
|
29
|
+
```
|
30
|
+
|
31
|
+
Note: NgOnRailsApp is automatically created if it doesn't already exsit
|
32
|
+
```javascript
|
33
|
+
# app/assets/javascripts/app.js
|
34
|
+
if (!window.NgOnRailsApp){
|
35
|
+
window.NgOnRailsApp = angular.module("NgOnRailsApp", ["ngResource","ngAnimate","ngSanitize"])
|
36
|
+
}
|
37
|
+
```
|
38
|
+
If you want to overide NgOnRailsApp - so you can inject your own providers
|
39
|
+
Just incldue a app.js file that defines NgOnRailsApp in your own app and load it **before** ng\_on\_rails
|
40
|
+
```javascript
|
41
|
+
# your_app/app/assets/javascripts/angular_app/app.js
|
42
|
+
window.NgOnRailsApp = angular.module("NgOnRailsApp", ["ngResource","ngAnimate","ngSanitize","angular-sortable-view"])
|
43
|
+
|
44
|
+
# your_app/app/assets/javascripts/application.js
|
45
|
+
//= require ...
|
46
|
+
//= require angular_app/app.js
|
47
|
+
//= require ng_on_rails
|
48
|
+
//= require tree.
|
19
49
|
```
|
20
50
|
|
21
51
|
I would love feed back (especially on convention choices) and possibly other contributers. Send me a note!
|
@@ -26,7 +56,7 @@ As time goes on generators for angular controllers and services (rails-models) w
|
|
26
56
|
|
27
57
|
It relies on two pieces of slight magic
|
28
58
|
|
29
|
-
|
59
|
+
* a "Rails" service that holds all your rails variables. This service automatically turns rails instance variables into json that can be used by Angular. For example the rails instance variable `@pages` will get mapped to `Rails.pages` that can be used by angular
|
30
60
|
```
|
31
61
|
<div ng-repeat="page in Rails.pages">...
|
32
62
|
```
|
@@ -37,7 +67,8 @@ To get this work you simply need to load the rails_service.js.erb partial
|
|
37
67
|
</script>
|
38
68
|
```
|
39
69
|
"rails_service.js.erb" calls the `locals_to_json` helper method to automatically turn instance variables into json. Here `ng_data` is a local rails variable used to customize how this is converted. This will be discussed in detail [below](#locals_to_json).
|
40
|
-
|
70
|
+
|
71
|
+
* Your angular views(partials) should be placed in app/views/angular_app. This solution is discussed in a handfull of places including [here](http://stackoverflow.com/questions/12116476/rails-static-html-template-files-in-the-asset-pipeline-and-caching-in-developmen), but the key parts are:
|
41
72
|
```ruby
|
42
73
|
# routes.rb
|
43
74
|
scope :angular_app do
|
@@ -69,6 +100,8 @@ to load your angualar views in at 'app/views/angular_app'
|
|
69
100
|
|
70
101
|
#### Conventions
|
71
102
|
|
103
|
+
The test_app serves as an example of the conventions discussed below, but before looking it over read [this](#test_app).
|
104
|
+
|
72
105
|
* Put Angular controllers/directives/... in a folder "angular\_app" in the assets directory. Similarly, as discussed above, the angular views(partials) are placed in a folder "angular\_app" in the views directory
|
73
106
|
```
|
74
107
|
|-- app/
|
@@ -109,7 +142,7 @@ You are going to have a service for each rails model. I plan on adding generato
|
|
109
142
|
```coffeescript
|
110
143
|
# app/assets/javascripts/angular_app/services/page.js.coffee
|
111
144
|
NgOnRailsApp.factory "Page", ($resource) ->
|
112
|
-
PageResource = $resource "/
|
145
|
+
PageResource = $resource "/questions/:id.json", {id: "@id"}, {
|
113
146
|
update:{method: "PUT"}
|
114
147
|
}
|
115
148
|
class Page extends PageResource
|
@@ -246,17 +279,27 @@ As mentioned using the Rails-service you can get access to all your rails variab
|
|
246
279
|
= render( partial: 'angular_app/rails_service', formats: ['js'], locals: { ng_data: ng_data} )
|
247
280
|
</script>
|
248
281
|
```
|
249
|
-
Here, ng_data is a local rails variable that
|
282
|
+
Here, ng_data is a local rails variable that describes how to create the json:
|
250
283
|
|
251
284
|
* if ng_data is nil all varibles will be converted with `.to_json` ( or if its a string/numeric with .to_s )
|
252
285
|
* if `ng_data['BUILD'].blank?` the default will be to use `.to_json` for conversion.
|
253
286
|
* if `ng_data['BUILD']=true` the default will be to look for a `.json` file in the app/views directory. It will guess the name and path to this file using the name of var. For instance, if we have @page it will look for the the file app/views/pages/page.json.
|
254
|
-
* if `ng_data[var_name].blank?` the conversion will use the
|
255
|
-
* if `ng_data[var_name]={ path: 'path/to/file', as: model_name } it will use this info to try and find the build file. For instance, suppose I have a collection of pages called `@admin_pages`. Then `ng_data['admin_pages'] = { path: "
|
287
|
+
* if `ng_data[var_name].blank?` the conversion will use the default discussed above
|
288
|
+
* if `ng_data[var_name]={ path: 'path/to/file', as: model_name } it will use this info to try and find the build file. For instance, suppose I have a collection of pages called `@admin_pages`. Then `ng_data['admin_pages'] = { path: "pages/pages", as: :pages }` will look for the file app/views/pages/pages.json seting the local variable `pages = @admin_pages`.
|
256
289
|
|
257
290
|
To understand it better look at [ng_on_rails_helper.rb](https://github.com/brookisme/ng_on_rails/blob/master/app/helpers/ng_on_rails_helper.rb).
|
258
291
|
|
259
|
-
|
292
|
+
<a name="test_app"></a>
|
293
|
+
#### Test App
|
294
|
+
The [test_app](https://github.com/brookisme/ng_on_rails/blob/master/app/spec/test_app) can be used as an example application. A some details to mention:
|
295
|
+
|
296
|
+
* The DB is Postgres
|
297
|
+
* The (Angular) Views use Slim
|
298
|
+
* The JS uses CoffeeScript (except for _rails_service.js.erb -- where I need access to Rails)
|
299
|
+
* Much of app/views/angular_app & app/assests/javascripts/angular_app has been cut and pasted in from a different project and the models have been generated with Rails scaffolding. This leads to a few oddities:
|
300
|
+
* There is a mixture of both erb and slim
|
301
|
+
* The full scaffolding has been left in but the Angular views are contained solely withing the docs-index and doc-show pages.
|
302
|
+
* Though there is limited CSS but I use both bootstrap and font-awesome
|
260
303
|
|
261
304
|
|
262
305
|
|
@@ -2,6 +2,8 @@ module NgOnRailsHelper
|
|
2
2
|
def locals_to_json ng_data
|
3
3
|
j = ActiveSupport::JSON
|
4
4
|
locals_hash = {}
|
5
|
+
puts "***********"
|
6
|
+
puts "#{instance_variable_names}"
|
5
7
|
instance_variable_names.each do |var_name|
|
6
8
|
unless !!var_name.match(/^@_/)
|
7
9
|
unless ignorables.include? var_name
|
@@ -58,7 +60,8 @@ private
|
|
58
60
|
"@controller",
|
59
61
|
"@request",
|
60
62
|
"@output_buffer",
|
61
|
-
"@rendered"
|
63
|
+
"@rendered",
|
64
|
+
"@marked_for_same_origin_verification"
|
62
65
|
]
|
63
66
|
end
|
64
67
|
|
data/lib/ng_on_rails/engine.rb
CHANGED
data/lib/ng_on_rails/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ng_on_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1.
|
4
|
+
version: 0.0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brookie Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: angularjs-rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.2.22
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.2.22
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: angular_rails_csrf
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.0.2
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.0.2
|
13
41
|
- !ruby/object:Gem::Dependency
|
14
42
|
name: rails
|
15
43
|
requirement: !ruby/object:Gem::Requirement
|