bemer 0.3.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE-RU.txt +1 -1
- data/LICENSE.txt +1 -1
- data/README.md +268 -27
- data/docs//320/232/320/276/320/275/321/202/320/265/320/272/321/201/321/202-/321/203/320/267/320/273/320/260.md +1 -1
- data/docs//320/245/320/265/320/273/320/277/320/265/321/200-bem_attrs_for.md +58 -0
- data/docs//320/245/320/265/320/273/320/277/320/265/321/200-bem_mix.md +0 -6
- data/docs//320/245/320/265/320/273/320/277/320/265/321/200-block_tag.md +10 -4
- data/docs//320/245/320/265/320/273/320/277/320/265/321/200-elem_tag.md +1 -1
- data/lib/bemer/configuration.rb +3 -0
- data/lib/bemer/entity.rb +1 -1
- data/lib/bemer/entity_builder.rb +44 -9
- data/lib/bemer/helpers.rb +10 -1
- data/lib/bemer/mixes.rb +43 -0
- data/lib/bemer/predicate.rb +1 -1
- data/lib/bemer/railtie.rb +1 -4
- data/lib/bemer/version.rb +1 -1
- data/lib/bemer.rb +4 -3
- data/spec/action_view/helpers/bem_attrs_for_spec.rb +35 -0
- data/spec/action_view/helpers/block_tag_spec.rb +1 -1
- data/spec/action_view/helpers/elem_tag_spec.rb +166 -0
- data/spec/bemer/railtie_spec.rb +1 -1
- data/spec/rails_helper.rb +2 -0
- metadata +14 -179
- data/lib/bemer/mixin_list.rb +0 -74
- data/spec/bemer/mixin_list_spec.rb +0 -99
- data/spec/support/shared_examples/an_html_entity_tree_builder_method.rb +0 -21
data/lib/bemer/mixes.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/core_ext/object/blank'
|
4
|
+
require 'active_support/core_ext/array/wrap'
|
5
|
+
require 'active_support/core_ext/hash/slice'
|
6
|
+
|
7
|
+
module Bemer
|
8
|
+
class Mixes
|
9
|
+
def initialize(*mixes)
|
10
|
+
@mixes = Array.wrap(mixes).flatten
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_a
|
14
|
+
@to_a ||= entities.map { |e| [e.bem_class, e.mods] }.flatten.reject(&:blank?).uniq
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_s
|
18
|
+
@to_s ||= to_a.join(' ')
|
19
|
+
end
|
20
|
+
|
21
|
+
def entities # rubocop:disable Metrics/MethodLength
|
22
|
+
@entities ||= mixes.flat_map do |mix|
|
23
|
+
if mix.is_a?(Hash)
|
24
|
+
options = mix.extract!(:js, :mods)
|
25
|
+
|
26
|
+
mix.flat_map do |block, elems|
|
27
|
+
if elems.nil?
|
28
|
+
EntityBuilder.new(block, **options, bem: true)
|
29
|
+
else
|
30
|
+
Array(elems).map { |elem| EntityBuilder.new(block, elem, **options, bem: true) }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
else
|
34
|
+
Array(mix).flat_map { |block| EntityBuilder.new(block) }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
protected
|
40
|
+
|
41
|
+
attr_reader :mixes
|
42
|
+
end
|
43
|
+
end
|
data/lib/bemer/predicate.rb
CHANGED
@@ -7,7 +7,7 @@ module Bemer
|
|
7
7
|
@condition = options[:condition].nil? ? true : options[:condition]
|
8
8
|
@element = options[:elem]
|
9
9
|
@mask = build_mask(options[:block], options[:elem])
|
10
|
-
@mixins =
|
10
|
+
@mixins = Mixes.new(options[:mix])
|
11
11
|
@modifiers = ModifierList.new(:block, :elem, options[:mods])
|
12
12
|
@wildcard = nil
|
13
13
|
end
|
data/lib/bemer/railtie.rb
CHANGED
@@ -9,10 +9,7 @@ module Bemer
|
|
9
9
|
class Railtie < ::Rails::Railtie
|
10
10
|
class << self
|
11
11
|
def assets_path_initializer
|
12
|
-
|
13
|
-
when 5..6 then :append_assets_path
|
14
|
-
when 3..4 then :load_config_initializers
|
15
|
-
end
|
12
|
+
::Rails::VERSION::MAJOR < 5 ? :load_config_initializers : :append_assets_path
|
16
13
|
end
|
17
14
|
end
|
18
15
|
|
data/lib/bemer/version.rb
CHANGED
data/lib/bemer.rb
CHANGED
@@ -20,7 +20,7 @@ module Bemer
|
|
20
20
|
autoload :DefaultTemplateList
|
21
21
|
autoload :Entity
|
22
22
|
autoload :EntityBuilder
|
23
|
-
autoload :
|
23
|
+
autoload :Mixes
|
24
24
|
autoload :ModifierList
|
25
25
|
autoload :PathResolver
|
26
26
|
autoload :Pipeline
|
@@ -44,7 +44,7 @@ module Bemer
|
|
44
44
|
class << self
|
45
45
|
extend Forwardable
|
46
46
|
|
47
|
-
# rubocop:disable Layout/
|
47
|
+
# rubocop:disable Layout/AlignArguments
|
48
48
|
def_delegators :config, :asset_paths,
|
49
49
|
:bem,
|
50
50
|
:can_use_new_matcher?,
|
@@ -57,7 +57,7 @@ module Bemer
|
|
57
57
|
:path,
|
58
58
|
:paths,
|
59
59
|
:prepend_asset_paths
|
60
|
-
# rubocop:enable Layout/
|
60
|
+
# rubocop:enable Layout/AlignArguments
|
61
61
|
|
62
62
|
alias prepend_asset_paths? prepend_asset_paths
|
63
63
|
|
@@ -76,6 +76,7 @@ module Bemer
|
|
76
76
|
end
|
77
77
|
|
78
78
|
# entity_class??
|
79
|
+
# bem
|
79
80
|
# Добавить в хелперы
|
80
81
|
def bem_class(block, element = nil)
|
81
82
|
return '' if block.blank? || (!element.nil? && element.blank?)
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe 'bem_attrs_for helper' do
|
4
|
+
delegate :bem_attrs_for, to: :view
|
5
|
+
|
6
|
+
context 'when a block and element have no name' do
|
7
|
+
it { expect(bem_attrs_for).to be_empty }
|
8
|
+
end
|
9
|
+
|
10
|
+
context 'when only a block name is specified' do
|
11
|
+
it { expect(bem_attrs_for(:block)).to include(class: 'block i-bem', 'data-bem': '{"block":{}}') }
|
12
|
+
it { expect(bem_attrs_for(:block, mods: :enabled)).to include(class: 'block block_enabled i-bem', 'data-bem': '{"block":{}}') }
|
13
|
+
it { expect(bem_attrs_for(:block, mix: { block1: :elem })).to include(class: 'block block1__elem i-bem', 'data-bem': '{"block":{}}') }
|
14
|
+
it { expect(bem_attrs_for(:block, js: { key: :val })).to include(class: 'block i-bem', 'data-bem': '{"block":{"key":"val"}}') }
|
15
|
+
it { expect(bem_attrs_for(:block, js: false)).to include(class: 'block') }
|
16
|
+
|
17
|
+
['', false].each do |elem|
|
18
|
+
it { expect(bem_attrs_for(:block, elem)).to be_empty }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'when only an element name is specified' do
|
23
|
+
['', nil, false].each do |block|
|
24
|
+
it { expect(bem_attrs_for(block, :elem)).to be_empty }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'when a name is specified for a block and element' do
|
29
|
+
it { expect(bem_attrs_for(:block, :elem)).to include(class: 'block__elem i-bem', 'data-bem': '{"block__elem":{}}') }
|
30
|
+
it { expect(bem_attrs_for(:block, :elem, mods: :enabled)).to include(class: 'block__elem block__elem_enabled i-bem', 'data-bem': '{"block__elem":{}}') }
|
31
|
+
it { expect(bem_attrs_for(:block, :elem, mix: :block_2)).to include(class: 'block__elem block-2 i-bem', 'data-bem': '{"block__elem":{}}') }
|
32
|
+
it { expect(bem_attrs_for(:block, :elem, js: { key: :val })).to include(class: 'block__elem i-bem', 'data-bem': '{"block__elem":{"key":"val"}}') }
|
33
|
+
it { expect(bem_attrs_for(:block, :elem, js: false)).to include(class: 'block__elem') }
|
34
|
+
end
|
35
|
+
end
|
@@ -38,7 +38,7 @@ RSpec.describe 'block_tag helper' do
|
|
38
38
|
# it_behaves_like 'a BEM entity', '<div></div>'
|
39
39
|
# it_behaves_like 'a block entity builder method', 'Helloo', :yeyeye
|
40
40
|
# it_behaves_like 'an entity builder method', 'html'
|
41
|
-
it_behaves_like 'an HTML entity tree builder method', :hello, { tag: :strong }, 'html'
|
41
|
+
# it_behaves_like 'an HTML entity tree builder method', :hello, { tag: :strong }, 'html'
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
@@ -0,0 +1,166 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe 'elem_tag helper' do
|
4
|
+
delegate :elem_tag, to: :view
|
5
|
+
|
6
|
+
context 'when the `default_element_tag` is set to `span`' do
|
7
|
+
before do
|
8
|
+
Bemer.config.default_element_tag = :span
|
9
|
+
end
|
10
|
+
|
11
|
+
it { expect(elem_tag(:block, :elem)).to have_empty_tag(:span, with: { class: 'block__elem' }, count: 1) }
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'when the `element_name_separator` is set to `___`' do
|
15
|
+
before do
|
16
|
+
Bemer.config.element_name_separator = '___'
|
17
|
+
end
|
18
|
+
|
19
|
+
it { expect(elem_tag(:block, :elem)).to have_empty_tag(:div, with: { class: 'block___elem' }, count: 1) }
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'when the `modifier_name_separator` is set to `--`' do
|
23
|
+
before do
|
24
|
+
Bemer.config.modifier_name_separator = '--'
|
25
|
+
end
|
26
|
+
|
27
|
+
it { expect(elem_tag(:block, :elem, mods: :enabled)).to have_empty_tag(:div, with: { class: 'block__elem block__elem--enabled' }, count: 1) }
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'when the `modifier_value_separator` is set to `___`' do
|
31
|
+
before do
|
32
|
+
Bemer.config.modifier_value_separator = '___'
|
33
|
+
end
|
34
|
+
|
35
|
+
it { expect(elem_tag(:block, :elem, mods: { theme: :gray })).to have_empty_tag(:div, with: { class: 'block__elem block__elem_theme___gray' }, count: 1) }
|
36
|
+
end
|
37
|
+
|
38
|
+
# The bem parameter from the configuration does not affect the operation of elem_tag in any way.
|
39
|
+
[true, false].each do |bem|
|
40
|
+
context "when the `bem` is globally set to `#{bem}`" do
|
41
|
+
before do
|
42
|
+
Bemer.config.bem = bem
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'when a block and element have no name' do
|
46
|
+
it { expect(elem_tag).to(have_empty_tag(:div, count: 1)) { without_tag 'div[class]' } }
|
47
|
+
it { expect(elem_tag(bem: true)).to(have_empty_tag(:div, count: 1)) { without_tag 'div[class]' } }
|
48
|
+
it { expect(elem_tag(js: true)).to(have_empty_tag(:div, without: { class: 'i-bem' }, count: 1)) { without_tag 'div[data-bem]' } }
|
49
|
+
|
50
|
+
['', nil, false].repeated_permutation(2).each do |block, elem|
|
51
|
+
it { expect(elem_tag(block, elem, bem: true)).to(have_empty_tag(:div, count: 1)) { without_tag 'div[class]' } }
|
52
|
+
it { expect(elem_tag(block, elem, js: true)).to(have_empty_tag(:div, without: { class: 'i-bem' }, count: 1)) { without_tag 'div[data-bem]' } }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'when only a block name is specified' do
|
57
|
+
it { expect(elem_tag(:block, nil, bem: true)).to have_empty_tag(:div, with: { class: 'block' }, count: 1) }
|
58
|
+
it { expect(elem_tag(:block, nil, js: true)).to have_empty_tag(:div, with: { class: 'block i-bem', 'data-bem': '{"block":{}}' }, count: 1) }
|
59
|
+
|
60
|
+
['', false].each do |elem|
|
61
|
+
it { expect(elem_tag(:block, elem, bem: true)).to(have_empty_tag(:div, count: 1)) { without_tag 'div[class]' } }
|
62
|
+
it { expect(elem_tag(:block, elem, js: true)).to(have_empty_tag(:div, without: { class: 'i-bem' }, count: 1)) { without_tag 'div[data-bem]' } }
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context 'when only an element name is specified' do
|
67
|
+
['', nil, false].each do |block|
|
68
|
+
it { expect(elem_tag(block, :elem)).to(have_empty_tag(:div, count: 1)) { without_tag 'div[class]' } }
|
69
|
+
it { expect(elem_tag(block, :elem, bem: true)).to(have_empty_tag(:div, count: 1)) { without_tag 'div[class]' } }
|
70
|
+
it { expect(elem_tag(block, :elem, js: true)).to(have_empty_tag(:div, without: { class: 'i-bem' }, count: 1)) { without_tag 'div[data-bem]' } }
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context 'when a name is specified for a block and element' do
|
75
|
+
# Entity name
|
76
|
+
it { expect(elem_tag(:block_name, :elem_name)).to have_empty_tag(:div, with: { class: 'block-name__elem-name' }, count: 1) }
|
77
|
+
it { expect(elem_tag('Block_Name', 'Elem_Name')).to have_empty_tag(:div, with: { class: 'Block_Name__Elem_Name' }, count: 1) }
|
78
|
+
it { expect(elem_tag(:Block_Name, :Elem_Name)).to have_empty_tag(:div, with: { class: 'Block-Name__Elem-Name' }, count: 1) }
|
79
|
+
it { expect(elem_tag('BlockName', 'ElemName')).to have_empty_tag(:div, with: { class: 'BlockName__ElemName' }, count: 1) }
|
80
|
+
|
81
|
+
# bem parameter
|
82
|
+
it { expect(elem_tag(:block, :elem, mix: :css_mixin, mods: :enabled, js: true, cls: :css_class)).to have_empty_tag(:div, with: { class: 'block__elem block__elem_enabled css-mixin css-class i-bem', 'data-bem': '{"block__elem":{}}' }, count: 1) }
|
83
|
+
it { expect(elem_tag(:block, :elem, bem: true, mix: :css_mixin, mods: :enabled, js: true, cls: :css_class)).to have_empty_tag(:div, with: { class: 'block__elem block__elem_enabled css-mixin css-class i-bem', 'data-bem': '{"block__elem":{}}' }, count: 1) }
|
84
|
+
it { expect(elem_tag(:block, :elem, bem: false, mix: :css_mixin, mods: :enabled, js: true, cls: :css_class)).to(have_empty_tag(:div, with: { class: 'css-class' }, without: { class: 'block__elem block__elem_enabled css-mixin i-bem' }, count: 1)) { without_tag 'div[data-bem]' } }
|
85
|
+
|
86
|
+
# bem_cascade parameter
|
87
|
+
it { expect(elem_tag(:block, :elem, bem_cascade: false)).to(have_empty_tag(:div, count: 1)) { without_tag 'div[class]' } }
|
88
|
+
it { expect(elem_tag(:block, :elem, bem: true, bem_cascade: false)).to have_empty_tag(:div, with: { class: 'block__elem' }, count: 1) }
|
89
|
+
it { expect(elem_tag(:block, :elem, bem: false, bem_cascade: true)).to(have_empty_tag(:div, count: 1)) { without_tag 'div[class]' } }
|
90
|
+
|
91
|
+
# cls and class parameters
|
92
|
+
it { expect(elem_tag(:block, :elem, cls: :css_class)).to have_empty_tag(:div, with: { class: 'block__elem css-class' }, count: 1) }
|
93
|
+
it { expect(elem_tag(:block, :elem, class: :css_class)).to have_empty_tag(:div, with: { class: 'block__elem css-class' }, count: 1) }
|
94
|
+
it { expect(elem_tag(:block, :elem, class: :css_class1, cls: :css_class2)).to have_empty_tag(:div, with: { class: 'block__elem css-class1 css-class2' }, count: 1) }
|
95
|
+
it { expect(elem_tag(:block, :elem, class: 'css_class1', cls: 'css_class2')).to have_empty_tag(:div, with: { class: 'block__elem css_class1 css_class2' }, count: 1) }
|
96
|
+
it { expect(elem_tag(:block, :elem, class: ['css_class1', :css_class2])).to have_empty_tag(:div, with: { class: 'block__elem css_class1 css-class2' }, count: 1) }
|
97
|
+
it { expect(elem_tag(:block, :elem, cls: ['css_class1', :css_class2])).to have_empty_tag(:div, with: { class: 'block__elem css_class1 css-class2' }, count: 1) }
|
98
|
+
|
99
|
+
# js parameter
|
100
|
+
it { expect(elem_tag(:block, :elem, js: true)).to have_empty_tag(:div, with: { class: 'block__elem i-bem', 'data-bem': '{"block__elem":{}}' }, count: 1) }
|
101
|
+
it { expect(elem_tag(:block, :elem, js: [1, 2])).to have_empty_tag(:div, with: { class: 'block__elem i-bem', 'data-bem': '{"block__elem":[1,2]}' }, count: 1) }
|
102
|
+
it { expect(elem_tag(:block, :elem, js: { key: :val })).to have_empty_tag(:div, with: { class: 'block__elem i-bem', 'data-bem': '{"block__elem":{"key":"val"}}' }, count: 1) }
|
103
|
+
|
104
|
+
# mix parameter
|
105
|
+
it { expect(elem_tag(:block, :elem, mix: :css_mixin)).to have_empty_tag(:div, with: { class: 'block__elem css-mixin' }, count: 1) }
|
106
|
+
it { expect(elem_tag(:block, :elem, mix: ['css_mixin', :block_name, block2: :elem])).to have_empty_tag(:div, with: { class: 'block__elem css_mixin block-name block2__elem' }, count: 1) }
|
107
|
+
it { expect(elem_tag(:block, :elem, mix: { block_name: :elem })).to have_empty_tag(:div, with: { class: 'block__elem block-name__elem' }, count: 1) }
|
108
|
+
it { expect(elem_tag(:block, :elem, mix: { block_name: :elem, js: true })).to have_empty_tag(:div, with: { class: 'block__elem block-name__elem i-bem', 'data-bem': '{"block-name__elem":{}}' }, count: 1) }
|
109
|
+
it { expect(elem_tag(:block, :elem, js: true, mix: { block_1: :elem, js: { key: :val } })).to have_empty_tag(:div, with: { class: 'block__elem block-1__elem i-bem', 'data-bem': '{"block__elem":{},"block-1__elem":{"key":"val"}}' }, count: 1) }
|
110
|
+
it { expect(elem_tag(:block, :elem, js: true, mix: { block: :elem, js: { key: :val } })).to have_empty_tag(:div, with: { class: 'block__elem i-bem', 'data-bem': '{"block__elem":{"key":"val"}}' }, count: 1) }
|
111
|
+
it { expect(elem_tag(:block, :elem, mix: { block_name: :elem, mods: :enabled })).to have_empty_tag(:div, with: { class: 'block__elem block-name__elem block-name__elem_enabled' }, count: 1) }
|
112
|
+
it { expect(elem_tag(:block, :elem, mix: [:mix, block_name: :elem, js: true])).to have_empty_tag(:div, with: { class: 'block__elem mix block-name__elem i-bem', 'data-bem': '{"block-name__elem":{}}' }, count: 1) }
|
113
|
+
it { expect(elem_tag(:block, :elem, mix: [{ block_1: nil, mods: :enabled, js: { key: :val } }, { block_name: :elem, js: true }])).to have_empty_tag(:div, with: { class: 'block__elem block-1 block-1_enabled block-name__elem i-bem', 'data-bem': '{"block-1":{"key":"val"},"block-name__elem":{}}' }, count: 1) }
|
114
|
+
it { expect(elem_tag(:block, :elem, mix: [:block_1, block2: %i[elem1 elem2], js: true])).to have_empty_tag(:div, with: { class: 'block__elem block-1 block2__elem1 block2__elem2 i-bem', 'data-bem': '{"block2__elem1":{},"block2__elem2":{}}' }, count: 1) }
|
115
|
+
it { expect(elem_tag(:block, :elem, mix: { block2: %i[elem1 elem2], js: true })).to have_empty_tag(:div, with: { class: 'block__elem block2__elem1 block2__elem2 i-bem', 'data-bem': '{"block2__elem1":{},"block2__elem2":{}}' }, count: 1) }
|
116
|
+
|
117
|
+
# mods parameter
|
118
|
+
it { expect(elem_tag(:block, :elem, mods: :enabled)).to have_empty_tag(:div, with: { class: 'block__elem block__elem_enabled' }, count: 1) }
|
119
|
+
it { expect(elem_tag(:block, :elem, mods: { enabled: true })).to have_empty_tag(:div, with: { class: 'block__elem block__elem_enabled' }, count: 1) }
|
120
|
+
it { expect(elem_tag(:block, :elem, mods: { enabled: 'true' })).to have_empty_tag(:div, with: { class: 'block__elem block__elem_enabled_true' }, count: 1) }
|
121
|
+
it { expect(elem_tag(:block, :elem, mods: { enabled: false })).to have_empty_tag(:div, with: { class: 'block__elem' }, without: { class: 'block__elem_enabled' }, count: 1) }
|
122
|
+
it { expect(elem_tag(:block, :elem, mods: { enabled: 'false' })).to have_empty_tag(:div, with: { class: 'block__elem block__elem_enabled_false' }, count: 1) }
|
123
|
+
it { expect(elem_tag(:block, :elem, mods: { enabled: '' })).to have_empty_tag(:div, with: { class: 'block__elem' }, without: { class: 'block__elem_enabled' }, count: 1) }
|
124
|
+
it { expect(elem_tag(:block, :elem, mods: { enabled: nil })).to have_empty_tag(:div, with: { class: 'block__elem' }, without: { class: 'block__elem_enabled' }, count: 1) }
|
125
|
+
it { expect(elem_tag(:block, :elem, mods: { enabled: 'nil' })).to have_empty_tag(:div, with: { class: 'block__elem block__elem_enabled_nil' }, count: 1) }
|
126
|
+
it { expect(elem_tag(:block, :elem, mods: [:enabled, size: :small])).to have_empty_tag(:div, with: { class: 'block__elem block__elem_enabled block__elem_size_small' }, count: 1) }
|
127
|
+
it { expect(elem_tag(:block, :elem, mods: [:enabled, %i[size small], %i[size large]])).to have_empty_tag(:div, with: { class: 'block__elem block__elem_enabled block__elem_size_large' }, count: 1) }
|
128
|
+
|
129
|
+
# tag parameter
|
130
|
+
it { expect(elem_tag(:block, :elem, tag: :span)).to have_empty_tag(:span, with: { class: 'block__elem' }, count: 1) }
|
131
|
+
it { expect(elem_tag(:block, :elem, tag: '', content: 'Content')).to eq 'Content' }
|
132
|
+
it { expect(elem_tag(:block, :elem, tag: '', content: '')).to eq '' }
|
133
|
+
# got: nil
|
134
|
+
# it { expect(elem_tag(:block, :elem, tag: '')).to eq '' }
|
135
|
+
it { expect(elem_tag(:block, :elem, tag: false, content: 'Content')).to eq 'Content' }
|
136
|
+
it { expect(elem_tag(:block, :elem, tag: false, content: '')).to eq '' }
|
137
|
+
# got: nil
|
138
|
+
# it { expect(elem_tag(:block, :elem, tag: false)).to eq '' }
|
139
|
+
it { expect(elem_tag(:block, :elem, tag: nil, content: 'Content')).to have_tag(:div, with: { class: 'block__elem' }, text: 'Content', count: 1) }
|
140
|
+
|
141
|
+
# attributes
|
142
|
+
it { expect(elem_tag(:block, :elem, data: { key: :val })).to have_empty_tag(:div, with: { class: 'block__elem', 'data-key': 'val' }, count: 1) }
|
143
|
+
it { expect(elem_tag(:block, :elem, 'data-key': :val)).to have_empty_tag(:div, with: { class: 'block__elem', 'data-key': 'val' }, count: 1) }
|
144
|
+
it { expect(elem_tag(:block, :elem, data: { key: :val }, 'data-key2': :val)).to have_empty_tag(:div, with: { class: 'block__elem', 'data-key': 'val', 'data-key2': 'val' }, count: 1) }
|
145
|
+
it { expect(elem_tag(:block, :elem, tag: :a, href: '#')).to have_empty_tag(:a, with: { class: 'block__elem', href: '#' }, count: 1) }
|
146
|
+
|
147
|
+
# content parameter
|
148
|
+
it { expect(elem_tag(:block, :elem, content: 'Content')).to have_tag(:div, with: { class: 'block__elem' }, text: 'Content', count: 1) }
|
149
|
+
|
150
|
+
it do # rubocop:disable RSpec/ExampleLength
|
151
|
+
html = elem_tag :block, :elem do
|
152
|
+
elem_tag :block, :elem1, content: 'Content' do
|
153
|
+
'<div></div>'.html_safe
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
expect(html).to have_tag(:div, with: { class: 'block__elem' }, count: 1) do
|
158
|
+
with_tag :div, with: { class: 'block__elem1' }, count: 1 do
|
159
|
+
with_tag :div, without: { class: 'block__elem1' }, blank: true, count: 1
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
data/spec/bemer/railtie_spec.rb
CHANGED
@@ -38,7 +38,7 @@ RSpec.describe Bemer::Railtie do
|
|
38
38
|
describe 'bemer.helpers initializer' do
|
39
39
|
subject(:initializer) { find_initializer('bemer.helpers') }
|
40
40
|
|
41
|
-
let(:action_view) { ActionView::Base.new }
|
41
|
+
let(:action_view) { ActionView::Base.respond_to?(:empty) ? ActionView::Base.empty : ActionView::Base.new }
|
42
42
|
|
43
43
|
helper_methods = %i[
|
44
44
|
block_tag elem_tag bem_mix bem_mods render_component
|
data/spec/rails_helper.rb
CHANGED
@@ -7,6 +7,7 @@ require_relative 'dummy/config/environment'
|
|
7
7
|
require 'rspec/rails'
|
8
8
|
require 'spec_helper'
|
9
9
|
require 'fuubar'
|
10
|
+
require 'rspec-html-matchers'
|
10
11
|
|
11
12
|
RSpec.configure do |config|
|
12
13
|
# RSpec Rails can automatically mix in different behaviours to your tests
|
@@ -36,4 +37,5 @@ RSpec.configure do |config|
|
|
36
37
|
end
|
37
38
|
|
38
39
|
config.include Bemer::Test::ConfigurationHelpers
|
40
|
+
config.include RSpecHtmlMatchers
|
39
41
|
end
|
metadata
CHANGED
@@ -1,183 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bemer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.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:
|
11
|
+
date: 2023-03-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: appraisal
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 2.2.0
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: 2.2.0
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: bundler
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '1.16'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '1.16'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: bundler-audit
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: 0.6.1
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: 0.6.1
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: fasterer
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: 0.7.1
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: 0.7.1
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: fuubar
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - "~>"
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: 2.5.0
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - "~>"
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: 2.5.0
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: overcommit
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - "~>"
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: 0.47.0
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - "~>"
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: 0.47.0
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: rake
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - "~>"
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: 12.3.0
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - "~>"
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: 12.3.0
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: rspec
|
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
|
125
|
-
- !ruby/object:Gem::Dependency
|
126
|
-
name: rspec-rails
|
127
|
-
requirement: !ruby/object:Gem::Requirement
|
128
|
-
requirements:
|
129
|
-
- - "~>"
|
130
|
-
- !ruby/object:Gem::Version
|
131
|
-
version: 3.9.0
|
132
|
-
type: :development
|
133
|
-
prerelease: false
|
134
|
-
version_requirements: !ruby/object:Gem::Requirement
|
135
|
-
requirements:
|
136
|
-
- - "~>"
|
137
|
-
- !ruby/object:Gem::Version
|
138
|
-
version: 3.9.0
|
139
|
-
- !ruby/object:Gem::Dependency
|
140
|
-
name: rubocop
|
141
|
-
requirement: !ruby/object:Gem::Requirement
|
142
|
-
requirements:
|
143
|
-
- - "~>"
|
144
|
-
- !ruby/object:Gem::Version
|
145
|
-
version: 0.64.0
|
146
|
-
type: :development
|
147
|
-
prerelease: false
|
148
|
-
version_requirements: !ruby/object:Gem::Requirement
|
149
|
-
requirements:
|
150
|
-
- - "~>"
|
151
|
-
- !ruby/object:Gem::Version
|
152
|
-
version: 0.64.0
|
153
|
-
- !ruby/object:Gem::Dependency
|
154
|
-
name: rubocop-rspec
|
155
|
-
requirement: !ruby/object:Gem::Requirement
|
156
|
-
requirements:
|
157
|
-
- - "~>"
|
158
|
-
- !ruby/object:Gem::Version
|
159
|
-
version: 1.32.0
|
160
|
-
type: :development
|
161
|
-
prerelease: false
|
162
|
-
version_requirements: !ruby/object:Gem::Requirement
|
163
|
-
requirements:
|
164
|
-
- - "~>"
|
165
|
-
- !ruby/object:Gem::Version
|
166
|
-
version: 1.32.0
|
167
|
-
- !ruby/object:Gem::Dependency
|
168
|
-
name: wwtd
|
169
|
-
requirement: !ruby/object:Gem::Requirement
|
170
|
-
requirements:
|
171
|
-
- - "~>"
|
172
|
-
- !ruby/object:Gem::Version
|
173
|
-
version: 1.4.0
|
174
|
-
type: :development
|
175
|
-
prerelease: false
|
176
|
-
version_requirements: !ruby/object:Gem::Requirement
|
177
|
-
requirements:
|
178
|
-
- - "~>"
|
179
|
-
- !ruby/object:Gem::Version
|
180
|
-
version: 1.4.0
|
181
13
|
- !ruby/object:Gem::Dependency
|
182
14
|
name: railties
|
183
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -192,7 +24,8 @@ dependencies:
|
|
192
24
|
- - ">="
|
193
25
|
- !ruby/object:Gem::Version
|
194
26
|
version: 3.2.22
|
195
|
-
description: Build reusable UI components for Rails applications
|
27
|
+
description: Build reusable UI components for Rails applications with the ability
|
28
|
+
to use the BEM methodology.
|
196
29
|
email: vill@rubyinventory.org
|
197
30
|
executables: []
|
198
31
|
extensions: []
|
@@ -205,6 +38,7 @@ extra_rdoc_files:
|
|
205
38
|
- docs/Режимы.md
|
206
39
|
- docs/Создание-и-использование-UI-компонент.md
|
207
40
|
- docs/Файловая-структура.md
|
41
|
+
- docs/Хелпер-bem_attrs_for.md
|
208
42
|
- docs/Хелпер-bem_mix.md
|
209
43
|
- docs/Хелпер-bem_mods.md
|
210
44
|
- docs/Хелпер-block_tag.md
|
@@ -228,6 +62,7 @@ files:
|
|
228
62
|
- docs/Режимы.md
|
229
63
|
- docs/Создание-и-использование-UI-компонент.md
|
230
64
|
- docs/Файловая-структура.md
|
65
|
+
- docs/Хелпер-bem_attrs_for.md
|
231
66
|
- docs/Хелпер-bem_mix.md
|
232
67
|
- docs/Хелпер-bem_mods.md
|
233
68
|
- docs/Хелпер-block_tag.md
|
@@ -260,7 +95,7 @@ files:
|
|
260
95
|
- lib/bemer/entity.rb
|
261
96
|
- lib/bemer/entity_builder.rb
|
262
97
|
- lib/bemer/helpers.rb
|
263
|
-
- lib/bemer/
|
98
|
+
- lib/bemer/mixes.rb
|
264
99
|
- lib/bemer/modifier_list.rb
|
265
100
|
- lib/bemer/path_resolver.rb
|
266
101
|
- lib/bemer/pipeline.rb
|
@@ -280,10 +115,11 @@ files:
|
|
280
115
|
- lib/bemer/tree/node.rb
|
281
116
|
- lib/bemer/tree/text_node.rb
|
282
117
|
- lib/bemer/version.rb
|
118
|
+
- spec/action_view/helpers/bem_attrs_for_spec.rb
|
283
119
|
- spec/action_view/helpers/block_tag_spec.rb
|
120
|
+
- spec/action_view/helpers/elem_tag_spec.rb
|
284
121
|
- spec/bemer/entity_builder_spec.rb
|
285
122
|
- spec/bemer/entity_spec.rb
|
286
|
-
- spec/bemer/mixin_list_spec.rb
|
287
123
|
- spec/bemer/modifier_list_spec.rb
|
288
124
|
- spec/bemer/railtie_spec.rb
|
289
125
|
- spec/bemer_spec.rb
|
@@ -301,7 +137,6 @@ files:
|
|
301
137
|
- spec/rails_helper.rb
|
302
138
|
- spec/spec_helper.rb
|
303
139
|
- spec/support/bemer.rb
|
304
|
-
- spec/support/shared_examples/an_html_entity_tree_builder_method.rb
|
305
140
|
homepage:
|
306
141
|
licenses:
|
307
142
|
- MIT
|
@@ -325,16 +160,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
325
160
|
- !ruby/object:Gem::Version
|
326
161
|
version: 2.2.0
|
327
162
|
requirements: []
|
328
|
-
|
329
|
-
rubygems_version: 2.7.7
|
163
|
+
rubygems_version: 3.4.3
|
330
164
|
signing_key:
|
331
165
|
specification_version: 4
|
332
|
-
summary: Build reusable UI components for Rails applications
|
166
|
+
summary: Build reusable UI components for Rails applications with the ability to use
|
167
|
+
the BEM methodology.
|
333
168
|
test_files:
|
169
|
+
- spec/action_view/helpers/bem_attrs_for_spec.rb
|
334
170
|
- spec/action_view/helpers/block_tag_spec.rb
|
171
|
+
- spec/action_view/helpers/elem_tag_spec.rb
|
335
172
|
- spec/bemer/entity_builder_spec.rb
|
336
173
|
- spec/bemer/entity_spec.rb
|
337
|
-
- spec/bemer/mixin_list_spec.rb
|
338
174
|
- spec/bemer/modifier_list_spec.rb
|
339
175
|
- spec/bemer/railtie_spec.rb
|
340
176
|
- spec/bemer_spec.rb
|
@@ -352,4 +188,3 @@ test_files:
|
|
352
188
|
- spec/rails_helper.rb
|
353
189
|
- spec/spec_helper.rb
|
354
190
|
- spec/support/bemer.rb
|
355
|
-
- spec/support/shared_examples/an_html_entity_tree_builder_method.rb
|