angular-ujs 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 06f196964d6af0ad40b1fff56ff89e5dbafd0efe
4
+ data.tar.gz: 8dc4dbe22240e97cb70a93fcda8db3ddb74e8d76
5
+ SHA512:
6
+ metadata.gz: 167cc2d65dc44f7c9df4a6bbdb16b1270641d852fab0aec2a13c8f34129a225849e4984ffe38db3e08b4ea176566e6056198eb05c13a820a5ed318236f12b9f1
7
+ data.tar.gz: a2b55a9f431368d04f75deb31767a31dc4aef322960851c3f7fe702f9943f90c75507f6d84b7207aab6e02220976a805c50a6017160ab1afd5719d70efd6ea51
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright © 2013 Tom Chen <developer@tomchentw.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,106 @@
1
+ # angular-ujs ( [`Angular::Ujs`](https://rubygems.org/gems/angular-ujs) )
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/angular-ujs.png)](http://badge.fury.io/rb/angular-ujs) [![Build Status](https://secure.travis-ci.org/tomchentw/angular-ujs.png)](http://travis-ci.org/tomchentw/angular-ujs) [![Code Climate](https://codeclimate.com/github/tomchentw/angular-ujs.png)](https://codeclimate.com/github/tomchentw/angular-ujs)
4
+
5
+ Ruby on Rails unobtrusive scripting adapter for angularjs ( Without jQuery dependency )
6
+
7
+ ## Project philosophy
8
+
9
+ ### Native, lightweight directives
10
+ Unobtrusive scripting in `jquery_ujs` provides the same interface with angular `directives`.
11
+ We use the similarity between them and provides seamless intergration with `jquery_ujs`.
12
+
13
+ ### Develop in LiveScript
14
+ [LiveScript](http://livescript.net/) is a compile-to-js language, which provides us more robust way to write JavaScript.
15
+ It also has great readibility and lots of syntax sugar just like you're writting python/ruby.
16
+
17
+ ### Spec/Scenario coverage
18
+ We use `krama` to run unit test against [angular-ujs.spec.ls](https://github.com/tomchentw/angular-ujs/blob/master/src/angular-ujs.spec.ls) and use `protractor` to run intergration test via [angular-ujs.scenario.ls](https://github.com/tomchentw/angular-ujs/blob/master/src/angular-ujs.scenario.ls).
19
+
20
+ ## Installation
21
+
22
+ This project follows **DRY** principle and has one dependency only on `angularjs`.
23
+ However, we recommend you add [`ng-rails-csrf`](https://github.com/xrd/ng-rails-csrf/) into your project. As it name suggests, `ng-rails-csrf` automatically resolves CSRF in `angularjs` environment withour `jquery_ujs`.
24
+
25
+ ### Just use it
26
+
27
+ * (Optional) Download and include [`ng-rails-csrf.js`](https://github.com/xrd/ng-rails-csrf/blob/master/vendor/assets/javascripts/ng-rails-csrf.js).
28
+ * Download and include [`angular-ujs.js`](https://github.com/tomchentw/angular-ujs/blob/master/angular-ujs.js) OR [`angular-ujs.min.js`](https://github.com/tomchentw/angular-ujs/blob/master/angular-ujs.min.js).
29
+
30
+ Then include them through script tag in your HTML.
31
+
32
+ ### **Rails** projects (Only support 3.1+)
33
+
34
+ Add these line to your application's Gemfile:
35
+ ```ruby
36
+ gem 'ng-rails-csrf' # Optional
37
+ gem 'angular-ujs'
38
+ ```
39
+
40
+ And then execute:
41
+
42
+ $ bundle
43
+
44
+ Then add these lines to the top of your `app/assets/javascripts/application.js` file:
45
+
46
+ ```javascript
47
+ //= require angular
48
+ //= require ng-rails-csrf
49
+ //= require angular-ujs
50
+ ```
51
+
52
+ And include in your `angular` module definition:
53
+
54
+ /* 'angular.ujs' DO NOT depend on 'ng-rails-csrf' module.
55
+ * You need to include it yourself.
56
+ */
57
+ var module = angular.module('my-awesome-project', [/* 'ng-rails-csrf', */ 'angular.ujs']).
58
+
59
+ ## Usage
60
+
61
+ ### "data-confirm": Confirmation dialogs for links and forms
62
+
63
+ ```html
64
+ <form data-confirm="Are you sure you want to submit?">...</form>
65
+ ```
66
+
67
+ ### "data-method": Links that result in POST, PUT, or DELETE requests
68
+
69
+ ```html
70
+ <a href="..." data-method="delete" rel="nofollow">Delete this entry</a>
71
+ ```
72
+
73
+ ### "data-remote": Make links and forms submit asynchronously with Ajax
74
+ ** Notice : API changed **
75
+
76
+ For `angularjs` apps, **ONLY** those items with `ng-model` will be submitted with `data-remote`
77
+
78
+ ```html
79
+ <form data-remote="true" action="...">
80
+ <input type="text" name="name" ng-model="name">
81
+ </form>
82
+ ```
83
+
84
+ #### You can specify the model name via `data-remote` :
85
+ ```html
86
+ <form data-remote="user" action="...">
87
+ <input type="text" name="name" ng-model="user.name">
88
+ <input type="email" name="email" ng-model="user.email">
89
+ </form>
90
+ ```
91
+
92
+ ### Use them all together :
93
+
94
+ ```html
95
+ <a href="..." data-method="delete" data-remote="true" data-confirm="Are you sure you want to delete?" rel="nofollow">Delete this entry</a>
96
+ ```
97
+
98
+ ## Contributing
99
+
100
+ [![devDependency Status](https://david-dm.org/tomchentw/angular-ujs/dev-status.png?branch=master)](https://david-dm.org/tomchentw/angular-ujs#info=devDependencies)
101
+
102
+ 1. Fork it
103
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
104
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
105
+ 4. Push to the branch (`git push origin my-new-feature`)
106
+ 5. Create new Pull Request
@@ -0,0 +1,11 @@
1
+ require 'json'
2
+
3
+ module Angular
4
+ module Ujs
5
+ JSON.parse(File.read(
6
+ File.expand_path('../../../../package.json', __FILE__)
7
+ )).each do |key, value|
8
+ const_set(key.upcase, value)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ require "angular/ujs/package"
2
+
3
+ module Angular
4
+ module Ujs
5
+ # http://prioritized.net/blog/gemify-assets-for-rails/
6
+ class Engine < ::Rails::Engine
7
+ end
8
+ end
9
+ end
data/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "angular-ujs",
3
+ "version": "0.4.3",
4
+ "description": "Unobtrusive scripting adapter for angularjs",
5
+ "summary": "Ruby on Rails unobtrusive scripting adapter for angularjs ( Without jQuery dependency )",
6
+ "main": "angular-ujs.js",
7
+ "scripts": {
8
+ "test": "echo \"Error: no test specified\" && exit 1"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git://github.com/tomchentw/angular-ujs.git"
13
+ },
14
+ "keywords": [
15
+ "Ruby on Rails",
16
+ "RoR",
17
+ "AngularJS",
18
+ "jQuery",
19
+ "Unobtrusive scripting"
20
+ ],
21
+ "author": {
22
+ "name": "tomchentw",
23
+ "email": "developer@tomchentw.com",
24
+ "url": "https://github.com/tomchentw/"
25
+ },
26
+ "license": {
27
+ "type": "MIT",
28
+ "url": "http://tomchentw.mit-license.org/"
29
+ },
30
+ "bugs": {
31
+ "url": "https://github.com/tomchentw/angular-ujs/issues"
32
+ },
33
+ "homepage": "https://github.com/tomchentw/angular-ujs",
34
+ "devDependencies": {
35
+ "grunt": "~0.4.2",
36
+ "grunt-contrib-uglify": "~0.2.7",
37
+ "grunt-livescript": "~0.5.1",
38
+ "grunt-contrib-copy": "~0.5.0",
39
+ "karma-script-launcher": "~0.1.0",
40
+ "karma-chrome-launcher": "~0.1.2",
41
+ "karma-firefox-launcher": "~0.1.3",
42
+ "karma-html2js-preprocessor": "~0.1.0",
43
+ "karma-jasmine": "~0.1.5",
44
+ "karma-coffee-preprocessor": "~0.1.2",
45
+ "requirejs": "~2.1.9",
46
+ "karma-requirejs": "~0.2.1",
47
+ "karma-phantomjs-launcher": "~0.1.1",
48
+ "karma": "~0.10.8",
49
+ "grunt-karma": "~0.6.2",
50
+ "grunt-contrib-watch": "~0.5.3",
51
+ "grunt-bump": "0.0.13",
52
+ "grunt-protractor-runner": "~0.2.0",
53
+ "protractor": "~0.15.0",
54
+ "grunt-shell": "~0.6.1",
55
+ "grunt-conventional-changelog": "~1.0.0"
56
+ }
57
+ }
@@ -0,0 +1,185 @@
1
+ /*global angular:false*/
2
+ (function(){
3
+ 'use strict';
4
+ var denyDefaultAction;
5
+ denyDefaultAction = function(event){
6
+ event.preventDefault();
7
+ event.stopPropagation();
8
+ };
9
+ angular.module('angular.ujs', []).config(['$provide', '$injector'].concat(function($provide, $injector){
10
+ var NAME;
11
+ NAME = '$getRailsCSRF';
12
+ if ($injector.has(NAME)) {
13
+ return;
14
+ }
15
+ /*
16
+ * Maybe provided in `ng-rails-csrf`
17
+ */
18
+ $provide.factory(NAME, ['$document'].concat(function($document){
19
+ return function(){
20
+ var metas, i$, ref$, len$, meta;
21
+ metas = {};
22
+ for (i$ = 0, len$ = (ref$ = $document[0].querySelectorAll('meta[name^="csrf-"]')).length; i$ < len$; ++i$) {
23
+ meta = ref$[i$];
24
+ meta = angular.element(meta);
25
+ metas[meta.attr('name')] = meta.attr('content');
26
+ }
27
+ return metas;
28
+ };
29
+ }));
30
+ })).controller('noopRailsConfirmCtrl', function(){
31
+ this.allowAction = function(){
32
+ return true;
33
+ };
34
+ this.denyDefaultAction = denyDefaultAction;
35
+ }).controller('noopRailsRemoteFormCtrl', function(){
36
+ this.submit = function($form){
37
+ $form[0].submit();
38
+ return {
39
+ then: angular.noop
40
+ };
41
+ };
42
+ }).controller('RailsConfirmCtrl', ['$window'].concat(function($window){
43
+ this.allowAction = function($attrs){
44
+ var message;
45
+ message = $attrs.confirm;
46
+ return angular.isDefined(message) && $window.confirm(message);
47
+ };
48
+ this.denyDefaultAction = denyDefaultAction;
49
+ })).directive('confirm', function(){
50
+ var postLinkFn;
51
+ postLinkFn = function($scope, $element, $attrs, $ctrls){
52
+ var confirmCtrl, onClickHandler;
53
+ confirmCtrl = $ctrls[0];
54
+ onClickHandler = function(event){
55
+ if (!confirmCtrl.allowAction($attrs)) {
56
+ confirmCtrl.denyDefaultAction(event);
57
+ }
58
+ };
59
+ $element.on('click', onClickHandler);
60
+ $scope.$on('$destroy', function(){
61
+ $element.off('click', onClickHandler);
62
+ });
63
+ };
64
+ return {
65
+ restrict: 'A',
66
+ require: ['confirm'],
67
+ controller: 'RailsConfirmCtrl',
68
+ compile: function(tElement, tAttrs){
69
+ var $attr;
70
+ $attr = tAttrs.$attr;
71
+ if ($attr.confirm !== 'data-confirm' || $attr.remote === 'data-remote' || $attr.method === 'data-method') {
72
+ return;
73
+ }
74
+ return postLinkFn;
75
+ }
76
+ };
77
+ }).controller('RailsRemoteFormCtrl', ['$scope', '$parse', '$http'].concat(function($scope, $parse, $http){
78
+ var successCallback, errorCallback;
79
+ successCallback = function(response){
80
+ $scope.$emit('rails:remote:success', response);
81
+ };
82
+ errorCallback = function(response){
83
+ $scope.$emit('rails:remote:error', response);
84
+ };
85
+ this.submit = function($form, modelName){
86
+ var targetScope, data, key, value, config, METHOD, own$ = {}.hasOwnProperty;
87
+ targetScope = $form.scope();
88
+ data = {};
89
+ if (modelName + "" !== 'true') {
90
+ $parse(modelName).assign(data, targetScope.$eval(modelName));
91
+ } else {
92
+ for (key in targetScope) if (own$.call(targetScope, key)) {
93
+ value = targetScope[key];
94
+ if (key === 'this' || key[0] === '$') {
95
+ continue;
96
+ }
97
+ data[key] = value;
98
+ }
99
+ }
100
+ config = {
101
+ url: $form.attr('action'),
102
+ method: $form.attr('method'),
103
+ data: data
104
+ };
105
+ METHOD = data._method;
106
+ if (METHOD !== 'GET' && METHOD !== 'POST') {
107
+ config.headers = {
108
+ 'X-Http-Method-Override': METHOD
109
+ };
110
+ }
111
+ return $http(config).then(successCallback, errorCallback);
112
+ };
113
+ })).directive('remote', ['$controller'].concat(function($controller){
114
+ var postLinkFn;
115
+ postLinkFn = function($scope, $element, $attrs, $ctrls){
116
+ var remoteCtrl, confirmCtrl, onSubmitHandler;
117
+ remoteCtrl = $ctrls[0], confirmCtrl = $ctrls[1] || $controller('noopRailsConfirmCtrl', {
118
+ $scope: $scope
119
+ });
120
+ onSubmitHandler = function(event){
121
+ confirmCtrl.denyDefaultAction(event);
122
+ if (!confirmCtrl.allowAction($attrs)) {
123
+ return;
124
+ }
125
+ remoteCtrl.submit($element, $attrs.remote);
126
+ };
127
+ $element.on('submit', onSubmitHandler);
128
+ $scope.$on('$destroy', function(){
129
+ $element.off('submit', onSubmitHandler);
130
+ });
131
+ };
132
+ return {
133
+ require: ['remote', '?confirm'],
134
+ restrict: 'A',
135
+ controller: 'RailsRemoteFormCtrl',
136
+ compile: function(tElement, tAttrs){
137
+ if (tAttrs.$attr.remote !== 'data-remote') {
138
+ return;
139
+ }
140
+ return postLinkFn;
141
+ }
142
+ };
143
+ })).directive('method', ['$controller', '$compile', '$document', '$getRailsCSRF'].concat(function($controller, $compile, $document, $getRailsCSRF){
144
+ var postLinkFn;
145
+ postLinkFn = function($scope, $element, $attrs, $ctrls){
146
+ var confirmCtrl, remoteCtrl, onClickHandler;
147
+ confirmCtrl = $ctrls[0] || $controller('noopRailsConfirmCtrl', {
148
+ $scope: $scope
149
+ }), remoteCtrl = $ctrls[1] || $controller('noopRailsRemoteFormCtrl', {
150
+ $scope: $scope
151
+ });
152
+ onClickHandler = function(event){
153
+ var metaTags, childScope, $form;
154
+ if (confirmCtrl.allowAction($attrs)) {
155
+ confirmCtrl.denyDefaultAction(event);
156
+ }
157
+ metaTags = $getRailsCSRF();
158
+ childScope = $scope.$new();
159
+ $form = $compile("<form class=\"ng-hide\" method=\"POST\" action=\"" + $attrs.href + "\">\n <input type=\"text\" name=\"_method\" ng-model=\"_method\">\n <input type=\"text\" name=\"" + metaTags['csrf-param'] + "\" value=\"" + metaTags['csrf-token'] + "\">\n</form>")(childScope);
160
+ $document.find('body').append($form);
161
+ childScope.$apply(function(){
162
+ childScope._method = $attrs.method;
163
+ });
164
+ remoteCtrl.submit($form, true).then(function(){
165
+ childScope.$destroy();
166
+ $form.remove();
167
+ });
168
+ };
169
+ $element.on('click', onClickHandler);
170
+ $scope.$on('$destroy', function(){
171
+ $element.off('click', onClickHandler);
172
+ });
173
+ };
174
+ return {
175
+ require: ['?confirm', '?remote'],
176
+ restrict: 'A',
177
+ compile: function(tElement, tAttrs){
178
+ if (tAttrs.$attr.method !== 'data-method') {
179
+ return;
180
+ }
181
+ return postLinkFn;
182
+ }
183
+ };
184
+ }));
185
+ }).call(this);
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: angular-ujs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.3
5
+ platform: ruby
6
+ authors:
7
+ - tomchentw
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: railties
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '3.1'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '3.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: ng-rails-csrf
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.1.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.1.0
69
+ description: Unobtrusive scripting adapter for angularjs
70
+ email:
71
+ - developer@tomchentw.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - LICENSE
77
+ - README.md
78
+ - lib/angular/ujs.rb
79
+ - lib/angular/ujs/package.rb
80
+ - package.json
81
+ - vendor/assets/javascripts/angular-ujs.js
82
+ homepage: https://github.com/tomchentw/angular-ujs
83
+ licenses:
84
+ - MIT
85
+ metadata: {}
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ requirements: []
101
+ rubyforge_project:
102
+ rubygems_version: 2.2.0
103
+ signing_key:
104
+ specification_version: 4
105
+ summary: Ruby on Rails unobtrusive scripting adapter for angularjs ( Without jQuery
106
+ dependency )
107
+ test_files: []