magicka 0.3.1 → 0.4.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
  SHA256:
3
- metadata.gz: 7939778de2faac419e42a17986de873d7cbefa0b65531dcc968f697411e0ee7a
4
- data.tar.gz: 831909938f84d296ba8706893b13c5ef7bf9f5b16e2d57cb10986e83151a2ed3
3
+ metadata.gz: 81717f300e575454157f07d2e37f93b68a43aee24374cc84d49142f3815b26de
4
+ data.tar.gz: f50c9807efb97e1fa9719f010c39d261eb6fe9ccf12d3a199c33521b515ea2ae
5
5
  SHA512:
6
- metadata.gz: 74b61fb09691f38d280b08adde917d838866b918f23d4b9a530bf0f43cd22d8c963980bd5e02de23b89e601bbb708fd374da6e5285e7507d33e1b319fe9937a7
7
- data.tar.gz: 8a263ca1eb2a0fc180e4fdc9eff054aede6452e19819d788b1e6c3f203875104ea177c1f2b8d38b14d5909d506528fb2a621fcdb4aafe9ab7ff49513bac3509e
6
+ metadata.gz: ede839d74d03176271d66aaf5ac672cdf0774e3be38edcf7306414de16f64fea51f73b3390c184f684c1c9189978bc045d51f8f0a1dc7d5e408432fd7b3863fa
7
+ data.tar.gz: e67ed028a79ef8dbfdb1ed0c16e592df1749941429002cc5f83522bb744b16a20fee771004326a853165d25d11beb7376bd7fee5243d4e398556426c256e1fcd
data/README.md CHANGED
@@ -11,7 +11,7 @@ Magicka
11
11
 
12
12
  Yard Documentation
13
13
  -------------------
14
- [https://www.rubydoc.info/gems/magicka/0.3.1](https://www.rubydoc.info/gems/magicka/0.3.1)
14
+ [https://www.rubydoc.info/gems/magicka/0.4.0](https://www.rubydoc.info/gems/magicka/0.4.0)
15
15
 
16
16
  Installation
17
17
  ---------------
@@ -1,4 +1,4 @@
1
- threshold: 92.2
1
+ threshold: 85.5
2
2
  require_exact_threshold: false
3
3
  rules:
4
4
  ApiTag::Presence:
@@ -14,6 +14,7 @@ module Magicka
14
14
  autoload :Button, 'magicka/button'
15
15
  autoload :Element, 'magicka/element'
16
16
  autoload :FormElement, 'magicka/form_element'
17
+ autoload :Form, 'magicka/form'
17
18
  autoload :Input, 'magicka/input'
18
19
  autoload :MethodBuilder, 'magicka/method_builder'
19
20
  autoload :Select, 'magicka/select'
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Magicka
4
+ # Class responsible for controlling one object form
5
+ class Form
6
+ attr_reader :model
7
+
8
+ def initialize(renderer, model)
9
+ @renderer = renderer
10
+ @model = model
11
+ end
12
+
13
+ def input(field, model: self.model, **args)
14
+ Input.render(renderer: renderer, field: field, model: model, **args)
15
+ end
16
+
17
+ def select(field, model: self.model, **args)
18
+ Select.render(renderer: renderer, field: field, model: model, **args)
19
+ end
20
+
21
+ def button(**args)
22
+ Button.render(renderer: renderer, **args)
23
+ end
24
+
25
+ def with_model(model)
26
+ new_model = [self.model, model].join('.')
27
+
28
+ yield Form.new(renderer, new_model)
29
+ end
30
+
31
+ def equal?(other)
32
+ return unless other.class == self.class
33
+
34
+ other.renderer == renderer &&
35
+ other.model == model
36
+ end
37
+
38
+ alias == equal?
39
+
40
+ protected
41
+
42
+ attr_reader :renderer
43
+
44
+ delegate :render, to: :renderer
45
+ end
46
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Magicka
4
- VERSION = '0.3.1'
4
+ VERSION = '0.4.0'
5
5
  end
@@ -0,0 +1,122 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Magicka::Form do
6
+ subject(:form) { described_class.new(renderer, model) }
7
+
8
+ let(:model) { :my_model }
9
+ let(:renderer) { instance_double('renderer') }
10
+ let(:template) { 'templates/forms/input' }
11
+ let(:locals) { {} }
12
+
13
+ before do
14
+ allow(renderer)
15
+ .to receive(:render)
16
+ .with(partial: template, locals: locals)
17
+ end
18
+
19
+ describe '#input' do
20
+ let(:template) { 'templates/forms/input' }
21
+ let(:field) { :field }
22
+ let(:label) { 'Label' }
23
+ let(:placeholder) { 'Value' }
24
+
25
+ let(:locals) do
26
+ {
27
+ field: field,
28
+ label: label,
29
+ ng_errors: 'my_model.errors.field',
30
+ ng_model: 'my_model.field',
31
+ placeholder: placeholder
32
+ }
33
+ end
34
+
35
+ let(:arguments) do
36
+ {
37
+ label: label,
38
+ placeholder: placeholder,
39
+ model: model
40
+ }
41
+ end
42
+
43
+ it 'renders an input' do
44
+ form.input(field, arguments)
45
+
46
+ expect(renderer).to have_received(:render)
47
+ end
48
+ end
49
+
50
+ describe '#select' do
51
+ let(:template) { 'templates/forms/select' }
52
+ let(:field) { :field }
53
+ let(:label) { 'Label' }
54
+ let(:options) { %i[option_a option_b] }
55
+
56
+ let(:locals) do
57
+ {
58
+ field: field,
59
+ label: label,
60
+ ng_errors: 'my_model.errors.field',
61
+ ng_model: 'my_model.field',
62
+ options: options
63
+ }
64
+ end
65
+
66
+ let(:arguments) do
67
+ {
68
+ label: label,
69
+ model: model,
70
+ options: options
71
+ }
72
+ end
73
+
74
+ it 'renders an input' do
75
+ form.select(field, arguments)
76
+
77
+ expect(renderer).to have_received(:render)
78
+ end
79
+ end
80
+
81
+ describe '#button' do
82
+ let(:template) { 'templates/forms/button' }
83
+ let(:ng_click) { 'controler.click()' }
84
+ let(:ng_disabled) { 'false' }
85
+ let(:classes) { 'custom class' }
86
+ let(:text) { 'Click' }
87
+
88
+ let(:locals) do
89
+ {
90
+ ng_click: ng_click,
91
+ ng_disabled: ng_disabled,
92
+ classes: classes,
93
+ text: text
94
+ }
95
+ end
96
+
97
+ let(:arguments) do
98
+ {
99
+ ng_click: ng_click,
100
+ ng_disabled: ng_disabled,
101
+ classes: classes,
102
+ text: text
103
+ }
104
+ end
105
+
106
+ it 'renders an input' do
107
+ form.button(arguments)
108
+
109
+ expect(renderer).to have_received(:render)
110
+ end
111
+ end
112
+
113
+ describe '#with_model' do
114
+ let(:expected_form) { described_class.new(renderer, 'my_model.inner') }
115
+
116
+ it do
117
+ form.with_model(:inner) do |new_form|
118
+ expect(new_form).to eq(expected_form)
119
+ end
120
+ end
121
+ end
122
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: magicka
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - DarthJee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-03 00:00:00.000000000 Z
11
+ date: 2020-06-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -400,6 +400,7 @@ files:
400
400
  - lib/magicka/button.rb
401
401
  - lib/magicka/element.rb
402
402
  - lib/magicka/element/class_methods.rb
403
+ - lib/magicka/form.rb
403
404
  - lib/magicka/form_element.rb
404
405
  - lib/magicka/input.rb
405
406
  - lib/magicka/method_builder.rb
@@ -472,6 +473,7 @@ files:
472
473
  - spec/lib/magicka/element/class_methods_spec.rb
473
474
  - spec/lib/magicka/element_spec.rb
474
475
  - spec/lib/magicka/form_element_spec.rb
476
+ - spec/lib/magicka/form_spec.rb
475
477
  - spec/lib/magicka/input_spec.rb
476
478
  - spec/lib/magicka/method_builder_spec.rb
477
479
  - spec/lib/magicka/select_spec.rb