rbem 0.1.5 → 0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +24 -0
  3. data/lib/rbem.rb +55 -20
  4. data/lib/rbem/version.rb +1 -1
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 736da0b495fca2527279fc8d70994d3eb61a2ba9
4
- data.tar.gz: 27a10eb42501f9fa68f1ab29336030f93368f2c7
3
+ metadata.gz: 720d03b5417352538a07c97a1e5fce646a17b671
4
+ data.tar.gz: 3893b7c30e91d4da744877698f9cc06ef18c0f8c
5
5
  SHA512:
6
- metadata.gz: 2d6dafc38af764bdec869db5073cc99962e663246df75adf2fcdd62e85c8882d563c623a3c0d9fa5452c8c9f98bdc675f8b5014a9b5c1bb4d78984ec0a60693e
7
- data.tar.gz: 9d8a198ebce633f9788cb82ce234e25f8499f6381c1d9f16e3a7c6cd6e5aee01d8fe4f1c0f27062631c2f45c5f6f9bf4d970bbf914c88f04d25aa730320c570f
6
+ metadata.gz: df9d32c6d3cffdfb53d92fe302314f1be1346f5cdf56215b45ecdd6ca5fde912a0813a66946e02b658ae6ad4249b2356f23a12554d061d656d7e3fd320dc5c23
7
+ data.tar.gz: e049adf1955637122b9b89fd51075c300ff039968288e7b9fbf90f78a74043bccf9f39a35b9910df4c691ec1f0c091a95b501d9bae85fddcce0c68b71036961c
data/README.md CHANGED
@@ -60,6 +60,18 @@ end
60
60
  / </div>
61
61
  ```
62
62
 
63
+ Multiple modifiers:
64
+
65
+ ```slim
66
+ = b 'block', 'full hot'
67
+ = e 'element', 'active fix'
68
+
69
+ / == Returns:
70
+ / <span class="block block_full block_hot">
71
+ / <a class="block__element block__element_active block__element_fix"></a>
72
+ / </span>
73
+ ```
74
+
63
75
  Set block/element type(`Symbol`):
64
76
 
65
77
  ```slim
@@ -108,6 +120,18 @@ Inherit block modifier to element `&modifier`:
108
120
  / </div>
109
121
  ```
110
122
 
123
+ Inherit specific block modifier to element `&modifier:block_mod`:
124
+
125
+ ```slim
126
+ = b 'block', 'full hot'
127
+ = e 'element', '&active:hot'
128
+
129
+ / == Returns:
130
+ / <div class="block block_full block_hot">
131
+ / <div class="block__element block__element_active block_hot__element_active"></div>
132
+ / </div>
133
+ ```
134
+
111
135
  ## Contributing
112
136
 
113
137
  1. Fork it ( https://github.com/vadimskrotsky/rbem/fork )
@@ -11,12 +11,12 @@ module Rbem
11
11
  _args = parse_args(args)
12
12
 
13
13
  @block_name = _args[:name]
14
- @block_mod = _args[:mod]
14
+ @block_mods = _args[:mods]
15
15
 
16
16
  block_type = _args[:type]
17
17
  block_opts = _args[:options]
18
18
 
19
- block_opts[:class] = collect_bem_class(@block_name, @block_mod, block_opts, type: :block)
19
+ block_opts[:class] = collect_bem_class(@block_name, @block_mods, block_opts, type: :block)
20
20
 
21
21
  content_tag(block_type, block_given? ? capture(&block) : nil, block_opts)
22
22
  end
@@ -25,17 +25,17 @@ module Rbem
25
25
  _args = parse_args(args)
26
26
 
27
27
  el_name = _args[:name]
28
- el_mod = _args[:mod]
28
+ el_mods = _args[:mods]
29
29
 
30
30
  el_type = _args[:type]
31
31
  el_opts = _args[:options]
32
32
 
33
33
  el_opts[:class] = collect_bem_class(el_name,
34
- el_mod,
34
+ el_mods,
35
35
  el_opts,
36
- type: :element,
37
- inherit_name: _args[:i_name],
38
- inherit_mod: _args[:i_mod] )
36
+ type: :element,
37
+ inherit_names: _args[:i_names],
38
+ inherit_mods: _args[:i_mods] )
39
39
 
40
40
  content_tag(el_type, block_given? ? capture(&block) : nil, el_opts)
41
41
  end
@@ -47,20 +47,30 @@ module Rbem
47
47
  _type = args.select{ |e| e.is_a?(Symbol) }
48
48
  _options = args.select{ |e| e.is_a?(Hash) }
49
49
  _return = {}
50
+
50
51
  if _name_mod[0].present?
51
- _return[:name] = _name_mod[0].sub('&','')
52
- _return[:i_name] = _name_mod[0].start_with?('&')
52
+ _return[:name] = _name_mod[0].sub('&','').split(':')[0]
53
+ if _name_mod[0].start_with?('&')
54
+ _names = _name_mod[0].split(':')
55
+ _names.shift
56
+ if _names.empty?
57
+ _names = @block_mods
58
+ end
59
+ _return[:i_names] = _names
60
+ end
53
61
  end
62
+
54
63
  if _name_mod[1].present?
55
- _return[:mod] = _name_mod[1].sub('&','')
56
- _return[:i_mod] = _name_mod[1].start_with?('&')
64
+ _return[:mods] = _name_mod[1].split.map { |e| e.sub('&','') }
65
+ _return[:i_mods] = _name_mod[1].split.select { |e| e.start_with?('&') }
57
66
  end
67
+
58
68
  _return[:type] = _type[0] || :div
59
69
  _return[:options] = _options[0] || {}
60
70
  _return
61
71
  end
62
72
 
63
- def collect_bem_class(name, mod, options, type: nil, inherit_name: nil, inherit_mod: nil)
73
+ def collect_bem_class(name, mods, options, type: nil, inherit_names: nil, inherit_mods: nil)
64
74
  _separ = @@notation
65
75
  _separ = '_' unless _separ.is_a?(String)
66
76
 
@@ -68,21 +78,46 @@ module Rbem
68
78
 
69
79
  if type === :block
70
80
  _class << "#{name}"
71
- if mod.present?
72
- _class << "#{name}#{_separ}#{mod}"
81
+ if mods
82
+ for mod in mods
83
+ _class << "#{name}#{_separ}#{mod}"
84
+ end
73
85
  end
74
86
  end
75
87
 
76
88
  if type === :element
89
+
90
+ # block__element
77
91
  _class << "#{@block_name}__#{name}"
78
- if mod.present?
79
- _class << "#{@block_name}__#{name}#{_separ}#{mod}"
92
+
93
+ # block__element_mod
94
+ if mods
95
+ for mod in mods
96
+ mod = mod.split(':')[0].sub('&','')
97
+ _class << "#{@block_name}__#{name}#{_separ}#{mod}"
98
+ end
80
99
  end
81
- if inherit_name and @block_mod.present?
82
- _class << "#{@block_name}#{_separ}#{@block_mod}__#{name}"
100
+
101
+ # block_mod__element
102
+ if inherit_names and @block_mods.present?
103
+ for inherit_name in inherit_names
104
+ _class << "#{@block_name}#{_separ}#{inherit_name}__#{name}"
105
+ end
83
106
  end
84
- if inherit_mod and @block_mod.present? and mod.present?
85
- _class << "#{@block_name}#{_separ}#{@block_mod}__#{name}#{_separ}#{mod}"
107
+
108
+ # block_mod__element_mod
109
+ if inherit_mods and mods and @block_mods.present?
110
+ for i_mod in inherit_mods
111
+ el_mod = i_mod.split(':')[0].sub('&','')
112
+ block_mods = i_mod.split(':')
113
+ block_mods.shift
114
+ if block_mods.empty?
115
+ block_mods = @block_mods
116
+ end
117
+ for block_mod in block_mods
118
+ _class << "#{@block_name}#{_separ}#{block_mod}__#{name}#{_separ}#{el_mod}"
119
+ end
120
+ end
86
121
  end
87
122
  end
88
123
 
@@ -1,3 +1,3 @@
1
1
  module Rbem
2
- VERSION = '0.1.5'
2
+ VERSION = '0.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbem
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: '0.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vadim Skrotsky
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-04 00:00:00.000000000 Z
11
+ date: 2014-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler