angular_sprinkles 0.0.9 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -2
- data/Gemfile.lock +2 -2
- data/README.md +4 -1
- data/VERSION +1 -1
- data/angular_sprinkles.gemspec +10 -9
- data/lib/angular_sprinkles.rb +1 -0
- data/lib/angular_sprinkles/helpers.rb +2 -1
- data/lib/angular_sprinkles/helpers/bind_helper.rb +14 -0
- data/lib/angular_sprinkles/helpers/service_helper.rb +2 -2
- data/lib/angular_sprinkles/java_script.rb +19 -2
- data/spec/angular_sprinkles/constructor_collection_spec.rb +1 -6
- data/spec/angular_sprinkles/content_yielder_spec.rb +2 -12
- data/spec/angular_sprinkles/context_spec.rb +4 -4
- data/spec/angular_sprinkles/directive/attributes_spec.rb +4 -9
- data/spec/angular_sprinkles/key_generator_spec.rb +2 -6
- data/spec/angular_sprinkles/model_decorator_spec.rb +2 -2
- data/spec/dummy/app/views/test/new.html.erb +10 -2
- data/spec/features/javascript_spec.rb +8 -2
- metadata +15 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 43af97b13d208a75928debe2dedf10426a0470a4
|
4
|
+
data.tar.gz: cb7babecbd9b850ba8d23c80d9580f64ee91bff8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f47f112dacb01baf3afae724b08778257a4b2569a19b824589ce3b92f1ec78293792e7e5f18813e2fba79a19591f1ec556af76a16da808837f80a719bf20b63f
|
7
|
+
data.tar.gz: 0397bac1e5cb7337ff27a541fb01496e9a939b961c8236b05dac3bae7e1e4d52517566a7c0d592e434d1f08b26b1fc56801e6d2c2a997496afd005031b8d7942
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -8,7 +8,7 @@ Angular Sprinkles is a gem for writing Rails-flavored AngularJS.
|
|
8
8
|
|
9
9
|
- __No frontend setup required:__ By just requiring it in your project, Sprinkles dynamically generates an Angular application around your Rails templates. It's never been easier to start developing with Angular and Rails.
|
10
10
|
- __Rails as it was intended to be written:__ Angular's two-way data binding, directives, and function calls are all done in the view via helper methods, giving you just a sprinkle of JavaScript.
|
11
|
-
-
|
11
|
+
- __A cleaner approach to JavaScript:__ Sprinkles allows you to continue to write Rails applications as you always have without all of the nasty jQuery spaghetti.
|
12
12
|
|
13
13
|
## Examples
|
14
14
|
|
@@ -56,11 +56,14 @@ sprinkles.service('alertMe', function () {
|
|
56
56
|
<button ng-click="<%= service(:alert_me, "world") %>">Click me!</button>
|
57
57
|
```
|
58
58
|
|
59
|
+
Also see the [demo application](https://github.com/BrewhouseTeam/angular_sprinkles_example) for more examples.
|
60
|
+
|
59
61
|
## Setup
|
60
62
|
|
61
63
|
Add `angular_sprinkles` to your `Gemfile`.
|
62
64
|
|
63
65
|
```ruby
|
66
|
+
gem 'angularjs-rails'
|
64
67
|
gem 'angular_sprinkles'
|
65
68
|
```
|
66
69
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
data/angular_sprinkles.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: angular_sprinkles 0.0
|
5
|
+
# stub: angular_sprinkles 0.1.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "angular_sprinkles"
|
9
|
-
s.version = "0.0
|
9
|
+
s.version = "0.1.0"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Gabe Scholz"]
|
14
|
-
s.date = "2014-09-
|
14
|
+
s.date = "2014-09-19"
|
15
15
|
s.description = "Add a few sprinkles of AngularJS to your Rails App"
|
16
16
|
s.email = "gabe@brewhouse.io"
|
17
17
|
s.extra_rdoc_files = [
|
@@ -42,6 +42,7 @@ Gem::Specification.new do |s|
|
|
42
42
|
"lib/angular_sprinkles/directive/name.rb",
|
43
43
|
"lib/angular_sprinkles/engine.rb",
|
44
44
|
"lib/angular_sprinkles/helpers.rb",
|
45
|
+
"lib/angular_sprinkles/helpers/bind_helper.rb",
|
45
46
|
"lib/angular_sprinkles/helpers/directive_helper.rb",
|
46
47
|
"lib/angular_sprinkles/helpers/service_helper.rb",
|
47
48
|
"lib/angular_sprinkles/java_script.rb",
|
@@ -122,17 +123,17 @@ Gem::Specification.new do |s|
|
|
122
123
|
s.specification_version = 4
|
123
124
|
|
124
125
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
125
|
-
s.add_runtime_dependency(%q<rails>, [">=
|
126
|
-
s.add_runtime_dependency(%q<angularjs-rails>, ["
|
126
|
+
s.add_runtime_dependency(%q<rails>, ["< 5", ">= 3"])
|
127
|
+
s.add_runtime_dependency(%q<angularjs-rails>, ["~> 1"])
|
127
128
|
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
128
129
|
else
|
129
|
-
s.add_dependency(%q<rails>, [">=
|
130
|
-
s.add_dependency(%q<angularjs-rails>, ["
|
130
|
+
s.add_dependency(%q<rails>, ["< 5", ">= 3"])
|
131
|
+
s.add_dependency(%q<angularjs-rails>, ["~> 1"])
|
131
132
|
s.add_dependency(%q<jeweler>, [">= 0"])
|
132
133
|
end
|
133
134
|
else
|
134
|
-
s.add_dependency(%q<rails>, [">=
|
135
|
-
s.add_dependency(%q<angularjs-rails>, ["
|
135
|
+
s.add_dependency(%q<rails>, ["< 5", ">= 3"])
|
136
|
+
s.add_dependency(%q<angularjs-rails>, ["~> 1"])
|
136
137
|
s.add_dependency(%q<jeweler>, [">= 0"])
|
137
138
|
end
|
138
139
|
end
|
data/lib/angular_sprinkles.rb
CHANGED
@@ -10,6 +10,7 @@ require "angular_sprinkles/context"
|
|
10
10
|
require "angular_sprinkles/controller"
|
11
11
|
require "angular_sprinkles/counter"
|
12
12
|
require "angular_sprinkles/engine"
|
13
|
+
require "angular_sprinkles/helpers/bind_helper"
|
13
14
|
require "angular_sprinkles/helpers/directive_helper"
|
14
15
|
require "angular_sprinkles/helpers/service_helper"
|
15
16
|
require "angular_sprinkles/helpers"
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module AngularSprinkles
|
2
|
+
module Helpers
|
3
|
+
module BindHelper
|
4
|
+
def bind(*input)
|
5
|
+
camelized = input.map(&:to_s).map { |i| i.camelize(:lower) }
|
6
|
+
|
7
|
+
register_service = ObjectKeyWrapper.new(*camelized, JavaScript::RegisterVariable)
|
8
|
+
@_sprinkles.content_yielder.call(register_service)
|
9
|
+
|
10
|
+
ObjectKeyWrapper.new(*camelized, JavaScript::BindVariable)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module AngularSprinkles
|
2
2
|
module Helpers
|
3
3
|
module ServiceHelper
|
4
|
-
def service(
|
5
|
-
camelized =
|
4
|
+
def service(name, *input)
|
5
|
+
camelized = name.to_s.camelize(:lower)
|
6
6
|
|
7
7
|
register_service = ObjectKeyWrapper.new(camelized, JavaScript::RegisterService)
|
8
8
|
@_sprinkles.content_yielder.call(register_service)
|
@@ -45,6 +45,10 @@ module AngularSprinkles
|
|
45
45
|
"this.#{key} = #{object.to_json};"
|
46
46
|
end
|
47
47
|
|
48
|
+
ControllerPrototypeVariable = ->(*args) do
|
49
|
+
"#{CONTROLLER_FN}.prototype.#{args.join('.')}"
|
50
|
+
end
|
51
|
+
|
48
52
|
RegisterService = ->(method) do
|
49
53
|
"#{SERVICE_QUEUE}.push('#{method}')"
|
50
54
|
end
|
@@ -53,8 +57,21 @@ module AngularSprinkles
|
|
53
57
|
"#{CONTROLLER_NAME}.#{method}(#{input.join(',')})"
|
54
58
|
end
|
55
59
|
|
56
|
-
|
57
|
-
|
60
|
+
RegisterVariable = ->(*args) do
|
61
|
+
args.pop
|
62
|
+
|
63
|
+
acc, _ = args.inject(['', []]) do |(acc, store), arg|
|
64
|
+
store.push(arg)
|
65
|
+
prototype = ControllerPrototypeVariable.call(store)
|
66
|
+
acc += "#{prototype} = #{prototype} || {};\n"
|
67
|
+
[acc, store]
|
68
|
+
end
|
69
|
+
|
70
|
+
acc
|
71
|
+
end
|
72
|
+
|
73
|
+
BindVariable = ->(*args) do
|
74
|
+
[CONTROLLER_NAME, *args].flatten.compact.join('.')
|
58
75
|
end
|
59
76
|
end
|
60
77
|
end
|
@@ -2,13 +2,8 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe AngularSprinkles::ConstructorCollection do
|
4
4
|
let(:json_wrapper) { ->{} }
|
5
|
-
let(:object_wrapper) { Object.new }
|
6
|
-
|
7
5
|
let(:stub) { "stub" }
|
8
|
-
|
9
|
-
before do
|
10
|
-
allow(object_wrapper).to receive(:new).and_return(stub)
|
11
|
-
end
|
6
|
+
let(:object_wrapper) { double(new: stub) }
|
12
7
|
|
13
8
|
subject { described_class.new(json_wrapper: json_wrapper, object_wrapper: object_wrapper) }
|
14
9
|
|
@@ -2,23 +2,15 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe AngularSprinkles::ContentYielder do
|
4
4
|
let(:context) { ActionController::Base.new.view_context }
|
5
|
-
let(:cache) { Object.new }
|
6
5
|
let(:yield_to) { :yield_to }
|
7
6
|
let(:content) { 'content' }
|
8
7
|
|
9
8
|
subject { described_class.new(context: context, cache: cache, yield_to: yield_to) }
|
10
9
|
|
11
|
-
before do
|
12
|
-
allow(cache).to receive(:set).and_return(true)
|
13
|
-
end
|
14
|
-
|
15
10
|
context "when the content hasn't yet been set" do
|
11
|
+
let(:cache) { double(set: true, set?: false) }
|
16
12
|
let(:script_tag) { "<script>#{content.to_json}</script>" }
|
17
13
|
|
18
|
-
before do
|
19
|
-
allow(cache).to receive(:set?).and_return(false)
|
20
|
-
end
|
21
|
-
|
22
14
|
it 'returns a script tag' do
|
23
15
|
expect(subject.call(content)).to eq(script_tag)
|
24
16
|
end
|
@@ -33,9 +25,7 @@ describe AngularSprinkles::ContentYielder do
|
|
33
25
|
end
|
34
26
|
|
35
27
|
context "when the content has been set" do
|
36
|
-
|
37
|
-
allow(cache).to receive(:set?).and_return(true)
|
38
|
-
end
|
28
|
+
let(:cache) { double(set: true, set?: true) }
|
39
29
|
|
40
30
|
it 'returns an empty string' do
|
41
31
|
expect(subject.call(content)).to eq('')
|
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe AngularSprinkles::Context do
|
4
|
-
let(:key_generator) {
|
5
|
-
let(:constructor) {
|
6
|
-
let(:constructor_collection) {
|
7
|
-
let(:view_context) {
|
4
|
+
let(:key_generator) { double }
|
5
|
+
let(:constructor) { double }
|
6
|
+
let(:constructor_collection) { double }
|
7
|
+
let(:view_context) { double }
|
8
8
|
|
9
9
|
subject do
|
10
10
|
described_class.new({
|
@@ -1,18 +1,13 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe AngularSprinkles::Directive::Attributes do
|
4
|
-
let(:
|
5
|
-
|
6
|
-
let(:
|
7
|
-
let(:
|
8
|
-
let(:options) { stub }
|
4
|
+
let(:something) { double(attributes: {}) }
|
5
|
+
let(:name) { something }
|
6
|
+
let(:input) { something }
|
7
|
+
let(:options) { something }
|
9
8
|
let(:content) { 'content' }
|
10
9
|
let(:tag) { :div }
|
11
10
|
|
12
|
-
before do
|
13
|
-
allow(stub).to receive(:attributes).and_return({})
|
14
|
-
end
|
15
|
-
|
16
11
|
subject do
|
17
12
|
described_class.new([name, input, options], content: content, tag: tag)
|
18
13
|
end
|
@@ -1,13 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe AngularSprinkles::KeyGenerator do
|
4
|
-
let(:counter) {
|
4
|
+
let(:counter) { double(inc: inc) }
|
5
5
|
let(:inc) { 1 }
|
6
|
-
let(:object) {
|
7
|
-
|
8
|
-
before do
|
9
|
-
allow(counter).to receive(:inc).with(object.class).and_return(inc)
|
10
|
-
end
|
6
|
+
let(:object) { double }
|
11
7
|
|
12
8
|
subject { described_class.new(counter: counter) }
|
13
9
|
|
@@ -2,10 +2,10 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe AngularSprinkles::ModelDecorator do
|
4
4
|
let(:key) { 'key' }
|
5
|
-
let(:object) {
|
5
|
+
let(:object) { double }
|
6
6
|
let(:attribute) { :a }
|
7
7
|
let(:json_wrapper) { ->(key, attribute) { "#{key}+#{attribute}"} }
|
8
|
-
let(:object_wrapper) {
|
8
|
+
let(:object_wrapper) { double }
|
9
9
|
|
10
10
|
subject do
|
11
11
|
described_class.new(key: key, object: object, json_wrapper: json_wrapper, object_wrapper: object_wrapper)
|
@@ -1,9 +1,17 @@
|
|
1
1
|
<div id="data-binding-div" ng-bind="<%= @model.bind(:name) %>"></div>
|
2
2
|
<div id="bind-service-div" ng-bind="<%= service(:hello_world, @model.bind(:name)) %>"></div>
|
3
|
+
<div id="bind-div" ng-bind="<%= bind(:hello, :world) %>"></div>
|
3
4
|
|
4
5
|
<%= directive(:big_hello_world, html: { id: "directive-div" }) do %>
|
5
6
|
<%= directive(:nested_directive, name: @model.bind(:name), html: { tag: 'h1' }) %>
|
6
7
|
<% end %>
|
7
8
|
|
8
|
-
<
|
9
|
-
<
|
9
|
+
<div id="model-bind">
|
10
|
+
<label for="input">Input</label>
|
11
|
+
<input id="input" name="input" type="text" ng-model="<%= @model.bind(:name) %>" />
|
12
|
+
</div>
|
13
|
+
|
14
|
+
<div id="bind-bind">
|
15
|
+
<label for="bind">Bind</label>
|
16
|
+
<input id="bind" name="bind" type="text" ng-model="<%= bind(:hello, :world) %>" />
|
17
|
+
</div>
|
@@ -12,15 +12,21 @@ feature "javascript", js: true do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
it "should test all the things" do
|
15
|
+
# these elements start with the @model binding
|
15
16
|
expect(find("#data-binding-div")).to have_content(name)
|
16
17
|
expect(find("#bind-service-div")).to have_content("Hello #{name}")
|
17
18
|
expect(find("#directive-div h1 h2")).to have_content(name)
|
18
19
|
|
19
|
-
|
20
|
+
# this element starts out empty
|
21
|
+
expect { find("#bind-div") }.to raise_error
|
22
|
+
|
20
23
|
|
24
|
+
fill_in("Input", with: new_name)
|
21
25
|
expect(find("#data-binding-div")).to have_content(new_name)
|
22
26
|
expect(find("#bind-service-div")).to have_content("Hello #{new_name}")
|
23
|
-
|
24
27
|
expect(find("#directive-div h1 h2")).to have_content(new_name)
|
28
|
+
|
29
|
+
fill_in("Bind", with: new_name)
|
30
|
+
expect(find("#bind-div")).to have_content(new_name)
|
25
31
|
end
|
26
32
|
end
|
metadata
CHANGED
@@ -1,43 +1,49 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: angular_sprinkles
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gabe Scholz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
+
- - "<"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5'
|
17
20
|
- - ">="
|
18
21
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
22
|
+
version: '3'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
27
|
+
- - "<"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '5'
|
24
30
|
- - ">="
|
25
31
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
32
|
+
version: '3'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: angularjs-rails
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
30
36
|
requirements:
|
31
|
-
- - "
|
37
|
+
- - "~>"
|
32
38
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
39
|
+
version: '1'
|
34
40
|
type: :runtime
|
35
41
|
prerelease: false
|
36
42
|
version_requirements: !ruby/object:Gem::Requirement
|
37
43
|
requirements:
|
38
|
-
- - "
|
44
|
+
- - "~>"
|
39
45
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
46
|
+
version: '1'
|
41
47
|
- !ruby/object:Gem::Dependency
|
42
48
|
name: jeweler
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -83,6 +89,7 @@ files:
|
|
83
89
|
- lib/angular_sprinkles/directive/name.rb
|
84
90
|
- lib/angular_sprinkles/engine.rb
|
85
91
|
- lib/angular_sprinkles/helpers.rb
|
92
|
+
- lib/angular_sprinkles/helpers/bind_helper.rb
|
86
93
|
- lib/angular_sprinkles/helpers/directive_helper.rb
|
87
94
|
- lib/angular_sprinkles/helpers/service_helper.rb
|
88
95
|
- lib/angular_sprinkles/java_script.rb
|