bemer-simple_form 0.0.0 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE-RU.txt +1 -1
  3. data/LICENSE.txt +1 -1
  4. data/lib/bemer-simple_form.rb +3 -0
  5. data/lib/bemer/simple_form.rb +31 -1
  6. data/lib/bemer/simple_form/builder.rb +72 -0
  7. data/lib/bemer/simple_form/configuration.rb +33 -0
  8. data/lib/bemer/simple_form/inputs.rb +75 -0
  9. data/lib/bemer/simple_form/test/configuration_helpers.rb +30 -0
  10. data/lib/bemer/simple_form/version.rb +1 -1
  11. data/spec/action_view/block_builder_with_a_name_as_a_passed_object_spec.rb +119 -0
  12. data/spec/action_view/first_spec.rb +54 -0
  13. data/spec/action_view/simple_form_for_as_a_block_builder_spec.rb +47 -0
  14. data/spec/bemer/simple_form/configuration_spec.rb +13 -0
  15. data/spec/dummy/Rakefile +5 -0
  16. data/spec/dummy/app/forms/search_form.rb +7 -0
  17. data/spec/dummy/app/models/article.rb +2 -0
  18. data/spec/dummy/bin/rails +7 -0
  19. data/spec/dummy/config.ru +7 -0
  20. data/spec/dummy/config/application.rb +49 -0
  21. data/spec/dummy/config/boot.rb +7 -0
  22. data/spec/dummy/config/database.yml +3 -0
  23. data/spec/dummy/config/environment.rb +7 -0
  24. data/spec/dummy/config/initializers/backtrace_silencers.rb +4 -0
  25. data/spec/dummy/config/initializers/bemer.rb +6 -0
  26. data/spec/dummy/config/initializers/simple_form.rb +179 -0
  27. data/spec/dummy/config/initializers/sqlite3.rb +1 -0
  28. data/spec/dummy/db/migrate/20191215094046_create_articles.rb +9 -0
  29. data/spec/dummy/db/schema.rb +21 -0
  30. data/spec/rails_helper.rb +30 -0
  31. data/spec/spec_helper.rb +41 -0
  32. data/spec/support/active_record.rb +11 -0
  33. data/spec/support/bemer_simple_form.rb +8 -0
  34. data/spec/support/helpers/simple_form.rb +11 -0
  35. metadata +146 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bfff629861512437d2e903a3511e5fa27d971ccd79d5943b5f3abaa05dacaa2c
4
- data.tar.gz: bf49c67882816074d3908d48972fdfc2770b433b60acb8997aaee0ab86d91ed9
3
+ metadata.gz: be75bc218822b46c9d58c77805d5a0b27069f49a1e86c37a67710c5593e8070b
4
+ data.tar.gz: a33c533dd18ad43cdc298e285ce655bd306b35478c76ccc9d234e3ff94768a4a
5
5
  SHA512:
6
- metadata.gz: 948717b4869ce06a5ecc1de36c0aa182d3c49003a4c96ce96aa0bcd6e644d7bf23fc2a19e2a9451fc5eac40a760c7081bfd1a3c21b25fdd12a5afc3ad20d6cfa
7
- data.tar.gz: b9451c62845a60cb8bc54ccbb054c201ffd494d2b22e37b06d1335b4d14d185864c8b3af501acdaafec95d186ca55a2febbc4645a7a8087e828c34d4b039a614
6
+ metadata.gz: eb2f862f3be9a652a2ffab4e0ab75612e359fcf4a4d2180e89dc35e946be828fc39b1cff25a0db2308e000c8a771097544eeb17f9edae42d4f2724350b1ea385
7
+ data.tar.gz: 885e499b291bf83e8ed0428b6295429c69f2f49d5fedeb18467d9b421ca85ca5c2b6f72110268ec5ef893414479b97846c66fe39fe297a143f5a2b5a08433aa2
@@ -1,6 +1,6 @@
1
1
  Лицензия MIT
2
2
 
3
- Copyright (c) 2019 Александр Григорьев
3
+ Copyright (c) 2020 Александр Григорьев
4
4
 
5
5
  Данная лицензия разрешает лицам, получившим копию данного программного
6
6
  обеспечения и сопутствующей документации (в дальнейшем именуемыми
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2019 Alexander Grigorev
3
+ Copyright (c) 2020 Alexander Grigorev
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bemer/simple_form'
@@ -1,8 +1,38 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'bemer/simple_form/version'
3
+ require 'bemer'
4
+ require 'simple_form'
5
+ require 'active_support'
6
+ require 'active_support/dependencies/autoload'
7
+ require 'active_support/lazy_load_hooks'
4
8
 
5
9
  module Bemer
6
10
  module SimpleForm
11
+ extend ActiveSupport::Autoload
12
+
13
+ autoload :Builder
14
+ autoload :Configuration
15
+ autoload :Inputs
16
+
17
+ module Test
18
+ autoload :ConfigurationHelpers, 'bemer/simple_form/test/configuration_helpers'
19
+ end
20
+
21
+ class << self
22
+ delegate :bemify_suffix_namespaces, :input_type_modifiers_for_suffix_namespaces, to: :config
23
+
24
+ def config
25
+ Bemer::SimpleForm::Configuration.instance
26
+ end
27
+
28
+ def setup
29
+ yield config
30
+ end
31
+ end
7
32
  end
8
33
  end
34
+
35
+ ActiveSupport.on_load :action_view do
36
+ ::SimpleForm::FormBuilder.send :prepend, Bemer::SimpleForm::Builder
37
+ ::SimpleForm::Inputs::Base.send :prepend, Bemer::SimpleForm::Inputs
38
+ end
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/core_ext/string/inflections'
4
+
5
+ module Bemer
6
+ module SimpleForm
7
+ module Builder
8
+ def initialize(*)
9
+ super
10
+
11
+ extract_block_options!(options)
12
+ end
13
+
14
+ def button(type, *args, &block)
15
+ options = args.extract_options!
16
+ elem = extract_name_for!(:elem, type, options)
17
+ entity = Bemer::EntityBuilder.new(block_entity.block, elem, extract_bem_options!(options))
18
+
19
+ options.delete(:block)
20
+
21
+ args << options.merge!(entity.attrs)
22
+
23
+ super
24
+ end
25
+
26
+ protected
27
+
28
+ def block_entity
29
+ @defaults.dig(:block_entity)
30
+ end
31
+
32
+ def extract_block_options!(options)
33
+ @defaults ||= {}
34
+ options ||= {}
35
+ options[:html] ||= {}
36
+
37
+ block = extract_name_for!(:block, object_name, options)
38
+
39
+ options.delete(:elem)
40
+
41
+ @defaults[:block_entity] = Bemer::EntityBuilder.new(block, extract_bem_options!(options))
42
+
43
+ options[:html].merge!(block_entity.attrs)
44
+ end
45
+
46
+ def extract_bem_options!(options)
47
+ bem = options.delete(:bem)
48
+ bem_cascade = extract_bem_cascade!(options)
49
+ css_classes = [options.delete(:cls), options.delete(:class), options[:html]&.delete(:class)]
50
+ js = options.delete(:js)
51
+ mix = options.delete(:mix)
52
+ mods = options.delete(:mods)
53
+
54
+ { bem: bem, js: js, mods: mods, mix: mix, bem_cascade: bem_cascade, cls: css_classes }
55
+ end
56
+
57
+ def extract_name_for!(key, default_name, options)
58
+ name = options.delete(key)
59
+
60
+ name.nil? ? default_name.to_s.to_sym : name
61
+ end
62
+
63
+ def extract_bem_cascade!(options)
64
+ bem_cascade = options.delete(:bem_cascade)
65
+
66
+ return bem_cascade if block_entity.nil?
67
+
68
+ bem_cascade.nil? ? block_entity.bem_cascade : bem_cascade
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'singleton'
4
+ require 'active_support/core_ext/array/wrap'
5
+
6
+ module Bemer
7
+ module SimpleForm
8
+ class Configuration
9
+ include Singleton
10
+
11
+ attr_accessor :bemify_namespaces, :input_type_modifiers_for_namespaces
12
+
13
+ def initialize
14
+ @bemify_namespaces = %i[error hint input wrapper label]
15
+ @input_type_modifiers_for_namespaces = %i[input wrapper label]
16
+ end
17
+
18
+ def bemify_suffix_namespaces
19
+ @bemify_suffix_namespaces ||= Array.wrap(bemify_namespaces).uniq.map { |n| add_sufix(n) }
20
+ end
21
+
22
+ def input_type_modifiers_for_suffix_namespaces
23
+ @input_type_modifiers_for_suffix_namespaces ||= Array.wrap(input_type_modifiers_for_namespaces).uniq.map { |n| add_sufix(n) }
24
+ end
25
+
26
+ protected
27
+
28
+ def add_sufix(namespace)
29
+ [namespace, :html].join('_').to_sym
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bemer
4
+ module SimpleForm
5
+ module Inputs
6
+ def initialize(builder, attribute_name, column, input_type, options = {})
7
+ super
8
+
9
+ bemify_input!
10
+ end
11
+
12
+ protected
13
+
14
+ def block_entity
15
+ @block_entity ||= @options.delete(:block_entity)
16
+ end
17
+
18
+ def bemify_input!
19
+ return unless block_entity
20
+
21
+ Bemer::SimpleForm.bemify_suffix_namespaces.each do |namespace|
22
+ elem = extract_elem_name_for!(namespace)
23
+ options = extract_bem_options_for!(namespace)
24
+
25
+ add_input_type_modifiers!(namespace, options)
26
+
27
+ elem_entity = ::Bemer::EntityBuilder.new(block_entity.block, elem, options)
28
+
29
+ bem_options_for(namespace).merge!(elem_entity.attrs).delete(:block)
30
+ end
31
+ end
32
+
33
+ def extract_elem_name_for!(namespace)
34
+ bem_options = bem_options_for(namespace)
35
+ elem = bem_options.delete(:elem)
36
+
37
+ return elem unless elem.nil?
38
+
39
+ suffix = namespace.to_s.chomp('_html') unless namespace.eql?(:input_html)
40
+
41
+ [reflection_or_attribute_name, suffix].compact.join('_').to_sym
42
+ end
43
+
44
+ def add_input_type_modifiers!(namespace, options)
45
+ return if Bemer::SimpleForm.input_type_modifiers_for_suffix_namespaces.exclude?(namespace)
46
+
47
+ options[:mods] = Array.wrap(options[:mods])
48
+
49
+ options[:mods].push(*additional_classes)
50
+ end
51
+
52
+ def bem_options_for(namespace)
53
+ namespace.eql?(:input_html) ? @input_html_options : @options[namespace] ||= {}
54
+ end
55
+
56
+ def extract_bem_options_for!(namespace)
57
+ bem_options = bem_options_for(namespace)
58
+ bem = bem_options.delete(:bem)
59
+ bem_cascade = extract_bem_cascade!(bem_options)
60
+ css_classes = [bem_options.delete(:cls), bem_options.delete(:class)]
61
+ js = bem_options.delete(:js)
62
+ mix = bem_options.delete(:mix)
63
+ mods = bem_options.delete(:mods)
64
+
65
+ { bem: bem, js: js, mods: mods, mix: mix, bem_cascade: bem_cascade, cls: css_classes }
66
+ end
67
+
68
+ def extract_bem_cascade!(options)
69
+ bem_cascade = options.delete(:bem_cascade)
70
+
71
+ bem_cascade.nil? ? block_entity.bem_cascade : bem_cascade
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bemer
4
+ module SimpleForm
5
+ module Test
6
+ module ConfigurationHelpers
7
+ def reset_bemer_simple_form_configuration(initializer_name = :bemer_simple_form)
8
+ Singleton.send(:__init__, Bemer::SimpleForm::Configuration)
9
+
10
+ return unless initializer_name
11
+
12
+ begin
13
+ load Rails.root.join('config', 'initializers', "#{initializer_name}.rb")
14
+ rescue LoadError # rubocop:disable Lint/HandleExceptions
15
+ end
16
+ end
17
+
18
+ def reset_bemer_simple_form_configuration_and_execute(initializer_name = :bemer_simple_form)
19
+ return unless block_given?
20
+
21
+ reset_bemer_simple_form_configuration(initializer_name)
22
+
23
+ yield Bemer::SimpleForm.config
24
+
25
+ reset_bemer_simple_form_configuration(initializer_name)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Bemer
4
4
  module SimpleForm
5
- VERSION = '0.0.0'
5
+ VERSION = '0.1.0'
6
6
  end
7
7
  end
@@ -0,0 +1,119 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe 'block builder with a name as a passed object' do
4
+ #########################
5
+ # Покрыть тестами:
6
+ #########################
7
+ # -------------------
8
+ # @bem = options.delete(:bem)
9
+ # @bem_cascade = options.delete(:bem_cascade)
10
+ # @css_classes = [options.delete(:class), options.delete(:cls)]
11
+ # @js = options.delete(:js)
12
+ # @mixins = MixinList.new(options.delete(:mix))
13
+ # @modifiers = ModifierList.new(block, element, options.delete(:mods))
14
+ # @tag = build_tag(options.delete(:tag))
15
+ # @html_attrs = options
16
+ # -------------------
17
+ # bem: false,nil... bem_cascade: false.. cls: [], class: ..
18
+ # { bem: bem, js: js, mods: mods, mix: mix, bem_cascade: bem_cascade, cls: css_classes }
19
+ # -------------------
20
+ # Bemer.config
21
+ # Bemer::SimpleForm.config
22
+ # -------------------
23
+ # simple_form_for([:admin, Article.new])
24
+ # simple_form_for('')
25
+ # -------------------
26
+ # @bem = false
27
+ # @default_block_tag = :div
28
+ # @default_element_tag = :div
29
+ # @element_name_separator = '__'
30
+ # @modifier_name_separator = '_'
31
+ # @modifier_value_separator = '_'
32
+ # -------------------
33
+ # @bemify_namespaces = %i[error hint input wrapper label]
34
+ # @input_type_modifiers_for_namespaces = %i[input wrapper label]
35
+
36
+ context 'when an object name is used as a block name' do
37
+ context 'when the object name as a string' do
38
+ it 'creates an HTML form as a block' do
39
+ form = simple_form_for('') do |f|
40
+ f.input :elem
41
+ end
42
+
43
+ p form
44
+ expect(form).to have_tag(:form) do
45
+ without_tag 'form[class]'
46
+ without_tag 'input[name="elem"][class]'
47
+ end
48
+ end
49
+ end
50
+
51
+ # it 'creates an HTML form as a block with elements' do
52
+ # form = simple_form_for '' do |f|
53
+ # f.input :elem
54
+ # end
55
+
56
+ # p form
57
+ # expect(form).to have_tag(:form, with: { class: 'form' }) do
58
+ # with_tag :input, with: { class: 'form__elem' }
59
+ # end
60
+ # end
61
+ end
62
+
63
+ # context 'when a block name is specified using the `as` parameter' do
64
+ # it 'creates an HTML form as a block' do
65
+ # form = simple_form_for(:form, as: :form_block)
66
+
67
+ # expect(form).to have_tag(:form, with: { class: 'form' })
68
+ # end
69
+ # end
70
+
71
+ # context 'when a block name is specified using the `block` parameter' do
72
+ # it 'creates an HTML form as a block' do
73
+ # form = simple_form_for(:form, block: :form_block)
74
+
75
+ # expect(form).to have_tag(:form, with: { class: 'form-block' })
76
+ # end
77
+
78
+ # it 'creates an HTML form as a block with elements' do
79
+ # form = simple_form_for :form, block: :form_block do |f|
80
+ # f.input :elem
81
+ # end
82
+
83
+ # expect(form).to have_tag(:form, with: { class: 'form' }) do
84
+ # with_tag :input, with: { class: 'form__elem' }
85
+ # end
86
+ # end
87
+ # end
88
+
89
+ # =================
90
+
91
+ # , as: :form, block: :search
92
+
93
+ # context 'when an object name is overridden with `as`' do
94
+ # context 'when an object name as a symbol' do
95
+ # end
96
+
97
+ # when an object name is used as a block name
98
+ # when a block name is specified using the `as` parameter
99
+ # when a block name is specified using the `block` parameter
100
+
101
+ # context 'when the block name is overridden with `as`' do
102
+ # end
103
+
104
+ # context 'when the block name is overridden with `block`' do
105
+ # end
106
+
107
+ # it 'creates an HTML form as a block with element' do
108
+ # form = simple_form_for :form do |f|
109
+ # f.input :elem
110
+ # f.simple_fields_for :hhh do |b|
111
+ # b.input :ddd
112
+ # end
113
+ # end
114
+
115
+ # expect(form).to have_tag(:form, with: { class: 'form' }) do
116
+ # with_tag :input, with: { class: 'form__elem' }
117
+ # end
118
+ # end
119
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ # RSpec.describe 'block_tag helper' do
4
+ # # def simple_form_for(record, options = {}, &block)
5
+ # # view.simple_form_for(record, { url: '', html: { class: '' } }.deep_merge(options), &block)
6
+ # # end
7
+
8
+ # it 'sdgfb' do
9
+ # form = simple_form_for :hello, html: { class: 'hh' } do |hello|
10
+ # concat hello.input :yuu
11
+ # concat hello.input :ooo
12
+ # concat hello.input :ooo1
13
+ # concat hello.button :submit
14
+ # end
15
+ # # form = view.simple_form_for(:hello, url: '', html: { class: '' }) do |hello|
16
+ # # concat hello.input :yuu
17
+ # # concat hello.input :ooo
18
+ # # concat hello.button :submit
19
+ # # end
20
+ # # view.render html: html
21
+ # # p page
22
+ # # assert_select 'ol'
23
+ # p form
24
+ # # eval_erb
25
+ # expect(form).to have_tag(:form, with: { class: 'hello' }) do
26
+ # with_tag :div, with: { class: 'hello__ooo-wrapper' }
27
+ # with_tag :input, with: { type: :submit, class: 'hello__submit' }
28
+ # end
29
+ # end
30
+ # end
31
+
32
+
33
+ # it 'sdgfb' do
34
+ # form = simple_form_for :hello, html: { class: 'hh' } do |hello|
35
+ # concat hello.input :yuu
36
+ # concat hello.input :ooo
37
+ # concat hello.input :ooo1
38
+ # concat hello.button :submit
39
+ # end
40
+ # # form = view.simple_form_for(:hello, url: '', html: { class: '' }) do |hello|
41
+ # # concat hello.input :yuu
42
+ # # concat hello.input :ooo
43
+ # # concat hello.button :submit
44
+ # # end
45
+ # # view.render html: html
46
+ # # p page
47
+ # # assert_select 'ol'
48
+ # # p form
49
+ # # eval_erb
50
+ # expect(form).to have_tag(:form, with: { class: 'hello' }) do
51
+ # with_tag :div, with: { class: 'hello__ooo-wrapper' }
52
+ # with_tag :input, with: { type: :submit, class: 'hello__submit' }
53
+ # end
54
+ # end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe 'simple_form_for as a block builder' do
4
+ # context 'when a form is created from a symbol' do
5
+ # it 'creates an HTML form as a block' do
6
+ # form = simple_form_for(:form)
7
+
8
+ # expect(form).to have_tag(:form, with: { class: 'form' })
9
+ # end
10
+
11
+ # it 'creates an HTML form as a block with element' do
12
+ # form = simple_form_for :form do |f|
13
+ # f.input :elem
14
+ # end
15
+
16
+ # expect(form).to have_tag(:form, with: { class: 'form' }) do
17
+ # with_tag :input, with: { class: 'form__elem' }
18
+ # end
19
+ # end
20
+ # end
21
+
22
+ # context 'when a form is created from an ActiveModel instance' do
23
+ # it 'creates an HTML form as a block with element' do
24
+ # form = simple_form_for SearchForm.new, as: :form, block: :search do |f|
25
+ # f.input :query
26
+ # end
27
+
28
+ # p form
29
+ # expect(form).to have_tag(:form, with: { class: 'search-form' }) do
30
+ # with_tag :input, with: { class: 'search-form__query' }
31
+ # end
32
+ # end
33
+ # end
34
+
35
+ # context 'when a form is created from an ActiveRecord instance' do
36
+ # it 'creates an HTML form as a block with element' do
37
+ # form = simple_form_for Article.new, as: :form, block: :search do |f|
38
+ # f.input :title, wrapper_html: { block: :hshsh, elem: :rr, mods: :disabled, mix: :shshsh }
39
+ # end
40
+
41
+ # p form
42
+ # expect(form).to have_tag(:form, with: { class: 'search-form' }) do
43
+ # with_tag :input, with: { class: 'search-form__query' }
44
+ # end
45
+ # end
46
+ # end
47
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Bemer::SimpleForm::Configuration do
4
+ subject(:configuration) { described_class.instance }
5
+
6
+ describe '#bemify_namespaces' do
7
+ it { expect(configuration.bemify_namespaces).to match_array %i[error hint input wrapper label] }
8
+ end
9
+
10
+ describe '#input_type_modifiers_for_namespaces' do
11
+ it { expect(configuration.input_type_modifiers_for_namespaces).to match_array %i[input wrapper label] }
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'config/application'
4
+
5
+ Rails.application.load_tasks
@@ -0,0 +1,7 @@
1
+ class SearchForm
2
+ include ::ActiveModel::Model
3
+
4
+ attr_accessor :query
5
+
6
+ validates :query, presence: true
7
+ end
@@ -0,0 +1,2 @@
1
+ class Article < ActiveRecord::Base
2
+ end
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ APP_PATH = File.expand_path('../config/application', __dir__)
5
+
6
+ require_relative '../config/boot'
7
+ require 'rails/commands'
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This file is used by Rack-based servers to start the application.
4
+
5
+ require_relative 'config/environment'
6
+
7
+ run Rails.application
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'boot'
4
+
5
+ require 'action_view/railtie'
6
+ require 'active_model/railtie'
7
+ require 'active_record/railtie'
8
+
9
+ Bundler.require(*Rails.groups)
10
+
11
+ require 'bemer/simple_form'
12
+
13
+ module Dummy
14
+ class Application < ::Rails::Application
15
+ config.cache_classes = true
16
+
17
+ # Do not eager load code on boot. This avoids loading your whole application
18
+ # just for the purpose of running a single test. If you are using a tool that
19
+ # preloads Rails for running tests, you may have to set it to true.
20
+ config.eager_load = false
21
+
22
+ # Show full error reports and disable caching.
23
+ config.consider_all_requests_local = true
24
+ config.action_controller.perform_caching = false
25
+
26
+ # Raise exceptions instead of rendering exception templates.
27
+ config.action_dispatch.show_exceptions = false
28
+
29
+ # Disable request forgery protection in test environment.
30
+ config.action_controller.allow_forgery_protection = false
31
+
32
+ # Print deprecation notices to the stderr.
33
+ config.active_support.deprecation = :stderr
34
+
35
+ config.secret_key_base = 'secret_key_base'
36
+
37
+ unless ENV['RAILS_ENABLE_TEST_LOG']
38
+ config.logger = Logger.new(nil)
39
+ config.log_level = :fatal
40
+ end
41
+
42
+ config.generators do |g|
43
+ g.test_framework nil
44
+ g.assets false
45
+ g.helper false
46
+ g.stylesheets false
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Set up gems listed in the Gemfile.
4
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../Gemfile', __dir__)
5
+
6
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
7
+ $LOAD_PATH.unshift File.expand_path('../../../lib', __dir__)
@@ -0,0 +1,3 @@
1
+ <%= Rails.env %>:
2
+ adapter: sqlite3
3
+ database: ":memory:"
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Load the Rails application.
4
+ require_relative 'application'
5
+
6
+ # Initialize the Rails application.
7
+ Rails.application.initialize!
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
4
+ Rails.backtrace_cleaner.remove_silencers!
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ Bemer.setup do |config|
4
+ config.bem = true
5
+ config.path = 'app/frontend/components'
6
+ end
@@ -0,0 +1,179 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Uncomment this and change the path if necessary to include your own
4
+ # components.
5
+ # See https://github.com/plataformatec/simple_form#custom-components to know
6
+ # more about custom components.
7
+ # Dir[Rails.root.join('lib/components/**/*.rb')].each { |f| require f }
8
+ #
9
+ # Use this setup block to configure all options available in SimpleForm.
10
+ SimpleForm.setup do |config|
11
+ # Wrappers are used by the form builder to generate a
12
+ # complete input. You can remove any component from the
13
+ # wrapper, change the order or even add your own to the
14
+ # stack. The options given below are used to wrap the
15
+ # whole input.
16
+ config.wrappers :default, hint_class: :field_with_hint, error_class: :field_with_errors,
17
+ valid_class: :field_without_errors do |b|
18
+ ## Extensions enabled by default
19
+ # Any of these extensions can be disabled for a
20
+ # given input by passing: `f.input EXTENSION_NAME => false`.
21
+ # You can make any of these extensions optional by
22
+ # renaming `b.use` to `b.optional`.
23
+
24
+ # Determines whether to use HTML5 (:email, :url, ...)
25
+ # and required attributes
26
+ b.use :html5
27
+
28
+ # Calculates placeholders automatically from I18n
29
+ # You can also pass a string as f.input placeholder: "Placeholder"
30
+ b.use :placeholder
31
+
32
+ ## Optional extensions
33
+ # They are disabled unless you pass `f.input EXTENSION_NAME => true`
34
+ # to the input. If so, they will retrieve the values from the model
35
+ # if any exists. If you want to enable any of those
36
+ # extensions by default, you can change `b.optional` to `b.use`.
37
+
38
+ # Calculates maxlength from length validations for string inputs
39
+ # and/or database column lengths
40
+ b.optional :maxlength
41
+
42
+ # Calculate minlength from length validations for string inputs
43
+ b.optional :minlength
44
+
45
+ # Calculates pattern from format validations for string inputs
46
+ b.optional :pattern
47
+
48
+ # Calculates min and max from length validations for numeric inputs
49
+ b.optional :min_max
50
+
51
+ # Calculates readonly automatically from readonly attributes
52
+ b.optional :readonly
53
+
54
+ ## Inputs
55
+ # b.use :input, class: 'input', error_class: 'is-invalid', valid_class: 'is-valid'
56
+ b.use :label_input
57
+ b.use :hint, wrap_with: { tag: :span }
58
+ b.use :error, wrap_with: { tag: :span }
59
+
60
+ ## full_messages_for
61
+ # If you want to display the full error message for the attribute, you can
62
+ # use the component :full_error, like:
63
+ #
64
+ # b.use :full_error, wrap_with: { tag: :span, class: :error }
65
+ end
66
+
67
+ # The default wrapper to be used by the FormBuilder.
68
+ config.default_wrapper = :default
69
+
70
+ # Define the way to render check boxes / radio buttons with labels.
71
+ # Defaults to :nested for bootstrap config.
72
+ # inline: input + label
73
+ # nested: label > input
74
+ config.boolean_style = :nested
75
+
76
+ # Default class for buttons
77
+ config.button_class = nil
78
+
79
+ # Method used to tidy up errors. Specify any Rails Array method.
80
+ # :first lists the first message for each field.
81
+ # Use :to_sentence to list all errors for each field.
82
+ # config.error_method = :first
83
+
84
+ # Default tag used for error notification helper.
85
+ config.error_notification_tag = :div
86
+
87
+ # CSS class to add for error notification helper.
88
+ config.error_notification_class = nil
89
+
90
+ # Series of attempts to detect a default label method for collection.
91
+ # config.collection_label_methods = [ :to_label, :name, :title, :to_s ]
92
+
93
+ # Series of attempts to detect a default value method for collection.
94
+ # config.collection_value_methods = [ :id, :to_s ]
95
+
96
+ # You can wrap a collection of radio/check boxes in a pre-defined tag, defaulting to none.
97
+ # config.collection_wrapper_tag = nil
98
+
99
+ # You can define the class to use on all collection wrappers. Defaulting to none.
100
+ # config.collection_wrapper_class = nil
101
+
102
+ # You can wrap each item in a collection of radio/check boxes with a tag,
103
+ # defaulting to :span.
104
+ # config.item_wrapper_tag = :span
105
+
106
+ # You can define a class to use in all item wrappers. Defaulting to none.
107
+ # config.item_wrapper_class = nil
108
+
109
+ # How the label text should be generated altogether with the required text.
110
+ # config.label_text = lambda { |label, required, explicit_label| "#{required} #{label}" }
111
+
112
+ # You can define the class to use on all labels. Default is nil.
113
+ # config.label_class = nil
114
+
115
+ # You can define the default class to be used on forms. Can be overriden
116
+ # with `html: { :class }`. Defaulting to none.
117
+ # config.default_form_class = nil
118
+
119
+ # DEPRECATED: You can define the class to be used on all forms. Default is simple_form.
120
+ config.form_class = nil
121
+
122
+ # You can define which elements should obtain additional classes
123
+ config.generate_additional_classes_for = []
124
+
125
+ # Whether attributes are required by default (or not). Default is true.
126
+ # config.required_by_default = true
127
+
128
+ # Tell browsers whether to use the native HTML5 validations (novalidate form option).
129
+ # These validations are enabled in SimpleForm's internal config but disabled by default
130
+ # in this configuration, which is recommended due to some quirks from different browsers.
131
+ # To stop SimpleForm from generating the novalidate option, enabling the HTML5 validations,
132
+ # change this configuration to true.
133
+ config.browser_validations = false
134
+
135
+ # Custom mappings for input types. This should be a hash containing a regexp
136
+ # to match as key, and the input type that will be used when the field name
137
+ # matches the regexp as value.
138
+ # config.input_mappings = { /count/ => :integer }
139
+
140
+ # Custom wrappers for input types. This should be a hash containing an input
141
+ # type as key and the wrapper that will be used for all inputs with specified type.
142
+ # config.wrapper_mappings = { string: :prepend }
143
+
144
+ # Namespaces where SimpleForm should look for custom input classes that
145
+ # override default inputs.
146
+ # config.custom_inputs_namespaces << "CustomInputs"
147
+
148
+ # Default priority for time_zone inputs.
149
+ # config.time_zone_priority = nil
150
+
151
+ # Default priority for country inputs.
152
+ # config.country_priority = nil
153
+
154
+ # When false, do not use translations for labels.
155
+ # config.translate_labels = true
156
+
157
+ # Automatically discover new inputs in Rails' autoload path.
158
+ # config.inputs_discovery = true
159
+
160
+ # Cache SimpleForm inputs discovery
161
+ # config.cache_discovery = !Rails.env.development?
162
+
163
+ # Default class for inputs
164
+ config.input_class = nil
165
+
166
+ # Define the default class of the input wrapper of the boolean input.
167
+ config.boolean_label_class = nil
168
+
169
+ # Defines if the default input wrapper class should be included in radio
170
+ # collection wrappers.
171
+ config.include_default_input_wrapper_class = false
172
+
173
+ # Defines which i18n scope will be used in Simple Form.
174
+ # config.i18n_scope = 'simple_form'
175
+
176
+ # Defines validation classes to the input_field. By default it's nil.
177
+ # config.input_field_valid_class = nil
178
+ # config.input_field_error_class = nil
179
+ end
@@ -0,0 +1 @@
1
+ Rails.application.config.active_record.sqlite3.represent_boolean_as_integer = true
@@ -0,0 +1,9 @@
1
+ class CreateArticles < ActiveRecord::Migration[5.2]
2
+ def change
3
+ create_table :articles do |t|
4
+ t.string :title
5
+
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,21 @@
1
+ # This file is auto-generated from the current state of the database. Instead
2
+ # of editing this file, please use the migrations feature of Active Record to
3
+ # incrementally modify your database, and then regenerate this schema definition.
4
+ #
5
+ # Note that this schema.rb definition is the authoritative source for your
6
+ # database schema. If you need to create the application database on another
7
+ # system, you should be using db:schema:load, not running all the migrations
8
+ # from scratch. The latter is a flawed and unsustainable approach (the more migrations
9
+ # you'll amass, the slower it'll run and the greater likelihood for issues).
10
+ #
11
+ # It's strongly recommended that you check this file into your version control system.
12
+
13
+ ActiveRecord::Schema.define(version: 2019_12_15_094046) do
14
+
15
+ create_table "articles", force: :cascade do |t|
16
+ t.string "title"
17
+ t.datetime "created_at", null: false
18
+ t.datetime "updated_at", null: false
19
+ end
20
+
21
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ ENV['RAILS_ENV'] = 'test'
4
+
5
+ require_relative 'dummy/config/environment'
6
+
7
+ require 'rspec/rails'
8
+ require 'spec_helper'
9
+ require 'fuubar'
10
+ require 'rspec-html-matchers'
11
+
12
+ RSpec.configure do |config|
13
+ config.infer_spec_type_from_file_location!
14
+
15
+ # Filter lines from Rails gems in backtraces.
16
+ config.filter_rails_from_backtrace!
17
+
18
+ config.fuubar_progress_bar_options = {
19
+ format: "Rails: #{::Rails::VERSION::STRING} %c/%C |%w>%i| %e "
20
+ }
21
+
22
+ config.define_derived_metadata file_path: %r{/spec/action_view/} do |metadata|
23
+ metadata[:type] = :view
24
+ end
25
+
26
+ config.include Bemer::Test::ConfigurationHelpers
27
+ config.include Bemer::SimpleForm::Test::ConfigurationHelpers
28
+ config.include RSpecHtmlMatchers
29
+ config.include Helpers::SimpleForm, type: :view
30
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/setup'
4
+ require 'bemer/simple_form'
5
+
6
+ support_files = File.expand_path('spec/support/**/*.rb')
7
+
8
+ Dir[support_files].each { |file| require file }
9
+
10
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
11
+ RSpec.configure do |config|
12
+ # rspec-expectations config goes here. You can use an alternate
13
+ # assertion/expectation library such as wrong or the stdlib/minitest
14
+ # assertions if you prefer.
15
+ config.expect_with :rspec do |expectations|
16
+ # This option will default to `true` in RSpec 4. It makes the `description`
17
+ # and `failure_message` of custom matchers include text for helper methods
18
+ # defined using `chain`, e.g.:
19
+ # be_bigger_than(2).and_smaller_than(4).description
20
+ # # => "be bigger than 2 and smaller than 4"
21
+ # ...rather than:
22
+ # # => "be bigger than 2"
23
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
24
+ end
25
+
26
+ # rspec-mocks config goes here. You can use an alternate test double
27
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
28
+ config.mock_with :rspec do |mocks|
29
+ # Prevents you from mocking or stubbing a method that does not exist on
30
+ # a real object. This is generally recommended, and will default to
31
+ # `true` in RSpec 4.
32
+ mocks.verify_partial_doubles = true
33
+ end
34
+
35
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
36
+ # have no way to turn it off -- the option exists only for backwards
37
+ # compatibility in RSpec 3). It causes shared context metadata to be
38
+ # inherited by the metadata hash of host groups and examples, rather than
39
+ # triggering implicit auto-inclusion in groups with matching metadata.
40
+ config.shared_context_metadata_behavior = :apply_to_host_groups
41
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.configure do |config|
4
+ config.before(:all) do
5
+ ActiveRecord::Migration.verbose = false
6
+
7
+ ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
8
+
9
+ load Rails.root.join('db', 'schema.rb')
10
+ end
11
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.configure do |config|
4
+ config.before do
5
+ reset_bemer_configuration
6
+ reset_bemer_simple_form_configuration
7
+ end
8
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Helpers
4
+ module SimpleForm
5
+ def simple_form_for(record, options = {}, &block)
6
+ options = { url: '', html: { class: '' } }.deep_merge(options)
7
+
8
+ view.simple_form_for(record, options, &(block || proc {}))
9
+ end
10
+ end
11
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bemer-simple_form
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Grigorev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-27 00:00:00.000000000 Z
11
+ date: 2020-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: 0.5.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: fuubar
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 2.5.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 2.5.0
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: overcommit
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +94,34 @@ dependencies:
80
94
  - - "~>"
81
95
  - !ruby/object:Gem::Version
82
96
  version: 12.3.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec-html-matchers
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.9.2
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.9.2
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec-rails
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 3.9.0
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 3.9.0
83
125
  - !ruby/object:Gem::Dependency
84
126
  name: rubocop
85
127
  requirement: !ruby/object:Gem::Requirement
@@ -122,6 +164,54 @@ dependencies:
122
164
  - - "~>"
123
165
  - !ruby/object:Gem::Version
124
166
  version: 1.33.0
167
+ - !ruby/object:Gem::Dependency
168
+ name: activesupport
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :runtime
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: bemer
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: 0.1.0
188
+ - - "<"
189
+ - !ruby/object:Gem::Version
190
+ version: '1.0'
191
+ type: :runtime
192
+ prerelease: false
193
+ version_requirements: !ruby/object:Gem::Requirement
194
+ requirements:
195
+ - - ">="
196
+ - !ruby/object:Gem::Version
197
+ version: 0.1.0
198
+ - - "<"
199
+ - !ruby/object:Gem::Version
200
+ version: '1.0'
201
+ - !ruby/object:Gem::Dependency
202
+ name: simple_form
203
+ requirement: !ruby/object:Gem::Requirement
204
+ requirements:
205
+ - - ">="
206
+ - !ruby/object:Gem::Version
207
+ version: '0'
208
+ type: :runtime
209
+ prerelease: false
210
+ version_requirements: !ruby/object:Gem::Requirement
211
+ requirements:
212
+ - - ">="
213
+ - !ruby/object:Gem::Version
214
+ version: '0'
125
215
  description: Add the BEM methodology to your SimpleForm forms.
126
216
  email: vill@rubyinventory.org
127
217
  executables: []
@@ -132,8 +222,37 @@ files:
132
222
  - LICENSE-RU.txt
133
223
  - LICENSE.txt
134
224
  - README.md
225
+ - lib/bemer-simple_form.rb
135
226
  - lib/bemer/simple_form.rb
227
+ - lib/bemer/simple_form/builder.rb
228
+ - lib/bemer/simple_form/configuration.rb
229
+ - lib/bemer/simple_form/inputs.rb
230
+ - lib/bemer/simple_form/test/configuration_helpers.rb
136
231
  - lib/bemer/simple_form/version.rb
232
+ - spec/action_view/block_builder_with_a_name_as_a_passed_object_spec.rb
233
+ - spec/action_view/first_spec.rb
234
+ - spec/action_view/simple_form_for_as_a_block_builder_spec.rb
235
+ - spec/bemer/simple_form/configuration_spec.rb
236
+ - spec/dummy/Rakefile
237
+ - spec/dummy/app/forms/search_form.rb
238
+ - spec/dummy/app/models/article.rb
239
+ - spec/dummy/bin/rails
240
+ - spec/dummy/config.ru
241
+ - spec/dummy/config/application.rb
242
+ - spec/dummy/config/boot.rb
243
+ - spec/dummy/config/database.yml
244
+ - spec/dummy/config/environment.rb
245
+ - spec/dummy/config/initializers/backtrace_silencers.rb
246
+ - spec/dummy/config/initializers/bemer.rb
247
+ - spec/dummy/config/initializers/simple_form.rb
248
+ - spec/dummy/config/initializers/sqlite3.rb
249
+ - spec/dummy/db/migrate/20191215094046_create_articles.rb
250
+ - spec/dummy/db/schema.rb
251
+ - spec/rails_helper.rb
252
+ - spec/spec_helper.rb
253
+ - spec/support/active_record.rb
254
+ - spec/support/bemer_simple_form.rb
255
+ - spec/support/helpers/simple_form.rb
137
256
  homepage:
138
257
  licenses:
139
258
  - MIT
@@ -161,4 +280,28 @@ rubygems_version: 2.7.7
161
280
  signing_key:
162
281
  specification_version: 4
163
282
  summary: Add the BEM methodology to your SimpleForm forms.
164
- test_files: []
283
+ test_files:
284
+ - spec/action_view/block_builder_with_a_name_as_a_passed_object_spec.rb
285
+ - spec/action_view/first_spec.rb
286
+ - spec/action_view/simple_form_for_as_a_block_builder_spec.rb
287
+ - spec/bemer/simple_form/configuration_spec.rb
288
+ - spec/dummy/app/forms/search_form.rb
289
+ - spec/dummy/app/models/article.rb
290
+ - spec/dummy/bin/rails
291
+ - spec/dummy/config/application.rb
292
+ - spec/dummy/config/boot.rb
293
+ - spec/dummy/config/database.yml
294
+ - spec/dummy/config/environment.rb
295
+ - spec/dummy/config/initializers/backtrace_silencers.rb
296
+ - spec/dummy/config/initializers/bemer.rb
297
+ - spec/dummy/config/initializers/simple_form.rb
298
+ - spec/dummy/config/initializers/sqlite3.rb
299
+ - spec/dummy/config.ru
300
+ - spec/dummy/db/migrate/20191215094046_create_articles.rb
301
+ - spec/dummy/db/schema.rb
302
+ - spec/dummy/Rakefile
303
+ - spec/rails_helper.rb
304
+ - spec/spec_helper.rb
305
+ - spec/support/active_record.rb
306
+ - spec/support/bemer_simple_form.rb
307
+ - spec/support/helpers/simple_form.rb