angular-rails 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +18 -7
- data/lib/angular-rails/version.rb +1 -1
- data/lib/generators/angular/install/install_generator.rb +7 -3
- data/lib/generators/angular/resource_helpers.rb +4 -0
- data/test/dummy/log/test.log +1 -0
- data/test/dummy/tmp/cache/assets/D21/570/sprockets%2Fc943c801ce0caac77ad24200450912ae +0 -0
- data/test/generators/controller_generator_test.rb +1 -2
- data/test/generators/install_generator_test.rb +8 -1
- metadata +6 -6
data/README.md
CHANGED
@@ -6,17 +6,19 @@ This project lets you use angularjs with the yummy Rails 3.1 asset pipeline. Th
|
|
6
6
|
|
7
7
|
This README (and some of the accompanying code) is being copied/pasted/ripped from the [backbone-rails](http://github.com/codebrew/backbone-rails) project to help bootstrap things. Later on I'll cut the cord.
|
8
8
|
|
9
|
-
##
|
9
|
+
## Assumptions
|
10
10
|
|
11
11
|
* Rails 3.1 - For the asset pipeline
|
12
|
-
* Coffeescript - Because
|
13
|
-
* Ruby 1.9.2 - Because I like the syntax enhancements (but if there's an outcry I can
|
12
|
+
* Coffeescript - Because less LOC means less bugs, plus it is the Rails Way, like it or not.
|
13
|
+
* Ruby 1.9.2 - Because I like the syntax enhancements (but if there's an outcry I can support 1.8.7)
|
14
|
+
* RSpec - This is a loose requirement, but all specs generated will be, well rspec. Once we have end-to-end coverage, someone can add a patch for testunit (or mini*) support.
|
15
|
+
* RESTful controllers - another loose requirement, but it will help things be smoother for you. The goal is as little friction as possible between the front and back ends, without resorting to Node.js :).
|
14
16
|
|
15
17
|
### Installation
|
16
18
|
|
17
19
|
Add to your gemfile:
|
18
20
|
|
19
|
-
gem "rails
|
21
|
+
gem "angular-rails"
|
20
22
|
|
21
23
|
And bundle away. To bootstrap things then type:
|
22
24
|
|
@@ -45,7 +47,7 @@ This file is empty except for the class declaration, but I will be adding some R
|
|
45
47
|
|
46
48
|
## Angular-Helpers
|
47
49
|
|
48
|
-
In an attempt to DRY up angular apps I added an angular-helpers coffeescript file to the assets path. So far
|
50
|
+
In an attempt to DRY up angular apps I added an angular-helpers coffeescript file to the assets path. So far it has a Router superclass for your main application router. If you subclass it in Coffeescript like so:
|
49
51
|
|
50
52
|
class @PhotoGalleryCtrl extends Router
|
51
53
|
routes:->
|
@@ -62,11 +64,20 @@ In an attempt to DRY up angular apps I added an angular-helpers coffeescript fil
|
|
62
64
|
controller: PhotosCtrl
|
63
65
|
}
|
64
66
|
|
65
|
-
You will have those routes set up.
|
67
|
+
You will have those routes set up. All this class needs is a member function called `routes` that returns a hash of routing information.
|
68
|
+
|
69
|
+
Note that this class will need to be injected with both the $xhr and the $route object like so:
|
66
70
|
|
67
71
|
PhotoGalleryCtrl.$inject = ['$route', '$xhr']
|
68
72
|
|
69
|
-
This is
|
73
|
+
This is because it sets us sowe CSRF preventions using $xhr as well. All this is pretty much ripped from a demo by [Daniel Nelson](https://github.com/centresource/angularjs_rails_demo).
|
74
|
+
|
75
|
+
Another thing added is a `resourceService` function. This function is called like:
|
76
|
+
|
77
|
+
resourceService 'Photos', 'photographers/:photographer_id/galleries/:gallery_id/photos', 'index'
|
78
|
+
resourceService 'SelectedPhotos', 'selected_photos/:selected_photo_id'
|
79
|
+
|
80
|
+
This sets up angular services for at the listed paths. Also add to the end all the actions that you want it to support. So far the accepted actions are 'index', 'update', 'create' and 'destroy'. If you leave off all actions, it will automatically assume that you want to support all 4.
|
70
81
|
|
71
82
|
## Example Usage
|
72
83
|
|
@@ -20,11 +20,15 @@ module Angular
|
|
20
20
|
|
21
21
|
def create_dir_layout
|
22
22
|
%W{controllers filters services widgets}.each do |dir|
|
23
|
-
empty_directory "
|
24
|
-
create_file "
|
23
|
+
empty_directory "#{angular_path}/#{dir}"
|
24
|
+
create_file "#{angular_path}/#{dir}/.gitkeep" unless options[:skip_git]
|
25
25
|
end
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
|
+
def create_spec_dir_layout
|
29
|
+
empty_directory angular_spec_path
|
30
|
+
create_file "#{angular_spec_path}/.gitkeep" unless options[:skip_git]
|
31
|
+
end
|
28
32
|
end
|
29
33
|
end
|
30
34
|
end
|
data/test/dummy/log/test.log
CHANGED
Binary file
|
@@ -6,9 +6,8 @@ class ControllerGeneratorTest < Rails::Generators::TestCase
|
|
6
6
|
include GeneratorsTestHelper
|
7
7
|
tests Angular::Generators::ControllerGenerator
|
8
8
|
|
9
|
-
test "simple
|
9
|
+
test "simple controller" do
|
10
10
|
run_generator %w(Post)
|
11
|
-
puts angular_path
|
12
11
|
assert_file "#{angular_path}/controllers/posts.coffee" do |controller|
|
13
12
|
controller_class = Regexp.escape("class @PostsController")
|
14
13
|
assert_match /#{controller_class}/, controller
|
@@ -23,14 +23,21 @@ class InstallGeneratorTest < Rails::Generators::TestCase
|
|
23
23
|
assert_file "#{angular_path}/#{dir}/.gitkeep"
|
24
24
|
end
|
25
25
|
end
|
26
|
+
|
27
|
+
test "Assert angular spec directory structure is created" do
|
28
|
+
run_generator
|
29
|
+
assert_directory "#{angular_spec_path}"
|
30
|
+
assert_file "#{angular_spec_path}/.gitkeep"
|
31
|
+
end
|
26
32
|
|
33
|
+
|
27
34
|
test "Assert no gitkeep files are created when skipping git" do
|
28
35
|
run_generator [destination_root, "--skip-git"]
|
29
36
|
|
30
37
|
%W{controllers filters services widgets}.each do |dir|
|
31
|
-
assert_directory "#{angular_path}/#{dir}"
|
32
38
|
assert_no_file "#{angular_path}/#{dir}/.gitkeep"
|
33
39
|
end
|
40
|
+
assert_no_file "#{angular_spec_path}/.gitkeep"
|
34
41
|
end
|
35
42
|
|
36
43
|
test "Assert application.js require angular.js and angular directory" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: angular-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-11-
|
12
|
+
date: 2011-11-28 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
16
|
-
requirement: &
|
16
|
+
requirement: &2998070 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 3.1.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2998070
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: coffee-script
|
27
|
-
requirement: &
|
27
|
+
requirement: &2997820 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: 2.2.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2997820
|
36
36
|
description: Helpers for angularjs in a rails project (ripped from backbone-rails)
|
37
37
|
email:
|
38
38
|
- nate@ludicast.com
|