magicka 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/config/yardstick.yml +1 -1
- data/lib/magicka.rb +2 -0
- data/lib/magicka/aggregator.rb +28 -0
- data/lib/magicka/display.rb +11 -0
- data/lib/magicka/form.rb +0 -28
- data/lib/magicka/text.rb +8 -0
- data/lib/magicka/version.rb +1 -1
- data/spec/lib/magicka/display_spec.rb +142 -0
- data/spec/lib/magicka/text_spec.rb +52 -0
- metadata +5 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce6145b05f6ec0b77cf8a501ec0f0f886f0bd512a492eec2495e1dad100c16da
|
4
|
+
data.tar.gz: 89a0393acd79ab69f998694dbe94d302bf899903b75d60a66a3a07574845bc3e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: abf9488e091894dd7619cbc5b2d29b05d40552eacf74c93538862ad066b5807bb812913e033fa291959d04e23daa8a86878744876c83779d3d7b9b15062abd79
|
7
|
+
data.tar.gz: 1d9fd2d213b949bd2506c46962433b5b674d0c96dc8f9cb115d756e1a2dc71e8595e5cae60bb935382f6bd1fcb589ca78708823c092e38981c422b10276edf70
|
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.5.
|
14
|
+
[https://www.rubydoc.info/gems/magicka/0.5.1](https://www.rubydoc.info/gems/magicka/0.5.1)
|
15
15
|
|
16
16
|
Installation
|
17
17
|
---------------
|
data/config/yardstick.yml
CHANGED
data/lib/magicka.rb
CHANGED
@@ -13,9 +13,11 @@ module Magicka
|
|
13
13
|
autoload :VERSION, 'magicka/version'
|
14
14
|
autoload :Aggregator, 'magicka/aggregator'
|
15
15
|
autoload :Button, 'magicka/button'
|
16
|
+
autoload :Display, 'magicka/display'
|
16
17
|
autoload :Element, 'magicka/element'
|
17
18
|
autoload :FormElement, 'magicka/form_element'
|
18
19
|
autoload :Form, 'magicka/form'
|
19
20
|
autoload :Input, 'magicka/input'
|
20
21
|
autoload :Select, 'magicka/select'
|
22
|
+
autoload :Text, 'magicka/text'
|
21
23
|
end
|
data/lib/magicka/aggregator.rb
CHANGED
@@ -15,5 +15,33 @@ module Magicka
|
|
15
15
|
.build
|
16
16
|
end
|
17
17
|
end
|
18
|
+
|
19
|
+
attr_reader :model
|
20
|
+
|
21
|
+
def initialize(renderer, model)
|
22
|
+
@renderer = renderer
|
23
|
+
@model = model
|
24
|
+
end
|
25
|
+
|
26
|
+
def with_model(model)
|
27
|
+
new_model = [self.model, model].join('.')
|
28
|
+
|
29
|
+
yield self.class.new(renderer, new_model)
|
30
|
+
end
|
31
|
+
|
32
|
+
def equal?(other)
|
33
|
+
return unless other.class == self.class
|
34
|
+
|
35
|
+
other.renderer == renderer &&
|
36
|
+
other.model == model
|
37
|
+
end
|
38
|
+
|
39
|
+
alias == equal?
|
40
|
+
|
41
|
+
protected
|
42
|
+
|
43
|
+
attr_reader :renderer
|
44
|
+
|
45
|
+
delegate :render, to: :renderer
|
18
46
|
end
|
19
47
|
end
|
data/lib/magicka/form.rb
CHANGED
@@ -3,39 +3,11 @@
|
|
3
3
|
module Magicka
|
4
4
|
# Class responsible for controlling one object form
|
5
5
|
class Form < Aggregator
|
6
|
-
attr_reader :model
|
7
|
-
|
8
|
-
def initialize(renderer, model)
|
9
|
-
@renderer = renderer
|
10
|
-
@model = model
|
11
|
-
end
|
12
|
-
|
13
6
|
with_element(Input)
|
14
7
|
with_element(Select)
|
15
8
|
|
16
9
|
def button(**args)
|
17
10
|
Button.render(renderer: renderer, **args)
|
18
11
|
end
|
19
|
-
|
20
|
-
def with_model(model)
|
21
|
-
new_model = [self.model, model].join('.')
|
22
|
-
|
23
|
-
yield Form.new(renderer, new_model)
|
24
|
-
end
|
25
|
-
|
26
|
-
def equal?(other)
|
27
|
-
return unless other.class == self.class
|
28
|
-
|
29
|
-
other.renderer == renderer &&
|
30
|
-
other.model == model
|
31
|
-
end
|
32
|
-
|
33
|
-
alias == equal?
|
34
|
-
|
35
|
-
protected
|
36
|
-
|
37
|
-
attr_reader :renderer
|
38
|
-
|
39
|
-
delegate :render, to: :renderer
|
40
12
|
end
|
41
13
|
end
|
data/lib/magicka/text.rb
ADDED
data/lib/magicka/version.rb
CHANGED
@@ -0,0 +1,142 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Magicka::Display 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/display/text' }
|
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/display/text' }
|
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
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
let(:arguments) do
|
35
|
+
{
|
36
|
+
label: label,
|
37
|
+
placeholder: placeholder
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'renders a text' do
|
42
|
+
form.input(field, arguments)
|
43
|
+
|
44
|
+
expect(renderer).to have_received(:render)
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'when passing a custom model' do
|
48
|
+
let(:locals) do
|
49
|
+
{
|
50
|
+
field: field,
|
51
|
+
label: label,
|
52
|
+
ng_errors: 'my_custom_model.errors.field',
|
53
|
+
ng_model: 'my_custom_model.field'
|
54
|
+
}
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'renders a text' do
|
58
|
+
form.input(field, model: 'my_custom_model', **arguments)
|
59
|
+
|
60
|
+
expect(renderer).to have_received(:render)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe '#select' do
|
66
|
+
let(:template) { 'templates/display/text' }
|
67
|
+
let(:field) { :field }
|
68
|
+
let(:label) { 'Label' }
|
69
|
+
let(:options) { %i[option_a option_b] }
|
70
|
+
|
71
|
+
let(:locals) do
|
72
|
+
{
|
73
|
+
field: field,
|
74
|
+
label: label,
|
75
|
+
ng_errors: 'my_model.errors.field',
|
76
|
+
ng_model: 'my_model.field'
|
77
|
+
}
|
78
|
+
end
|
79
|
+
|
80
|
+
let(:arguments) do
|
81
|
+
{
|
82
|
+
label: label,
|
83
|
+
options: options
|
84
|
+
}
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'renders a text' do
|
88
|
+
form.select(field, arguments)
|
89
|
+
|
90
|
+
expect(renderer).to have_received(:render)
|
91
|
+
end
|
92
|
+
|
93
|
+
context 'when passing a custom model' do
|
94
|
+
let(:locals) do
|
95
|
+
{
|
96
|
+
field: field,
|
97
|
+
label: label,
|
98
|
+
ng_errors: 'my_custom_model.errors.field',
|
99
|
+
ng_model: 'my_custom_model.field'
|
100
|
+
}
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'renders a text' do
|
104
|
+
form.select(field, model: 'my_custom_model', **arguments)
|
105
|
+
|
106
|
+
expect(renderer).to have_received(:render)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
describe '#button' do
|
112
|
+
let(:ng_click) { 'controler.click()' }
|
113
|
+
let(:ng_disabled) { 'false' }
|
114
|
+
let(:classes) { 'custom class' }
|
115
|
+
let(:text) { 'Click' }
|
116
|
+
|
117
|
+
let(:arguments) do
|
118
|
+
{
|
119
|
+
ng_click: ng_click,
|
120
|
+
ng_disabled: ng_disabled,
|
121
|
+
classes: classes,
|
122
|
+
text: text
|
123
|
+
}
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'renders nothing' do
|
127
|
+
form.button(arguments)
|
128
|
+
|
129
|
+
expect(renderer).not_to have_received(:render)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
describe '#with_model' do
|
134
|
+
let(:expected_form) { described_class.new(renderer, 'my_model.inner') }
|
135
|
+
|
136
|
+
it do
|
137
|
+
form.with_model(:inner) do |new_form|
|
138
|
+
expect(new_form).to eq(expected_form)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Magicka::Text do
|
6
|
+
let(:renderer) { instance_double('renderer') }
|
7
|
+
let(:template) { 'templates/display/text' }
|
8
|
+
|
9
|
+
let(:model) { :my_model }
|
10
|
+
let(:field) { :field }
|
11
|
+
let(:label) { 'Label' }
|
12
|
+
|
13
|
+
let(:locals) do
|
14
|
+
{
|
15
|
+
field: field,
|
16
|
+
label: label,
|
17
|
+
ng_model: 'my_model.field',
|
18
|
+
ng_errors: 'my_model.errors.field'
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '.render' do
|
23
|
+
let(:arguments) do
|
24
|
+
{
|
25
|
+
renderer: renderer,
|
26
|
+
field: field,
|
27
|
+
label: label,
|
28
|
+
model: model
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
before do
|
33
|
+
allow(renderer)
|
34
|
+
.to receive(:render)
|
35
|
+
.with(partial: template, locals: locals)
|
36
|
+
end
|
37
|
+
|
38
|
+
it do
|
39
|
+
described_class.render(arguments)
|
40
|
+
|
41
|
+
expect(renderer).to have_received(:render)
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'when called with extra params' do
|
45
|
+
it do
|
46
|
+
described_class.render(name: 'Name', **arguments)
|
47
|
+
|
48
|
+
expect(renderer).to have_received(:render)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: magicka
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- DarthJee
|
@@ -400,6 +400,7 @@ files:
|
|
400
400
|
- lib/magicka/aggregator.rb
|
401
401
|
- lib/magicka/aggregator/method_builder.rb
|
402
402
|
- lib/magicka/button.rb
|
403
|
+
- lib/magicka/display.rb
|
403
404
|
- lib/magicka/element.rb
|
404
405
|
- lib/magicka/element/class_methods.rb
|
405
406
|
- lib/magicka/element/method_builder.rb
|
@@ -407,6 +408,7 @@ files:
|
|
407
408
|
- lib/magicka/form_element.rb
|
408
409
|
- lib/magicka/input.rb
|
409
410
|
- lib/magicka/select.rb
|
411
|
+
- lib/magicka/text.rb
|
410
412
|
- lib/magicka/version.rb
|
411
413
|
- magicka.gemspec
|
412
414
|
- magicka.jpg
|
@@ -472,6 +474,7 @@ files:
|
|
472
474
|
- spec/integration/readme/.keep
|
473
475
|
- spec/integration/yard/.keep
|
474
476
|
- spec/lib/magicka/button_spec.rb
|
477
|
+
- spec/lib/magicka/display_spec.rb
|
475
478
|
- spec/lib/magicka/element/class_methods_spec.rb
|
476
479
|
- spec/lib/magicka/element/method_builder_spec.rb
|
477
480
|
- spec/lib/magicka/element_spec.rb
|
@@ -479,6 +482,7 @@ files:
|
|
479
482
|
- spec/lib/magicka/form_spec.rb
|
480
483
|
- spec/lib/magicka/input_spec.rb
|
481
484
|
- spec/lib/magicka/select_spec.rb
|
485
|
+
- spec/lib/magicka/text_spec.rb
|
482
486
|
- spec/spec_helper.rb
|
483
487
|
- spec/support/models/.keep
|
484
488
|
- spec/support/shared_examples/.keep
|