angular_sprinkles 0.2.10 → 0.2.11

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: ff497a789844351965389703418e3b5cae9b1c0c
4
- data.tar.gz: 4d438528165b334ccea8b9c847cdcc6cea92cd4a
3
+ metadata.gz: 68f766924279c886f5d635fe5de390204d62f2e7
4
+ data.tar.gz: de793ea045764fcbe4db8bff350386161247b514
5
5
  SHA512:
6
- metadata.gz: c6d40cdf9eca41e89d92bc60a91b93996a207b3bb65f536991091c14453dd94ec506de92c4bfa3f5db005aee0700f94eb5898a8e0c6e0b56206a79c5ff6b4f7d
7
- data.tar.gz: bb5d25e126014778a1219b391884df2865df8d8f4d0493938513587420aca99f0a1af6d44a4ce9b88558b5370b2d03d39c4cf394e70ec3aa2bd141d6862e5a6d
6
+ metadata.gz: cac41b688050c4b3054ef31a22d78dbfd008d063ea7524af5ba9b30abc3a22894787491722930efb2ad70ae1632ac0ed1d2e2d146da1fd92a5d4e86626986742
7
+ data.tar.gz: 16def7e9634067f93720d3dcc7660523a9440d59ace8e50cdc46d8f4e63f8a946675f34f751506bdce17f72ff3710bb096b802608c8e211da33a8307a4cd5e0f
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.10
1
+ 0.2.11
@@ -2,11 +2,11 @@
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.2.10 ruby lib
5
+ # stub: angular_sprinkles 0.2.11 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "angular_sprinkles"
9
- s.version = "0.2.10"
9
+ s.version = "0.2.11"
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"]
@@ -36,6 +36,7 @@ Gem::Specification.new do |s|
36
36
  "lib/angular_sprinkles/context.rb",
37
37
  "lib/angular_sprinkles/counter.rb",
38
38
  "lib/angular_sprinkles/directive/attributes.rb",
39
+ "lib/angular_sprinkles/directive/controller.rb",
39
40
  "lib/angular_sprinkles/directive/html.rb",
40
41
  "lib/angular_sprinkles/directive/input.rb",
41
42
  "lib/angular_sprinkles/directive/name.rb",
@@ -62,6 +63,7 @@ Gem::Specification.new do |s|
62
63
  "spec/angular_sprinkles/context_spec.rb",
63
64
  "spec/angular_sprinkles/counter_spec.rb",
64
65
  "spec/angular_sprinkles/directive/attributes_spec.rb",
66
+ "spec/angular_sprinkles/directive/controller_spec.rb",
65
67
  "spec/angular_sprinkles/directive/html_spec.rb",
66
68
  "spec/angular_sprinkles/directive/input_spec.rb",
67
69
  "spec/angular_sprinkles/directive/name_spec.rb",
@@ -0,0 +1,20 @@
1
+ module AngularSprinkles
2
+ module Directive
3
+ class Controller
4
+ def initialize(args)
5
+ @name = args.fetch(:name)
6
+ @object_wrapper = args.fetch(:object_wrapper)
7
+ @bind_json_wrapper = args.fetch(:bind_json_wrapper)
8
+ @call_json_wrapper = args.fetch(:call_json_wrapper)
9
+ end
10
+
11
+ def bind(attribute = nil)
12
+ @object_wrapper.new(@name, attribute, @bind_json_wrapper)
13
+ end
14
+
15
+ def call(function, *input)
16
+ @object_wrapper.new(@name, function, input, @call_json_wrapper)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -2,7 +2,16 @@ module AngularSprinkles
2
2
  module Helpers
3
3
  module DirectiveHelper
4
4
  def directive(directive_name, options = {}, &block)
5
- content = capture(&block) if block_given?
5
+ if block_given?
6
+ controller = Directive::Controller.new({
7
+ name: "#{directive_name.to_s.camelize(:lower)}Ctrl",
8
+ object_wrapper: ObjectKeyWrapper,
9
+ bind_json_wrapper: JavaScript::NoOp,
10
+ call_json_wrapper: JavaScript::BindService
11
+ })
12
+
13
+ content = capture(controller, &block)
14
+ end
6
15
 
7
16
  name = Directive::Name.new(directive_name)
8
17
  input = Directive::Input.new(options.except(:html))
@@ -7,7 +7,7 @@ module AngularSprinkles
7
7
  register_service = ObjectKeyWrapper.new(camelized, JavaScript::RegisterService)
8
8
  @_sprinkles.content_yielder.call(register_service)
9
9
 
10
- ObjectKeyWrapper.new(camelized, input, JavaScript::BindService)
10
+ ObjectKeyWrapper.new(camelized, input, JavaScript::BindRootService)
11
11
  end
12
12
  end
13
13
  end
@@ -53,8 +53,12 @@ module AngularSprinkles
53
53
  "#{SERVICE_QUEUE}.push('#{method}')"
54
54
  end
55
55
 
56
- BindService = ->(method, input) do
57
- "#{CONTROLLER_NAME}.#{method}(#{input.join(',')})"
56
+ BindRootService = ->(*args) do
57
+ BindService.call(CONTROLLER_NAME, *args)
58
+ end
59
+
60
+ BindService = ->(controller_name, method, input) do
61
+ "#{controller_name}.#{method}(#{input.map(&:to_json).join(',')})"
58
62
  end
59
63
 
60
64
  RegisterVariable = ->(*args) do
@@ -71,11 +75,11 @@ module AngularSprinkles
71
75
  end
72
76
 
73
77
  BindVariable = ->(*args) do
74
- [CONTROLLER_NAME, *args].flatten.compact.join('.')
78
+ NoOp.call(*[CONTROLLER_NAME, *args])
75
79
  end
76
80
 
77
81
  NoOp = ->(*args) do
78
- args.join('.')
82
+ args.flatten.compact.join('.')
79
83
  end
80
84
  end
81
85
  end
@@ -3,6 +3,7 @@ require "angular_sprinkles/constructor"
3
3
  require "angular_sprinkles/constructor_collection"
4
4
  require "angular_sprinkles/content_yielder"
5
5
  require "angular_sprinkles/directive/attributes"
6
+ require "angular_sprinkles/directive/controller"
6
7
  require "angular_sprinkles/directive/input"
7
8
  require "angular_sprinkles/directive/name"
8
9
  require "angular_sprinkles/directive/html"
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe AngularSprinkles::Directive::Controller do
4
+ let(:name) { double }
5
+ let(:object_wrapper) { double }
6
+ let(:bind_json_wrapper) { double }
7
+ let(:call_json_wrapper) { double }
8
+
9
+ subject do
10
+ described_class.new({
11
+ name: name,
12
+ object_wrapper: object_wrapper,
13
+ bind_json_wrapper: bind_json_wrapper,
14
+ call_json_wrapper: call_json_wrapper
15
+ })
16
+ end
17
+
18
+ describe "#bind" do
19
+ it "wraps the controller name" do
20
+ attribute = double
21
+
22
+ expect(object_wrapper).to receive(:new).with(name, attribute, bind_json_wrapper)
23
+ subject.bind(attribute)
24
+
25
+ expect(object_wrapper).to receive(:new).with(name, nil, bind_json_wrapper)
26
+ subject.bind
27
+ end
28
+ end
29
+
30
+ describe "#call" do
31
+ it "wraps the controller name" do
32
+ function = double
33
+ input = [double, double]
34
+
35
+ expect(object_wrapper).to receive(:new).with(name, function, input, call_json_wrapper)
36
+ subject.call(function, *input)
37
+ end
38
+ end
39
+ end
@@ -12,7 +12,7 @@ describe AngularSprinkles::ModelDecorator do
12
12
  end
13
13
 
14
14
  describe "#bind" do
15
- it 'returns a binding object' do
15
+ it "returns a binding object" do
16
16
  expect(object_wrapper).to receive(:new).with(key, attribute, json_wrapper)
17
17
  subject.bind(attribute)
18
18
 
@@ -21,4 +21,10 @@ describe AngularSprinkles::ModelDecorator do
21
21
  end
22
22
  end
23
23
 
24
+ describe "#class" do
25
+ it "delegates to the wrapped object" do
26
+ expect(subject.class).to eq(object.class)
27
+ end
28
+ end
29
+
24
30
  end
@@ -25,6 +25,20 @@ sprinkles.service('formSubmitted', function () {
25
25
  };
26
26
  });
27
27
 
28
+ sprinkles.directive('bigHelloWorld', function () {
29
+ return {
30
+ scope: true,
31
+ controllerAs: 'bigHelloWorldCtrl',
32
+ controller: function () {
33
+ this.attribute = 'bigHelloWorldCtrlAttribute';
34
+
35
+ this.func = function (name) {
36
+ return name;
37
+ };
38
+ }
39
+ }
40
+ });
41
+
28
42
  sprinkles.directive('nestedDirective', function () {
29
43
  return {
30
44
  scope: {
@@ -2,7 +2,10 @@
2
2
  <div id="bind-service-div" ng-bind="<%= service(:hello_world, @model.bind(:name)) %>"></div>
3
3
  <div id="bind-div" ng-bind="<%= bind(:hello, :world) %>"></div>
4
4
 
5
- <%= directive(:big_hello_world, html: { id: "directive-div" }) do %>
5
+ <%= directive(:big_hello_world, html: { id: "directive-div" }) do |ctrl| %>
6
+ <div id="directive-ctrl-bind" ng-bind="<%= ctrl.bind(:attribute) %>"></div>
7
+ <div id="directive-ctrl-call" ng-bind="<%= ctrl.call(:func, 'func result') %>"></div>
8
+
6
9
  <%= directive(:nested_directive, name: @model.bind(:name), html: { tag: 'h1' }) %>
7
10
  <% end %>
8
11
 
@@ -17,7 +17,6 @@ feature "javascript_bindings", js: true do
17
17
  # this element starts out empty
18
18
  expect { find("#bind-div") }.to raise_error
19
19
 
20
-
21
20
  fill_in("Input", with: new_name)
22
21
  expect(find("#data-binding-div")).to have_content(new_name)
23
22
  expect(find("#bind-service-div")).to have_content("Hello #{new_name}")
@@ -25,5 +24,9 @@ feature "javascript_bindings", js: true do
25
24
 
26
25
  fill_in("Bind", with: new_name)
27
26
  expect(find("#bind-div")).to have_content(new_name)
27
+
28
+ # directive controller results
29
+ expect(find("#directive-ctrl-bind")).to have_content("bigHelloWorldCtrlAttribute")
30
+ expect(find("#directive-ctrl-call")).to have_content('func result')
28
31
  end
29
32
  end
data/spec/spec_helper.rb CHANGED
@@ -1,9 +1,7 @@
1
1
  if ENV["COVERALLS_REPO_TOKEN"]
2
2
  require "coveralls"
3
3
  Coveralls.wear! do
4
- add_filter 'dummy'
5
- add_filter 'rails_helper.rb'
6
- add_filter 'spec_helper.rb'
4
+ add_filter 'spec'
7
5
  end
8
6
  end
9
7
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: angular_sprinkles
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.10
4
+ version: 0.2.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabe Scholz
@@ -83,6 +83,7 @@ files:
83
83
  - lib/angular_sprinkles/context.rb
84
84
  - lib/angular_sprinkles/counter.rb
85
85
  - lib/angular_sprinkles/directive/attributes.rb
86
+ - lib/angular_sprinkles/directive/controller.rb
86
87
  - lib/angular_sprinkles/directive/html.rb
87
88
  - lib/angular_sprinkles/directive/input.rb
88
89
  - lib/angular_sprinkles/directive/name.rb
@@ -109,6 +110,7 @@ files:
109
110
  - spec/angular_sprinkles/context_spec.rb
110
111
  - spec/angular_sprinkles/counter_spec.rb
111
112
  - spec/angular_sprinkles/directive/attributes_spec.rb
113
+ - spec/angular_sprinkles/directive/controller_spec.rb
112
114
  - spec/angular_sprinkles/directive/html_spec.rb
113
115
  - spec/angular_sprinkles/directive/input_spec.rb
114
116
  - spec/angular_sprinkles/directive/name_spec.rb