bem-on-rails 0.0.2 → 0.0.3
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +19 -10
- data/app/helpers/bemonrails/bem_render_helper.rb +96 -91
- data/app/views/bemonrails/essences/_content.html.haml +16 -14
- data/lib/bem-on-rails.rb +2 -1
- data/lib/bem-on-rails/build/bem_names.rb +104 -90
- data/lib/bem-on-rails/build/console_messages.rb +24 -0
- data/lib/bem-on-rails/engine.rb +4 -4
- data/lib/bem-on-rails/generators/install_generator.rb +6 -22
- data/lib/bem-on-rails/generators/templates/config/initializer.tt.rb +42 -42
- data/lib/bem-on-rails/generators/templates/techs/coffee.tt +1 -1
- data/lib/bem-on-rails/generators/templates/techs/haml.tt +2 -2
- data/lib/bem-on-rails/generators/templates/techs/slim.tt +2 -0
- data/lib/bem-on-rails/generators/templates/thor/bem.tt.rb +174 -278
- data/lib/bem-on-rails/railtie.rb +13 -0
- data/lib/bem-on-rails/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6995691b232fdf4379ed487cfd5e617e160a3eb3
|
4
|
+
data.tar.gz: b4c0d05d26cd0985fc2cc99d4e586a5e68a8f2aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b29fdc8916e7cf7ef078084ff5d399a3633842c3df8978285a5d6e1253ec25dad707fcf3cc53823f64e7fdbc65a1595a2855cd9f7ce5c4960f4291d3e63a6129
|
7
|
+
data.tar.gz: ee7691bd4bcbc1709c361896e74d6355e32ad9e1d540819c9d78ce73c6c65c28fc91776731a0a56ca982c213c05dcd88afe337e9c2636511bbf0cd03593ac3f3
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
[](https://github.com/verybigman/bem-on-rails)
|
2
2
|
|
3
|
-
# BEM on Rails
|
3
|
+
# BEM on Rails [](https://codeclimate.com/github/verybigman/bem-on-rails)
|
4
4
|
|
5
5
|
Work with BEM methodology in Rails applications. BEM on Rails is ruby copy from bem-tools.
|
6
6
|
You can read about bem-tools [here](http://bem.info/tools/bem/) and BEM methodology [here](http://bem.info/method/).
|
@@ -23,8 +23,7 @@ Then you should run install generator:
|
|
23
23
|
|
24
24
|
$ rails g bemonrails:install
|
25
25
|
|
26
|
-
This generator
|
27
|
-
You should run to watch your new instruments:
|
26
|
+
This generator creates Thor task with templates. You should run to watch your new instruments:
|
28
27
|
|
29
28
|
$ thor -T
|
30
29
|
|
@@ -125,6 +124,11 @@ Block with custom class for tag:
|
|
125
124
|
= b "test", cls: "custom", content: []
|
126
125
|
```
|
127
126
|
|
127
|
+
Block with custom tag for block( 'div' is default ):
|
128
|
+
```ruby
|
129
|
+
= b "test", tag: "article", content: []
|
130
|
+
```
|
131
|
+
|
128
132
|
Syntax is look like [bemhtml](http://ru.bem.info/articles/bemhtml-reference/).
|
129
133
|
|
130
134
|
### Templates
|
@@ -132,7 +136,12 @@ Syntax is look like [bemhtml](http://ru.bem.info/articles/bemhtml-reference/).
|
|
132
136
|
Now templates exists for haml, sass, coffee and md technologies, but you will create your templates in
|
133
137
|
lib/tasks/templates. For example, you can watch haml template:
|
134
138
|
```haml
|
135
|
-
|
139
|
+
- haml_tag bemtag, bemattrs
|
140
|
+
= bemcontent
|
141
|
+
```
|
142
|
+
Or Slim template:
|
143
|
+
```slim
|
144
|
+
* bemtag, bemattrs
|
136
145
|
= bemcontent
|
137
146
|
```
|
138
147
|
Bemclass and bemcontent is BEM helpers for rendering.
|
@@ -144,15 +153,15 @@ Read [here](http://habrahabr.ru/post/181880/) about it.
|
|
144
153
|
|
145
154
|
If you want it, please watch [here](https://github.com/Vasfed/csso-rails).
|
146
155
|
|
156
|
+
*__Stay BEMed!__*
|
157
|
+
|
147
158
|
## Tomorrow
|
148
159
|
|
149
160
|
0. Incapsulate helpers methods and isolate them from project helpers.
|
150
|
-
1.
|
151
|
-
2.
|
152
|
-
3.
|
153
|
-
4.
|
154
|
-
5. Mods with restructure. Now you can't use mods with templates(haml, slim and etc.), but they generates.
|
155
|
-
6. Bem exutable. Work with Thor is not convenient.
|
161
|
+
1. Flags bem and js.
|
162
|
+
2. Mix blocks and elements.
|
163
|
+
3. Mods with restructure. Now you can't use mods with templates(haml, slim and etc.), but they generates.
|
164
|
+
4. Bem exutable. Work with Thor is not convenient.
|
156
165
|
|
157
166
|
## Contributing
|
158
167
|
|
@@ -1,102 +1,107 @@
|
|
1
1
|
module Bemonrails
|
2
|
-
|
3
|
-
|
4
|
-
include Bemonrails::BemNames
|
2
|
+
module BemRenderHelper
|
3
|
+
include Bemonrails::BemNames
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
path = File.join BEM[:blocks][:dir], build_path_for(:block, builder)
|
10
|
-
target = File.join path, block(name), block(name)
|
11
|
-
# Block details
|
12
|
-
@block_name = name
|
13
|
-
@block_mods = builder[:mods]
|
14
|
-
@custom_attrs = builder[:attrs]
|
15
|
-
@custom_class = builder[:cls]
|
16
|
-
@content = builder[:content]
|
17
|
-
# Render block in view
|
18
|
-
template_exists?(target) ? render(file: target) : bemempty
|
19
|
-
end
|
20
|
-
end
|
21
|
-
alias :b :render_block
|
5
|
+
def bemtag
|
6
|
+
@custom_tag ||= "div"
|
7
|
+
end
|
22
8
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
9
|
+
def render_block(name, builder={})
|
10
|
+
unless name.blank?
|
11
|
+
# Generate block paths
|
12
|
+
path = File.join BEM[:blocks][:dir], build_path_for(:block, builder)
|
13
|
+
target = File.join path, block(name), block(name)
|
14
|
+
# Block details
|
15
|
+
@block_name = name
|
16
|
+
@block_mods = builder[:mods]
|
17
|
+
@custom_attrs = builder[:attrs]
|
18
|
+
@custom_class = builder[:cls]
|
19
|
+
@custom_tag = builder[:tag]
|
20
|
+
@content = builder[:content]
|
21
|
+
# Render block in view
|
22
|
+
template_exists?(target) ? render(file: target) : bemempty
|
23
|
+
end
|
24
|
+
end
|
25
|
+
alias :b :render_block
|
40
26
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
classes_array = [ block(@block_name) + element(@element_name) ]
|
60
|
-
# Install mods
|
61
|
-
if @element_mods
|
62
|
-
@element_mods.each do |mod_name, mod_value|
|
63
|
-
# Generate mods classes
|
64
|
-
if mod_value
|
65
|
-
classes_array.push block(@block_name) + element(@element_name) + mod(mod_name.to_s) + mod(mod_name.to_s, mod_value)
|
66
|
-
else
|
67
|
-
classes_array.push block(@block_name) + element(@element_name) + mod(mod_name.to_s)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
27
|
+
def render_element(name, builder={})
|
28
|
+
unless name.blank?
|
29
|
+
# Generate element paths
|
30
|
+
path = File.join build_path_for(:element, builder)
|
31
|
+
target = File.join path, element(name), element(name)
|
32
|
+
# Element details
|
33
|
+
@element_name = name
|
34
|
+
@element_mods = builder[:elemMods]
|
35
|
+
@custom_attrs = builder[:attrs]
|
36
|
+
@custom_class = builder[:cls]
|
37
|
+
@custom_tag = builder[:tag]
|
38
|
+
puts @element_mods
|
39
|
+
@content = builder[:content]
|
40
|
+
# Render element in block
|
41
|
+
template_exists?(target) ? render(file: target) : bemempty
|
42
|
+
end
|
43
|
+
end
|
44
|
+
alias :e :render_element
|
72
45
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
46
|
+
def render_bemattributes
|
47
|
+
if @block_name && !@element_name
|
48
|
+
classes_array = [ block(@block_name) ]
|
49
|
+
# Install mods
|
50
|
+
if @block_mods
|
51
|
+
@block_mods.each do |mod|
|
52
|
+
# Generate mods classes
|
53
|
+
if mod.kind_of? Hash
|
54
|
+
mod.each do |mod_name, mod_value|
|
55
|
+
classes_array.push block(@block_name) + mod(mod_name.to_s) + mod(mod_name.to_s, mod_value)
|
56
|
+
end
|
57
|
+
else
|
58
|
+
classes_array.push block(@block_name) + mod(mod.to_s)
|
59
|
+
end
|
60
|
+
# TODO: Find mod with restructure .haml, .erb or etc.
|
61
|
+
end
|
62
|
+
end
|
63
|
+
elsif @element_name
|
64
|
+
classes_array = [ block(@block_name) + element(@element_name) ]
|
65
|
+
# Install mods
|
66
|
+
if @element_mods
|
67
|
+
@element_mods.each do |mod_name, mod_value|
|
68
|
+
# Generate mods classes
|
69
|
+
if mod_value
|
70
|
+
classes_array.push block(@block_name) + element(@element_name) + mod(mod_name.to_s) + mod(mod_name.to_s, mod_value)
|
71
|
+
else
|
72
|
+
classes_array.push block(@block_name) + element(@element_name) + mod(mod_name.to_s)
|
78
73
|
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
79
77
|
|
80
|
-
|
81
|
-
bemattributes = { class: bemclass }
|
78
|
+
bemclass = classes_array.join(" ")
|
82
79
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
80
|
+
# If custom class exist
|
81
|
+
if @custom_class
|
82
|
+
bemclass = [bemclass, @custom_class].join(" ")
|
83
|
+
end
|
84
|
+
|
85
|
+
# String for tag attributes
|
86
|
+
bemattributes = { class: bemclass }
|
87
|
+
|
88
|
+
# If custom attributes exist
|
89
|
+
if @custom_attrs
|
90
|
+
bemattributes.merge! @custom_attrs
|
91
|
+
end
|
87
92
|
|
88
|
-
|
89
|
-
|
90
|
-
|
93
|
+
bemattributes
|
94
|
+
end
|
95
|
+
alias :bemattrs :render_bemattributes
|
91
96
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
97
|
+
def render_empty
|
98
|
+
"<div class=#{ bemclass }></div>".html_safe
|
99
|
+
end
|
100
|
+
alias :bemempty :render_empty
|
96
101
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
end
|
102
|
+
def render_content
|
103
|
+
render "bemonrails/essences/content"
|
104
|
+
end
|
105
|
+
alias :bemcontent :render_content
|
106
|
+
end
|
107
|
+
end
|
@@ -1,18 +1,20 @@
|
|
1
1
|
- if @content.kind_of?(Array)
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
2
|
+
- @content.each do |essence|
|
3
|
+
- if essence.kind_of?(Hash) && essence[:elem]
|
4
|
+
= e essence[:elem], { content: essence[:content],
|
5
|
+
mods: essence[:elemMods],
|
6
|
+
attrs: essence[:attrs],
|
7
|
+
cls: essence[:cls],
|
8
|
+
tag: essence[:tag] }
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
- elsif essence.kind_of?(Hash) && essence[:block]
|
11
|
+
= b essence[:block], { content: essence[:content],
|
12
|
+
mods: essence[:mods],
|
13
|
+
attrs: essence[:attrs],
|
14
|
+
cls: essence[:cls],
|
15
|
+
tag: essence[:tag] }
|
14
16
|
|
15
|
-
|
16
|
-
|
17
|
+
- else
|
18
|
+
= essence
|
17
19
|
- else
|
18
|
-
|
20
|
+
= @content
|
data/lib/bem-on-rails.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
require "bem-on-rails/version"
|
2
2
|
require "bem-on-rails/engine"
|
3
3
|
require "bem-on-rails/build/bem_names"
|
4
|
+
require "bem-on-rails/build/console_messages"
|
4
5
|
require "bem-on-rails/generators/install_generator"
|
6
|
+
require 'bem-on-rails/railtie' if defined?(Rails)
|
5
7
|
|
6
8
|
module Bemonrails
|
7
|
-
|
8
9
|
end
|
@@ -1,110 +1,124 @@
|
|
1
1
|
module Bemonrails
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
end
|
22
|
-
when :element
|
23
|
-
path.push(element_directory)
|
24
|
-
when :block
|
25
|
-
# Yea! Do nothing!
|
26
|
-
else
|
27
|
-
raise print_message("Unknown params. Try 'thor help bem:create'", 'red')
|
28
|
-
end
|
29
|
-
File.join(path.compact)
|
2
|
+
module BemNames
|
3
|
+
# Directories paths.
|
4
|
+
def build_path_for(essence, builder=options)
|
5
|
+
# I think all block can be in groups
|
6
|
+
path = [builder[:group]]
|
7
|
+
case essence
|
8
|
+
when :mod
|
9
|
+
# This is for mods with value
|
10
|
+
if builder[:block] && builder[:element] && builder[:value]
|
11
|
+
path.push(mod_directory(:element), mod)
|
12
|
+
elsif builder[:block] && builder[:value]
|
13
|
+
path.push(mod_directory(:block), mod)
|
14
|
+
# This is for mods without value
|
15
|
+
elsif builder[:block] && builder[:element]
|
16
|
+
path.push(mod_directory(:element))
|
17
|
+
elsif builder[:block]
|
18
|
+
path.push(mod_directory(:block))
|
19
|
+
else
|
20
|
+
raise print_message("Mods must be for block or element.", 'red')
|
30
21
|
end
|
22
|
+
when :element
|
23
|
+
path.push(element_directory)
|
24
|
+
when :block
|
25
|
+
# Yea! Do nothing!
|
26
|
+
else
|
27
|
+
raise print_message("Unknown params. Try 'thor help bem:create'", 'red')
|
28
|
+
end
|
29
|
+
File.join(path.compact)
|
30
|
+
end
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
if builder[:block]
|
32
|
+
def path_to_block(path)
|
33
|
+
BEM[:blocks][:path] + path
|
34
|
+
end
|
36
35
|
|
37
|
-
|
36
|
+
def generate_names(builder=options)
|
37
|
+
names = {}
|
38
|
+
# Generate names for block, his mods and they values
|
39
|
+
if builder[:block]
|
38
40
|
|
39
|
-
|
40
|
-
names[:name] = mod
|
41
|
-
names[:klass] = block + names[:name]
|
42
|
-
end
|
41
|
+
names[:klass] = names[:name] = block
|
43
42
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
end
|
49
|
-
|
50
|
-
# Generate names for elements, his mods and they values
|
51
|
-
if builder[:element]
|
43
|
+
if builder[:mod]
|
44
|
+
names[:name] = mod
|
45
|
+
names[:klass] = block + names[:name]
|
46
|
+
end
|
52
47
|
|
53
|
-
|
54
|
-
|
48
|
+
if builder[:value]
|
49
|
+
names[:name] = mod(builder[:value])
|
50
|
+
names[:klass] = block + mod + names[:name]
|
51
|
+
end
|
52
|
+
end
|
55
53
|
|
56
|
-
|
57
|
-
|
58
|
-
names[:klass] = block + element + names[:name]
|
59
|
-
end
|
54
|
+
# Generate names for elements, his mods and they values
|
55
|
+
if builder[:element]
|
60
56
|
|
61
|
-
|
62
|
-
|
63
|
-
names[:klass] = block + element + mod + names[:name]
|
64
|
-
end
|
65
|
-
end
|
57
|
+
names[:name] = element
|
58
|
+
names[:klass] += names[:name]
|
66
59
|
|
67
|
-
|
60
|
+
if builder[:mod]
|
61
|
+
names[:name] = mod
|
62
|
+
names[:klass] = block + element + names[:name]
|
68
63
|
end
|
69
64
|
|
70
|
-
|
71
|
-
|
65
|
+
if builder[:value]
|
66
|
+
names[:name] = mod(builder[:value])
|
67
|
+
names[:klass] = block + element + mod + names[:name]
|
72
68
|
end
|
69
|
+
end
|
73
70
|
|
74
|
-
|
75
|
-
|
76
|
-
File.join(block(block_name), BEM[:elements][:dir])
|
77
|
-
end
|
71
|
+
names
|
72
|
+
end
|
78
73
|
|
79
|
-
|
80
|
-
|
81
|
-
|
74
|
+
def essence
|
75
|
+
if options[:block] && !options[:element] && !options[:mod]
|
76
|
+
:block
|
77
|
+
elsif options[:element] && !options[:mod]
|
78
|
+
:element
|
79
|
+
elsif options[:mod]
|
80
|
+
:mod
|
81
|
+
end
|
82
|
+
end
|
82
83
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
File.join(block, BEM[:mods][:dir])
|
87
|
-
when :element
|
88
|
-
File.join(element_directory, element, BEM[:mods][:dir])
|
89
|
-
else
|
90
|
-
File.join(block, BEM[:mods][:dir])
|
91
|
-
end
|
92
|
-
end
|
84
|
+
def block(name=options[:block])
|
85
|
+
BEM[:blocks][:prefix] + name
|
86
|
+
end
|
93
87
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
88
|
+
def element_directory
|
89
|
+
block_name = @block_name ? @block_name : options[:block]
|
90
|
+
File.join(block(block_name), BEM[:elements][:dir])
|
91
|
+
end
|
92
|
+
|
93
|
+
def element(name=options[:element])
|
94
|
+
BEM[:elements][:prefix] + name
|
95
|
+
end
|
96
|
+
|
97
|
+
def mod_directory(essence)
|
98
|
+
case essence
|
99
|
+
when :block
|
100
|
+
File.join(block, BEM[:mods][:dir])
|
101
|
+
when :element
|
102
|
+
File.join(element_directory, element, BEM[:mods][:dir])
|
103
|
+
else
|
104
|
+
File.join(block, BEM[:mods][:dir])
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def mod(name= options[:mod], value=false)
|
109
|
+
if value
|
110
|
+
BEM[:mods][:prefix] + value
|
111
|
+
else
|
112
|
+
BEM[:mods][:prefix] + name
|
113
|
+
end
|
114
|
+
end
|
101
115
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
end
|
107
|
-
end
|
116
|
+
def template_exists?(file)
|
117
|
+
BEM[:techs].each do |tech, extension|
|
118
|
+
if File.exists? file + extension
|
119
|
+
return true
|
108
120
|
end
|
109
|
-
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
110
124
|
end
|