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 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
- ## Requirements
9
+ ## Assumptions
10
10
 
11
11
  * Rails 3.1 - For the asset pipeline
12
- * Coffeescript - Because more LOC means more bugs
13
- * Ruby 1.9.2 - Because I like the syntax enhancements (but if there's an outcry I can maybe support 1.8.7)
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-angular"
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 all it has is a Router class that sets up some defaults. If you subclass it in Coffeescript like so:
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. Note that this class will need to be injected with both the $xhr and the $route object like so:
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 pretty much an adaption of the routing code at a demo by [Daniel Nelson](https://github.com/centresource/angularjs_rails_demo).
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
 
@@ -1,3 +1,3 @@
1
1
  module AngularRails
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -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 "app/assets/javascripts/angular/#{dir}"
24
- create_file "app/assets/javascripts/angular/#{dir}/.gitkeep" unless options[:skip_git]
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
@@ -12,6 +12,10 @@ module Angular
12
12
  def angular_path
13
13
  "app/assets/javascripts/angular"
14
14
  end
15
+
16
+ def angular_spec_path
17
+ "spec/javascripts/angular"
18
+ end
15
19
  end
16
20
  end
17
21
  end
@@ -7,3 +7,4 @@ Compiled angular-helpers (174ms) (pid 46674)
7
7
  Compiled angular.min (2ms) (pid 46699)
8
8
  Compiled angular-helpers (589ms) (pid 50164)
9
9
  Compiled angular.min (7ms) (pid 50164)
10
+ Compiled angular-helpers (184ms) (pid 56225)
@@ -6,9 +6,8 @@ class ControllerGeneratorTest < Rails::Generators::TestCase
6
6
  include GeneratorsTestHelper
7
7
  tests Angular::Generators::ControllerGenerator
8
8
 
9
- test "simple model" do
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.5
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-23 00:00:00.000000000Z
12
+ date: 2011-11-28 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &2986850 !ruby/object:Gem::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: *2986850
24
+ version_requirements: *2998070
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: coffee-script
27
- requirement: &2986600 !ruby/object:Gem::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: *2986600
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