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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dafbcaba32994ad34dc1f4a823842cfbca68fbdc
4
- data.tar.gz: c8b63cd4e09c91447ca816e4dc87ab8ed1653161
3
+ metadata.gz: 43af97b13d208a75928debe2dedf10426a0470a4
4
+ data.tar.gz: cb7babecbd9b850ba8d23c80d9580f64ee91bff8
5
5
  SHA512:
6
- metadata.gz: d2713e0baf4e6969edf8c5d48916bebd8b91bf0d833fd91a6fe73fd7cd77c3bced85620cccabe5cae9ea3a618643980b62feef80801be40c93c43b0f92bbc53d
7
- data.tar.gz: b9c31e8430583dee715be944325215a0f5906f01db398d7cb5814af23d829e1c89a2a03a00e1bc41aa58a9488e6cf017acb8f23a4eedab863360cba50876a8bc
6
+ metadata.gz: f47f112dacb01baf3afae724b08778257a4b2569a19b824589ce3b92f1ec78293792e7e5f18813e2fba79a19591f1ec556af76a16da808837f80a719bf20b63f
7
+ data.tar.gz: 0397bac1e5cb7337ff27a541fb01496e9a939b961c8236b05dac3bae7e1e4d52517566a7c0d592e434d1f08b26b1fc56801e6d2c2a997496afd005031b8d7942
data/Gemfile CHANGED
@@ -1,7 +1,7 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- gem "rails"
4
- gem "angularjs-rails"
3
+ gem "rails", ">= 3", "< 5"
4
+ gem "angularjs-rails", "~> 1"
5
5
 
6
6
  group :development do
7
7
  gem "jeweler"
data/Gemfile.lock CHANGED
@@ -178,12 +178,12 @@ PLATFORMS
178
178
  ruby
179
179
 
180
180
  DEPENDENCIES
181
- angularjs-rails
181
+ angularjs-rails (~> 1)
182
182
  capybara
183
183
  coveralls
184
184
  jeweler
185
185
  launchy
186
- rails
186
+ rails (>= 3, < 5)
187
187
  rspec-rails
188
188
  selenium-webdriver
189
189
  sqlite3
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
- - __Forget about the SPA:__ If you're not using Rails an API, trying to build an SPA on top of it is a huge pain. Sprinkles allows you to continue to write Rails applications as you always have without all of the nasty jQuery spaghetti.
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.9
1
+ 0.1.0
@@ -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.9 ruby lib
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"
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-13"
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>, [">= 0"])
126
- s.add_runtime_dependency(%q<angularjs-rails>, [">= 0"])
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>, [">= 0"])
130
- s.add_dependency(%q<angularjs-rails>, [">= 0"])
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>, [">= 0"])
135
- s.add_dependency(%q<angularjs-rails>, [">= 0"])
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
@@ -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"
@@ -1,6 +1,7 @@
1
1
  module AngularSprinkles
2
2
  module Helpers
3
- include ServiceHelper
3
+ include BindHelper
4
4
  include DirectiveHelper
5
+ include ServiceHelper
5
6
  end
6
7
  end
@@ -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(service, *input)
5
- camelized = service.to_s.camelize(:lower)
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
- BindVariable = ->(key, attribute) do
57
- [CONTROLLER_NAME, key, attribute].flatten.compact.join('.')
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
- before do
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) { Object.new }
5
- let(:constructor) { Object.new }
6
- let(:constructor_collection) { Object.new }
7
- let(:view_context) { Object.new }
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(:stub) { Object.new }
5
-
6
- let(:name) { stub }
7
- let(:input) { stub }
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) { Object.new }
4
+ let(:counter) { double(inc: inc) }
5
5
  let(:inc) { 1 }
6
- let(:object) { Object.new }
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) { Object.new }
5
+ let(:object) { double }
6
6
  let(:attribute) { :a }
7
7
  let(:json_wrapper) { ->(key, attribute) { "#{key}+#{attribute}"} }
8
- let(:object_wrapper) { Array }
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
- <label for="input">Input</label>
9
- <input id="input" name="input" type="text" ng-model="<%= @model.bind(:name) %>" />
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
- fill_in("Input", with: new_name)
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.9
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-13 00:00:00.000000000 Z
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: '0'
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: '0'
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: '0'
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: '0'
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