magicka 0.5.6 → 1.0.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: 2b014302f0498ecea2e69670c168bdf2ee5eaaa8162b210faf007351d4417976
4
- data.tar.gz: 1ee57425d99ce223334f9567156ff1ab791f78e6f043c9ae5adca87291e28f1b
3
+ metadata.gz: 662d942d270879b97fb0ee3be36a41c4448db92ab11f2f3462fd4315a53b06d7
4
+ data.tar.gz: b6dc02755727b9f84ab61dd66eb34d71a8ecac53da565594e49f69c1e632b784
5
5
  SHA512:
6
- metadata.gz: 37e81304adc719f63fd65d3a643d2392cca27fdce94489072f675571b440815f074e9bf5613bf365dae1b8f26edc24cdf4a564d8821e69a49d4419488bf7cd0c
7
- data.tar.gz: 20b572511516fd8af749499059b2d14d01bf0047fbe3b509304b4c117032b617427aa84d7389ed400aa5b9acfb0d6c6dff539cd67e448b55e0c25dd5582f17ab
6
+ metadata.gz: 7bad26b83421ea3d47a6d002aa521f754fea7df036ed89ebf457297b076ffc2118bbdaf3fe2465a8cff8e1b3f176ef02dddb0211b20e3b2ab9f0c010b1cf75f6
7
+ data.tar.gz: ce04771c5649517ee7c17b54978b61137c897e0e23118aac1806b4035ab96aafba6aef857f1cc498048e4ff37b37d0eef433f0133fd871cb364b19cedab5a08a
data/.circleci/config.yml CHANGED
@@ -22,7 +22,7 @@ workflows:
22
22
  jobs:
23
23
  test:
24
24
  docker:
25
- - image: darthjee/circleci_rails_gems:0.7.0
25
+ - image: darthjee/circleci_rails_gems:1.2.0
26
26
  environment:
27
27
  PROJECT: magicka
28
28
  steps:
@@ -41,7 +41,7 @@ jobs:
41
41
  command: cc-test-reporter after-build --exit-code $?
42
42
  checks:
43
43
  docker:
44
- - image: darthjee/circleci_rails_gems:0.7.0
44
+ - image: darthjee/circleci_rails_gems:1.2.0
45
45
  environment:
46
46
  PROJECT: magicka
47
47
  steps:
@@ -66,7 +66,7 @@ jobs:
66
66
  command: check_specs
67
67
  build-and-release:
68
68
  docker:
69
- - image: darthjee/circleci_rails_gems:0.7.0
69
+ - image: darthjee/circleci_rails_gems:1.2.0
70
70
  environment:
71
71
  PROJECT: magicka
72
72
  steps:
data/.rubocop.yml CHANGED
@@ -2,7 +2,7 @@ require: rubocop-rspec
2
2
  inherit_from: .rubocop_todo.yml
3
3
 
4
4
  AllCops:
5
- TargetRubyVersion: 2.5
5
+ TargetRubyVersion: 2.7
6
6
 
7
7
  Metrics/BlockLength:
8
8
  Exclude:
data/Dockerfile CHANGED
@@ -1,6 +1,6 @@
1
- FROM darthjee/scripts:0.1.8 as scripts
1
+ FROM darthjee/scripts:0.3.1 as scripts
2
2
 
3
- FROM darthjee/rails_gems:0.7.0 as base
3
+ FROM darthjee/rails_gems:1.2.0 as base
4
4
 
5
5
  COPY --chown=app:app ./ /home/app/app/
6
6
 
@@ -19,3 +19,4 @@ FROM base
19
19
 
20
20
  COPY --chown=app:app --from=builder /home/app/bundle/ /usr/local/bundle/
21
21
  RUN bundle install
22
+ RUN bundle clean --force
data/README.md CHANGED
@@ -12,9 +12,13 @@ Magicka
12
12
  Magica helps creating html templates for forms and display data using js applications
13
13
  such as AngulaJS
14
14
 
15
+ Current Release: [2.0.0](https://github.com/darthjee/magicka/tree/1.0.0)
16
+
17
+ [Next release](https://github.com/darthjee/magicka/compare/1.0.0...master)
18
+
15
19
  Yard Documentation
16
20
  -------------------
17
- [https://www.rubydoc.info/gems/magicka/0.5.6](https://www.rubydoc.info/gems/magicka/0.5.6)
21
+ [https://www.rubydoc.info/gems/magicka/1.0.0](https://www.rubydoc.info/gems/magicka/1.0.0)
18
22
 
19
23
  Installation
20
24
  ---------------
@@ -66,7 +70,11 @@ different ways
66
70
  <%= form.input(:last_name) %>
67
71
  <%= form.input(:age) %>
68
72
  <%= form.select(:gender, options: %w[MALE FEMALE] %>
69
- <%= form.button(ng_click: 'controller.save', text: 'Save') %>
73
+
74
+ <%= form.only(:form) do %>
75
+ <!-- this block only appears in a form -->
76
+ <%= form.button(ng_click: 'controller.save', text: 'Save') %>
77
+ <% end %>
70
78
  ```
71
79
 
72
80
  ## Configuring
@@ -1,5 +1,7 @@
1
1
  ignore:
2
2
  - lib/magicka/version.rb
3
3
  - lib/magicka.rb
4
+ - lib/magicka/aggregator/class_methods.rb
4
5
  - lib/magicka/aggregator/method_builder.rb
5
- - lib/magicka/helper.rb
6
+ - lib/magicka/helper/class_methods.rb
7
+ - lib/magicka/helper/method_builder.rb
data/config/yardstick.yml CHANGED
@@ -1,4 +1,4 @@
1
- threshold: 84.1
1
+ threshold: 90.0
2
2
  require_exact_threshold: false
3
3
  rules:
4
4
  ApiTag::Presence:
@@ -23,6 +23,8 @@ rules:
23
23
  enabled: true
24
24
  exclude:
25
25
  - Magicka::Element#initialize
26
+ - Magicka::Aggregator#initialize
27
+ - Magicka::Aggregator::MethodBuilder#initialize
26
28
  Summary::Length:
27
29
  enabled: true
28
30
  exclude: []
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Magicka
4
+ class Aggregator
5
+ # Class methods for {Magicka::Aggregator}
6
+ module ClassMethods
7
+ # (see Aggregator.with_element)
8
+ def with_element(element_class, method_name = nil, template: nil)
9
+ MethodBuilder
10
+ .new(self, element_class, method_name, template: template)
11
+ .prepare
12
+ .build
13
+ end
14
+
15
+ # Set and return the type of the aggregator
16
+ #
17
+ # When new_type is ommited, returns the last value
18
+ #
19
+ # @param new_type [Symbol,String] The value to be set
20
+ #
21
+ # @return [Symbol] the type of the aggregator
22
+ def type(new_type = nil)
23
+ return @type ||= default_type unless new_type
24
+
25
+ @type = new_type.to_sym
26
+ end
27
+
28
+ private
29
+
30
+ # @private
31
+ # @api private
32
+ #
33
+ # Default type when type is not defined
34
+ #
35
+ # Default type is extracted from class name
36
+ #
37
+ # @return [Symbol]
38
+ def default_type
39
+ name&.demodulize&.underscore&.to_sym
40
+ end
41
+ end
42
+ end
43
+ end
@@ -6,6 +6,13 @@ module Magicka
6
6
  #
7
7
  # Class responsible for building an {Aggregator} method
8
8
  class MethodBuilder < Sinclair
9
+ # @param klass [Class.new<Aggregator>]
10
+ # Aggragator class to receive the method
11
+ # @param element_class [Class<Magicka::ELement>]
12
+ # Class of the element to be rendered
13
+ # @param method_name [String,Symbol]
14
+ # Name of the method that will render the element
15
+ # @param template [String] custom template file to be used
9
16
  def initialize(klass, element_class, method_name = nil, template: nil)
10
17
  super(klass)
11
18
 
@@ -14,6 +21,9 @@ module Magicka
14
21
  @template = template
15
22
  end
16
23
 
24
+ # Prepare methods to be built
25
+ #
26
+ # @return [Aggregator::MethodBuilder] return self
17
27
  def prepare
18
28
  element_klass = element_class
19
29
  template_file = template
@@ -32,7 +42,28 @@ module Magicka
32
42
  private
33
43
 
34
44
  attr_reader :element_class, :template
45
+ # @method element_class
46
+ # @api private
47
+ # @private
48
+ #
49
+ # Class of the element to be rendered by the method
50
+ #
51
+ # @return [Class<Magicka::Element>]
35
52
 
53
+ # @method template
54
+ # @api private
55
+ # @private
56
+ #
57
+ # template file
58
+ #
59
+ # @return [String]
60
+
61
+ # name of the method to be generated
62
+ #
63
+ # When the method name was not supplied in the constructor,
64
+ # it is infered from {#element_class}
65
+ #
66
+ # @return [String,Symbol]
36
67
  def method_name
37
68
  @method_name ||= element_class
38
69
  .name
@@ -6,29 +6,86 @@ module Magicka
6
6
  # Class representing an element agregator, representing a model
7
7
  class Aggregator
8
8
  autoload :MethodBuilder, 'magicka/aggregator/method_builder'
9
+ autoload :ClassMethods, 'magicka/aggregator/class_methods'
9
10
 
10
11
  class << self
11
- def with_element(element_class, method_name = nil, template: nil)
12
- MethodBuilder
13
- .new(self, element_class, method_name, template: template)
14
- .prepare
15
- .build
16
- end
12
+ include Aggregator::ClassMethods
17
13
  end
18
14
 
19
15
  attr_reader :model
16
+ # @method model
17
+ # @api public
18
+ #
19
+ # Model where the form elements will focus
20
+ #
21
+ # @return [String]
20
22
 
23
+ # @method self.with_element(element_class, method_name = nil, template: nil)
24
+ #
25
+ # Configure an {Aggregator} adding a method to render an element
26
+ #
27
+ # @param element_class [Class<Magicka::ELement>]
28
+ # Class of the element to be rendered
29
+ # @param method_name [String,Symbol]
30
+ # Name of the method that will render the element
31
+ # @param template [String] custom template file to be used
32
+ #
33
+ # @see Aggregator::ClassMethods#with_element
34
+ # @see Aggregator::MethodBuilder
35
+ #
36
+ # @return [Array<NilClass>]
37
+
38
+ # @param renderer [ActionView::Base] Object responsible for rendering
39
+ # @param model [String] Model where the form elements will focus
21
40
  def initialize(renderer, model)
22
41
  @renderer = renderer
23
42
  @model = model
24
43
  end
25
44
 
45
+ # Returns a new aggregator focusing on a new model
46
+ #
47
+ # The new model is an attribute of +model+ unless base is given
48
+ #
49
+ # @param model [String] Model where the form elements will focus
50
+ # @param base [String] Model base
51
+ #
52
+ # @yield [Aggregator] new aggregator focused in the new model
53
+ #
54
+ # @return [Aggregator]
26
55
  def with_model(model, base: self.model)
27
56
  new_model = [base, model].compact.join('.')
28
57
 
29
58
  yield self.class.new(renderer, new_model)
30
59
  end
31
60
 
61
+ # Executes a block only when aggregator is one of given types
62
+ #
63
+ # @param types [Array<Symbol>] posssible types
64
+ #
65
+ # @return [Object] Result of the block
66
+ def only(*types)
67
+ return unless types.include?(self.class.type)
68
+
69
+ yield
70
+ end
71
+
72
+ # Executes a block only when aggregator is not one of given types
73
+ #
74
+ # @param types [Array<Symbol>] posssible types
75
+ #
76
+ # @return [Object] Result of the block
77
+ def except(*types)
78
+ return if types.include?(self.class.type)
79
+
80
+ yield
81
+ end
82
+
83
+ # @api private
84
+ # Checks if other aggragate is equal to this one
85
+ #
86
+ # @param [Object] other object to be compared
87
+ #
88
+ # @return [TrueClass,FalseClass]
32
89
  def equal?(other)
33
90
  return unless other.class == self.class
34
91
 
@@ -41,6 +98,13 @@ module Magicka
41
98
  protected
42
99
 
43
100
  attr_reader :renderer
101
+ # @method renderer
102
+ # @private
103
+ # @api private
104
+ #
105
+ # Returns the element needed to render the view
106
+ #
107
+ # @return [ActionView::Base]
44
108
 
45
109
  delegate :render, to: :renderer
46
110
  end
@@ -1,11 +1,43 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Magicka
4
+ # @api public
5
+ #
4
6
  # Class responsible for controlling one object display
5
7
  class Display < Aggregator
6
8
  with_element(Text, :input)
7
9
  with_element(Text, :select)
8
10
 
11
+ # Noop
12
+ #
13
+ # Used to not render a button when using
14
+ # display and not form
15
+ #
16
+ # #return [NilClass]
9
17
  def button(**_args); end
18
+
19
+ # @method input(field, model: self.model, **options)
20
+ # @api public
21
+ #
22
+ # @param field [String,Symbol] field to be shown
23
+ # @param model [String] model being rendered
24
+ # (when omited, use the aggregator model)
25
+ # @param options [Hash]
26
+ #
27
+ # @see Magicka::Text
28
+ #
29
+ # @return (see Magicka::Element#render)
30
+
31
+ # @method select(field, model: self.model, **options)
32
+ # @api public
33
+ #
34
+ # @param field [String,Symbol] field to be shown
35
+ # @param model [String] model being rendered
36
+ # (when omited, use the aggregator model)
37
+ # @param options [Hash]
38
+ #
39
+ # @see Magicka::Text
40
+ #
41
+ # @return (see Magicka::Element#render)
10
42
  end
11
43
  end
@@ -25,7 +25,7 @@ module Magicka
25
25
  #
26
26
  # The method will always return the template folder given in the params
27
27
  #
28
- # @param template_folder [String] path to template folder
28
+ # @param folder [String] path to template folder
29
29
  #
30
30
  # @return [Array<Sinclair::MethodDefinition>]
31
31
  def add_template_folder(folder)
@@ -33,6 +33,9 @@ module Magicka
33
33
  # @return [Array]
34
34
 
35
35
  # Render element HTML
36
+ # @api private
37
+ #
38
+ # @return [ActionView::OutputBuffer]
36
39
  def render
37
40
  renderer.render partial: template, locals: locals
38
41
  end
data/lib/magicka/form.rb CHANGED
@@ -6,8 +6,35 @@ module Magicka
6
6
  with_element(Input)
7
7
  with_element(Select)
8
8
 
9
+ # Renders a button
10
+ #
11
+ # @return (see Magicka::Element#render)
9
12
  def button(**args)
10
13
  Button.render(renderer: renderer, **args)
11
14
  end
15
+
16
+ # @method input(field, model: self.model, **options)
17
+ # @api public
18
+ #
19
+ # @param field [String,Symbol] field to be shown
20
+ # @param model [String] model being rendered
21
+ # (when omited, use the aggregator model)
22
+ # @param options [Hash]
23
+ #
24
+ # @see Magicka::Input
25
+ #
26
+ # @return (see Magicka::Element#render)
27
+
28
+ # @method select(field, model: self.model, **options)
29
+ # @api public
30
+ #
31
+ # @param field [String,Symbol] field to be shown
32
+ # @param model [String] model being rendered
33
+ # (when omited, use the aggregator model)
34
+ # @param options [Hash]
35
+ #
36
+ # @see Magicka::Select
37
+ #
38
+ # @return (see Magicka::Element#render)
12
39
  end
13
40
  end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Magicka
4
+ module Helper
5
+ # Class methods for {Magicka::Helper}
6
+ module ClassMethods
7
+ # (see Magicka::Helper.with)
8
+ def with(aggregator_class, type = aggregator_class.type)
9
+ MethodBuilder.new(self).build_aggregator(aggregator_class, type)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Magicka
4
+ module Helper
5
+ # Builds methods for {Magicka::Helper}
6
+ class MethodBuilder < Sinclair
7
+ # (see Magicka::Helper.with)
8
+ def build_aggregator(aggregator_class, type = aggregator_class.type)
9
+ add_method("magicka_#{type}") do |model, &block|
10
+ block.call(aggregator_class.new(self, model))
11
+ end
12
+
13
+ build
14
+ end
15
+ end
16
+ end
17
+ end
@@ -3,12 +3,55 @@
3
3
  module Magicka
4
4
  # Helper module to be used on rails
5
5
  module Helper
6
- def magicka_form(model)
7
- yield Form.new(self, model)
8
- end
6
+ autoload :ClassMethods, 'magicka/helper/class_methods'
7
+ autoload :MethodBuilder, 'magicka/helper/method_builder'
9
8
 
10
- def magicka_display(model)
11
- yield Display.new(self, model)
9
+ class << self
10
+ include Helper::ClassMethods
12
11
  end
12
+
13
+ with Form
14
+ with Display
15
+
16
+ # @method self.with(aggregator_class, type = aggregator_class.type)
17
+ #
18
+ # Adds a helper method magicka_+type+
19
+ #
20
+ # The created method executes a block with a an aggragator
21
+ #
22
+ # @param aggregator_class [Class<Magicka::Aggregator>]
23
+ # Agragator to be initialized
24
+ # @param type [String,Symbol] type of aggregator,
25
+ # this will define the method name
26
+ #
27
+ # @return [Array<NilClass>]
28
+
29
+ # @method magicka_form(model)
30
+ #
31
+ # Execute a block with an aggregator focused on a model
32
+ #
33
+ # The aggregator renders elements as form elements
34
+ #
35
+ # @param model [String] Model to be processed
36
+ #
37
+ # @yield [Magicka::Form] Agregator to edit a model
38
+ #
39
+ # @see Magicka::Form
40
+ #
41
+ # @return [String]
42
+
43
+ # @method magicka_display(model)
44
+ #
45
+ # Execute a block with an aggregator focused on a model
46
+ #
47
+ # The aggregator renders elements as display elements
48
+ #
49
+ # @param model [String] Model to be processed
50
+ #
51
+ # @yield [Magicka::Display] Agregator to show a model
52
+ #
53
+ # @see Magicka::Display
54
+ #
55
+ # @return [String]
13
56
  end
14
57
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Magicka
4
- VERSION = '0.5.6'
4
+ VERSION = '1.0.0'
5
5
  end
data/magicka.gemspec CHANGED
@@ -12,24 +12,24 @@ Gem::Specification.new do |gem|
12
12
  gem.homepage = 'https://github.com/darthjee/magicka'
13
13
  gem.description = 'Gem for easy form templating'
14
14
  gem.summary = gem.description
15
- gem.required_ruby_version = '>= 2.5.0'
15
+ gem.required_ruby_version = '>= 2.7.0'
16
16
 
17
17
  gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
18
18
  gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
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.x'
23
- gem.add_runtime_dependency 'sinclair', '>= 1.6.7'
22
+ gem.add_runtime_dependency 'activesupport', '~> 7.0.x'
23
+ gem.add_runtime_dependency 'sinclair', '>= 2.0.0'
24
24
 
25
- gem.add_development_dependency 'actionpack', '~> 5.2.x'
26
- gem.add_development_dependency 'activerecord', '~> 5.2.x'
27
- gem.add_development_dependency 'bundler', '1.16.1'
25
+ gem.add_development_dependency 'actionpack', '7.0.4.3'
26
+ gem.add_development_dependency 'activerecord', '7.0.4.3'
27
+ gem.add_development_dependency 'bundler', '>= 2.3.25'
28
28
  gem.add_development_dependency 'factory_bot', '5.2.0'
29
- gem.add_development_dependency 'nokogiri', '1.11.4'
29
+ gem.add_development_dependency 'nokogiri', '1.12.5'
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.x'
32
+ gem.add_development_dependency 'rails', '7.0.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', '6.0.3'
@@ -43,7 +43,9 @@ Gem::Specification.new do |gem|
43
43
  gem.add_development_dependency 'rubocop-rspec', '1.38.1'
44
44
  gem.add_development_dependency 'rubycritic', '4.6.1'
45
45
  gem.add_development_dependency 'simplecov', '0.17.1'
46
+ gem.add_development_dependency 'sprockets-rails', '3.4.2'
46
47
  gem.add_development_dependency 'sqlite3', '1.4.2'
48
+ gem.add_development_dependency 'tzinfo-data', '~> 1.2022.1'
47
49
  gem.add_development_dependency 'yard', '0.9.26'
48
50
  gem.add_development_dependency 'yardstick', '0.9.9'
49
51
  end
@@ -11,6 +11,31 @@ describe Magicka::Aggregator do
11
11
  let(:template) { 'templates/forms/input' }
12
12
  let(:locals) { {} }
13
13
 
14
+ describe '.type' do
15
+ let(:type) { %w[form display other].sample }
16
+
17
+ it 'sets aggregator type' do
18
+ expect { aggregator_class.type(type) }
19
+ .to change(aggregator_class, :type)
20
+ .from(nil).to(type.to_sym)
21
+ end
22
+
23
+ context 'when type has not been set' do
24
+ let(:aggregator_class) do
25
+ Class.new(described_class) do
26
+ def self.name
27
+ 'Magicka::MyClass'
28
+ end
29
+ end
30
+ end
31
+
32
+ it 'Uses class name as type' do
33
+ expect(aggregator_class.type)
34
+ .to eq(:my_class)
35
+ end
36
+ end
37
+ end
38
+
14
39
  describe '.with_element' do
15
40
  context 'when seeting element class only' do
16
41
  it do
@@ -51,7 +76,7 @@ describe Magicka::Aggregator do
51
76
  end
52
77
 
53
78
  it 'renders an input' do
54
- aggregator.input(field, arguments)
79
+ aggregator.input(field, **arguments)
55
80
 
56
81
  expect(renderer).to have_received(:render)
57
82
  end
@@ -115,7 +140,7 @@ describe Magicka::Aggregator do
115
140
  end
116
141
 
117
142
  it 'renders an input' do
118
- aggregator.my_input(field, arguments)
143
+ aggregator.my_input(field, **arguments)
119
144
 
120
145
  expect(renderer).to have_received(:render)
121
146
  end
@@ -181,7 +206,7 @@ describe Magicka::Aggregator do
181
206
  end
182
207
 
183
208
  it 'renders an input' do
184
- aggregator.input(field, arguments)
209
+ aggregator.input(field, **arguments)
185
210
 
186
211
  expect(renderer).to have_received(:render)
187
212
  end
@@ -206,4 +231,68 @@ describe Magicka::Aggregator do
206
231
  end
207
232
  end
208
233
  end
234
+
235
+ describe '#with_model' do
236
+ let(:expected_aggregator) do
237
+ aggregator_class.new(renderer, 'my_model.inner')
238
+ end
239
+
240
+ it do
241
+ aggregator.with_model(:inner) do |new_aggregator|
242
+ expect(new_aggregator).to eq(expected_aggregator)
243
+ end
244
+ end
245
+ end
246
+
247
+ describe '#only' do
248
+ let(:aggregator_class) do
249
+ Class.new(described_class) do
250
+ type :included
251
+ end
252
+ end
253
+
254
+ context 'when the type is included in the list' do
255
+ it 'executes the block' do
256
+ value = 0
257
+
258
+ aggregator.only(:not_included, :included, :other) { value += 1 }
259
+ expect(value).to eq(1)
260
+ end
261
+ end
262
+
263
+ context 'when the type is not included in the list' do
264
+ it 'does not execute the block' do
265
+ value = 0
266
+
267
+ aggregator.only(:not_included, :other) { value += 1 }
268
+ expect(value).to be_zero
269
+ end
270
+ end
271
+ end
272
+
273
+ describe '#except' do
274
+ let(:aggregator_class) do
275
+ Class.new(described_class) do
276
+ type :included
277
+ end
278
+ end
279
+
280
+ context 'when the type is included in the list' do
281
+ it 'does not execute the block' do
282
+ value = 0
283
+
284
+ aggregator.except(:not_included, :included, :other) { value += 1 }
285
+ expect(value).to be_zero
286
+ end
287
+ end
288
+
289
+ context 'when the type is not included in the list' do
290
+ it 'executes the block' do
291
+ value = 0
292
+
293
+ aggregator.except(:not_included, :other) { value += 1 }
294
+ expect(value).to eq(1)
295
+ end
296
+ end
297
+ end
209
298
  end
@@ -38,7 +38,7 @@ describe Magicka::Button do
38
38
  end
39
39
 
40
40
  it do
41
- described_class.render(arguments)
41
+ described_class.render(**arguments)
42
42
 
43
43
  expect(renderer).to have_received(:render)
44
44
  end
@@ -16,6 +16,12 @@ describe Magicka::Display do
16
16
  .with(partial: template, locals: locals)
17
17
  end
18
18
 
19
+ describe '.type' do
20
+ it do
21
+ expect(described_class.type).to eq(:display)
22
+ end
23
+ end
24
+
19
25
  describe '#input' do
20
26
  let(:template) { 'templates/display/text' }
21
27
  let(:field) { :field }
@@ -39,7 +45,7 @@ describe Magicka::Display do
39
45
  end
40
46
 
41
47
  it 'renders a text' do
42
- form.input(field, arguments)
48
+ form.input(field, **arguments)
43
49
 
44
50
  expect(renderer).to have_received(:render)
45
51
  end
@@ -85,7 +91,7 @@ describe Magicka::Display do
85
91
  end
86
92
 
87
93
  it 'renders a text' do
88
- form.select(field, arguments)
94
+ form.select(field, **arguments)
89
95
 
90
96
  expect(renderer).to have_received(:render)
91
97
  end
@@ -124,7 +130,7 @@ describe Magicka::Display do
124
130
  end
125
131
 
126
132
  it 'renders nothing' do
127
- form.button(arguments)
133
+ form.button(**arguments)
128
134
 
129
135
  expect(renderer).not_to have_received(:render)
130
136
  end
@@ -166,4 +172,44 @@ describe Magicka::Display do
166
172
  end
167
173
  end
168
174
  end
175
+
176
+ describe '#only' do
177
+ context 'when the type is included in the list' do
178
+ it 'executes the block' do
179
+ value = 0
180
+
181
+ form.only(:not_included, :display, :other) { value += 1 }
182
+ expect(value).to eq(1)
183
+ end
184
+ end
185
+
186
+ context 'when the type is not included in the list' do
187
+ it 'does not execute the block' do
188
+ value = 0
189
+
190
+ form.only(:not_included, :other) { value += 1 }
191
+ expect(value).to be_zero
192
+ end
193
+ end
194
+ end
195
+
196
+ describe '#except' do
197
+ context 'when the type is included in the list' do
198
+ it 'does not execute the block' do
199
+ value = 0
200
+
201
+ form.except(:not_included, :display, :other) { value += 1 }
202
+ expect(value).to be_zero
203
+ end
204
+ end
205
+
206
+ context 'when the type is not included in the list' do
207
+ it 'executes the block' do
208
+ value = 0
209
+
210
+ form.except(:not_included, :other) { value += 1 }
211
+ expect(value).to eq(1)
212
+ end
213
+ end
214
+ end
169
215
  end
@@ -44,7 +44,7 @@ describe Magicka::FormElement do
44
44
  end
45
45
 
46
46
  it do
47
- klass.render(arguments)
47
+ klass.render(**arguments)
48
48
 
49
49
  expect(renderer).to have_received(:render)
50
50
  end
@@ -70,7 +70,7 @@ describe Magicka::FormElement do
70
70
  end
71
71
 
72
72
  it do
73
- klass.render(arguments)
73
+ klass.render(**arguments)
74
74
 
75
75
  expect(renderer).to have_received(:render)
76
76
  end
@@ -16,6 +16,12 @@ describe Magicka::Form do
16
16
  .with(partial: template, locals: locals)
17
17
  end
18
18
 
19
+ describe '.type' do
20
+ it do
21
+ expect(described_class.type).to eq(:form)
22
+ end
23
+ end
24
+
19
25
  describe '#input' do
20
26
  let(:template) { 'templates/forms/input' }
21
27
  let(:field) { :field }
@@ -40,7 +46,7 @@ describe Magicka::Form do
40
46
  end
41
47
 
42
48
  it 'renders an input' do
43
- form.input(field, arguments)
49
+ form.input(field, **arguments)
44
50
 
45
51
  expect(renderer).to have_received(:render)
46
52
  end
@@ -88,7 +94,7 @@ describe Magicka::Form do
88
94
  end
89
95
 
90
96
  it 'renders a select' do
91
- form.select(field, arguments)
97
+ form.select(field, **arguments)
92
98
 
93
99
  expect(renderer).to have_received(:render)
94
100
  end
@@ -138,7 +144,7 @@ describe Magicka::Form do
138
144
  end
139
145
 
140
146
  it 'renders an input' do
141
- form.button(arguments)
147
+ form.button(**arguments)
142
148
 
143
149
  expect(renderer).to have_received(:render)
144
150
  end
@@ -180,4 +186,44 @@ describe Magicka::Form do
180
186
  end
181
187
  end
182
188
  end
189
+
190
+ describe '#only' do
191
+ context 'when the type is included in the list' do
192
+ it 'executes the block' do
193
+ value = 0
194
+
195
+ form.only(:not_included, :form, :other) { value += 1 }
196
+ expect(value).to eq(1)
197
+ end
198
+ end
199
+
200
+ context 'when the type is not included in the list' do
201
+ it 'does not execute the block' do
202
+ value = 0
203
+
204
+ form.only(:not_included, :other) { value += 1 }
205
+ expect(value).to be_zero
206
+ end
207
+ end
208
+ end
209
+
210
+ describe '#except' do
211
+ context 'when the type is included in the list' do
212
+ it 'does not execute the block' do
213
+ value = 0
214
+
215
+ form.except(:not_included, :form, :other) { value += 1 }
216
+ expect(value).to be_zero
217
+ end
218
+ end
219
+
220
+ context 'when the type is not included in the list' do
221
+ it 'executes the block' do
222
+ value = 0
223
+
224
+ form.except(:not_included, :other) { value += 1 }
225
+ expect(value).to eq(1)
226
+ end
227
+ end
228
+ end
183
229
  end
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Magicka::Helper do
6
+ subject(:object) { klass.new }
7
+
8
+ let(:klass) do
9
+ Class.new do
10
+ include Magicka::Helper
11
+ end
12
+ end
13
+
14
+ let(:model) { 'model' }
15
+
16
+ describe '.with' do
17
+ let(:aggregator_class) do
18
+ Class.new(Magicka::Aggregator) do
19
+ def self.name
20
+ 'Magicka::MyClass'
21
+ end
22
+ end
23
+ end
24
+
25
+ it do
26
+ expect { described_class.with(aggregator_class) }
27
+ .to add_method('magicka_my_class')
28
+ .to(object)
29
+ end
30
+ end
31
+
32
+ describe '#magicka_display' do
33
+ it do
34
+ object.magicka_display(model) do |display|
35
+ expect(display).to be_a(Magicka::Display)
36
+ end
37
+ end
38
+
39
+ it 'populates the model' do
40
+ object.magicka_display(model) do |display|
41
+ expect(display.model).to eq(model)
42
+ end
43
+ end
44
+
45
+ it 'populates the renderer' do
46
+ object.magicka_display(model) do |display|
47
+ expect(display.send(:renderer)).to eq(object)
48
+ end
49
+ end
50
+ end
51
+
52
+ describe '#magicka_form' do
53
+ it do
54
+ object.magicka_form(model) do |form|
55
+ expect(form).to be_a(Magicka::Form)
56
+ end
57
+ end
58
+
59
+ it 'populates the model' do
60
+ object.magicka_form(model) do |form|
61
+ expect(form.model).to eq(model)
62
+ end
63
+ end
64
+
65
+ it 'populates the renderer' do
66
+ object.magicka_form(model) do |form|
67
+ expect(form.send(:renderer)).to eq(object)
68
+ end
69
+ end
70
+ end
71
+ end
@@ -39,7 +39,7 @@ describe Magicka::Input do
39
39
  end
40
40
 
41
41
  it do
42
- described_class.render(arguments)
42
+ described_class.render(**arguments)
43
43
 
44
44
  expect(renderer).to have_received(:render)
45
45
  end
@@ -39,7 +39,7 @@ describe Magicka::Select do
39
39
  end
40
40
 
41
41
  it do
42
- described_class.render(arguments)
42
+ described_class.render(**arguments)
43
43
 
44
44
  expect(renderer).to have_received(:render)
45
45
  end
@@ -36,7 +36,7 @@ describe Magicka::Text do
36
36
  end
37
37
 
38
38
  it do
39
- described_class.render(arguments)
39
+ described_class.render(**arguments)
40
40
 
41
41
  expect(renderer).to have_received(:render)
42
42
  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.5.6
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - DarthJee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-21 00:00:00.000000000 Z
11
+ date: 2023-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,70 +16,70 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 5.2.x
19
+ version: 7.0.x
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.x
26
+ version: 7.0.x
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.7
33
+ version: 2.0.0
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.7
40
+ version: 2.0.0
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.x
47
+ version: 7.0.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.x
54
+ version: 7.0.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.x
61
+ version: 7.0.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.x
68
+ version: 7.0.4.3
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: bundler
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: 1.16.1
75
+ version: 2.3.25
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: 1.16.1
82
+ version: 2.3.25
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: factory_bot
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -100,14 +100,14 @@ dependencies:
100
100
  requirements:
101
101
  - - '='
102
102
  - !ruby/object:Gem::Version
103
- version: 1.11.4
103
+ version: 1.12.5
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - '='
109
109
  - !ruby/object:Gem::Version
110
- version: 1.11.4
110
+ version: 1.12.5
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: pry
113
113
  requirement: !ruby/object:Gem::Requirement
@@ -140,16 +140,16 @@ dependencies:
140
140
  name: rails
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - "~>"
143
+ - - '='
144
144
  - !ruby/object:Gem::Version
145
- version: 5.2.x
145
+ version: 7.0.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.x
152
+ version: 7.0.4.3
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: rails-controller-testing
155
155
  requirement: !ruby/object:Gem::Requirement
@@ -332,6 +332,20 @@ dependencies:
332
332
  - - '='
333
333
  - !ruby/object:Gem::Version
334
334
  version: 0.17.1
335
+ - !ruby/object:Gem::Dependency
336
+ name: sprockets-rails
337
+ requirement: !ruby/object:Gem::Requirement
338
+ requirements:
339
+ - - '='
340
+ - !ruby/object:Gem::Version
341
+ version: 3.4.2
342
+ type: :development
343
+ prerelease: false
344
+ version_requirements: !ruby/object:Gem::Requirement
345
+ requirements:
346
+ - - '='
347
+ - !ruby/object:Gem::Version
348
+ version: 3.4.2
335
349
  - !ruby/object:Gem::Dependency
336
350
  name: sqlite3
337
351
  requirement: !ruby/object:Gem::Requirement
@@ -346,6 +360,20 @@ dependencies:
346
360
  - - '='
347
361
  - !ruby/object:Gem::Version
348
362
  version: 1.4.2
363
+ - !ruby/object:Gem::Dependency
364
+ name: tzinfo-data
365
+ requirement: !ruby/object:Gem::Requirement
366
+ requirements:
367
+ - - "~>"
368
+ - !ruby/object:Gem::Version
369
+ version: 1.2022.1
370
+ type: :development
371
+ prerelease: false
372
+ version_requirements: !ruby/object:Gem::Requirement
373
+ requirements:
374
+ - - "~>"
375
+ - !ruby/object:Gem::Version
376
+ version: 1.2022.1
349
377
  - !ruby/object:Gem::Dependency
350
378
  name: yard
351
379
  requirement: !ruby/object:Gem::Requirement
@@ -398,6 +426,7 @@ files:
398
426
  - docker-compose.yml
399
427
  - lib/magicka.rb
400
428
  - lib/magicka/aggregator.rb
429
+ - lib/magicka/aggregator/class_methods.rb
401
430
  - lib/magicka/aggregator/method_builder.rb
402
431
  - lib/magicka/button.rb
403
432
  - lib/magicka/display.rb
@@ -407,6 +436,8 @@ files:
407
436
  - lib/magicka/form.rb
408
437
  - lib/magicka/form_element.rb
409
438
  - lib/magicka/helper.rb
439
+ - lib/magicka/helper/class_methods.rb
440
+ - lib/magicka/helper/method_builder.rb
410
441
  - lib/magicka/input.rb
411
442
  - lib/magicka/select.rb
412
443
  - lib/magicka/text.rb
@@ -482,6 +513,7 @@ files:
482
513
  - spec/lib/magicka/element_spec.rb
483
514
  - spec/lib/magicka/form_element_spec.rb
484
515
  - spec/lib/magicka/form_spec.rb
516
+ - spec/lib/magicka/helper_spec.rb
485
517
  - spec/lib/magicka/input_spec.rb
486
518
  - spec/lib/magicka/select_spec.rb
487
519
  - spec/lib/magicka/text_spec.rb
@@ -499,15 +531,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
499
531
  requirements:
500
532
  - - ">="
501
533
  - !ruby/object:Gem::Version
502
- version: 2.5.0
534
+ version: 2.7.0
503
535
  required_rubygems_version: !ruby/object:Gem::Requirement
504
536
  requirements:
505
537
  - - ">="
506
538
  - !ruby/object:Gem::Version
507
539
  version: '0'
508
540
  requirements: []
509
- rubyforge_project:
510
- rubygems_version: 2.7.6
541
+ rubygems_version: 3.1.2
511
542
  signing_key:
512
543
  specification_version: 4
513
544
  summary: Gem for easy form templating