rails_blocks 0.5.6 → 0.6.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/.travis.yml +1 -0
- data/app/assets/javascripts/bem_blocks.coffee +106 -0
- data/app/assets/javascripts/block.coffee +21 -55
- data/app/assets/javascripts/jquery_bem_copy.coffee +1 -1
- data/app/assets/javascripts/rails_blocks.js +3 -5
- data/app/assets/javascripts/utils.coffee +9 -0
- data/app/assets/stylesheets/rails_blocks.sass +3 -5
- data/app/helpers/block_helper.rb +73 -26
- data/lib/rails_blocks/blocks/block.rb +1 -1
- data/lib/rails_blocks/configuration.rb +1 -3
- data/lib/rails_blocks/names.rb +18 -10
- data/lib/rails_blocks/version.rb +1 -1
- data/rails_blocks.gemspec +0 -7
- data/spec/helpers/block_helper_spec.rb +46 -7
- data/spec/rails_blocks/blocks/block_spec.rb +1 -1
- data/spec/rails_blocks/configuration_spec.rb +0 -12
- data/spec/rails_blocks/names_spec.rb +11 -11
- data/spec/rails_blocks_spec.rb +0 -13
- metadata +5 -103
- data/spec/internal/log/test.log +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a65055e52b9b72247afafaba66b23b0587b2d6fe
|
4
|
+
data.tar.gz: 5b998796ec4d8eb8e0fb8bf93065792517312446
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef4f8298d9330e4b357fe8482b4116dd90cff5d25fbfc1feade504becbf2198534243de744ce17658659ddb98a7869e29d9f943836fceb3d6b62c833fe0cd481
|
7
|
+
data.tar.gz: d730c6e442c72c40f60cab48cd354b14382dd308f709269af3dc3547c4a748b6812e91cbbc4d6f7720a96d5cd395db48b0e2be9880adda96f153caf82391c019
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -0,0 +1,106 @@
|
|
1
|
+
window.$$ =
|
2
|
+
decls: {}
|
3
|
+
cache: {}
|
4
|
+
bem_class: 'js-bem'
|
5
|
+
bem_class_selector: ".js-bem"
|
6
|
+
bemDataKey: 'bem'
|
7
|
+
|
8
|
+
processOptions: ($dom, b_name, o) ->
|
9
|
+
if o.attrs
|
10
|
+
for attr, attr_value of o.attrs
|
11
|
+
$dom.prop(attr, attr_value)
|
12
|
+
if o.content
|
13
|
+
$dom.html(o.content)
|
14
|
+
if o.mix
|
15
|
+
$dom.addClass($$.mixClass(o.mix))
|
16
|
+
if o.elements
|
17
|
+
for e_name, e_o of o.elements
|
18
|
+
$$.makeElement($dom, b_name, e_name, e_o)
|
19
|
+
|
20
|
+
makeElement: ($parent, b_name, e_name, o) ->
|
21
|
+
tag = o.tag || 'div'
|
22
|
+
$e = $("<#{tag} class='#{b_name}__#{e_name}'>")
|
23
|
+
$$.processOptions($e, b_name, o)
|
24
|
+
if o.prepend
|
25
|
+
$parent.prepend $e
|
26
|
+
else
|
27
|
+
$parent.append $e
|
28
|
+
$e
|
29
|
+
|
30
|
+
makeBlock: (b_name, o) ->
|
31
|
+
o ||= {}
|
32
|
+
tag = o.tag || 'div'
|
33
|
+
$b = $("<#{tag} class='#{b_name}'>")
|
34
|
+
$$.processOptions($b, b_name, o)
|
35
|
+
$b
|
36
|
+
|
37
|
+
init: ($context) ->
|
38
|
+
$blocks = $context.find($$.bem_class_selector)
|
39
|
+
$blocks = $blocks.add($context) if $context.hasClass $$.bem_class
|
40
|
+
$$.initBlocks($blocks)
|
41
|
+
|
42
|
+
initBlocks: ($context, options) ->
|
43
|
+
$context.each ->
|
44
|
+
$node = $(this)
|
45
|
+
allParams = $node.data($$.bemDataKey)
|
46
|
+
for own name, params of allParams
|
47
|
+
continue if name.indexOf('__') != -1
|
48
|
+
$$.getBlock($node, name, params)
|
49
|
+
|
50
|
+
getBlock: ($b, name, params)->
|
51
|
+
cacheKey = "#{name}_bid"
|
52
|
+
bid = $b.data(cacheKey)
|
53
|
+
if bid
|
54
|
+
return $$.cache[bid]
|
55
|
+
block = new $$.decls[$$.utils.camelCase(name)]($b, params, name)
|
56
|
+
bid = block.id
|
57
|
+
$b.data cacheKey, bid
|
58
|
+
$$.cache[bid] = block
|
59
|
+
block
|
60
|
+
|
61
|
+
makeMod: (name, value) ->
|
62
|
+
mod = name
|
63
|
+
mod += "_#{value}" if value
|
64
|
+
mod
|
65
|
+
|
66
|
+
mixClass: (mix) ->
|
67
|
+
return "#{mix.b}__#{mix.e}" if mix.e
|
68
|
+
mix.b
|
69
|
+
|
70
|
+
blockModClass: (name, mod, value) ->
|
71
|
+
"#{name}--#{$$.makeMod(mod, value)}"
|
72
|
+
|
73
|
+
elementModClass: (b_name, e_name, mod, value) ->
|
74
|
+
"#{$$.elementClass(b_name, e_name)}--#{$$.makeMod(mod, value)}"
|
75
|
+
|
76
|
+
elementClass: (b_name, e_name) ->
|
77
|
+
"#{b_name}__#{e_name}"
|
78
|
+
|
79
|
+
$.fn.destroyBlocks = ->
|
80
|
+
@find($$.bem_class_selector).getBlocks().each ->
|
81
|
+
@destroy()
|
82
|
+
|
83
|
+
$.fn.addMod = (name, value) ->
|
84
|
+
mod = $$.makeMod(name, value)
|
85
|
+
if @e_name
|
86
|
+
@addClass("#{@b_name}__#{@e_name}--#{mod}")
|
87
|
+
else
|
88
|
+
@addClass("#{@b_name}--#{mod}")
|
89
|
+
|
90
|
+
$.fn.delMod = (name, value) ->
|
91
|
+
mod = $$.makeMod(name, value)
|
92
|
+
if @e_name
|
93
|
+
@removeClass("#{@b_name}__#{@e_name}--#{mod}")
|
94
|
+
else
|
95
|
+
@removeClass("#{@b_name}--#{mod}")
|
96
|
+
|
97
|
+
$.fn.asBlock = (name, o) ->
|
98
|
+
@addClass("#{name}")
|
99
|
+
$$.getBlock(@, name, o)
|
100
|
+
|
101
|
+
$.fn.bemParams = () ->
|
102
|
+
allParams = @data($$.bemDataKey)
|
103
|
+
if @e_name
|
104
|
+
return allParams[$$.elementClass(@b_name, @e_name)]
|
105
|
+
else
|
106
|
+
console.log('Error, only for elements. Use initBlock for blocks.')
|
@@ -1,10 +1,10 @@
|
|
1
1
|
class window.Block
|
2
|
-
constructor: ($b,
|
2
|
+
constructor: ($b, params, name) ->
|
3
3
|
@$node = $b
|
4
|
-
@name =
|
5
|
-
|
6
|
-
@id = $$.guid()
|
7
|
-
@params =
|
4
|
+
@name = name
|
5
|
+
console.log(@name)
|
6
|
+
@id = $$.utils.guid()
|
7
|
+
@params = params
|
8
8
|
#$.extend this, decl.methods
|
9
9
|
@_addEvents() if @events
|
10
10
|
# if @elements
|
@@ -12,11 +12,11 @@ class window.Block
|
|
12
12
|
# @_addEvents(element)
|
13
13
|
@init() if @init
|
14
14
|
|
15
|
-
elem: (e_name, mod_name, mod_value, context) ->
|
16
|
-
klass = ".b-#{@name}__#{e_name}"
|
17
|
-
$elem = $(klass, context || @$node)
|
15
|
+
elem: (e_name, mod_name, mod_value, context = @$node) ->
|
18
16
|
if mod_name
|
19
|
-
$elem = $
|
17
|
+
$elem = $(".#{$$.elementModClass(@name, e_name, mod_name, mod_value)}", context)
|
18
|
+
else
|
19
|
+
$elem = $(".#{@_elementClass(e_name)}", context)
|
20
20
|
|
21
21
|
$elem.e_name = e_name
|
22
22
|
$elem.b_name = @name
|
@@ -32,19 +32,27 @@ class window.Block
|
|
32
32
|
|
33
33
|
_trigger: (event) ->
|
34
34
|
@$node.trigger event
|
35
|
-
|
35
|
+
|
36
|
+
_elementClass: (e_name) ->
|
37
|
+
$$.elementClass(@name, e_name)
|
38
|
+
|
36
39
|
addElem: (e_name, o, $parent) ->
|
37
40
|
o ||= {}
|
38
41
|
$elem = $$.makeElement($parent || @$node, @name, e_name, o)
|
39
42
|
$elem.e_name = e_name
|
40
43
|
$elem.b_name = @name
|
41
44
|
$elem
|
45
|
+
|
46
|
+
asElem: ($elem, name) ->
|
47
|
+
$elem.e_name = name
|
48
|
+
$elem.b_name = @name
|
49
|
+
$elem
|
42
50
|
|
43
51
|
addMod: (mod, value) ->
|
44
|
-
@$node.
|
52
|
+
@$node.addClass($$.blockModClass(@name, mod, value))
|
45
53
|
|
46
54
|
delMod: (mod, value) ->
|
47
|
-
@$node.
|
55
|
+
@$node.removeClass($$.blockModClass(@name, mod, value))
|
48
56
|
|
49
57
|
toggleMod: (mod, value) ->
|
50
58
|
if @hasMod(mod, value)
|
@@ -53,46 +61,4 @@ class window.Block
|
|
53
61
|
@$node.addMod(mod, value)
|
54
62
|
|
55
63
|
hasMod: (mod, value) ->
|
56
|
-
|
57
|
-
@$node.hasClass("b-#{@name}--#{mod}")
|
58
|
-
|
59
|
-
# class window.Block
|
60
|
-
# constructor: ($b) ->
|
61
|
-
# name = $b.getBlockName()
|
62
|
-
# params = $b.data('bem')
|
63
|
-
# decl = RB.decls[name]
|
64
|
-
# if !decl
|
65
|
-
# throw new Error(name + ' block is not declared')
|
66
|
-
# @name = name
|
67
|
-
# @params = params
|
68
|
-
# @$node = $b
|
69
|
-
# @id = $$.guid()
|
70
|
-
#
|
71
|
-
# $.extend this, decl.methods
|
72
|
-
# @_addEvents()
|
73
|
-
# @_setInited()
|
74
|
-
# @_trigger 'b-inited'
|
75
|
-
# return
|
76
|
-
#
|
77
|
-
# _addEvents: ->
|
78
|
-
# decl = $$.decls[@name]
|
79
|
-
# events = decl.events
|
80
|
-
# for e of events
|
81
|
-
# if events.hasOwnProperty(e)
|
82
|
-
# p = e.split(' ')
|
83
|
-
# handler = events[e]
|
84
|
-
# if typeof handler == 'string'
|
85
|
-
# handler = decl.methods[handler]
|
86
|
-
# @$node.on p[0], p[1], handler.bind(@)
|
87
|
-
#
|
88
|
-
# _setInited:->
|
89
|
-
#
|
90
|
-
# setMod: (mod, value) ->
|
91
|
-
#
|
92
|
-
# _trigger: (event) ->
|
93
|
-
# @$node.trigger event
|
94
|
-
#
|
95
|
-
# destroy: ->
|
96
|
-
# $$.cache[@id] = null
|
97
|
-
# @$node.off()
|
98
|
-
# @_trigger 'b-destroyed'
|
64
|
+
@$node.hasClass($$.blockModClass(@name, mod, value))
|
@@ -1,9 +1,8 @@
|
|
1
|
-
$
|
2
|
-
$bemElementSeparator: '__'
|
1
|
+
$bemElementSeparator: '__'
|
3
2
|
$bemModifierSeparator: '--'
|
4
3
|
|
5
4
|
@function b-class($block)
|
6
|
-
@return ".#{$
|
5
|
+
@return ".#{$block}"
|
7
6
|
|
8
7
|
@function selectorToString($selector)
|
9
8
|
$selector: inspect($selector) //cast to string
|
@@ -40,7 +39,7 @@ $bemModifierSeparator: '--'
|
|
40
39
|
@return str-slice($selector, 0, $start)
|
41
40
|
|
42
41
|
=b($block)
|
43
|
-
.#{$
|
42
|
+
.#{$block}
|
44
43
|
@content
|
45
44
|
|
46
45
|
=plus_b
|
@@ -90,5 +89,4 @@ $bemModifierSeparator: '--'
|
|
90
89
|
$selector: &
|
91
90
|
$selector: selectorToString($selector)
|
92
91
|
$block: if(containsModifier($selector) or containsPseudo($selector) or containsElement($selector), getBlock($selector), selectorToString($selector))
|
93
|
-
$block: str-slice($block, str-length($bemBlockPrefix) + 1)
|
94
92
|
@return image-url("#{$level}/#{$block}/images/#{$image}")
|
data/app/helpers/block_helper.rb
CHANGED
@@ -21,14 +21,11 @@ module BlockHelper
|
|
21
21
|
|
22
22
|
#TODO бога ради, отрефактори это дерьмо
|
23
23
|
def b(b_name, options = {}, &block)
|
24
|
-
parent_block = context_block
|
25
|
-
push_context_block b_name
|
26
24
|
options = page_options.merge options
|
27
|
-
options[:parent_block] =
|
25
|
+
options[:parent_block] = context_block
|
26
|
+
push_context_block b_name
|
28
27
|
template = block_template b_name, options
|
29
|
-
|
30
|
-
|
31
|
-
result = element(classes, template, options, &block)
|
28
|
+
result = entity(template, :block, b_name, options, &block)
|
32
29
|
pop_context_block
|
33
30
|
result
|
34
31
|
end
|
@@ -51,13 +48,12 @@ module BlockHelper
|
|
51
48
|
end
|
52
49
|
|
53
50
|
def e(e_name, options = {}, &block)
|
51
|
+
options = page_options.merge options
|
54
52
|
parent_block = options[:b] || context_block
|
55
53
|
raise RailsBlocks::NoBlockContextError unless parent_block
|
56
|
-
options = page_options.merge options
|
57
54
|
options[:parent_block] = parent_block
|
58
55
|
template = element_template parent_block, e_name, options
|
59
|
-
|
60
|
-
element(classes, template, options, &block)
|
56
|
+
entity(template, :elem, e_name, options, &block)
|
61
57
|
end
|
62
58
|
|
63
59
|
def e_classes(e_name, options = {})
|
@@ -68,42 +64,93 @@ module BlockHelper
|
|
68
64
|
element_classes(parent_block, e_name, options).join(' ')
|
69
65
|
end
|
70
66
|
|
71
|
-
def
|
67
|
+
def entity(template, type, name, options, &block)
|
72
68
|
content = block ? capture(&block) : options[:content]
|
73
|
-
|
74
|
-
@attrs
|
75
|
-
@
|
76
|
-
@
|
77
|
-
|
69
|
+
#важно заполнять публичные поля только после того, как закапчюрится то, что внутри энтити, иначе они перезапишутся.
|
70
|
+
@attrs = nil
|
71
|
+
@current_options = options
|
72
|
+
@current_entity = {type: type, name: name}
|
73
|
+
Rails.logger.debug "------------------------------------------------#{@current_options}-------------------------------#{@current_entity}"
|
78
74
|
template.nil? ? empty(content) : render(file: template, locals: {content: content, options: options})
|
79
75
|
end
|
80
76
|
|
81
|
-
#убрать после тестов производительности
|
82
|
-
# def empty(content)
|
83
|
-
# atrrs = @attrs.except(:tag).map do |key, value|
|
84
|
-
# key.to_s + '=\'' + value.to_s + "'"
|
85
|
-
# end
|
86
|
-
# "<#{@attrs[:tag]} #{atrrs.join(' ')}>#{content}</#{@attrs[:tag]}>".html_safe
|
87
|
-
# end
|
88
|
-
|
89
77
|
def empty(content)
|
90
78
|
content_tag bem_tag, content, bem_attrs_without_tag
|
91
79
|
end
|
92
80
|
|
93
81
|
def bem_tag
|
94
|
-
|
82
|
+
bem_attrs[:tag]
|
95
83
|
end
|
96
84
|
|
97
85
|
def bem_attrs
|
86
|
+
if @attrs.nil?
|
87
|
+
@attrs = {class: current_entity_classes.join(' ')}
|
88
|
+
@attrs.merge! @current_options[:attrs] if @current_options[:attrs]
|
89
|
+
data = current_bem_data
|
90
|
+
@attrs['data-bem'] = data.to_json if data
|
91
|
+
@attrs[:tag] = @current_options[:tag] || 'div'
|
92
|
+
end
|
93
|
+
|
98
94
|
@attrs
|
99
95
|
end
|
100
96
|
|
101
97
|
def bem_attrs_without_tag
|
102
|
-
|
98
|
+
bem_attrs.except :tag
|
99
|
+
end
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
def set_tag(tag)
|
104
|
+
@current_options[:tag] = tag
|
105
|
+
end
|
106
|
+
|
107
|
+
def set_js(value)
|
108
|
+
@current_options[:js] = value
|
103
109
|
end
|
104
110
|
|
105
111
|
private
|
106
|
-
|
112
|
+
def current_bem_data
|
113
|
+
data = {}
|
114
|
+
data.merge! entity_data(current_entity_name, @current_options[:js]) if @current_options[:js]
|
115
|
+
data.merge! mix_data(@current_options[:mix]) if @current_options[:mix]
|
116
|
+
|
117
|
+
return nil if data == {}
|
118
|
+
data
|
119
|
+
end
|
120
|
+
|
121
|
+
def mix_data(mixes)
|
122
|
+
mixes = [mixes] unless mixes.is_a? Array
|
123
|
+
data = mixes.map do |mix|
|
124
|
+
next unless mix[:js]
|
125
|
+
if mix[:e]
|
126
|
+
if mix[:b]
|
127
|
+
entity_data(element_name(mix[:b], mix[:e]), mix[:js])
|
128
|
+
else
|
129
|
+
entity_data(element_name(context_block, mix[:e]), mix[:js])
|
130
|
+
end
|
131
|
+
else
|
132
|
+
raise RailsBlocks::BadMixError if mix[:b].nil?
|
133
|
+
entity_data(block_name(mix[:b]), mix[:js])
|
134
|
+
end
|
135
|
+
end.compact.inject(&:merge) || {}
|
136
|
+
end
|
137
|
+
|
138
|
+
def entity_data(name, data)
|
139
|
+
return {name => data} if data.is_a? Hash
|
140
|
+
return {name => {}} if data == true
|
141
|
+
{}
|
142
|
+
end
|
143
|
+
|
144
|
+
def current_entity_name
|
145
|
+
return block_name(@current_entity[:name]) if @current_entity[:type] == :block
|
146
|
+
element_name(@current_options[:parent_block], @current_entity[:name])
|
147
|
+
end
|
148
|
+
|
149
|
+
def current_entity_classes
|
150
|
+
return block_classes(@current_entity[:name], @current_options) if @current_entity[:type] == :block
|
151
|
+
element_classes(@current_options[:parent_block], @current_entity[:name], @current_options)
|
152
|
+
end
|
153
|
+
|
107
154
|
def blocks_stack
|
108
155
|
@blocks_stack = @blocks_stack || []
|
109
156
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
module RailsBlocks
|
2
2
|
class Configuration
|
3
|
-
attr_accessor :prefix
|
4
3
|
attr_accessor :blocks_dir
|
5
4
|
attr_accessor :levels
|
6
5
|
attr_accessor :template_engine
|
@@ -15,13 +14,12 @@ module RailsBlocks
|
|
15
14
|
end
|
16
15
|
|
17
16
|
def initialize
|
18
|
-
@prefix = 'b-'
|
19
17
|
@blocks_dir = 'app/blocks'
|
20
18
|
@levels = []
|
21
19
|
@template_engine = '.slim'
|
22
20
|
@element_separator = '__'
|
23
21
|
@modifier_separator = '--'
|
24
|
-
@js_class = '
|
22
|
+
@js_class = 'js-bem'
|
25
23
|
end
|
26
24
|
end
|
27
25
|
end
|
data/lib/rails_blocks/names.rb
CHANGED
@@ -2,22 +2,30 @@ module RailsBlocks
|
|
2
2
|
module Names
|
3
3
|
def element_classes(b_name, e_name, options = {})
|
4
4
|
base_class = element_class b_name, e_name
|
5
|
-
classes(base_class, options)
|
5
|
+
classes(base_class, false, options)
|
6
6
|
end
|
7
7
|
|
8
8
|
def block_classes(b_name, options = {})
|
9
9
|
base_class = block_class b_name
|
10
|
-
classes(base_class, options)
|
10
|
+
classes(base_class, true, options)
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
|
+
def block_name(b_name)
|
14
|
+
b_name.to_s
|
15
|
+
end
|
16
|
+
|
17
|
+
def element_name(b_name, e_name)
|
18
|
+
b_name.to_s + RailsBlocks.config.element_separator + e_name.to_s
|
19
|
+
end
|
20
|
+
|
13
21
|
private
|
14
|
-
def classes(base_class, options = {})
|
22
|
+
def classes(base_class, add_js, options = {})
|
15
23
|
classes = [base_class]
|
16
24
|
classes |= mods_classes(base_class, options[:mods]) unless options[:mods].nil?
|
17
25
|
classes |= mix_classes(options[:mix], options[:parent_block]) if options[:mix]
|
18
26
|
classes |= Array(options[:class]) if options[:class]
|
19
|
-
classes << RailsBlocks.config.js_class if options[:js]
|
20
|
-
classes
|
27
|
+
classes << RailsBlocks.config.js_class if options[:js] && add_js
|
28
|
+
classes.uniq
|
21
29
|
end
|
22
30
|
|
23
31
|
def mix_classes(mixes, context_block = nil)
|
@@ -48,13 +56,13 @@ module RailsBlocks
|
|
48
56
|
def mod_class(key, value)
|
49
57
|
value == true ? key.to_s : key.to_s + '_' + value.to_s
|
50
58
|
end
|
51
|
-
|
59
|
+
|
52
60
|
def block_class(b_name)
|
53
|
-
|
61
|
+
block_name(b_name)
|
54
62
|
end
|
55
|
-
|
63
|
+
|
56
64
|
def element_class(b_name, e_name)
|
57
|
-
|
65
|
+
element_name(b_name, e_name)
|
58
66
|
end
|
59
67
|
end
|
60
68
|
end
|
data/lib/rails_blocks/version.rb
CHANGED
data/rails_blocks.gemspec
CHANGED
@@ -28,11 +28,4 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.add_development_dependency 'rspec-rails', '~> 3.0'
|
29
29
|
spec.add_development_dependency 'memfs'
|
30
30
|
spec.add_development_dependency 'spring'
|
31
|
-
spec.add_development_dependency 'guard'
|
32
|
-
spec.add_development_dependency 'guard-rspec'
|
33
|
-
spec.add_development_dependency 'pry'
|
34
|
-
spec.add_development_dependency 'pry-remote'
|
35
|
-
spec.add_development_dependency 'pry-nav'
|
36
|
-
spec.add_development_dependency 'terminal-notifier'
|
37
|
-
spec.add_development_dependency 'terminal-notifier-guard'
|
38
31
|
end
|
@@ -6,24 +6,44 @@ describe BlockHelper, type: :helper do
|
|
6
6
|
context ".b" do
|
7
7
|
it "renders empty div with class when called without options" do
|
8
8
|
result = b :test
|
9
|
-
expect(result).to eq '<div class="
|
9
|
+
expect(result).to eq '<div class="test"></div>'
|
10
10
|
end
|
11
11
|
|
12
12
|
it "renders div with content when called with block" do
|
13
13
|
result = b 'test-block' do
|
14
14
|
'test-content'
|
15
15
|
end
|
16
|
-
expect(result).to eq '<div class="
|
16
|
+
expect(result).to eq '<div class="test-block">test-content</div>'
|
17
17
|
end
|
18
18
|
|
19
19
|
it "renders empty div with mods class when called with mods" do
|
20
20
|
result = b 'test-block', mods: {test: :one}
|
21
|
-
expect(result).to eq '<div class="
|
21
|
+
expect(result).to eq '<div class="test-block test-block--test_one"></div>'
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'renders file when one exists' do
|
25
25
|
result = b 'block1'
|
26
|
-
expect(result).to eq '<div class="
|
26
|
+
expect(result).to eq '<div class="block1">block1</div>'
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'ads js-bem class and data-bem when js: true' do
|
30
|
+
result = b 'b1', js: true
|
31
|
+
expect(result).to eq '<div class="b1 js-bem" data-bem="{"b1":{}}"></div>'
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'ads js-bem class and mixed data-bem when js: true in mix' do
|
35
|
+
result = b 'b1', mix: {b: 'b2', js: true}
|
36
|
+
expect(result).to eq '<div class="b1 b2 js-bem" data-bem="{"b2":{}}"></div>'
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'ads js-bem class and full data-bem when js: true in mix' do
|
40
|
+
result = b 'b1', js: true, mix: {b: 'b2', js: true}
|
41
|
+
expect(result).to eq '<div class="b1 b2 js-bem" data-bem="{"b1":{},"b2":{}}"></div>'
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'ads js-bem class and full custom data-bem when js: true in mix' do
|
45
|
+
result = b 'b1', js: {bb1: 'boo'}, mix: {b: 'b2', js: {bb2: 'boo2'}}
|
46
|
+
expect(result).to eq '<div class="b1 b2 js-bem" data-bem="{"b1":{"bb1":"boo"},"b2":{"bb2":"boo2"}}"></div>'
|
27
47
|
end
|
28
48
|
end
|
29
49
|
|
@@ -35,14 +55,14 @@ describe BlockHelper, type: :helper do
|
|
35
55
|
it "renders empty element with class when called without options" do
|
36
56
|
b 'test' do
|
37
57
|
result = e :element
|
38
|
-
expect(result).to eq '<div class="
|
58
|
+
expect(result).to eq '<div class="test__element"></div>'
|
39
59
|
end
|
40
60
|
end
|
41
61
|
|
42
62
|
it "renders element with mods class when called with mods" do
|
43
63
|
b 'test' do
|
44
64
|
result = e 'element', mods: {test: :boo, test2: true}
|
45
|
-
expect(result).to eq '<div class="
|
65
|
+
expect(result).to eq '<div class="test__element test__element--test_boo test__element--test2"></div>'
|
46
66
|
end
|
47
67
|
end
|
48
68
|
|
@@ -51,8 +71,27 @@ describe BlockHelper, type: :helper do
|
|
51
71
|
result = e 'element' do
|
52
72
|
"content"
|
53
73
|
end
|
54
|
-
expect(result).to eq '<div class="
|
74
|
+
expect(result).to eq '<div class="test__element">content</div>'
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'ads data-bem, but not js-bem class when js: true' do
|
79
|
+
b 'test' do
|
80
|
+
result = e 'e1', js: {test: 2}
|
81
|
+
expect(result).to eq '<div class="test__e1" data-bem="{"test__e1":{"test":2}}"></div>'
|
55
82
|
end
|
56
83
|
end
|
84
|
+
|
85
|
+
it 'ads js-bem class and mixed data-bem when js: true in mix with block' do
|
86
|
+
b 'test' do
|
87
|
+
result = e 'e1', mix: {b: 'b1', js: true}
|
88
|
+
expect(result).to eq '<div class="test__e1 b1 js-bem" data-bem="{"b1":{}}"></div>'
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'ads js-bem class and full data-bem when js: true in mix' do
|
93
|
+
result = b 'b1', js: true, mix: {b: 'b2', js: true}
|
94
|
+
expect(result).to eq '<div class="b1 b2 js-bem" data-bem="{"b1":{},"b2":{}}"></div>'
|
95
|
+
end
|
57
96
|
end
|
58
97
|
end
|
@@ -5,7 +5,7 @@ describe RailsBlocks::Blocks::Block do
|
|
5
5
|
b_name = 'test-block'
|
6
6
|
block = RailsBlocks.get_block b_name
|
7
7
|
result = block.render
|
8
|
-
klass =
|
8
|
+
klass = b_name
|
9
9
|
expect(result).to match(/<div.*\/div>/) & match(/class=\"#{klass}\"/)
|
10
10
|
end
|
11
11
|
end
|
@@ -1,18 +1,6 @@
|
|
1
1
|
describe RailsBlocks::Configuration do
|
2
2
|
subject { RailsBlocks::Configuration.new }
|
3
|
-
describe "#prefix" do
|
4
|
-
it "default value is 'b-'" do
|
5
|
-
expect(subject.prefix).to eq 'b-'
|
6
|
-
end
|
7
|
-
end
|
8
3
|
|
9
|
-
describe "#prefix=" do
|
10
|
-
it "can set value" do
|
11
|
-
subject.prefix = 't-'
|
12
|
-
expect(subject.prefix).to eq 't-'
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
4
|
describe "#ns" do
|
17
5
|
it 'yield new Configuration' do
|
18
6
|
subject.ns :admin do |config|
|
@@ -5,58 +5,58 @@ describe RailsBlocks::Names do
|
|
5
5
|
context '.element_classes' do
|
6
6
|
it 'returns simple element_classes without options' do
|
7
7
|
classes = element_classes 'block', 'element'
|
8
|
-
expect(classes).to contain_exactly '
|
8
|
+
expect(classes).to contain_exactly 'block__element'
|
9
9
|
end
|
10
10
|
|
11
11
|
it 'returns element_class & mods with options[:mods]' do
|
12
12
|
classes = element_classes 'block', 'element', mods: {test: :one}
|
13
|
-
expect(classes).to contain_exactly '
|
13
|
+
expect(classes).to contain_exactly 'block__element', 'block__element--test_one'
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
17
|
context '.block_classes' do
|
18
18
|
it 'returns simple block_class without options' do
|
19
19
|
classes = block_classes 'block'
|
20
|
-
expect(classes).to contain_exactly '
|
20
|
+
expect(classes).to contain_exactly 'block'
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'returns block_class & mods with options[:mods]' do
|
24
24
|
classes = block_classes 'block', mods: {test: :one}
|
25
|
-
expect(classes).to contain_exactly '
|
25
|
+
expect(classes).to contain_exactly 'block', 'block--test_one'
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
29
|
context '.mods_classes' do
|
30
30
|
it 'returns mods classes' do
|
31
|
-
classes = mods_classes '
|
32
|
-
expect(classes).to contain_exactly '
|
31
|
+
classes = mods_classes 'base', {test: :one, boo: :two}
|
32
|
+
expect(classes).to contain_exactly 'base--test_one', 'base--boo_two'
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
36
|
context '.mix_classes' do
|
37
37
|
it 'returns element class when one :b & :e exists' do
|
38
38
|
classes = mix_classes b: :block, e: :element
|
39
|
-
expect(classes).to contain_exactly '
|
39
|
+
expect(classes).to contain_exactly 'block__element'
|
40
40
|
end
|
41
41
|
|
42
42
|
it 'returns element classes when array :b & :e exists' do
|
43
43
|
classes = mix_classes [{b: :block, e: :element}, {b: 'block2', e: 'element2'}]
|
44
|
-
expect(classes).to contain_exactly '
|
44
|
+
expect(classes).to contain_exactly 'block__element', 'block2__element2'
|
45
45
|
end
|
46
46
|
|
47
47
|
it 'returns blocks classes when only :b exists' do
|
48
48
|
classes = mix_classes b: :block
|
49
|
-
expect(classes).to contain_exactly '
|
49
|
+
expect(classes).to contain_exactly 'block'
|
50
50
|
end
|
51
51
|
|
52
52
|
it 'returns blocks classes when array of :b exists' do
|
53
53
|
classes = mix_classes [{b: :block}, {b: :test}]
|
54
|
-
expect(classes).to contain_exactly '
|
54
|
+
expect(classes).to contain_exactly 'block', 'test'
|
55
55
|
end
|
56
56
|
|
57
57
|
it 'returns blocks classes & element classes when array of :b, :b & :e exists' do
|
58
58
|
classes = mix_classes [{b: :block}, {b: :test, e: :boo}]
|
59
|
-
expect(classes).to contain_exactly '
|
59
|
+
expect(classes).to contain_exactly 'block', 'test__boo'
|
60
60
|
end
|
61
61
|
|
62
62
|
it 'raise error if :b not exists' do
|
data/spec/rails_blocks_spec.rb
CHANGED
@@ -3,14 +3,7 @@ require 'rails'
|
|
3
3
|
|
4
4
|
describe RailsBlocks do
|
5
5
|
describe ".configure" do
|
6
|
-
it "set prefix for block class" do
|
7
|
-
RailsBlocks.configure do |config|
|
8
|
-
config.prefix = 't-'
|
9
|
-
end
|
10
6
|
|
11
|
-
expect(RailsBlocks.config.prefix).to eq 't-'
|
12
|
-
end
|
13
|
-
|
14
7
|
it "set path for blocks folder" do
|
15
8
|
RailsBlocks.configure do |config|
|
16
9
|
config.blocks_dir = 'bem'
|
@@ -63,7 +56,6 @@ describe RailsBlocks do
|
|
63
56
|
describe ".reset" do
|
64
57
|
before :each do
|
65
58
|
RailsBlocks.configure do |config|
|
66
|
-
config.prefix = 'test-'
|
67
59
|
config.blocks_dir = 'test_path'
|
68
60
|
config.levels = ['common', 'test']
|
69
61
|
config.template_engine = '.haml'
|
@@ -71,11 +63,6 @@ describe RailsBlocks do
|
|
71
63
|
end
|
72
64
|
end
|
73
65
|
|
74
|
-
it "resets the configuration prefix" do
|
75
|
-
RailsBlocks.reset
|
76
|
-
expect(RailsBlocks.config.prefix).to eq('b-')
|
77
|
-
end
|
78
|
-
|
79
66
|
it "resets the configuration block_path" do
|
80
67
|
RailsBlocks.reset
|
81
68
|
expect(RailsBlocks.config.blocks_dir).to eq('app/blocks')
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_blocks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrey Potetiurin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -142,104 +142,6 @@ dependencies:
|
|
142
142
|
- - ">="
|
143
143
|
- !ruby/object:Gem::Version
|
144
144
|
version: '0'
|
145
|
-
- !ruby/object:Gem::Dependency
|
146
|
-
name: guard
|
147
|
-
requirement: !ruby/object:Gem::Requirement
|
148
|
-
requirements:
|
149
|
-
- - ">="
|
150
|
-
- !ruby/object:Gem::Version
|
151
|
-
version: '0'
|
152
|
-
type: :development
|
153
|
-
prerelease: false
|
154
|
-
version_requirements: !ruby/object:Gem::Requirement
|
155
|
-
requirements:
|
156
|
-
- - ">="
|
157
|
-
- !ruby/object:Gem::Version
|
158
|
-
version: '0'
|
159
|
-
- !ruby/object:Gem::Dependency
|
160
|
-
name: guard-rspec
|
161
|
-
requirement: !ruby/object:Gem::Requirement
|
162
|
-
requirements:
|
163
|
-
- - ">="
|
164
|
-
- !ruby/object:Gem::Version
|
165
|
-
version: '0'
|
166
|
-
type: :development
|
167
|
-
prerelease: false
|
168
|
-
version_requirements: !ruby/object:Gem::Requirement
|
169
|
-
requirements:
|
170
|
-
- - ">="
|
171
|
-
- !ruby/object:Gem::Version
|
172
|
-
version: '0'
|
173
|
-
- !ruby/object:Gem::Dependency
|
174
|
-
name: pry
|
175
|
-
requirement: !ruby/object:Gem::Requirement
|
176
|
-
requirements:
|
177
|
-
- - ">="
|
178
|
-
- !ruby/object:Gem::Version
|
179
|
-
version: '0'
|
180
|
-
type: :development
|
181
|
-
prerelease: false
|
182
|
-
version_requirements: !ruby/object:Gem::Requirement
|
183
|
-
requirements:
|
184
|
-
- - ">="
|
185
|
-
- !ruby/object:Gem::Version
|
186
|
-
version: '0'
|
187
|
-
- !ruby/object:Gem::Dependency
|
188
|
-
name: pry-remote
|
189
|
-
requirement: !ruby/object:Gem::Requirement
|
190
|
-
requirements:
|
191
|
-
- - ">="
|
192
|
-
- !ruby/object:Gem::Version
|
193
|
-
version: '0'
|
194
|
-
type: :development
|
195
|
-
prerelease: false
|
196
|
-
version_requirements: !ruby/object:Gem::Requirement
|
197
|
-
requirements:
|
198
|
-
- - ">="
|
199
|
-
- !ruby/object:Gem::Version
|
200
|
-
version: '0'
|
201
|
-
- !ruby/object:Gem::Dependency
|
202
|
-
name: pry-nav
|
203
|
-
requirement: !ruby/object:Gem::Requirement
|
204
|
-
requirements:
|
205
|
-
- - ">="
|
206
|
-
- !ruby/object:Gem::Version
|
207
|
-
version: '0'
|
208
|
-
type: :development
|
209
|
-
prerelease: false
|
210
|
-
version_requirements: !ruby/object:Gem::Requirement
|
211
|
-
requirements:
|
212
|
-
- - ">="
|
213
|
-
- !ruby/object:Gem::Version
|
214
|
-
version: '0'
|
215
|
-
- !ruby/object:Gem::Dependency
|
216
|
-
name: terminal-notifier
|
217
|
-
requirement: !ruby/object:Gem::Requirement
|
218
|
-
requirements:
|
219
|
-
- - ">="
|
220
|
-
- !ruby/object:Gem::Version
|
221
|
-
version: '0'
|
222
|
-
type: :development
|
223
|
-
prerelease: false
|
224
|
-
version_requirements: !ruby/object:Gem::Requirement
|
225
|
-
requirements:
|
226
|
-
- - ">="
|
227
|
-
- !ruby/object:Gem::Version
|
228
|
-
version: '0'
|
229
|
-
- !ruby/object:Gem::Dependency
|
230
|
-
name: terminal-notifier-guard
|
231
|
-
requirement: !ruby/object:Gem::Requirement
|
232
|
-
requirements:
|
233
|
-
- - ">="
|
234
|
-
- !ruby/object:Gem::Version
|
235
|
-
version: '0'
|
236
|
-
type: :development
|
237
|
-
prerelease: false
|
238
|
-
version_requirements: !ruby/object:Gem::Requirement
|
239
|
-
requirements:
|
240
|
-
- - ">="
|
241
|
-
- !ruby/object:Gem::Version
|
242
|
-
version: '0'
|
243
145
|
description: Gem helps build UI with blocks approach
|
244
146
|
email:
|
245
147
|
- potetiurin@gmail.com
|
@@ -255,12 +157,14 @@ files:
|
|
255
157
|
- LICENSE.txt
|
256
158
|
- README.md
|
257
159
|
- Rakefile
|
160
|
+
- app/assets/javascripts/bem_blocks.coffee
|
258
161
|
- app/assets/javascripts/block.coffee
|
259
162
|
- app/assets/javascripts/jblocks.coffee
|
260
163
|
- app/assets/javascripts/jquery_bem.coffee
|
261
164
|
- app/assets/javascripts/jquery_bem_copy.coffee
|
262
165
|
- app/assets/javascripts/main.coffee
|
263
166
|
- app/assets/javascripts/rails_blocks.js
|
167
|
+
- app/assets/javascripts/utils.coffee
|
264
168
|
- app/assets/stylesheets/rails_blocks.sass
|
265
169
|
- app/helpers/block_helper.rb
|
266
170
|
- app/views/rails_blocks/element.slim
|
@@ -303,7 +207,6 @@ files:
|
|
303
207
|
- spec/internal/config/routes.rb
|
304
208
|
- spec/internal/db/schema.rb
|
305
209
|
- spec/internal/log/.gitignore
|
306
|
-
- spec/internal/log/test.log
|
307
210
|
- spec/internal/public/favicon.ico
|
308
211
|
- spec/rails_blocks/blocks/block_spec.rb
|
309
212
|
- spec/rails_blocks/configuration_spec.rb
|
@@ -331,7 +234,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
331
234
|
version: '0'
|
332
235
|
requirements: []
|
333
236
|
rubyforge_project:
|
334
|
-
rubygems_version: 2.4.
|
237
|
+
rubygems_version: 2.4.5
|
335
238
|
signing_key:
|
336
239
|
specification_version: 4
|
337
240
|
summary: Rails plugin for work with some modification of BEM methodology
|
@@ -358,7 +261,6 @@ test_files:
|
|
358
261
|
- spec/internal/config/routes.rb
|
359
262
|
- spec/internal/db/schema.rb
|
360
263
|
- spec/internal/log/.gitignore
|
361
|
-
- spec/internal/log/test.log
|
362
264
|
- spec/internal/public/favicon.ico
|
363
265
|
- spec/rails_blocks/blocks/block_spec.rb
|
364
266
|
- spec/rails_blocks/configuration_spec.rb
|
data/spec/internal/log/test.log
DELETED
@@ -1,8 +0,0 @@
|
|
1
|
-
Rendered app/blocks/common/block1/block1.slim (0.6ms)
|
2
|
-
Rendered app/blocks/common/block1/block1.slim (0.5ms)
|
3
|
-
Rendered app/blocks/common/block1/block1.slim (16.8ms)
|
4
|
-
Rendered app/blocks/common/block1/block1.slim (29.1ms)
|
5
|
-
Rendered app/blocks/common/block1/block1.slim (14.3ms)
|
6
|
-
Rendered app/blocks/common/block1/block1.slim (17.0ms)
|
7
|
-
Rendered app/blocks/common/block1/block1.slim (16.0ms)
|
8
|
-
Rendered app/blocks/common/block1/block1.slim (20.0ms)
|