angular-rails 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,14 +1,10 @@
1
- # Warning -
1
+ # Project Goals
2
2
 
3
- This is still being built. Don't use yet :)
4
-
5
- # Warning Code-Theft
6
-
7
- This README (and some of the accompanying code) is being copied/ripped from the backbone-rails project to help bootstrap things. Later on I'll cut the cord.
3
+ Easily setup and use angularjs (0.9.19) with rails 3.1
8
4
 
9
- # Angular-Rails [![Build Status](https://secure.travis-ci.org/codebrew/angular-rails.png)](http://travis-ci.org/codebrew/angular-rails)
5
+ ## Warning!! Code-Theft :)
10
6
 
11
- Easily setup and use angularjs (0.9.19) with rails 3.1
7
+ This README (and some of the accompanying code) is being copied/pasted/ripped from the [http://github.com/codebrew/backbone-rails](backbone-rails) project to help bootstrap things. Later on I'll cut the cord.
12
8
 
13
9
  ## Rails 3.1 setup
14
10
  This gem requires the use of rails 3.1, coffeescript and the new rails asset pipeline provided by sprockets.
@@ -33,19 +29,13 @@ Running `rails g angular:install` will create the following directory structure
33
29
  controllers/
34
30
  filters/
35
31
  services/
36
- views/
37
32
  widgets/
38
-
39
-
40
- ## Generators
41
- angular-rails provides a simple generator to help get you started using angular.js with rails 3.1.
42
- The generators will only create client side code (javascript).
43
33
 
44
- ### Controller Generator
34
+ It will also add to the application.js file the appropriate requires.
45
35
 
46
- rails g angular:controller ModelName
47
-
48
- This generator creates an angular controller inside `app/assets/javascript/angular/controllers` to be used to talk to the rails backend.
36
+ ## Generators
37
+
38
+ angular-rails provides a simple generator to help get you started using angular.js with rails 3.1. The generators will only create client side code (javascript).
49
39
 
50
40
  ## Example Usage
51
41
 
@@ -55,20 +45,11 @@ Created a new rails 3.1 application called `blog`.
55
45
 
56
46
  Edit your Gemfile and add
57
47
 
58
- gem 'rails-angular'
48
+ gem 'angular-rails'
59
49
 
60
50
  Install the gem and generate scaffolding.
61
51
 
62
52
  bundle install
63
53
  rails g angular:install
64
- rails g scaffold Post title:string content:string
65
- rake db:migrate
66
- rails g angular:controller Post
67
-
68
- You now have installed the angular-rails gem, setup a default directory structure for your frontend angular code.
69
- Then you generated the usual rails server side crud scaffolding and finally generated angular.js code to provide a simple single page crud app.
70
- You have one last step:
71
-
72
- Now start your server `rails s` and browse to [localhost:3000/posts](http://localhost:3000/posts)
73
- You should now have a fully functioning single page crud app for Post models.
74
-
54
+
55
+ You now have installed the angular-rails gem, setup a default directory structure for your frontend angular code.
@@ -1,3 +1,3 @@
1
1
  module AngularRails
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -0,0 +1,33 @@
1
+ require 'generators/angular/resource_helpers'
2
+
3
+ puts "loaded install generator"
4
+
5
+ module Angular
6
+ module Generators
7
+ class InstallGenerator < Rails::Generators::Base
8
+ include Angular::Generators::ResourceHelpers
9
+
10
+ source_root File.expand_path("../templates", __FILE__)
11
+
12
+ desc "This generator installs angular.js with a default folder layout in app/assets/javascripts/angular"
13
+
14
+ class_option :skip_git, :type => :boolean, :aliases => "-G", :default => false,
15
+ :desc => "Skip Git ignores and keeps"
16
+
17
+ def inject_angular
18
+ inject_into_file "app/assets/javascripts/application.js", :before => "//= require_tree" do
19
+ "//= require angular\n//= require_tree ./angular\n"
20
+ end
21
+ end
22
+
23
+ def create_dir_layout
24
+ %W{controllers filters services widgets}.each do |dir|
25
+ empty_directory "app/assets/javascripts/angular/#{dir}"
26
+ create_file "app/assets/javascripts/angular/#{dir}/.gitkeep" unless options[:skip_git]
27
+ end
28
+ end
29
+
30
+ end
31
+ end
32
+ end
33
+
@@ -0,0 +1,17 @@
1
+ module Angular
2
+ module Generators
3
+ module ResourceHelpers
4
+ def application_name
5
+ if defined?(Rails) && Rails.application
6
+ Rails.application.class.name.split('::').first
7
+ else
8
+ "application"
9
+ end
10
+ end
11
+
12
+ def angular_path
13
+ "app/assets/javascripts/angular"
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1 +1,2 @@
1
1
  Compiled angular (1ms) (pid 26934)
2
+ Compiled angular (1ms) (pid 28741)
@@ -0,0 +1,3 @@
1
+ //= require jquery
2
+ //= require jquery_ujs
3
+ //= require_tree .
@@ -0,0 +1,11 @@
1
+ require 'generators/angular/resource_helpers'
2
+
3
+ module GeneratorsTestHelper
4
+ def self.included(base)
5
+ base.class_eval do
6
+ destination File.expand_path("../tmp", File.dirname(__FILE__))
7
+ setup :prepare_destination
8
+ end
9
+ end
10
+ include Angular::Generators::ResourceHelpers
11
+ end
@@ -0,0 +1,49 @@
1
+ require 'test_helper'
2
+ require 'generators/generators_test_helper'
3
+ require "generators/angular/install/install_generator"
4
+ require 'mocha'
5
+
6
+ class InstallGeneratorTest < Rails::Generators::TestCase
7
+ include GeneratorsTestHelper
8
+ tests Angular::Generators::InstallGenerator
9
+
10
+ def setup
11
+ mkdir_p "#{destination_root}/app/assets/javascripts"
12
+ cp fixture("application.js"), "#{destination_root}/app/assets/javascripts"
13
+ Rails.application.class.stubs(:name).returns("Dummy::Application")
14
+
15
+ super
16
+ end
17
+
18
+ test "Assert angular directory structure is created" do
19
+ run_generator
20
+
21
+ %W{controllers filters services widgets}.each do |dir|
22
+ assert_directory "#{angular_path}/#{dir}"
23
+ assert_file "#{angular_path}/#{dir}/.gitkeep"
24
+ end
25
+ end
26
+
27
+ test "Assert no gitkeep files are created when skipping git" do
28
+ run_generator [destination_root, "--skip-git"]
29
+
30
+ %W{controllers filters services widgets}.each do |dir|
31
+ assert_directory "#{angular_path}/#{dir}"
32
+ assert_no_file "#{angular_path}/#{dir}/.gitkeep"
33
+ end
34
+ end
35
+
36
+ test "Assert application.js require angular.js and angular directory" do
37
+ run_generator
38
+
39
+ assert_file "app/assets/javascripts/application.js" do |application|
40
+ assert_match /require angular(.*)require_tree \.\/angular/m, application
41
+ end
42
+ end
43
+
44
+ def fixture(file)
45
+ File.expand_path("fixtures/#{file}", File.dirname(__FILE__))
46
+ end
47
+
48
+ end
49
+
data/test/test_helper.rb CHANGED
@@ -8,3 +8,6 @@ Rails.backtrace_cleaner.remove_silencers!
8
8
 
9
9
  # Load support files
10
10
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
11
+
12
+ # For Generators
13
+ require 'rails/generators/test_case'
@@ -0,0 +1,5 @@
1
+ //= require jquery
2
+ //= require jquery_ujs
3
+ //= require angular
4
+ //= require_tree ./angular
5
+ //= require_tree .
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.2
4
+ version: 0.0.3
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-17 00:00:00.000000000Z
12
+ date: 2011-11-18 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &2935550 !ruby/object:Gem::Requirement
16
+ requirement: &2950290 !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: *2935550
24
+ version_requirements: *2950290
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: coffee-script
27
- requirement: &2935300 !ruby/object:Gem::Requirement
27
+ requirement: &2950040 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,18 +32,7 @@ dependencies:
32
32
  version: 2.2.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2935300
36
- - !ruby/object:Gem::Dependency
37
- name: mongoid
38
- requirement: &2935110 !ruby/object:Gem::Requirement
39
- none: false
40
- requirements:
41
- - - ! '>='
42
- - !ruby/object:Gem::Version
43
- version: '0'
44
- type: :development
45
- prerelease: false
46
- version_requirements: *2935110
35
+ version_requirements: *2950040
47
36
  description: Helpers for angularjs in a rails project (ripped from backbone-rails)
48
37
  email:
49
38
  - nate@ludicast.com
@@ -53,7 +42,8 @@ extra_rdoc_files: []
53
42
  files:
54
43
  - lib/angular-rails/version.rb
55
44
  - lib/angular-rails.rb
56
- - lib/tasks/angular-rails_tasks.rake
45
+ - lib/generators/angular/install/install_generator.rb
46
+ - lib/generators/angular/resource_helpers.rb
57
47
  - vendor/assets/javascripts/angular.js
58
48
  - MIT-LICENSE
59
49
  - Rakefile
@@ -91,8 +81,12 @@ files:
91
81
  - test/dummy/Rakefile
92
82
  - test/dummy/script/rails
93
83
  - test/dummy/tmp/cache/assets/D11/830/sprockets%2F376c8de111107498cc89fc305dac169a
94
- - test/integration/navigation_test.rb
84
+ - test/dummy/tmp/cache/assets/D3C/4A0/sprockets%2F55361a479acf3690d592c04adddfa507
85
+ - test/generators/fixtures/application.js
86
+ - test/generators/generators_test_helper.rb
87
+ - test/generators/install_generator_test.rb
95
88
  - test/test_helper.rb
89
+ - test/tmp/app/assets/javascripts/application.js
96
90
  homepage: http://github.com/ludicast/angular-rails
97
91
  licenses: []
98
92
  post_install_message:
@@ -151,5 +145,9 @@ test_files:
151
145
  - test/dummy/Rakefile
152
146
  - test/dummy/script/rails
153
147
  - test/dummy/tmp/cache/assets/D11/830/sprockets%2F376c8de111107498cc89fc305dac169a
154
- - test/integration/navigation_test.rb
148
+ - test/dummy/tmp/cache/assets/D3C/4A0/sprockets%2F55361a479acf3690d592c04adddfa507
149
+ - test/generators/fixtures/application.js
150
+ - test/generators/generators_test_helper.rb
151
+ - test/generators/install_generator_test.rb
155
152
  - test/test_helper.rb
153
+ - test/tmp/app/assets/javascripts/application.js
@@ -1,4 +0,0 @@
1
- # desc "Explaining what the task does"
2
- # task :angular-rails do
3
- # # Task goes here
4
- # end
@@ -1,10 +0,0 @@
1
- require 'test_helper'
2
-
3
- class NavigationTest < ActionDispatch::IntegrationTest
4
- fixtures :all
5
-
6
- # test "the truth" do
7
- # assert true
8
- # end
9
- end
10
-