magicka 0.3.1 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +19 -5
- data/README.md +1 -1
- data/config/check_specs.yml +3 -0
- data/config/yardstick.yml +1 -1
- data/lib/magicka.rb +11 -7
- data/lib/magicka/aggregator.rb +47 -0
- data/lib/magicka/aggregator/method_builder.rb +40 -0
- data/lib/magicka/display.rb +11 -0
- data/lib/magicka/element.rb +2 -1
- data/lib/magicka/element/method_builder.rb +40 -0
- data/lib/magicka/form.rb +13 -0
- data/lib/magicka/helper.rb +14 -0
- data/lib/magicka/text.rb +8 -0
- data/lib/magicka/version.rb +1 -1
- data/spec/lib/magicka/display_spec.rb +169 -0
- data/spec/lib/magicka/{method_builder_spec.rb → element/method_builder_spec.rb} +1 -1
- data/spec/lib/magicka/form_spec.rb +183 -0
- data/spec/lib/magicka/text_spec.rb +52 -0
- metadata +13 -4
- data/lib/magicka/method_builder.rb +0 -38
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 790574b274384507133ba81bff57316fdee267695e6a86bbb36da2065d98f918
|
4
|
+
data.tar.gz: ded516626da7b9825e1711aa4d299cd0388de7293776cc20c9facc607b4ba8ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2fb23dfa2dca070216bede19831ca54bc0c9ee1340418848e647512d4ec7668ee97b0015aa8d7d3b85e6014883e263107ce8360efed4286342e714f502d93ce
|
7
|
+
data.tar.gz: 6e165bd37c83eb5d3c0c760164f2f93e9d51d05f284621960012e24b81d5b7779140cca6f1d47128bd24a4545201e77becd489fa20d9e0ac6ba816cd01dc8fdf
|
data/.circleci/config.yml
CHANGED
@@ -7,8 +7,12 @@ workflows:
|
|
7
7
|
filters:
|
8
8
|
tags:
|
9
9
|
only: /.*/
|
10
|
+
- checks:
|
11
|
+
filters:
|
12
|
+
tags:
|
13
|
+
only: /.*/
|
10
14
|
- build-and-release:
|
11
|
-
requires: [test]
|
15
|
+
requires: [test, checks]
|
12
16
|
filters:
|
13
17
|
tags:
|
14
18
|
only: /\d+\.\d+\.\d+/
|
@@ -18,7 +22,7 @@ workflows:
|
|
18
22
|
jobs:
|
19
23
|
test:
|
20
24
|
docker:
|
21
|
-
- image: darthjee/circleci_rails_gems:0.
|
25
|
+
- image: darthjee/circleci_rails_gems:0.6.0
|
22
26
|
environment:
|
23
27
|
PROJECT: magicka
|
24
28
|
steps:
|
@@ -32,12 +36,22 @@ jobs:
|
|
32
36
|
- run:
|
33
37
|
name: RSpec
|
34
38
|
command: bundle exec rspec
|
35
|
-
- run:
|
36
|
-
name: Rubocop
|
37
|
-
command: rubocop
|
38
39
|
- run:
|
39
40
|
name: Coverage Test Report
|
40
41
|
command: cc-test-reporter after-build --exit-code $?
|
42
|
+
checks:
|
43
|
+
docker:
|
44
|
+
- image: darthjee/circleci_rails_gems:0.6.0
|
45
|
+
environment:
|
46
|
+
PROJECT: magicka
|
47
|
+
steps:
|
48
|
+
- checkout
|
49
|
+
- run:
|
50
|
+
name: Bundle Install
|
51
|
+
command: bundle install
|
52
|
+
- run:
|
53
|
+
name: Rubocop
|
54
|
+
command: rubocop
|
41
55
|
- run:
|
42
56
|
name: Yardstick coverage check
|
43
57
|
command: bundle exec rake verify_measurements
|
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
|
14
|
+
[https://www.rubydoc.info/gems/magicka/0.5.3](https://www.rubydoc.info/gems/magicka/0.5.3)
|
15
15
|
|
16
16
|
Installation
|
17
17
|
---------------
|
data/config/check_specs.yml
CHANGED
data/config/yardstick.yml
CHANGED
data/lib/magicka.rb
CHANGED
@@ -10,11 +10,15 @@ require 'sinclair'
|
|
10
10
|
#
|
11
11
|
# module holding herlper to render inputs
|
12
12
|
module Magicka
|
13
|
-
autoload :VERSION,
|
14
|
-
autoload :
|
15
|
-
autoload :
|
16
|
-
autoload :
|
17
|
-
autoload :
|
18
|
-
autoload :
|
19
|
-
autoload :
|
13
|
+
autoload :VERSION, 'magicka/version'
|
14
|
+
autoload :Aggregator, 'magicka/aggregator'
|
15
|
+
autoload :Button, 'magicka/button'
|
16
|
+
autoload :Display, 'magicka/display'
|
17
|
+
autoload :Element, 'magicka/element'
|
18
|
+
autoload :FormElement, 'magicka/form_element'
|
19
|
+
autoload :Form, 'magicka/form'
|
20
|
+
autoload :Helper, 'magicka/helper'
|
21
|
+
autoload :Input, 'magicka/input'
|
22
|
+
autoload :Select, 'magicka/select'
|
23
|
+
autoload :Text, 'magicka/text'
|
20
24
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Magicka
|
4
|
+
# @api public
|
5
|
+
#
|
6
|
+
# Class representing an element agregator, representing a model
|
7
|
+
class Aggregator
|
8
|
+
autoload :MethodBuilder, 'magicka/aggregator/method_builder'
|
9
|
+
|
10
|
+
class << self
|
11
|
+
def with_element(element_class, method_name = nil)
|
12
|
+
MethodBuilder
|
13
|
+
.new(self, element_class, method_name)
|
14
|
+
.prepare
|
15
|
+
.build
|
16
|
+
end
|
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, base: self.model)
|
27
|
+
new_model = [base, model].compact.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
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Magicka
|
4
|
+
class Aggregator
|
5
|
+
# @api private
|
6
|
+
#
|
7
|
+
# Class responsible for building an {Aggregator} method
|
8
|
+
class MethodBuilder < Sinclair
|
9
|
+
def initialize(klass, element_class, method_name = nil)
|
10
|
+
super(klass)
|
11
|
+
|
12
|
+
@element_class = element_class
|
13
|
+
@method_name = method_name
|
14
|
+
end
|
15
|
+
|
16
|
+
def prepare
|
17
|
+
element_klass = element_class
|
18
|
+
|
19
|
+
add_method(method_name) do |field, model: self.model, **args|
|
20
|
+
element_klass.render(
|
21
|
+
renderer: renderer, field: field, model: model, **args
|
22
|
+
)
|
23
|
+
end
|
24
|
+
|
25
|
+
self
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
attr_reader :element_class
|
31
|
+
|
32
|
+
def method_name
|
33
|
+
@method_name ||= element_class
|
34
|
+
.name
|
35
|
+
.underscore
|
36
|
+
.gsub(%r{.*/}, '')
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/magicka/element.rb
CHANGED
@@ -5,7 +5,8 @@ module Magicka
|
|
5
5
|
#
|
6
6
|
# Base class for element rendering
|
7
7
|
class Element < Sinclair::Options
|
8
|
-
autoload :ClassMethods,
|
8
|
+
autoload :ClassMethods, 'magicka/element/class_methods'
|
9
|
+
autoload :MethodBuilder, 'magicka/element/method_builder'
|
9
10
|
|
10
11
|
skip_validation
|
11
12
|
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Magicka
|
4
|
+
class Element
|
5
|
+
# @api private
|
6
|
+
#
|
7
|
+
# class responsible for building methods on {Magicka::Element}
|
8
|
+
class MethodBuilder < Sinclair
|
9
|
+
# adds a mehtod +#template+
|
10
|
+
#
|
11
|
+
# The method will always return the template given in the params
|
12
|
+
#
|
13
|
+
# @param template [String] path to template file
|
14
|
+
#
|
15
|
+
# @return [Array<Sinclair::MethodDefinition>]
|
16
|
+
def add_template(template)
|
17
|
+
add_method(:template) do
|
18
|
+
template
|
19
|
+
end
|
20
|
+
|
21
|
+
build
|
22
|
+
end
|
23
|
+
|
24
|
+
# adds a mehtod +#template_folder+
|
25
|
+
#
|
26
|
+
# The method will always return the template folder given in the params
|
27
|
+
#
|
28
|
+
# @param template_folder [String] path to template folder
|
29
|
+
#
|
30
|
+
# @return [Array<Sinclair::MethodDefinition>]
|
31
|
+
def add_template_folder(folder)
|
32
|
+
add_method(:template_folder) do
|
33
|
+
folder
|
34
|
+
end
|
35
|
+
|
36
|
+
build
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/magicka/form.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Magicka
|
4
|
+
# Class responsible for controlling one object form
|
5
|
+
class Form < Aggregator
|
6
|
+
with_element(Input)
|
7
|
+
with_element(Select)
|
8
|
+
|
9
|
+
def button(**args)
|
10
|
+
Button.render(renderer: renderer, **args)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/magicka/text.rb
ADDED
data/lib/magicka/version.rb
CHANGED
@@ -0,0 +1,169 @@
|
|
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
|
+
|
143
|
+
describe '#with_form' do
|
144
|
+
it do
|
145
|
+
form.with_model('sub') do |new_form|
|
146
|
+
expect(new_form)
|
147
|
+
.to eq(described_class.new(renderer, 'my_model.sub'))
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
context 'when passing a new base' do
|
152
|
+
it do
|
153
|
+
form.with_model('sub', base: :other_model) do |new_form|
|
154
|
+
expect(new_form)
|
155
|
+
.to eq(described_class.new(renderer, 'other_model.sub'))
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
context 'when passing an empty base' do
|
161
|
+
it do
|
162
|
+
form.with_model('sub', base: nil) do |new_form|
|
163
|
+
expect(new_form)
|
164
|
+
.to eq(described_class.new(renderer, 'sub'))
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
@@ -0,0 +1,183 @@
|
|
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
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'renders an input' do
|
43
|
+
form.input(field, arguments)
|
44
|
+
|
45
|
+
expect(renderer).to have_received(:render)
|
46
|
+
end
|
47
|
+
|
48
|
+
context 'when passing a custom model' do
|
49
|
+
let(:locals) do
|
50
|
+
{
|
51
|
+
field: field,
|
52
|
+
label: label,
|
53
|
+
ng_errors: 'my_custom_model.errors.field',
|
54
|
+
ng_model: 'my_custom_model.field',
|
55
|
+
placeholder: placeholder
|
56
|
+
}
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'renders an input' do
|
60
|
+
form.input(field, model: 'my_custom_model', **arguments)
|
61
|
+
|
62
|
+
expect(renderer).to have_received(:render)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe '#select' do
|
68
|
+
let(:template) { 'templates/forms/select' }
|
69
|
+
let(:field) { :field }
|
70
|
+
let(:label) { 'Label' }
|
71
|
+
let(:options) { %i[option_a option_b] }
|
72
|
+
|
73
|
+
let(:locals) do
|
74
|
+
{
|
75
|
+
field: field,
|
76
|
+
label: label,
|
77
|
+
ng_errors: 'my_model.errors.field',
|
78
|
+
ng_model: 'my_model.field',
|
79
|
+
options: options
|
80
|
+
}
|
81
|
+
end
|
82
|
+
|
83
|
+
let(:arguments) do
|
84
|
+
{
|
85
|
+
label: label,
|
86
|
+
options: options
|
87
|
+
}
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'renders a select' do
|
91
|
+
form.select(field, arguments)
|
92
|
+
|
93
|
+
expect(renderer).to have_received(:render)
|
94
|
+
end
|
95
|
+
|
96
|
+
context 'when passing a custom model' do
|
97
|
+
let(:locals) do
|
98
|
+
{
|
99
|
+
field: field,
|
100
|
+
label: label,
|
101
|
+
ng_errors: 'my_custom_model.errors.field',
|
102
|
+
ng_model: 'my_custom_model.field',
|
103
|
+
options: options
|
104
|
+
}
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'renders a select' do
|
108
|
+
form.select(field, model: 'my_custom_model', **arguments)
|
109
|
+
|
110
|
+
expect(renderer).to have_received(:render)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
describe '#button' do
|
116
|
+
let(:template) { 'templates/forms/button' }
|
117
|
+
let(:ng_click) { 'controler.click()' }
|
118
|
+
let(:ng_disabled) { 'false' }
|
119
|
+
let(:classes) { 'custom class' }
|
120
|
+
let(:text) { 'Click' }
|
121
|
+
|
122
|
+
let(:locals) do
|
123
|
+
{
|
124
|
+
ng_click: ng_click,
|
125
|
+
ng_disabled: ng_disabled,
|
126
|
+
classes: classes,
|
127
|
+
text: text
|
128
|
+
}
|
129
|
+
end
|
130
|
+
|
131
|
+
let(:arguments) do
|
132
|
+
{
|
133
|
+
ng_click: ng_click,
|
134
|
+
ng_disabled: ng_disabled,
|
135
|
+
classes: classes,
|
136
|
+
text: text
|
137
|
+
}
|
138
|
+
end
|
139
|
+
|
140
|
+
it 'renders an input' do
|
141
|
+
form.button(arguments)
|
142
|
+
|
143
|
+
expect(renderer).to have_received(:render)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
describe '#with_model' do
|
148
|
+
let(:expected_form) { described_class.new(renderer, 'my_model.inner') }
|
149
|
+
|
150
|
+
it do
|
151
|
+
form.with_model(:inner) do |new_form|
|
152
|
+
expect(new_form).to eq(expected_form)
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
describe '#with_form' do
|
158
|
+
it do
|
159
|
+
form.with_model('sub') do |new_form|
|
160
|
+
expect(new_form)
|
161
|
+
.to eq(described_class.new(renderer, 'my_model.sub'))
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
context 'when passing a new base' do
|
166
|
+
it do
|
167
|
+
form.with_model('sub', base: :other_model) do |new_form|
|
168
|
+
expect(new_form)
|
169
|
+
.to eq(described_class.new(renderer, 'other_model.sub'))
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
context 'when passing an empty base' do
|
175
|
+
it do
|
176
|
+
form.with_model('sub', base: nil) do |new_form|
|
177
|
+
expect(new_form)
|
178
|
+
.to eq(described_class.new(renderer, 'sub'))
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
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,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: magicka
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3
|
4
|
+
version: 0.5.3
|
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-
|
11
|
+
date: 2020-06-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -397,13 +397,19 @@ files:
|
|
397
397
|
- config/yardstick.yml
|
398
398
|
- docker-compose.yml
|
399
399
|
- lib/magicka.rb
|
400
|
+
- lib/magicka/aggregator.rb
|
401
|
+
- lib/magicka/aggregator/method_builder.rb
|
400
402
|
- lib/magicka/button.rb
|
403
|
+
- lib/magicka/display.rb
|
401
404
|
- lib/magicka/element.rb
|
402
405
|
- lib/magicka/element/class_methods.rb
|
406
|
+
- lib/magicka/element/method_builder.rb
|
407
|
+
- lib/magicka/form.rb
|
403
408
|
- lib/magicka/form_element.rb
|
409
|
+
- lib/magicka/helper.rb
|
404
410
|
- lib/magicka/input.rb
|
405
|
-
- lib/magicka/method_builder.rb
|
406
411
|
- lib/magicka/select.rb
|
412
|
+
- lib/magicka/text.rb
|
407
413
|
- lib/magicka/version.rb
|
408
414
|
- magicka.gemspec
|
409
415
|
- magicka.jpg
|
@@ -469,12 +475,15 @@ files:
|
|
469
475
|
- spec/integration/readme/.keep
|
470
476
|
- spec/integration/yard/.keep
|
471
477
|
- spec/lib/magicka/button_spec.rb
|
478
|
+
- spec/lib/magicka/display_spec.rb
|
472
479
|
- spec/lib/magicka/element/class_methods_spec.rb
|
480
|
+
- spec/lib/magicka/element/method_builder_spec.rb
|
473
481
|
- spec/lib/magicka/element_spec.rb
|
474
482
|
- spec/lib/magicka/form_element_spec.rb
|
483
|
+
- spec/lib/magicka/form_spec.rb
|
475
484
|
- spec/lib/magicka/input_spec.rb
|
476
|
-
- spec/lib/magicka/method_builder_spec.rb
|
477
485
|
- spec/lib/magicka/select_spec.rb
|
486
|
+
- spec/lib/magicka/text_spec.rb
|
478
487
|
- spec/spec_helper.rb
|
479
488
|
- spec/support/models/.keep
|
480
489
|
- spec/support/shared_examples/.keep
|
@@ -1,38 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Magicka
|
4
|
-
# @api private
|
5
|
-
#
|
6
|
-
# class responsible for building methods on {Magicka::Element}
|
7
|
-
class MethodBuilder < Sinclair
|
8
|
-
# adds a mehtod +#template+
|
9
|
-
#
|
10
|
-
# The method will always return the template given in the params
|
11
|
-
#
|
12
|
-
# @param template [String] path to template file
|
13
|
-
#
|
14
|
-
# @return [Array<Sinclair::MethodDefinition>]
|
15
|
-
def add_template(template)
|
16
|
-
add_method(:template) do
|
17
|
-
template
|
18
|
-
end
|
19
|
-
|
20
|
-
build
|
21
|
-
end
|
22
|
-
|
23
|
-
# adds a mehtod +#template_folder+
|
24
|
-
#
|
25
|
-
# The method will always return the template folder given in the params
|
26
|
-
#
|
27
|
-
# @param template_folder [String] path to template folder
|
28
|
-
#
|
29
|
-
# @return [Array<Sinclair::MethodDefinition>]
|
30
|
-
def add_template_folder(folder)
|
31
|
-
add_method(:template_folder) do
|
32
|
-
folder
|
33
|
-
end
|
34
|
-
|
35
|
-
build
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|