angular_sprinkles 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +156 -0
- data/LICENSE.txt +20 -0
- data/README.md +153 -0
- data/Rakefile +50 -0
- data/VERSION +1 -0
- data/angular_sprinkles.gemspec +94 -0
- data/app/assets/javascripts/angular_sprinkles.js.erb +18 -0
- data/lib/angular_sprinkles/controller.rb +61 -0
- data/lib/angular_sprinkles/data/bind.rb +18 -0
- data/lib/angular_sprinkles/decorators/bind_decorator.rb +53 -0
- data/lib/angular_sprinkles/decorators.rb +6 -0
- data/lib/angular_sprinkles/engine.rb +6 -0
- data/lib/angular_sprinkles/helpers/bind_helper.rb +55 -0
- data/lib/angular_sprinkles/helpers/directive_helper.rb +30 -0
- data/lib/angular_sprinkles/helpers.rb +9 -0
- data/lib/angular_sprinkles/mixins/initializable.rb +20 -0
- data/lib/angular_sprinkles/mixins/js_transformable.rb +23 -0
- data/lib/angular_sprinkles/railtie.rb +11 -0
- data/lib/angular_sprinkles.rb +13 -0
- data/spec/controller_spec.rb +52 -0
- data/spec/data/bind_spec.rb +11 -0
- data/spec/decorators/bind_decorator_spec.rb +57 -0
- data/spec/helpers/bind_helper_spec.rb +101 -0
- data/spec/helpers/directive_helper_spec.rb +66 -0
- data/spec/mixins/initializable_spec.rb +31 -0
- data/spec/mixins/js_transformable_spec.rb +45 -0
- data/spec/spec_helper.rb +30 -0
- metadata +201 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9f6308b16a728b1c5e29241e0e94be0eec1d3735
|
4
|
+
data.tar.gz: c1f09fbcc331e60afe3860ea39283b990e4e21dd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7831c173521e159f22de88877f5796f65740dafb22578a3ec0bda94a7431fa7975a669093f1d06180c022b31c0b9ed808e83150a3c50cd1581b2deca35653fb5
|
7
|
+
data.tar.gz: 3b5cd766296c41a6ea3f08008e51356ca6470aad47b05b931339f1f808bcd4a8412d0723738eeea36d26122ee687e2ddf85b57caa4b7b01973e21882969ed371
|
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,156 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
actionmailer (4.1.4)
|
5
|
+
actionpack (= 4.1.4)
|
6
|
+
actionview (= 4.1.4)
|
7
|
+
mail (~> 2.5.4)
|
8
|
+
actionpack (4.1.4)
|
9
|
+
actionview (= 4.1.4)
|
10
|
+
activesupport (= 4.1.4)
|
11
|
+
rack (~> 1.5.2)
|
12
|
+
rack-test (~> 0.6.2)
|
13
|
+
actionview (4.1.4)
|
14
|
+
activesupport (= 4.1.4)
|
15
|
+
builder (~> 3.1)
|
16
|
+
erubis (~> 2.7.0)
|
17
|
+
activemodel (4.1.4)
|
18
|
+
activesupport (= 4.1.4)
|
19
|
+
builder (~> 3.1)
|
20
|
+
activerecord (4.1.4)
|
21
|
+
activemodel (= 4.1.4)
|
22
|
+
activesupport (= 4.1.4)
|
23
|
+
arel (~> 5.0.0)
|
24
|
+
activesupport (4.1.4)
|
25
|
+
i18n (~> 0.6, >= 0.6.9)
|
26
|
+
json (~> 1.7, >= 1.7.7)
|
27
|
+
minitest (~> 5.1)
|
28
|
+
thread_safe (~> 0.1)
|
29
|
+
tzinfo (~> 1.1)
|
30
|
+
addressable (2.3.6)
|
31
|
+
angularjs-rails (1.2.21)
|
32
|
+
arel (5.0.1.20140414130214)
|
33
|
+
builder (3.2.2)
|
34
|
+
byebug (3.2.0)
|
35
|
+
columnize (~> 0.8)
|
36
|
+
debugger-linecache (~> 1.2)
|
37
|
+
columnize (0.8.9)
|
38
|
+
debugger-linecache (1.2.0)
|
39
|
+
descendants_tracker (0.0.4)
|
40
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
41
|
+
diff-lcs (1.2.5)
|
42
|
+
docile (1.1.5)
|
43
|
+
erubis (2.7.0)
|
44
|
+
faraday (0.9.0)
|
45
|
+
multipart-post (>= 1.2, < 3)
|
46
|
+
git (1.2.8)
|
47
|
+
github_api (0.12.1)
|
48
|
+
addressable (~> 2.3)
|
49
|
+
descendants_tracker (~> 0.0.4)
|
50
|
+
faraday (~> 0.8, < 0.10)
|
51
|
+
hashie (>= 3.2)
|
52
|
+
multi_json (>= 1.7.5, < 2.0)
|
53
|
+
nokogiri (~> 1.6.3)
|
54
|
+
oauth2
|
55
|
+
hashie (3.2.0)
|
56
|
+
highline (1.6.21)
|
57
|
+
hike (1.2.3)
|
58
|
+
i18n (0.6.11)
|
59
|
+
jeweler (2.0.1)
|
60
|
+
builder
|
61
|
+
bundler (>= 1.0)
|
62
|
+
git (>= 1.2.5)
|
63
|
+
github_api
|
64
|
+
highline (>= 1.6.15)
|
65
|
+
nokogiri (>= 1.5.10)
|
66
|
+
rake
|
67
|
+
rdoc
|
68
|
+
json (1.8.1)
|
69
|
+
jwt (1.0.0)
|
70
|
+
mail (2.5.4)
|
71
|
+
mime-types (~> 1.16)
|
72
|
+
treetop (~> 1.4.8)
|
73
|
+
mime-types (1.25.1)
|
74
|
+
mini_portile (0.6.0)
|
75
|
+
minitest (5.4.0)
|
76
|
+
multi_json (1.10.1)
|
77
|
+
multi_xml (0.5.5)
|
78
|
+
multipart-post (2.0.0)
|
79
|
+
nokogiri (1.6.3.1)
|
80
|
+
mini_portile (= 0.6.0)
|
81
|
+
oauth2 (1.0.0)
|
82
|
+
faraday (>= 0.8, < 0.10)
|
83
|
+
jwt (~> 1.0)
|
84
|
+
multi_json (~> 1.3)
|
85
|
+
multi_xml (~> 0.5)
|
86
|
+
rack (~> 1.2)
|
87
|
+
polyglot (0.3.5)
|
88
|
+
rack (1.5.2)
|
89
|
+
rack-test (0.6.2)
|
90
|
+
rack (>= 1.0)
|
91
|
+
rails (4.1.4)
|
92
|
+
actionmailer (= 4.1.4)
|
93
|
+
actionpack (= 4.1.4)
|
94
|
+
actionview (= 4.1.4)
|
95
|
+
activemodel (= 4.1.4)
|
96
|
+
activerecord (= 4.1.4)
|
97
|
+
activesupport (= 4.1.4)
|
98
|
+
bundler (>= 1.3.0, < 2.0)
|
99
|
+
railties (= 4.1.4)
|
100
|
+
sprockets-rails (~> 2.0)
|
101
|
+
railties (4.1.4)
|
102
|
+
actionpack (= 4.1.4)
|
103
|
+
activesupport (= 4.1.4)
|
104
|
+
rake (>= 0.8.7)
|
105
|
+
thor (>= 0.18.1, < 2.0)
|
106
|
+
rake (10.3.2)
|
107
|
+
rdoc (4.1.1)
|
108
|
+
json (~> 1.4)
|
109
|
+
rspec (3.0.0)
|
110
|
+
rspec-core (~> 3.0.0)
|
111
|
+
rspec-expectations (~> 3.0.0)
|
112
|
+
rspec-mocks (~> 3.0.0)
|
113
|
+
rspec-core (3.0.4)
|
114
|
+
rspec-support (~> 3.0.0)
|
115
|
+
rspec-expectations (3.0.4)
|
116
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
117
|
+
rspec-support (~> 3.0.0)
|
118
|
+
rspec-mocks (3.0.4)
|
119
|
+
rspec-support (~> 3.0.0)
|
120
|
+
rspec-support (3.0.4)
|
121
|
+
simplecov (0.9.0)
|
122
|
+
docile (~> 1.1.0)
|
123
|
+
multi_json
|
124
|
+
simplecov-html (~> 0.8.0)
|
125
|
+
simplecov-html (0.8.0)
|
126
|
+
sprockets (2.12.1)
|
127
|
+
hike (~> 1.2)
|
128
|
+
multi_json (~> 1.0)
|
129
|
+
rack (~> 1.0)
|
130
|
+
tilt (~> 1.1, != 1.3.0)
|
131
|
+
sprockets-rails (2.1.3)
|
132
|
+
actionpack (>= 3.0)
|
133
|
+
activesupport (>= 3.0)
|
134
|
+
sprockets (~> 2.8)
|
135
|
+
thor (0.19.1)
|
136
|
+
thread_safe (0.3.4)
|
137
|
+
tilt (1.4.1)
|
138
|
+
treetop (1.4.15)
|
139
|
+
polyglot
|
140
|
+
polyglot (>= 0.3.1)
|
141
|
+
tzinfo (1.2.2)
|
142
|
+
thread_safe (~> 0.1)
|
143
|
+
|
144
|
+
PLATFORMS
|
145
|
+
ruby
|
146
|
+
|
147
|
+
DEPENDENCIES
|
148
|
+
actionview
|
149
|
+
angularjs-rails
|
150
|
+
bundler
|
151
|
+
byebug
|
152
|
+
jeweler
|
153
|
+
rails
|
154
|
+
rdoc
|
155
|
+
rspec
|
156
|
+
simplecov
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2014 Gabe Scholz
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
# Angular Sprinkles
|
2
|
+
|
3
|
+
Sprinkles is a Ruby on Rails gem for developers who want to use Angular's two most powerful features, two-way data binding and
|
4
|
+
custom directives, without all of the regular setup required for a typical Angular-based application.
|
5
|
+
|
6
|
+
Sprinkles injects just enough JavaScript onto your page to make you dangerous. It is intended to be used by developers who just
|
7
|
+
want a sprinkle of Angular instead of a full-blown application.
|
8
|
+
|
9
|
+
## Setup
|
10
|
+
|
11
|
+
Add Angular and Sprinkles to your `Gemfile`
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
# Gemfile
|
15
|
+
|
16
|
+
gem 'angularjs-rails'
|
17
|
+
gem 'angular_sprinkles'
|
18
|
+
```
|
19
|
+
|
20
|
+
Add a yield method for your sprinkles at the bottom of your body tag
|
21
|
+
|
22
|
+
```erb
|
23
|
+
<%=# app/views/layouts/application.html.erb %>
|
24
|
+
<body>
|
25
|
+
|
26
|
+
<%= yield %>
|
27
|
+
|
28
|
+
<%= yield :sprinkles %>
|
29
|
+
</body>
|
30
|
+
```
|
31
|
+
|
32
|
+
Include Angular and Sprinkles into your `application.js`
|
33
|
+
|
34
|
+
```js
|
35
|
+
// app/assets/javascripts/application.js
|
36
|
+
|
37
|
+
//= require angular
|
38
|
+
//= require angular_sprinkles
|
39
|
+
//= require_tree .
|
40
|
+
```
|
41
|
+
|
42
|
+
That's it! You are now read to begin using Sprinkles in your application. There is no need to create an application module or
|
43
|
+
controller. Sprinkles dynamically generates this for you.
|
44
|
+
|
45
|
+
## Data binding
|
46
|
+
|
47
|
+
Two-way data binding with Sprinkles is easy. We can use the `bind` view helper to create a binding between two elements
|
48
|
+
|
49
|
+
```erb
|
50
|
+
<%=# some view %>
|
51
|
+
|
52
|
+
<span ng-bind="<%= bind(:user) %>"></span>
|
53
|
+
<input type="text" ng-model="<%= bind(:user) %>" />
|
54
|
+
```
|
55
|
+
|
56
|
+
We can also create nested data structures and Sprinkles handles creating parent objects for us
|
57
|
+
|
58
|
+
```erb
|
59
|
+
<%=# some view %>
|
60
|
+
|
61
|
+
Bind the entire object: <span ng-bind="<%= bind(:user) %>"></span>
|
62
|
+
|
63
|
+
Full Name: <span ng-bind="<%= bind(:user, :first_name) %> + ' ' + <%= bind(:user, :last_name) %>"></span>
|
64
|
+
First Name: <input type="text" ng-model="<%= bind(:user, :first_name) %>" />
|
65
|
+
Last Name: <input type="text" ng-model="<%= bind(:user, :last_name) %>" />
|
66
|
+
```
|
67
|
+
|
68
|
+
This is okay, but it would be nice to inject some data that already exists. We will use the `bindable` controller helper to wrap our objects
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
class UserController < ApplicationController
|
72
|
+
include AngularSprinkles::Controller
|
73
|
+
|
74
|
+
def show
|
75
|
+
@user = bindable(User.find(params[:id]))
|
76
|
+
end
|
77
|
+
```
|
78
|
+
|
79
|
+
Our user is now also able to use `bind`
|
80
|
+
|
81
|
+
```erb
|
82
|
+
<%=# some view %>
|
83
|
+
|
84
|
+
Bind the entire object: <span ng-bind="<%= @user.bind %>"></span>
|
85
|
+
|
86
|
+
Full Name: <span ng-bind="<%= @user.bind(:first_name) %> + ' ' + <%= @user.bind(:last_name) %>"></span>
|
87
|
+
First Name: <input type="text" ng-model="<%= @user.bind(:first_name) %>" />
|
88
|
+
Last Name: <input type="text" ng-model="<%= @user.bind(:last_name) %>" />
|
89
|
+
```
|
90
|
+
|
91
|
+
We've got two-way data binding of persisted data without writing a single line of javascript!
|
92
|
+
|
93
|
+
## Custom Directives
|
94
|
+
|
95
|
+
Sprinkles also comes packaged with a helper for instantiating custom directives.
|
96
|
+
|
97
|
+
In order to write custom directives, you must add them to the sprinkles module which is attached to the global `sprinkles` variable.
|
98
|
+
Let's create an element that blinks some text.
|
99
|
+
|
100
|
+
```js
|
101
|
+
// some js file
|
102
|
+
|
103
|
+
sprinkles.directive('blink', function ($interval) {
|
104
|
+
return {
|
105
|
+
restrict: 'A',
|
106
|
+
scope: {
|
107
|
+
interval: '=',
|
108
|
+
text: '='
|
109
|
+
},
|
110
|
+
template: '<span>{{text}}</span>',
|
111
|
+
link: function (scope, el) {
|
112
|
+
var opacity = 1;
|
113
|
+
|
114
|
+
scope.text = scope.text || 'Hello World!';
|
115
|
+
scope.interval = scope.interval || 1000;
|
116
|
+
|
117
|
+
$interval(function () {
|
118
|
+
el.css({ opacity: opacity });
|
119
|
+
opacity = -opacity + 1;
|
120
|
+
}, scope.interval);
|
121
|
+
}
|
122
|
+
}
|
123
|
+
});
|
124
|
+
```
|
125
|
+
|
126
|
+
```erb
|
127
|
+
<%=# some view %>
|
128
|
+
|
129
|
+
<%= directive(:blink, { interval: 250, text: 'Blink Me!' }) %>
|
130
|
+
```
|
131
|
+
|
132
|
+
"Blink Me!" will now flash on the screen. We can also combine this directive with the `bind` helper so that we can change the text on the fly
|
133
|
+
|
134
|
+
```erb
|
135
|
+
<%=# some view %>
|
136
|
+
|
137
|
+
<%= directive(:blink, { interval: 250, text: bind(:blink_text) }) %>
|
138
|
+
<input type="text" ng-model="<%= bind(:blink_text) %>" />
|
139
|
+
```
|
140
|
+
|
141
|
+
## Including additional modules
|
142
|
+
|
143
|
+
Adding additional modules is just a matter of appending them to `sprinkles.requires`. This is already a feature of Angular and not Sprinkles
|
144
|
+
|
145
|
+
```js
|
146
|
+
// some js file
|
147
|
+
|
148
|
+
sprinkles.requires.push('ui.router');
|
149
|
+
```
|
150
|
+
|
151
|
+
## Copyright
|
152
|
+
|
153
|
+
Copyright (c) 2014 Brewhouse Software. See LICENSE.txt for further details.
|
data/Rakefile
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
|
17
|
+
gem.name = "angular_sprinkles"
|
18
|
+
gem.homepage = "http://github.com/BrewhouseTeam/angular_sprinkles"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Add few sprinkles of AngularJS to your Rails App}
|
21
|
+
gem.description = %Q{Add few sprinkles of AngularJS to your Rails App}
|
22
|
+
gem.email = "gabe@brewhouse.io"
|
23
|
+
gem.authors = ["Gabe Scholz"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
desc "Code coverage detail"
|
35
|
+
task :simplecov do
|
36
|
+
ENV['COVERAGE'] = "true"
|
37
|
+
Rake::Task['spec'].execute
|
38
|
+
end
|
39
|
+
|
40
|
+
task :default => :spec
|
41
|
+
|
42
|
+
require 'rdoc/task'
|
43
|
+
Rake::RDocTask.new do |rdoc|
|
44
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
45
|
+
|
46
|
+
rdoc.rdoc_dir = 'rdoc'
|
47
|
+
rdoc.title = "angular_sprinkles #{version}"
|
48
|
+
rdoc.rdoc_files.include('README*')
|
49
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
50
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
@@ -0,0 +1,94 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
# stub: angular_sprinkles 0.0.1 ruby lib
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "angular_sprinkles"
|
9
|
+
s.version = "0.0.1"
|
10
|
+
|
11
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
|
+
s.require_paths = ["lib"]
|
13
|
+
s.authors = ["Gabe Scholz"]
|
14
|
+
s.date = "2014-08-22"
|
15
|
+
s.description = "Add few sprinkles of AngularJS to your Rails App"
|
16
|
+
s.email = "gabe@brewhouse.io"
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"LICENSE.txt",
|
19
|
+
"README.md"
|
20
|
+
]
|
21
|
+
s.files = [
|
22
|
+
".document",
|
23
|
+
".rspec",
|
24
|
+
"Gemfile",
|
25
|
+
"Gemfile.lock",
|
26
|
+
"LICENSE.txt",
|
27
|
+
"README.md",
|
28
|
+
"Rakefile",
|
29
|
+
"VERSION",
|
30
|
+
"angular_sprinkles.gemspec",
|
31
|
+
"app/assets/javascripts/angular_sprinkles.js.erb",
|
32
|
+
"lib/angular_sprinkles.rb",
|
33
|
+
"lib/angular_sprinkles/controller.rb",
|
34
|
+
"lib/angular_sprinkles/data/bind.rb",
|
35
|
+
"lib/angular_sprinkles/decorators.rb",
|
36
|
+
"lib/angular_sprinkles/decorators/bind_decorator.rb",
|
37
|
+
"lib/angular_sprinkles/engine.rb",
|
38
|
+
"lib/angular_sprinkles/helpers.rb",
|
39
|
+
"lib/angular_sprinkles/helpers/bind_helper.rb",
|
40
|
+
"lib/angular_sprinkles/helpers/directive_helper.rb",
|
41
|
+
"lib/angular_sprinkles/mixins/initializable.rb",
|
42
|
+
"lib/angular_sprinkles/mixins/js_transformable.rb",
|
43
|
+
"lib/angular_sprinkles/railtie.rb",
|
44
|
+
"spec/controller_spec.rb",
|
45
|
+
"spec/data/bind_spec.rb",
|
46
|
+
"spec/decorators/bind_decorator_spec.rb",
|
47
|
+
"spec/helpers/bind_helper_spec.rb",
|
48
|
+
"spec/helpers/directive_helper_spec.rb",
|
49
|
+
"spec/mixins/initializable_spec.rb",
|
50
|
+
"spec/mixins/js_transformable_spec.rb",
|
51
|
+
"spec/spec_helper.rb"
|
52
|
+
]
|
53
|
+
s.homepage = "http://github.com/BrewhouseTeam/angular_sprinkles"
|
54
|
+
s.licenses = ["MIT"]
|
55
|
+
s.rubygems_version = "2.4.1"
|
56
|
+
s.summary = "Add few sprinkles of AngularJS to your Rails App"
|
57
|
+
|
58
|
+
if s.respond_to? :specification_version then
|
59
|
+
s.specification_version = 4
|
60
|
+
|
61
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
62
|
+
s.add_runtime_dependency(%q<rails>, [">= 0"])
|
63
|
+
s.add_runtime_dependency(%q<actionview>, [">= 0"])
|
64
|
+
s.add_runtime_dependency(%q<angularjs-rails>, [">= 0"])
|
65
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
66
|
+
s.add_development_dependency(%q<rdoc>, [">= 0"])
|
67
|
+
s.add_development_dependency(%q<bundler>, [">= 0"])
|
68
|
+
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
69
|
+
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
70
|
+
s.add_development_dependency(%q<byebug>, [">= 0"])
|
71
|
+
else
|
72
|
+
s.add_dependency(%q<rails>, [">= 0"])
|
73
|
+
s.add_dependency(%q<actionview>, [">= 0"])
|
74
|
+
s.add_dependency(%q<angularjs-rails>, [">= 0"])
|
75
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
76
|
+
s.add_dependency(%q<rdoc>, [">= 0"])
|
77
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
78
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
79
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
80
|
+
s.add_dependency(%q<byebug>, [">= 0"])
|
81
|
+
end
|
82
|
+
else
|
83
|
+
s.add_dependency(%q<rails>, [">= 0"])
|
84
|
+
s.add_dependency(%q<actionview>, [">= 0"])
|
85
|
+
s.add_dependency(%q<angularjs-rails>, [">= 0"])
|
86
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
87
|
+
s.add_dependency(%q<rdoc>, [">= 0"])
|
88
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
89
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
90
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
91
|
+
s.add_dependency(%q<byebug>, [">= 0"])
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
//= require angular
|
2
|
+
|
3
|
+
window.sprinkles = angular.module('<%= AngularSprinkles::APP_NAME %>', []);
|
4
|
+
|
5
|
+
window.onload = function () {
|
6
|
+
var angular = window.angular,
|
7
|
+
app = angular.module('<%= AngularSprinkles::APP_NAME %>'),
|
8
|
+
doc = document.documentElement,
|
9
|
+
ctrlName = (doc.attributes['ng-controller'] || doc.attributes['data-ng-controller']) || 'Ctrl';
|
10
|
+
|
11
|
+
ctrlName = ctrlName.split(' as ')[0];
|
12
|
+
|
13
|
+
<%= AngularSprinkles::CONTROLLER_FN %> = <%= AngularSprinkles::CONTROLLER_FN %> || function(){};
|
14
|
+
app.controller(ctrlName, <%= AngularSprinkles::CONTROLLER_FN %>);
|
15
|
+
doc.setAttribute('data-ng-controller', ctrlName + ' as <%= AngularSprinkles::CONTROLLER_NAME %>');
|
16
|
+
|
17
|
+
angular.bootstrap(doc, [app.name]);
|
18
|
+
};
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'angular_sprinkles/mixins/js_transformable'
|
2
|
+
require 'angular_sprinkles/mixins/initializable'
|
3
|
+
require 'angular_sprinkles/decorators/bind_decorator'
|
4
|
+
|
5
|
+
module AngularSprinkles
|
6
|
+
module Controller
|
7
|
+
include AngularSprinkles::Mixins::JsTransformable
|
8
|
+
include AngularSprinkles::Mixins::Initializable
|
9
|
+
|
10
|
+
def bindable(object)
|
11
|
+
klass = object.class
|
12
|
+
key = "#{klass}_#{inc_sprinkles_counter(klass)}"
|
13
|
+
assignable(key => object)
|
14
|
+
AngularSprinkles::Decorators::Bind.new(object, key, method(:view_context))
|
15
|
+
end
|
16
|
+
|
17
|
+
def assignable(hash)
|
18
|
+
raise TypeError unless hash.is_a?(Hash)
|
19
|
+
declare_js_controller_prototype unless app_initialized?
|
20
|
+
preload_to_page(hash)
|
21
|
+
end
|
22
|
+
|
23
|
+
def view_context
|
24
|
+
@_sprinkles_view_context ||= super.tap do |view|
|
25
|
+
if sprinkles_content.any?
|
26
|
+
content = view.content_tag(:script, (sprinkles_content.join(";\n") + ';').html_safe)
|
27
|
+
view.content_for(:sprinkles, content)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def sprinkles_counter
|
35
|
+
@_sprinkles_counter ||= {}
|
36
|
+
end
|
37
|
+
|
38
|
+
def inc_sprinkles_counter(klass)
|
39
|
+
sprinkles_counter[klass] ||= 0
|
40
|
+
sprinkles_counter[klass] += 1
|
41
|
+
end
|
42
|
+
|
43
|
+
def declare_js_controller_prototype
|
44
|
+
sprinkles_content.push(AngularSprinkles::CONSTRUCTOR_DEFINITION)
|
45
|
+
end
|
46
|
+
|
47
|
+
def preload_to_page(hash)
|
48
|
+
hash.each do |var_name, value|
|
49
|
+
if !var_initialized?(var_name)
|
50
|
+
str = set_prototype_variable(var_name, value)
|
51
|
+
sprinkles_content.push(str)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
sprinkles_content
|
55
|
+
end
|
56
|
+
|
57
|
+
def sprinkles_content
|
58
|
+
@_sprinkles_content ||= []
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'angular_sprinkles/mixins/js_transformable'
|
2
|
+
|
3
|
+
module AngularSprinkles
|
4
|
+
module Data
|
5
|
+
class Bind
|
6
|
+
include Mixins::JsTransformable
|
7
|
+
|
8
|
+
def initialize(*strs)
|
9
|
+
@strs = strs.flatten.compact
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_json
|
13
|
+
to_ctrl_variable(@strs.join('.'))
|
14
|
+
end
|
15
|
+
alias_method :to_s, :to_json
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module AngularSprinkles
|
2
|
+
module Decorators
|
3
|
+
class Bind < SimpleDelegator
|
4
|
+
def initialize(object, key, context_proc)
|
5
|
+
@_sprinkles_bind_wrapper = Wrapper.new(object, key, context_proc)
|
6
|
+
super(object)
|
7
|
+
end
|
8
|
+
|
9
|
+
def bind(_method = nil)
|
10
|
+
@_sprinkles_bind_wrapper.bind(_method)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
class Wrapper
|
16
|
+
# create BindWrapper so that methods and variables don't pollute
|
17
|
+
# the object being wrapped by Bind
|
18
|
+
|
19
|
+
attr_reader :_object, :key, :context_proc
|
20
|
+
|
21
|
+
def initialize(object, key, context_proc)
|
22
|
+
@_object, @key, @context_proc = object, key, context_proc
|
23
|
+
end
|
24
|
+
|
25
|
+
def bind(_method = nil)
|
26
|
+
if _method.present? && !context.var_initialized?([key, _method])
|
27
|
+
set_prototype_variable_and_yield(_method)
|
28
|
+
end
|
29
|
+
|
30
|
+
context.bind(key, _method)
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def context
|
36
|
+
context_proc.call
|
37
|
+
end
|
38
|
+
|
39
|
+
def set_prototype_variable_and_yield(_method)
|
40
|
+
var = [key, _method].join('.')
|
41
|
+
str = context.set_prototype_variable(var, _object.send(_method))
|
42
|
+
yield_to_sprinkles("#{str};")
|
43
|
+
end
|
44
|
+
|
45
|
+
def yield_to_sprinkles(content)
|
46
|
+
context.content_for(:sprinkles) do
|
47
|
+
context.content_tag(:script, content.html_safe)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|