angular-gem 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.md +36 -0
- data/Rakefile +39 -0
- data/lib/angular-gem.rb +6 -0
- data/lib/angular-gem/version.rb +3 -0
- data/lib/generators/angular/controller/controller_generator.rb +16 -0
- data/lib/generators/angular/controller/templates/controller.coffee +1 -0
- data/lib/generators/angular/install/install_generator.rb +40 -0
- data/lib/generators/angular/resource_helpers.rb +29 -0
- data/test/angular-gem_test.rb +12 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/javascripts/application.js +9 -0
- data/test/dummy/app/assets/stylesheets/application.css +7 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +45 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +30 -0
- data/test/dummy/config/environments/production.rb +60 -0
- data/test/dummy/config/environments/test.rb +39 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +10 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +4 -0
- data/test/dummy/log/test.log +3 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +26 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/dummy/tmp/cache/assets/CD5/C60/sprockets%2F4348b099c4aadda10262e757261e0f81 +0 -0
- data/test/dummy/tmp/cache/assets/CE3/300/sprockets%2Fc11999ba09d72e745355212e48bc72dd +0 -0
- data/test/dummy/tmp/cache/assets/CF7/120/sprockets%2Fd6adf41113c67a57c4a1330845ba0d08 +0 -0
- data/test/dummy/tmp/cache/assets/D71/060/sprockets%2Fc434a3f93ecb87049eb12e766005fede +0 -0
- data/test/dummy/tmp/cache/assets/D73/C00/sprockets%2Fa3620dc4bbd0562669b546e9c58eede4 +0 -0
- data/test/dummy/tmp/cache/assets/D79/F40/sprockets%2F9088cfe323d1b81dd526e6a9e3ed358c +0 -0
- data/test/dummy/tmp/cache/assets/D9E/830/sprockets%2Fbb7eb0f50f1afed5705594e9d812b8d0 +0 -0
- data/test/dummy/tmp/cache/assets/DD4/250/sprockets%2Feaa70f0d0954a5edffe77c9ca1e93860 +0 -0
- data/test/dummy/tmp/cache/assets/DF8/FD0/sprockets%2F87b01decd5c7fd3c6f174b8cba0d810f +0 -0
- data/test/generators/controller_generator_test.rb +29 -0
- data/test/generators/fixtures/application.js +3 -0
- data/test/generators/generators_test_helper.rb +11 -0
- data/test/generators/install_generator_test.rb +60 -0
- data/test/test_helper.rb +14 -0
- data/test/tmp/app/assets/javascripts/application.js +5 -0
- data/vendor/assets/javascripts/angular-ie-compat.js +35 -0
- data/vendor/assets/javascripts/angular-resource.js +472 -0
- data/vendor/assets/javascripts/angular-sanitize.js +556 -0
- data/vendor/assets/javascripts/angular.js +14882 -0
- metadata +213 -0
@@ -0,0 +1,39 @@
|
|
1
|
+
Dummy::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb
|
3
|
+
|
4
|
+
# The test environment is used exclusively to run your application's
|
5
|
+
# test suite. You never need to work with it otherwise. Remember that
|
6
|
+
# your test database is "scratch space" for the test suite and is wiped
|
7
|
+
# and recreated between test runs. Don't rely on the data there!
|
8
|
+
config.cache_classes = true
|
9
|
+
|
10
|
+
# Configure static asset server for tests with Cache-Control for performance
|
11
|
+
config.serve_static_assets = true
|
12
|
+
config.static_cache_control = "public, max-age=3600"
|
13
|
+
|
14
|
+
# Log error messages when you accidentally call methods on nil
|
15
|
+
config.whiny_nils = true
|
16
|
+
|
17
|
+
# Show full error reports and disable caching
|
18
|
+
config.consider_all_requests_local = true
|
19
|
+
config.action_controller.perform_caching = false
|
20
|
+
|
21
|
+
# Raise exceptions instead of rendering exception templates
|
22
|
+
config.action_dispatch.show_exceptions = false
|
23
|
+
|
24
|
+
# Disable request forgery protection in test environment
|
25
|
+
config.action_controller.allow_forgery_protection = false
|
26
|
+
|
27
|
+
# Tell Action Mailer not to deliver emails to the real world.
|
28
|
+
# The :test delivery method accumulates sent emails in the
|
29
|
+
# ActionMailer::Base.deliveries array.
|
30
|
+
#config.action_mailer.delivery_method = :test
|
31
|
+
|
32
|
+
# Use SQL instead of Active Record's schema dumper when creating the test database.
|
33
|
+
# This is necessary if your schema can't be completely dumped by the schema dumper,
|
34
|
+
# like if you have constraints or database-specific column types
|
35
|
+
# config.active_record.schema_format = :sql
|
36
|
+
|
37
|
+
# Print deprecation notices to the stderr
|
38
|
+
config.active_support.deprecation = :stderr
|
39
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
|
4
|
+
# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
|
5
|
+
|
6
|
+
# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
|
7
|
+
# Rails.backtrace_cleaner.remove_silencers!
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Add new inflection rules using the following format
|
4
|
+
# (all these examples are active by default):
|
5
|
+
# ActiveSupport::Inflector.inflections do |inflect|
|
6
|
+
# inflect.plural /^(ox)$/i, '\1en'
|
7
|
+
# inflect.singular /^(ox)en/i, '\1'
|
8
|
+
# inflect.irregular 'person', 'people'
|
9
|
+
# inflect.uncountable %w( fish sheep )
|
10
|
+
# end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Your secret key for verifying the integrity of signed cookies.
|
4
|
+
# If you change this key, all old signed cookies will become invalid!
|
5
|
+
# Make sure the secret is at least 30 characters and all random,
|
6
|
+
# no regular words or you'll be exposed to dictionary attacks.
|
7
|
+
Dummy::Application.config.secret_token = '867d0a104890885bc5b264492fbf0812f321b1da5e1eb455ed43e8b30689bacc4964fca8de76dd16f3d944132d47861c0436362c2e5e0e044b77c094dc46ea4c'
|
@@ -0,0 +1,8 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
Dummy::Application.config.session_store :cookie_store, key: '_dummy_session'
|
4
|
+
|
5
|
+
# Use the database for sessions instead of the cookie-based default,
|
6
|
+
# which shouldn't be used to store highly confidential information
|
7
|
+
# (create the session table with "rails generate session_migration")
|
8
|
+
# Dummy::Application.config.session_store :active_record_store
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
#
|
3
|
+
# This file contains settings for ActionController::ParamsWrapper which
|
4
|
+
# is enabled by default.
|
5
|
+
|
6
|
+
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
|
7
|
+
ActiveSupport.on_load(:action_controller) do
|
8
|
+
wrap_parameters format: [:json]
|
9
|
+
end
|
10
|
+
|
11
|
+
# Disable root element in JSON by default.
|
12
|
+
ActiveSupport.on_load(:active_record) do
|
13
|
+
self.include_root_in_json = false
|
14
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The page you were looking for doesn't exist (404)</title>
|
5
|
+
<style type="text/css">
|
6
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
7
|
+
div.dialog {
|
8
|
+
width: 25em;
|
9
|
+
padding: 0 4em;
|
10
|
+
margin: 4em auto 0 auto;
|
11
|
+
border: 1px solid #ccc;
|
12
|
+
border-right-color: #999;
|
13
|
+
border-bottom-color: #999;
|
14
|
+
}
|
15
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
16
|
+
</style>
|
17
|
+
</head>
|
18
|
+
|
19
|
+
<body>
|
20
|
+
<!-- This file lives in public/404.html -->
|
21
|
+
<div class="dialog">
|
22
|
+
<h1>The page you were looking for doesn't exist.</h1>
|
23
|
+
<p>You may have mistyped the address or the page may have moved.</p>
|
24
|
+
</div>
|
25
|
+
</body>
|
26
|
+
</html>
|
@@ -0,0 +1,26 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The change you wanted was rejected (422)</title>
|
5
|
+
<style type="text/css">
|
6
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
7
|
+
div.dialog {
|
8
|
+
width: 25em;
|
9
|
+
padding: 0 4em;
|
10
|
+
margin: 4em auto 0 auto;
|
11
|
+
border: 1px solid #ccc;
|
12
|
+
border-right-color: #999;
|
13
|
+
border-bottom-color: #999;
|
14
|
+
}
|
15
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
16
|
+
</style>
|
17
|
+
</head>
|
18
|
+
|
19
|
+
<body>
|
20
|
+
<!-- This file lives in public/422.html -->
|
21
|
+
<div class="dialog">
|
22
|
+
<h1>The change you wanted was rejected.</h1>
|
23
|
+
<p>Maybe you tried to change something you didn't have access to.</p>
|
24
|
+
</div>
|
25
|
+
</body>
|
26
|
+
</html>
|
@@ -0,0 +1,26 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>We're sorry, but something went wrong (500)</title>
|
5
|
+
<style type="text/css">
|
6
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
7
|
+
div.dialog {
|
8
|
+
width: 25em;
|
9
|
+
padding: 0 4em;
|
10
|
+
margin: 4em auto 0 auto;
|
11
|
+
border: 1px solid #ccc;
|
12
|
+
border-right-color: #999;
|
13
|
+
border-bottom-color: #999;
|
14
|
+
}
|
15
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
16
|
+
</style>
|
17
|
+
</head>
|
18
|
+
|
19
|
+
<body>
|
20
|
+
<!-- This file lives in public/500.html -->
|
21
|
+
<div class="dialog">
|
22
|
+
<h1>We're sorry, but something went wrong.</h1>
|
23
|
+
<p>We've been notified about this issue and we'll take a look at it shortly.</p>
|
24
|
+
</div>
|
25
|
+
</body>
|
26
|
+
</html>
|
File without changes
|
@@ -0,0 +1,6 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
3
|
+
|
4
|
+
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
5
|
+
require File.expand_path('../../config/boot', __FILE__)
|
6
|
+
require 'rails/commands'
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'generators/generators_test_helper'
|
3
|
+
require "generators/angular/controller/controller_generator"
|
4
|
+
|
5
|
+
class ControllerGeneratorTest < Rails::Generators::TestCase
|
6
|
+
include GeneratorsTestHelper
|
7
|
+
tests Angular::Generators::ControllerGenerator
|
8
|
+
|
9
|
+
test "simple controller" do
|
10
|
+
run_generator %w(Post)
|
11
|
+
assert_file "#{angular_path}/controllers/posts.coffee" do |controller|
|
12
|
+
controller_class = Regexp.escape("class @PostsController")
|
13
|
+
assert_match /#{controller_class}/, controller
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
test "two word model is camelcased" do
|
19
|
+
run_generator %w(BlogPost)
|
20
|
+
|
21
|
+
assert_file "#{angular_path}/controllers/blog_posts.coffee" do |controller|
|
22
|
+
controller_class = Regexp.escape("class @BlogPostsController")
|
23
|
+
|
24
|
+
assert_match /#{controller_class}/, controller
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -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,60 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'generators/generators_test_helper'
|
3
|
+
require "generators/angular/install/install_generator"
|
4
|
+
|
5
|
+
class InstallGeneratorTest < Rails::Generators::TestCase
|
6
|
+
include GeneratorsTestHelper
|
7
|
+
tests Angular::Generators::InstallGenerator
|
8
|
+
|
9
|
+
def setup
|
10
|
+
mkdir_p "#{destination_root}/app/assets/javascripts"
|
11
|
+
cp fixture("application.js"), "#{destination_root}/app/assets/javascripts"
|
12
|
+
super
|
13
|
+
end
|
14
|
+
|
15
|
+
test "Assert template directory structure is created" do
|
16
|
+
run_generator
|
17
|
+
assert_directory angular_templates_path
|
18
|
+
assert_file "#{angular_templates_path}/.gitkeep"
|
19
|
+
end
|
20
|
+
|
21
|
+
test "Assert angular directory structure is created" do
|
22
|
+
run_generator
|
23
|
+
|
24
|
+
%W{controllers filters services widgets}.each do |dir|
|
25
|
+
assert_directory "#{angular_path}/#{dir}"
|
26
|
+
assert_file "#{angular_path}/#{dir}/.gitkeep"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
test "Assert angular spec directory structure is created" do
|
31
|
+
run_generator
|
32
|
+
assert_directory angular_spec_path
|
33
|
+
assert_file "#{angular_spec_path}/.gitkeep"
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
test "Assert no gitkeep files are created when skipping git" do
|
38
|
+
run_generator [destination_root, "--skip-git"]
|
39
|
+
|
40
|
+
%W{controllers filters services widgets}.each do |dir|
|
41
|
+
assert_no_file "#{angular_path}/#{dir}/.gitkeep"
|
42
|
+
end
|
43
|
+
assert_no_file "#{angular_spec_path}/.gitkeep"
|
44
|
+
assert_no_file "#{assets_path}/templates/.gitkeep"
|
45
|
+
end
|
46
|
+
|
47
|
+
test "Assert application.js require angular.js and angular directory" do
|
48
|
+
run_generator
|
49
|
+
|
50
|
+
assert_file "app/assets/javascripts/application.js" do |application|
|
51
|
+
assert_match /require angular(.*)require_tree \.\/angular/m, application
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def fixture(file)
|
56
|
+
File.expand_path("fixtures/#{file}", File.dirname(__FILE__))
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# Configure Rails Environment
|
2
|
+
ENV["RAILS_ENV"] = "test"
|
3
|
+
|
4
|
+
require File.expand_path("../dummy/config/environment.rb", __FILE__)
|
5
|
+
require "rails/test_help"
|
6
|
+
require 'minitest/spec'
|
7
|
+
|
8
|
+
Rails.backtrace_cleaner.remove_silencers!
|
9
|
+
|
10
|
+
# Load support files
|
11
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
12
|
+
|
13
|
+
# For Generators
|
14
|
+
require 'rails/generators/test_case'
|
@@ -0,0 +1,35 @@
|
|
1
|
+
/*
|
2
|
+
Content-Type: multipart/related; boundary="_"
|
3
|
+
|
4
|
+
--_
|
5
|
+
Content-Location:img0
|
6
|
+
Content-Transfer-Encoding:base64
|
7
|
+
|
8
|
+
R0lGODlhCwAXAKIAAMzMzO/v7/f39////////wAAAAAAAAAAACH5BAUUAAQALAAAAAALABcAAAMrSLoc/AG8FeUUIN+sGebWAnbKSJodqqlsOxJtqYooU9vvk+vcJIcTkg+QAAA7
|
9
|
+
--_
|
10
|
+
Content-Location:img1
|
11
|
+
Content-Transfer-Encoding:base64
|
12
|
+
|
13
|
+
R0lGODlhCwAXAKIAAMzMzO/v7/f39////////wAAAAAAAAAAACH5BAUUAAQALAAAAAALABcAAAMrCLTcoM29yN6k9socs91e5X3EyJloipYrO4ohTMqA0Fn2XVNswJe+H+SXAAA7
|
14
|
+
--_
|
15
|
+
Content-Location:img2
|
16
|
+
Content-Transfer-Encoding:base64
|
17
|
+
|
18
|
+
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
|
19
|
+
--_--
|
20
|
+
*/
|
21
|
+
(function(){
|
22
|
+
var jsUri = document.location.href.replace(/\/[^\/]+(#.*)?$/, '/') +
|
23
|
+
document.getElementById('ng-ie-compat').src,
|
24
|
+
css = '#ng-callout .ng-arrow-left{*background-image:url("mhtml:' + jsUri + '!img0")}#ng-callout .ng-arrow-right{*background-image:url("mhtml:' + jsUri + '!img1")}.ng-input-indicator-wait {*background-image:url("mhtml:' + jsUri + '!img2")}',
|
25
|
+
s = document.createElement('style');
|
26
|
+
|
27
|
+
s.setAttribute('type', 'text/css');
|
28
|
+
|
29
|
+
if (s.styleSheet) {
|
30
|
+
s.styleSheet.cssText = css;
|
31
|
+
} else {
|
32
|
+
s.appendChild(document.createTextNode(css));
|
33
|
+
}
|
34
|
+
document.getElementsByTagName('head')[0].appendChild(s);
|
35
|
+
})();
|
@@ -0,0 +1,472 @@
|
|
1
|
+
/**
|
2
|
+
* @license AngularJS v1.1.2
|
3
|
+
* (c) 2010-2012 Google, Inc. http://angularjs.org
|
4
|
+
* License: MIT
|
5
|
+
*/
|
6
|
+
(function(window, angular, undefined) {
|
7
|
+
'use strict';
|
8
|
+
|
9
|
+
/**
|
10
|
+
* @ngdoc overview
|
11
|
+
* @name ngResource
|
12
|
+
* @description
|
13
|
+
*/
|
14
|
+
|
15
|
+
/**
|
16
|
+
* @ngdoc object
|
17
|
+
* @name ngResource.$resource
|
18
|
+
* @requires $http
|
19
|
+
*
|
20
|
+
* @description
|
21
|
+
* A factory which creates a resource object that lets you interact with
|
22
|
+
* [RESTful](http://en.wikipedia.org/wiki/Representational_State_Transfer) server-side data sources.
|
23
|
+
*
|
24
|
+
* The returned resource object has action methods which provide high-level behaviors without
|
25
|
+
* the need to interact with the low level {@link ng.$http $http} service.
|
26
|
+
*
|
27
|
+
* @param {string} url A parameterized URL template with parameters prefixed by `:` as in
|
28
|
+
* `/user/:username`. If you are using a URL with a port number (e.g.
|
29
|
+
* `http://example.com:8080/api`), you'll need to escape the colon character before the port
|
30
|
+
* number, like this: `$resource('http://example.com\\:8080/api')`.
|
31
|
+
*
|
32
|
+
* @param {Object=} paramDefaults Default values for `url` parameters. These can be overridden in
|
33
|
+
* `actions` methods. If any of the parameter value is a function, it will be executed every time
|
34
|
+
* when a param value needs to be obtained for a request (unless the param was overriden).
|
35
|
+
*
|
36
|
+
* Each key value in the parameter object is first bound to url template if present and then any
|
37
|
+
* excess keys are appended to the url search query after the `?`.
|
38
|
+
*
|
39
|
+
* Given a template `/path/:verb` and parameter `{verb:'greet', salutation:'Hello'}` results in
|
40
|
+
* URL `/path/greet?salutation=Hello`.
|
41
|
+
*
|
42
|
+
* If the parameter value is prefixed with `@` then the value of that parameter is extracted from
|
43
|
+
* the data object (useful for non-GET operations).
|
44
|
+
*
|
45
|
+
* @param {Object.<Object>=} actions Hash with declaration of custom action that should extend the
|
46
|
+
* default set of resource actions. The declaration should be created in the format of {@link
|
47
|
+
* ng.$http#Parameters $http.config}:
|
48
|
+
*
|
49
|
+
* {action1: {method:?, params:?, isArray:?, headers:?, ...},
|
50
|
+
* action2: {method:?, params:?, isArray:?, headers:?, ...},
|
51
|
+
* ...}
|
52
|
+
*
|
53
|
+
* Where:
|
54
|
+
*
|
55
|
+
* - **`action`** – {string} – The name of action. This name becomes the name of the method on your
|
56
|
+
* resource object.
|
57
|
+
* - **`method`** – {string} – HTTP request method. Valid methods are: `GET`, `POST`, `PUT`, `DELETE`,
|
58
|
+
* and `JSONP`.
|
59
|
+
* - **`params`** – {Object=} – Optional set of pre-bound parameters for this action. If any of the
|
60
|
+
* parameter value is a function, it will be executed every time when a param value needs to be
|
61
|
+
* obtained for a request (unless the param was overriden).
|
62
|
+
* - **`isArray`** – {boolean=} – If true then the returned object for this action is an array, see
|
63
|
+
* `returns` section.
|
64
|
+
* - **`transformRequest`** – `{function(data, headersGetter)|Array.<function(data, headersGetter)>}` –
|
65
|
+
* transform function or an array of such functions. The transform function takes the http
|
66
|
+
* request body and headers and returns its transformed (typically serialized) version.
|
67
|
+
* - **`transformResponse`** – `{function(data, headersGetter)|Array.<function(data, headersGetter)>}` –
|
68
|
+
* transform function or an array of such functions. The transform function takes the http
|
69
|
+
* response body and headers and returns its transformed (typically deserialized) version.
|
70
|
+
* - **`cache`** – `{boolean|Cache}` – If true, a default $http cache will be used to cache the
|
71
|
+
* GET request, otherwise if a cache instance built with
|
72
|
+
* {@link ng.$cacheFactory $cacheFactory}, this cache will be used for
|
73
|
+
* caching.
|
74
|
+
* - **`timeout`** – `{number}` – timeout in milliseconds.
|
75
|
+
* - **`withCredentials`** - `{boolean}` - whether to to set the `withCredentials` flag on the
|
76
|
+
* XHR object. See {@link https://developer.mozilla.org/en/http_access_control#section_5
|
77
|
+
* requests with credentials} for more information.
|
78
|
+
* - **`responseType`** - `{string}` - see {@link
|
79
|
+
* https://developer.mozilla.org/en-US/docs/DOM/XMLHttpRequest#responseType requestType}.
|
80
|
+
*
|
81
|
+
* @returns {Object} A resource "class" object with methods for the default set of resource actions
|
82
|
+
* optionally extended with custom `actions`. The default set contains these actions:
|
83
|
+
*
|
84
|
+
* { 'get': {method:'GET'},
|
85
|
+
* 'save': {method:'POST'},
|
86
|
+
* 'query': {method:'GET', isArray:true},
|
87
|
+
* 'remove': {method:'DELETE'},
|
88
|
+
* 'delete': {method:'DELETE'} };
|
89
|
+
*
|
90
|
+
* Calling these methods invoke an {@link ng.$http} with the specified http method,
|
91
|
+
* destination and parameters. When the data is returned from the server then the object is an
|
92
|
+
* instance of the resource class `save`, `remove` and `delete` actions are available on it as
|
93
|
+
* methods with the `$` prefix. This allows you to easily perform CRUD operations (create, read,
|
94
|
+
* update, delete) on server-side data like this:
|
95
|
+
* <pre>
|
96
|
+
var User = $resource('/user/:userId', {userId:'@id'});
|
97
|
+
var user = User.get({userId:123}, function() {
|
98
|
+
user.abc = true;
|
99
|
+
user.$save();
|
100
|
+
});
|
101
|
+
</pre>
|
102
|
+
*
|
103
|
+
* It is important to realize that invoking a $resource object method immediately returns an
|
104
|
+
* empty reference (object or array depending on `isArray`). Once the data is returned from the
|
105
|
+
* server the existing reference is populated with the actual data. This is a useful trick since
|
106
|
+
* usually the resource is assigned to a model which is then rendered by the view. Having an empty
|
107
|
+
* object results in no rendering, once the data arrives from the server then the object is
|
108
|
+
* populated with the data and the view automatically re-renders itself showing the new data. This
|
109
|
+
* means that in most case one never has to write a callback function for the action methods.
|
110
|
+
*
|
111
|
+
* The action methods on the class object or instance object can be invoked with the following
|
112
|
+
* parameters:
|
113
|
+
*
|
114
|
+
* - HTTP GET "class" actions: `Resource.action([parameters], [success], [error])`
|
115
|
+
* - non-GET "class" actions: `Resource.action([parameters], postData, [success], [error])`
|
116
|
+
* - non-GET instance actions: `instance.$action([parameters], [success], [error])`
|
117
|
+
*
|
118
|
+
*
|
119
|
+
* @example
|
120
|
+
*
|
121
|
+
* # Credit card resource
|
122
|
+
*
|
123
|
+
* <pre>
|
124
|
+
// Define CreditCard class
|
125
|
+
var CreditCard = $resource('/user/:userId/card/:cardId',
|
126
|
+
{userId:123, cardId:'@id'}, {
|
127
|
+
charge: {method:'POST', params:{charge:true}}
|
128
|
+
});
|
129
|
+
|
130
|
+
// We can retrieve a collection from the server
|
131
|
+
var cards = CreditCard.query(function() {
|
132
|
+
// GET: /user/123/card
|
133
|
+
// server returns: [ {id:456, number:'1234', name:'Smith'} ];
|
134
|
+
|
135
|
+
var card = cards[0];
|
136
|
+
// each item is an instance of CreditCard
|
137
|
+
expect(card instanceof CreditCard).toEqual(true);
|
138
|
+
card.name = "J. Smith";
|
139
|
+
// non GET methods are mapped onto the instances
|
140
|
+
card.$save();
|
141
|
+
// POST: /user/123/card/456 {id:456, number:'1234', name:'J. Smith'}
|
142
|
+
// server returns: {id:456, number:'1234', name: 'J. Smith'};
|
143
|
+
|
144
|
+
// our custom method is mapped as well.
|
145
|
+
card.$charge({amount:9.99});
|
146
|
+
// POST: /user/123/card/456?amount=9.99&charge=true {id:456, number:'1234', name:'J. Smith'}
|
147
|
+
});
|
148
|
+
|
149
|
+
// we can create an instance as well
|
150
|
+
var newCard = new CreditCard({number:'0123'});
|
151
|
+
newCard.name = "Mike Smith";
|
152
|
+
newCard.$save();
|
153
|
+
// POST: /user/123/card {number:'0123', name:'Mike Smith'}
|
154
|
+
// server returns: {id:789, number:'01234', name: 'Mike Smith'};
|
155
|
+
expect(newCard.id).toEqual(789);
|
156
|
+
* </pre>
|
157
|
+
*
|
158
|
+
* The object returned from this function execution is a resource "class" which has "static" method
|
159
|
+
* for each action in the definition.
|
160
|
+
*
|
161
|
+
* Calling these methods invoke `$http` on the `url` template with the given `method`, `params` and `headers`.
|
162
|
+
* When the data is returned from the server then the object is an instance of the resource type and
|
163
|
+
* all of the non-GET methods are available with `$` prefix. This allows you to easily support CRUD
|
164
|
+
* operations (create, read, update, delete) on server-side data.
|
165
|
+
|
166
|
+
<pre>
|
167
|
+
var User = $resource('/user/:userId', {userId:'@id'});
|
168
|
+
var user = User.get({userId:123}, function() {
|
169
|
+
user.abc = true;
|
170
|
+
user.$save();
|
171
|
+
});
|
172
|
+
</pre>
|
173
|
+
*
|
174
|
+
* It's worth noting that the success callback for `get`, `query` and other method gets passed
|
175
|
+
* in the response that came from the server as well as $http header getter function, so one
|
176
|
+
* could rewrite the above example and get access to http headers as:
|
177
|
+
*
|
178
|
+
<pre>
|
179
|
+
var User = $resource('/user/:userId', {userId:'@id'});
|
180
|
+
User.get({userId:123}, function(u, getResponseHeaders){
|
181
|
+
u.abc = true;
|
182
|
+
u.$save(function(u, putResponseHeaders) {
|
183
|
+
//u => saved user object
|
184
|
+
//putResponseHeaders => $http header getter
|
185
|
+
});
|
186
|
+
});
|
187
|
+
</pre>
|
188
|
+
|
189
|
+
* # Buzz client
|
190
|
+
|
191
|
+
Let's look at what a buzz client created with the `$resource` service looks like:
|
192
|
+
<doc:example>
|
193
|
+
<doc:source jsfiddle="false">
|
194
|
+
<script>
|
195
|
+
function BuzzController($resource) {
|
196
|
+
this.userId = 'googlebuzz';
|
197
|
+
this.Activity = $resource(
|
198
|
+
'https://www.googleapis.com/buzz/v1/activities/:userId/:visibility/:activityId/:comments',
|
199
|
+
{alt:'json', callback:'JSON_CALLBACK'},
|
200
|
+
{get:{method:'JSONP', params:{visibility:'@self'}}, replies: {method:'JSONP', params:{visibility:'@self', comments:'@comments'}}}
|
201
|
+
);
|
202
|
+
}
|
203
|
+
|
204
|
+
BuzzController.prototype = {
|
205
|
+
fetch: function() {
|
206
|
+
this.activities = this.Activity.get({userId:this.userId});
|
207
|
+
},
|
208
|
+
expandReplies: function(activity) {
|
209
|
+
activity.replies = this.Activity.replies({userId:this.userId, activityId:activity.id});
|
210
|
+
}
|
211
|
+
};
|
212
|
+
BuzzController.$inject = ['$resource'];
|
213
|
+
</script>
|
214
|
+
|
215
|
+
<div ng-controller="BuzzController">
|
216
|
+
<input ng-model="userId"/>
|
217
|
+
<button ng-click="fetch()">fetch</button>
|
218
|
+
<hr/>
|
219
|
+
<div ng-repeat="item in activities.data.items">
|
220
|
+
<h1 style="font-size: 15px;">
|
221
|
+
<img src="{{item.actor.thumbnailUrl}}" style="max-height:30px;max-width:30px;"/>
|
222
|
+
<a href="{{item.actor.profileUrl}}">{{item.actor.name}}</a>
|
223
|
+
<a href ng-click="expandReplies(item)" style="float: right;">Expand replies: {{item.links.replies[0].count}}</a>
|
224
|
+
</h1>
|
225
|
+
{{item.object.content | html}}
|
226
|
+
<div ng-repeat="reply in item.replies.data.items" style="margin-left: 20px;">
|
227
|
+
<img src="{{reply.actor.thumbnailUrl}}" style="max-height:30px;max-width:30px;"/>
|
228
|
+
<a href="{{reply.actor.profileUrl}}">{{reply.actor.name}}</a>: {{reply.content | html}}
|
229
|
+
</div>
|
230
|
+
</div>
|
231
|
+
</div>
|
232
|
+
</doc:source>
|
233
|
+
<doc:scenario>
|
234
|
+
</doc:scenario>
|
235
|
+
</doc:example>
|
236
|
+
*/
|
237
|
+
angular.module('ngResource', ['ng']).
|
238
|
+
factory('$resource', ['$http', '$parse', function($http, $parse) {
|
239
|
+
var DEFAULT_ACTIONS = {
|
240
|
+
'get': {method:'GET'},
|
241
|
+
'save': {method:'POST'},
|
242
|
+
'query': {method:'GET', isArray:true},
|
243
|
+
'remove': {method:'DELETE'},
|
244
|
+
'delete': {method:'DELETE'}
|
245
|
+
};
|
246
|
+
var noop = angular.noop,
|
247
|
+
forEach = angular.forEach,
|
248
|
+
extend = angular.extend,
|
249
|
+
copy = angular.copy,
|
250
|
+
isFunction = angular.isFunction,
|
251
|
+
getter = function(obj, path) {
|
252
|
+
return $parse(path)(obj);
|
253
|
+
};
|
254
|
+
|
255
|
+
/**
|
256
|
+
* We need our custom method because encodeURIComponent is too aggressive and doesn't follow
|
257
|
+
* http://www.ietf.org/rfc/rfc3986.txt with regards to the character set (pchar) allowed in path
|
258
|
+
* segments:
|
259
|
+
* segment = *pchar
|
260
|
+
* pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
|
261
|
+
* pct-encoded = "%" HEXDIG HEXDIG
|
262
|
+
* unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
|
263
|
+
* sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
|
264
|
+
* / "*" / "+" / "," / ";" / "="
|
265
|
+
*/
|
266
|
+
function encodeUriSegment(val) {
|
267
|
+
return encodeUriQuery(val, true).
|
268
|
+
replace(/%26/gi, '&').
|
269
|
+
replace(/%3D/gi, '=').
|
270
|
+
replace(/%2B/gi, '+');
|
271
|
+
}
|
272
|
+
|
273
|
+
|
274
|
+
/**
|
275
|
+
* This method is intended for encoding *key* or *value* parts of query component. We need a custom
|
276
|
+
* method becuase encodeURIComponent is too agressive and encodes stuff that doesn't have to be
|
277
|
+
* encoded per http://tools.ietf.org/html/rfc3986:
|
278
|
+
* query = *( pchar / "/" / "?" )
|
279
|
+
* pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
|
280
|
+
* unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
|
281
|
+
* pct-encoded = "%" HEXDIG HEXDIG
|
282
|
+
* sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
|
283
|
+
* / "*" / "+" / "," / ";" / "="
|
284
|
+
*/
|
285
|
+
function encodeUriQuery(val, pctEncodeSpaces) {
|
286
|
+
return encodeURIComponent(val).
|
287
|
+
replace(/%40/gi, '@').
|
288
|
+
replace(/%3A/gi, ':').
|
289
|
+
replace(/%24/g, '$').
|
290
|
+
replace(/%2C/gi, ',').
|
291
|
+
replace((pctEncodeSpaces ? null : /%20/g), '+');
|
292
|
+
}
|
293
|
+
|
294
|
+
function Route(template, defaults) {
|
295
|
+
this.template = template = template + '#';
|
296
|
+
this.defaults = defaults || {};
|
297
|
+
var urlParams = this.urlParams = {};
|
298
|
+
forEach(template.split(/\W/), function(param){
|
299
|
+
if (param && template.match(new RegExp("[^\\\\]:" + param + "\\W"))) {
|
300
|
+
urlParams[param] = true;
|
301
|
+
}
|
302
|
+
});
|
303
|
+
this.template = template.replace(/\\:/g, ':');
|
304
|
+
}
|
305
|
+
|
306
|
+
Route.prototype = {
|
307
|
+
url: function(params) {
|
308
|
+
var self = this,
|
309
|
+
url = this.template,
|
310
|
+
val,
|
311
|
+
encodedVal;
|
312
|
+
|
313
|
+
params = params || {};
|
314
|
+
forEach(this.urlParams, function(_, urlParam){
|
315
|
+
val = params.hasOwnProperty(urlParam) ? params[urlParam] : self.defaults[urlParam];
|
316
|
+
if (angular.isDefined(val) && val !== null) {
|
317
|
+
encodedVal = encodeUriSegment(val);
|
318
|
+
url = url.replace(new RegExp(":" + urlParam + "(\\W)", "g"), encodedVal + "$1");
|
319
|
+
} else {
|
320
|
+
url = url.replace(new RegExp("(\/?):" + urlParam + "(\\W)", "g"), function(match,
|
321
|
+
leadingSlashes, tail) {
|
322
|
+
if (tail.charAt(0) == '/') {
|
323
|
+
return tail;
|
324
|
+
} else {
|
325
|
+
return leadingSlashes + tail;
|
326
|
+
}
|
327
|
+
});
|
328
|
+
}
|
329
|
+
});
|
330
|
+
url = url.replace(/\/?#$/, '');
|
331
|
+
var query = [];
|
332
|
+
forEach(params, function(value, key){
|
333
|
+
if (!self.urlParams[key]) {
|
334
|
+
query.push(encodeUriQuery(key) + '=' + encodeUriQuery(value));
|
335
|
+
}
|
336
|
+
});
|
337
|
+
query.sort();
|
338
|
+
url = url.replace(/\/*$/, '');
|
339
|
+
return url + (query.length ? '?' + query.join('&') : '');
|
340
|
+
}
|
341
|
+
};
|
342
|
+
|
343
|
+
|
344
|
+
function ResourceFactory(url, paramDefaults, actions) {
|
345
|
+
var route = new Route(url);
|
346
|
+
|
347
|
+
actions = extend({}, DEFAULT_ACTIONS, actions);
|
348
|
+
|
349
|
+
function extractParams(data, actionParams){
|
350
|
+
var ids = {};
|
351
|
+
actionParams = extend({}, paramDefaults, actionParams);
|
352
|
+
forEach(actionParams, function(value, key){
|
353
|
+
if (isFunction(value)) { value = value(); }
|
354
|
+
ids[key] = value.charAt && value.charAt(0) == '@' ? getter(data, value.substr(1)) : value;
|
355
|
+
});
|
356
|
+
return ids;
|
357
|
+
}
|
358
|
+
|
359
|
+
function Resource(value){
|
360
|
+
copy(value || {}, this);
|
361
|
+
}
|
362
|
+
|
363
|
+
forEach(actions, function(action, name) {
|
364
|
+
action.method = angular.uppercase(action.method);
|
365
|
+
var hasBody = action.method == 'POST' || action.method == 'PUT' || action.method == 'PATCH';
|
366
|
+
Resource[name] = function(a1, a2, a3, a4) {
|
367
|
+
var params = {};
|
368
|
+
var data;
|
369
|
+
var success = noop;
|
370
|
+
var error = null;
|
371
|
+
switch(arguments.length) {
|
372
|
+
case 4:
|
373
|
+
error = a4;
|
374
|
+
success = a3;
|
375
|
+
//fallthrough
|
376
|
+
case 3:
|
377
|
+
case 2:
|
378
|
+
if (isFunction(a2)) {
|
379
|
+
if (isFunction(a1)) {
|
380
|
+
success = a1;
|
381
|
+
error = a2;
|
382
|
+
break;
|
383
|
+
}
|
384
|
+
|
385
|
+
success = a2;
|
386
|
+
error = a3;
|
387
|
+
//fallthrough
|
388
|
+
} else {
|
389
|
+
params = a1;
|
390
|
+
data = a2;
|
391
|
+
success = a3;
|
392
|
+
break;
|
393
|
+
}
|
394
|
+
case 1:
|
395
|
+
if (isFunction(a1)) success = a1;
|
396
|
+
else if (hasBody) data = a1;
|
397
|
+
else params = a1;
|
398
|
+
break;
|
399
|
+
case 0: break;
|
400
|
+
default:
|
401
|
+
throw "Expected between 0-4 arguments [params, data, success, error], got " +
|
402
|
+
arguments.length + " arguments.";
|
403
|
+
}
|
404
|
+
|
405
|
+
var value = this instanceof Resource ? this : (action.isArray ? [] : new Resource(data));
|
406
|
+
var httpConfig = {};
|
407
|
+
|
408
|
+
forEach(action, function(value, key) {
|
409
|
+
if (key != 'params' && key != 'isArray' ) {
|
410
|
+
httpConfig[key] = copy(value);
|
411
|
+
}
|
412
|
+
});
|
413
|
+
httpConfig.data = data;
|
414
|
+
httpConfig.url = route.url(extend({}, extractParams(data, action.params || {}), params))
|
415
|
+
|
416
|
+
$http(httpConfig).then(function(response) {
|
417
|
+
var data = response.data;
|
418
|
+
|
419
|
+
if (data) {
|
420
|
+
if (action.isArray) {
|
421
|
+
value.length = 0;
|
422
|
+
forEach(data, function(item) {
|
423
|
+
value.push(new Resource(item));
|
424
|
+
});
|
425
|
+
} else {
|
426
|
+
copy(data, value);
|
427
|
+
}
|
428
|
+
}
|
429
|
+
(success||noop)(value, response.headers);
|
430
|
+
}, error);
|
431
|
+
|
432
|
+
return value;
|
433
|
+
};
|
434
|
+
|
435
|
+
|
436
|
+
Resource.prototype['$' + name] = function(a1, a2, a3) {
|
437
|
+
var params = extractParams(this),
|
438
|
+
success = noop,
|
439
|
+
error;
|
440
|
+
|
441
|
+
switch(arguments.length) {
|
442
|
+
case 3: params = a1; success = a2; error = a3; break;
|
443
|
+
case 2:
|
444
|
+
case 1:
|
445
|
+
if (isFunction(a1)) {
|
446
|
+
success = a1;
|
447
|
+
error = a2;
|
448
|
+
} else {
|
449
|
+
params = a1;
|
450
|
+
success = a2 || noop;
|
451
|
+
}
|
452
|
+
case 0: break;
|
453
|
+
default:
|
454
|
+
throw "Expected between 1-3 arguments [params, success, error], got " +
|
455
|
+
arguments.length + " arguments.";
|
456
|
+
}
|
457
|
+
var data = hasBody ? this : undefined;
|
458
|
+
Resource[name].call(this, params, data, success, error);
|
459
|
+
};
|
460
|
+
});
|
461
|
+
|
462
|
+
Resource.bind = function(additionalParamDefaults){
|
463
|
+
return ResourceFactory(url, extend({}, paramDefaults, additionalParamDefaults), actions);
|
464
|
+
};
|
465
|
+
|
466
|
+
return Resource;
|
467
|
+
}
|
468
|
+
|
469
|
+
return ResourceFactory;
|
470
|
+
}]);
|
471
|
+
|
472
|
+
})(window, window.angular);
|