magicka 0.1.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Dockerfile +1 -1
- data/README.md +1 -1
- data/config/yardstick.yml +3 -2
- data/lib/magicka.rb +4 -0
- data/lib/magicka/button.rb +9 -0
- data/lib/magicka/element.rb +17 -0
- data/lib/magicka/element/class_methods.rb +13 -5
- data/lib/magicka/form.rb +46 -0
- data/lib/magicka/form_element.rb +49 -0
- data/lib/magicka/input.rb +2 -41
- data/lib/magicka/method_builder.rb +15 -0
- data/lib/magicka/select.rb +8 -0
- data/lib/magicka/version.rb +1 -1
- data/magicka.gemspec +5 -5
- data/spec/lib/magicka/button_spec.rb +54 -0
- data/spec/lib/magicka/element/class_methods_spec.rb +21 -3
- data/spec/lib/magicka/element_spec.rb +43 -18
- data/spec/lib/magicka/form_element_spec.rb +87 -0
- data/spec/lib/magicka/form_spec.rb +122 -0
- data/spec/lib/magicka/method_builder_spec.rb +18 -0
- data/spec/lib/magicka/select_spec.rb +55 -0
- metadata +20 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81717f300e575454157f07d2e37f93b68a43aee24374cc84d49142f3815b26de
|
4
|
+
data.tar.gz: f50c9807efb97e1fa9719f010c39d261eb6fe9ccf12d3a199c33521b515ea2ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ede839d74d03176271d66aaf5ac672cdf0774e3be38edcf7306414de16f64fea51f73b3390c184f684c1c9189978bc045d51f8f0a1dc7d5e408432fd7b3863fa
|
7
|
+
data.tar.gz: e67ed028a79ef8dbfdb1ed0c16e592df1749941429002cc5f83522bb744b16a20fee771004326a853165d25d11beb7376bd7fee5243d4e398556426c256e1fcd
|
data/Dockerfile
CHANGED
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.
|
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
|
---------------
|
data/config/yardstick.yml
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
threshold:
|
1
|
+
threshold: 85.5
|
2
2
|
require_exact_threshold: false
|
3
3
|
rules:
|
4
4
|
ApiTag::Presence:
|
@@ -21,7 +21,8 @@ rules:
|
|
21
21
|
exclude: []
|
22
22
|
Summary::Presence:
|
23
23
|
enabled: true
|
24
|
-
exclude:
|
24
|
+
exclude:
|
25
|
+
- Magicka::Element#initialize
|
25
26
|
Summary::Length:
|
26
27
|
enabled: true
|
27
28
|
exclude: []
|
data/lib/magicka.rb
CHANGED
@@ -11,7 +11,11 @@ require 'sinclair'
|
|
11
11
|
# module holding herlper to render inputs
|
12
12
|
module Magicka
|
13
13
|
autoload :VERSION, 'magicka/version'
|
14
|
+
autoload :Button, 'magicka/button'
|
14
15
|
autoload :Element, 'magicka/element'
|
16
|
+
autoload :FormElement, 'magicka/form_element'
|
17
|
+
autoload :Form, 'magicka/form'
|
15
18
|
autoload :Input, 'magicka/input'
|
16
19
|
autoload :MethodBuilder, 'magicka/method_builder'
|
20
|
+
autoload :Select, 'magicka/select'
|
17
21
|
end
|
data/lib/magicka/element.rb
CHANGED
@@ -10,6 +10,12 @@ module Magicka
|
|
10
10
|
skip_validation
|
11
11
|
|
12
12
|
class << self
|
13
|
+
# @api public
|
14
|
+
# @!visibility public
|
15
|
+
#
|
16
|
+
# Add available options
|
17
|
+
#
|
18
|
+
# @return [Array<Sinclair::MethodDefinition>]
|
13
19
|
alias with_attributes with_options
|
14
20
|
|
15
21
|
include ClassMethods
|
@@ -62,5 +68,16 @@ module Magicka
|
|
62
68
|
hash.merge!(attribute => send(attribute))
|
63
69
|
end
|
64
70
|
end
|
71
|
+
|
72
|
+
# @api public
|
73
|
+
# @private
|
74
|
+
#
|
75
|
+
# Returns template file location
|
76
|
+
#
|
77
|
+
# @return [String]
|
78
|
+
def template
|
79
|
+
self.class.name.underscore
|
80
|
+
.gsub(%r{^.*/}, "#{template_folder}/")
|
81
|
+
end
|
65
82
|
end
|
66
83
|
end
|
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
module Magicka
|
4
4
|
class Element < Sinclair::Options
|
5
|
+
# @api public
|
6
|
+
#
|
5
7
|
# Class methods used for metaprograming of elements
|
6
8
|
module ClassMethods
|
7
9
|
# render template using the given prameters
|
@@ -20,11 +22,6 @@ module Magicka
|
|
20
22
|
@locals ||= superclass.try(:locals)&.dup || Set.new([])
|
21
23
|
end
|
22
24
|
|
23
|
-
private
|
24
|
-
|
25
|
-
# @api public
|
26
|
-
# @!visibility public
|
27
|
-
#
|
28
25
|
# Sets template for element type
|
29
26
|
#
|
30
27
|
# @return [Array<Sinclair::MethodDefinition>]
|
@@ -34,6 +31,17 @@ module Magicka
|
|
34
31
|
.add_template(template)
|
35
32
|
end
|
36
33
|
|
34
|
+
# Sets template folder for element type
|
35
|
+
#
|
36
|
+
# @return [Array<Sinclair::MethodDefinition>]
|
37
|
+
def template_folder(folder)
|
38
|
+
MethodBuilder
|
39
|
+
.new(self)
|
40
|
+
.add_template_folder(folder)
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
37
45
|
# @api public
|
38
46
|
# @!visibility public
|
39
47
|
#
|
data/lib/magicka/form.rb
ADDED
@@ -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
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Magicka
|
4
|
+
# @api public
|
5
|
+
#
|
6
|
+
# Basic class for elements for forms
|
7
|
+
class FormElement < Element
|
8
|
+
with_attribute_locals :field, :label
|
9
|
+
with_attributes :model
|
10
|
+
with_locals :ng_errors, :ng_model
|
11
|
+
|
12
|
+
template_folder 'templates/forms'
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
# @api private
|
17
|
+
# @private
|
18
|
+
#
|
19
|
+
# Label to be shon near the input
|
20
|
+
#
|
21
|
+
# when no label is provided, the name of
|
22
|
+
# the field is used
|
23
|
+
#
|
24
|
+
# @return [String]
|
25
|
+
def label
|
26
|
+
@label ||= field.to_s.capitalize.gsub(/_/, ' ')
|
27
|
+
end
|
28
|
+
|
29
|
+
# @api private
|
30
|
+
# @private
|
31
|
+
#
|
32
|
+
# ng model to be represented with the input
|
33
|
+
#
|
34
|
+
# @return [String]
|
35
|
+
def ng_model
|
36
|
+
[model, field].join('.')
|
37
|
+
end
|
38
|
+
|
39
|
+
# @api private
|
40
|
+
# @private
|
41
|
+
#
|
42
|
+
# ng errors to be exposed with the input
|
43
|
+
#
|
44
|
+
# @return [String]
|
45
|
+
def ng_errors
|
46
|
+
[model, :errors, field].join('.')
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/magicka/input.rb
CHANGED
@@ -2,46 +2,7 @@
|
|
2
2
|
|
3
3
|
module Magicka
|
4
4
|
# Input element representing an HTML +<input/>+
|
5
|
-
class Input <
|
6
|
-
with_attribute_locals :
|
7
|
-
with_attributes :model
|
8
|
-
with_locals :ng_errors, :ng_model
|
9
|
-
|
10
|
-
template 'templates/forms/input'
|
11
|
-
|
12
|
-
private
|
13
|
-
|
14
|
-
# @api private
|
15
|
-
# @private
|
16
|
-
#
|
17
|
-
# Label to be shon near the input
|
18
|
-
#
|
19
|
-
# when no label is provided, the name of
|
20
|
-
# the field is used
|
21
|
-
#
|
22
|
-
# @return [String]
|
23
|
-
def label
|
24
|
-
@label ||= field.to_s.capitalize.gsub(/_/, ' ')
|
25
|
-
end
|
26
|
-
|
27
|
-
# @api private
|
28
|
-
# @private
|
29
|
-
#
|
30
|
-
# ng model to be represented with the input
|
31
|
-
#
|
32
|
-
# @return [String]
|
33
|
-
def ng_model
|
34
|
-
[model, field].join('.')
|
35
|
-
end
|
36
|
-
|
37
|
-
# @api private
|
38
|
-
# @private
|
39
|
-
#
|
40
|
-
# ng errors to be exposed with the input
|
41
|
-
#
|
42
|
-
# @return [String]
|
43
|
-
def ng_errors
|
44
|
-
[model, :errors, field].join('.')
|
45
|
-
end
|
5
|
+
class Input < FormElement
|
6
|
+
with_attribute_locals :placeholder
|
46
7
|
end
|
47
8
|
end
|
@@ -19,5 +19,20 @@ module Magicka
|
|
19
19
|
|
20
20
|
build
|
21
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
|
22
37
|
end
|
23
38
|
end
|
data/lib/magicka/version.rb
CHANGED
data/magicka.gemspec
CHANGED
@@ -19,17 +19,17 @@ Gem::Specification.new do |gem|
|
|
19
19
|
gem.test_files = gem.files.grep(%r{^(test|gem|features)/})
|
20
20
|
gem.require_paths = ['lib']
|
21
21
|
|
22
|
-
gem.add_runtime_dependency 'activesupport', '~> 5.2.4.
|
23
|
-
gem.add_runtime_dependency 'sinclair', '>= 1.6.
|
22
|
+
gem.add_runtime_dependency 'activesupport', '~> 5.2.4.3'
|
23
|
+
gem.add_runtime_dependency 'sinclair', '>= 1.6.7'
|
24
24
|
|
25
|
-
gem.add_development_dependency 'actionpack', '5.2.4.
|
26
|
-
gem.add_development_dependency 'activerecord', '5.2.4.
|
25
|
+
gem.add_development_dependency 'actionpack', '5.2.4.3'
|
26
|
+
gem.add_development_dependency 'activerecord', '5.2.4.3'
|
27
27
|
gem.add_development_dependency 'bundler', '1.16.1'
|
28
28
|
gem.add_development_dependency 'factory_bot', '5.2.0'
|
29
29
|
gem.add_development_dependency 'nokogiri', '1.10.9'
|
30
30
|
gem.add_development_dependency 'pry', '0.12.2'
|
31
31
|
gem.add_development_dependency 'pry-nav', '0.3.0'
|
32
|
-
gem.add_development_dependency 'rails', '5.2.4.
|
32
|
+
gem.add_development_dependency 'rails', '5.2.4.3'
|
33
33
|
gem.add_development_dependency 'rails-controller-testing', '1.0.4'
|
34
34
|
gem.add_development_dependency 'rake', '13.0.1'
|
35
35
|
gem.add_development_dependency 'reek', '5.6.0'
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Magicka::Button do
|
6
|
+
let(:renderer) { instance_double('renderer') }
|
7
|
+
let(:template) { 'templates/forms/button' }
|
8
|
+
|
9
|
+
let(:ng_click) { 'controler.click()' }
|
10
|
+
let(:ng_disabled) { 'false' }
|
11
|
+
let(:classes) { 'custom class' }
|
12
|
+
let(:text) { 'Click' }
|
13
|
+
|
14
|
+
let(:locals) do
|
15
|
+
{
|
16
|
+
ng_click: ng_click,
|
17
|
+
ng_disabled: ng_disabled,
|
18
|
+
classes: classes,
|
19
|
+
text: text
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '.render' do
|
24
|
+
let(:arguments) do
|
25
|
+
{
|
26
|
+
renderer: renderer,
|
27
|
+
ng_click: ng_click,
|
28
|
+
ng_disabled: ng_disabled,
|
29
|
+
classes: classes,
|
30
|
+
text: text
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
before do
|
35
|
+
allow(renderer)
|
36
|
+
.to receive(:render)
|
37
|
+
.with(partial: template, locals: locals)
|
38
|
+
end
|
39
|
+
|
40
|
+
it do
|
41
|
+
described_class.render(arguments)
|
42
|
+
|
43
|
+
expect(renderer).to have_received(:render)
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'when called with extra params' do
|
47
|
+
it do
|
48
|
+
described_class.render(name: 'Name', **arguments)
|
49
|
+
|
50
|
+
expect(renderer).to have_received(:render)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -23,13 +23,13 @@ describe Magicka::Element::ClassMethods do
|
|
23
23
|
|
24
24
|
describe '.template' do
|
25
25
|
it do
|
26
|
-
expect { klass.
|
26
|
+
expect { klass.template(template) }
|
27
27
|
.to add_method(:template)
|
28
28
|
.to(klass)
|
29
29
|
end
|
30
30
|
|
31
31
|
context 'when method is build as requested' do
|
32
|
-
before { klass.
|
32
|
+
before { klass.template(template) }
|
33
33
|
|
34
34
|
it 'returns the defined template when method is called' do
|
35
35
|
expect(element.template).to eq(template)
|
@@ -37,9 +37,27 @@ describe Magicka::Element::ClassMethods do
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
+
describe '.template_folder' do
|
41
|
+
let(:folder) { 'templates/forms' }
|
42
|
+
|
43
|
+
it do
|
44
|
+
expect { klass.template_folder(folder) }
|
45
|
+
.to add_method(:template_folder)
|
46
|
+
.to(klass)
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'when method is build as requested' do
|
50
|
+
before { klass.template_folder(folder) }
|
51
|
+
|
52
|
+
it 'returns the defined template when method is called' do
|
53
|
+
expect(element.template_folder).to eq(folder)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
40
58
|
describe '.render' do
|
41
59
|
before do
|
42
|
-
klass.
|
60
|
+
klass.template(template)
|
43
61
|
|
44
62
|
allow(renderer)
|
45
63
|
.to receive(:render)
|
@@ -11,26 +11,22 @@ describe Magicka::Element do
|
|
11
11
|
|
12
12
|
let(:renderer) { instance_double('renderer') }
|
13
13
|
let(:template) { 'templates/forms/element' }
|
14
|
+
let(:folder) { 'templates/forms' }
|
14
15
|
let(:locals) { {} }
|
15
16
|
|
17
|
+
let(:method_builder) { Sinclair.new(klass) }
|
18
|
+
let(:expected_template) { template }
|
19
|
+
|
16
20
|
describe '#render' do
|
17
21
|
before do
|
18
|
-
klass.send(:template, template)
|
19
|
-
|
20
22
|
allow(renderer)
|
21
23
|
.to receive(:render)
|
22
|
-
.with(partial:
|
23
|
-
end
|
24
|
-
|
25
|
-
it do
|
26
|
-
element.render
|
27
|
-
|
28
|
-
expect(renderer).to have_received(:render)
|
24
|
+
.with(partial: expected_template, locals: locals)
|
29
25
|
end
|
30
26
|
|
31
|
-
context 'when
|
32
|
-
|
33
|
-
klass.
|
27
|
+
context 'when class has a defined template' do
|
28
|
+
before do
|
29
|
+
klass.template(template)
|
34
30
|
end
|
35
31
|
|
36
32
|
it do
|
@@ -38,17 +34,46 @@ describe Magicka::Element do
|
|
38
34
|
|
39
35
|
expect(renderer).to have_received(:render)
|
40
36
|
end
|
41
|
-
end
|
42
37
|
|
43
|
-
|
44
|
-
|
45
|
-
|
38
|
+
context 'when initialized with extra params' do
|
39
|
+
subject(:element) do
|
40
|
+
klass.new(renderer: renderer, name: 'Name')
|
41
|
+
end
|
42
|
+
|
43
|
+
it do
|
44
|
+
element.render
|
45
|
+
|
46
|
+
expect(renderer).to have_received(:render)
|
47
|
+
end
|
46
48
|
end
|
47
49
|
|
48
|
-
|
50
|
+
context 'when class have locals defined' do
|
51
|
+
subject(:element) do
|
52
|
+
klass.new(renderer: renderer, name: 'Name')
|
53
|
+
end
|
54
|
+
|
55
|
+
let(:locals) { { name: 'Name' } }
|
56
|
+
|
57
|
+
before do
|
58
|
+
klass.send(:with_attribute_locals, :name)
|
59
|
+
end
|
60
|
+
|
61
|
+
it do
|
62
|
+
element.render
|
63
|
+
|
64
|
+
expect(renderer).to have_received(:render)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context 'when class has only folder defined' do
|
70
|
+
let(:expected_template) { 'templates/forms/my_element' }
|
49
71
|
|
50
72
|
before do
|
51
|
-
klass.
|
73
|
+
klass.template_folder(folder)
|
74
|
+
|
75
|
+
method_builder.add_class_method(:name) { 'Magicka::MyElement' }
|
76
|
+
method_builder.build
|
52
77
|
end
|
53
78
|
|
54
79
|
it do
|
@@ -0,0 +1,87 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Magicka::FormElement do
|
6
|
+
let(:renderer) { instance_double('renderer') }
|
7
|
+
let(:template) { 'templates/forms/custom_template' }
|
8
|
+
|
9
|
+
let(:expected_template) { template }
|
10
|
+
|
11
|
+
let(:model) { :my_model }
|
12
|
+
let(:field) { :field }
|
13
|
+
let(:label) { 'Label' }
|
14
|
+
let(:klass) { Class.new(described_class) }
|
15
|
+
|
16
|
+
let(:locals) do
|
17
|
+
{
|
18
|
+
field: field,
|
19
|
+
label: label,
|
20
|
+
ng_errors: 'my_model.errors.field',
|
21
|
+
ng_model: 'my_model.field'
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '.render' do
|
26
|
+
let(:arguments) do
|
27
|
+
{
|
28
|
+
renderer: renderer,
|
29
|
+
field: field,
|
30
|
+
label: label,
|
31
|
+
model: model
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
before do
|
36
|
+
allow(renderer)
|
37
|
+
.to receive(:render)
|
38
|
+
.with(partial: expected_template, locals: locals)
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'when defined template' do
|
42
|
+
before do
|
43
|
+
klass.template(template)
|
44
|
+
end
|
45
|
+
|
46
|
+
it do
|
47
|
+
klass.render(arguments)
|
48
|
+
|
49
|
+
expect(renderer).to have_received(:render)
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'when called with extra params' do
|
53
|
+
it do
|
54
|
+
klass.render(name: 'Name', **arguments)
|
55
|
+
|
56
|
+
expect(renderer).to have_received(:render)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'when not defining a template' do
|
62
|
+
let(:method_builder) { Sinclair.new(klass) }
|
63
|
+
let(:expected_template) { 'templates/forms/my_custom_element' }
|
64
|
+
|
65
|
+
before do
|
66
|
+
method_builder.add_class_method(:name) do
|
67
|
+
'Magicka::MyCustomElement'
|
68
|
+
end
|
69
|
+
method_builder.build
|
70
|
+
end
|
71
|
+
|
72
|
+
it do
|
73
|
+
klass.render(arguments)
|
74
|
+
|
75
|
+
expect(renderer).to have_received(:render)
|
76
|
+
end
|
77
|
+
|
78
|
+
context 'when called with extra params' do
|
79
|
+
it do
|
80
|
+
klass.render(name: 'Name', **arguments)
|
81
|
+
|
82
|
+
expect(renderer).to have_received(:render)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
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
|
@@ -25,4 +25,22 @@ describe Magicka::MethodBuilder do
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
28
|
+
|
29
|
+
describe '#add_template_folder' do
|
30
|
+
let(:folder) { 'path_to_template_folder' }
|
31
|
+
|
32
|
+
it do
|
33
|
+
expect { builder.add_template_folder(folder) }
|
34
|
+
.to add_method(:template_folder)
|
35
|
+
.to(klass)
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'when method is build as requested' do
|
39
|
+
before { builder.add_template_folder(folder) }
|
40
|
+
|
41
|
+
it 'returns the defined template folder when method is called' do
|
42
|
+
expect(instance.template_folder).to eq(folder)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
28
46
|
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Magicka::Select do
|
6
|
+
let(:renderer) { instance_double('renderer') }
|
7
|
+
let(:template) { 'templates/forms/select' }
|
8
|
+
|
9
|
+
let(:model) { :my_model }
|
10
|
+
let(:field) { :field }
|
11
|
+
let(:label) { 'Label' }
|
12
|
+
let(:options) { %i[option_a option_b] }
|
13
|
+
|
14
|
+
let(:locals) do
|
15
|
+
{
|
16
|
+
field: field,
|
17
|
+
label: label,
|
18
|
+
ng_errors: 'my_model.errors.field',
|
19
|
+
ng_model: 'my_model.field',
|
20
|
+
options: options
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '.render' do
|
25
|
+
let(:arguments) do
|
26
|
+
{
|
27
|
+
renderer: renderer,
|
28
|
+
field: field,
|
29
|
+
label: label,
|
30
|
+
model: model,
|
31
|
+
options: options
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
before do
|
36
|
+
allow(renderer)
|
37
|
+
.to receive(:render)
|
38
|
+
.with(partial: template, locals: locals)
|
39
|
+
end
|
40
|
+
|
41
|
+
it do
|
42
|
+
described_class.render(arguments)
|
43
|
+
|
44
|
+
expect(renderer).to have_received(:render)
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'when called with extra params' do
|
48
|
+
it do
|
49
|
+
described_class.render(name: 'Name', **arguments)
|
50
|
+
|
51
|
+
expect(renderer).to have_received(:render)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
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.
|
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-
|
11
|
+
date: 2020-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -16,56 +16,56 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 5.2.4.
|
19
|
+
version: 5.2.4.3
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 5.2.4.
|
26
|
+
version: 5.2.4.3
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: sinclair
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 1.6.
|
33
|
+
version: 1.6.7
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 1.6.
|
40
|
+
version: 1.6.7
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: actionpack
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - '='
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 5.2.4.
|
47
|
+
version: 5.2.4.3
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - '='
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 5.2.4.
|
54
|
+
version: 5.2.4.3
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: activerecord
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - '='
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 5.2.4.
|
61
|
+
version: 5.2.4.3
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - '='
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 5.2.4.
|
68
|
+
version: 5.2.4.3
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: bundler
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -142,14 +142,14 @@ dependencies:
|
|
142
142
|
requirements:
|
143
143
|
- - '='
|
144
144
|
- !ruby/object:Gem::Version
|
145
|
-
version: 5.2.4.
|
145
|
+
version: 5.2.4.3
|
146
146
|
type: :development
|
147
147
|
prerelease: false
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
150
|
- - '='
|
151
151
|
- !ruby/object:Gem::Version
|
152
|
-
version: 5.2.4.
|
152
|
+
version: 5.2.4.3
|
153
153
|
- !ruby/object:Gem::Dependency
|
154
154
|
name: rails-controller-testing
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
@@ -397,10 +397,14 @@ files:
|
|
397
397
|
- config/yardstick.yml
|
398
398
|
- docker-compose.yml
|
399
399
|
- lib/magicka.rb
|
400
|
+
- lib/magicka/button.rb
|
400
401
|
- lib/magicka/element.rb
|
401
402
|
- lib/magicka/element/class_methods.rb
|
403
|
+
- lib/magicka/form.rb
|
404
|
+
- lib/magicka/form_element.rb
|
402
405
|
- lib/magicka/input.rb
|
403
406
|
- lib/magicka/method_builder.rb
|
407
|
+
- lib/magicka/select.rb
|
404
408
|
- lib/magicka/version.rb
|
405
409
|
- magicka.gemspec
|
406
410
|
- magicka.jpg
|
@@ -465,10 +469,14 @@ files:
|
|
465
469
|
- spec/dummy/storage/.keep
|
466
470
|
- spec/integration/readme/.keep
|
467
471
|
- spec/integration/yard/.keep
|
472
|
+
- spec/lib/magicka/button_spec.rb
|
468
473
|
- spec/lib/magicka/element/class_methods_spec.rb
|
469
474
|
- spec/lib/magicka/element_spec.rb
|
475
|
+
- spec/lib/magicka/form_element_spec.rb
|
476
|
+
- spec/lib/magicka/form_spec.rb
|
470
477
|
- spec/lib/magicka/input_spec.rb
|
471
478
|
- spec/lib/magicka/method_builder_spec.rb
|
479
|
+
- spec/lib/magicka/select_spec.rb
|
472
480
|
- spec/spec_helper.rb
|
473
481
|
- spec/support/models/.keep
|
474
482
|
- spec/support/shared_examples/.keep
|