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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: db5b4a9a59a618f6262eccc08032c9d2ef7d9778
4
- data.tar.gz: 3f1f5738a05779c041f1debcad85651616af34f5
3
+ metadata.gz: 6995691b232fdf4379ed487cfd5e617e160a3eb3
4
+ data.tar.gz: b4c0d05d26cd0985fc2cc99d4e586a5e68a8f2aa
5
5
  SHA512:
6
- metadata.gz: f5bc8f7d40d5c28a7e7dc8f83a313526e1ee15705e91bdff65458972bdc164253aaa578451b784789caa03a8c034a3597e7b61da2242c7958c36e78b0f7b9d26
7
- data.tar.gz: 1e4e04663d0d743042146ff533d1b7890cb6d82d3cf14e74a749b6762e123c0c462c583628dbff95c5660f2bbf2bf9eda05d771a77c93d667fe345b2a6faa641
6
+ metadata.gz: b29fdc8916e7cf7ef078084ff5d399a3633842c3df8978285a5d6e1253ec25dad707fcf3cc53823f64e7fdbc65a1595a2855cd9f7ce5c4960f4291d3e63a6129
7
+ data.tar.gz: ee7691bd4bcbc1709c361896e74d6355e32ad9e1d540819c9d78ce73c6c65c28fc91776731a0a56ca982c213c05dcd88afe337e9c2636511bbf0cd03593ac3f3
data/CHANGELOG.md CHANGED
@@ -8,3 +8,9 @@
8
8
  * fix trubles with mods without value
9
9
  * add custom attributes for tags
10
10
  * add custom classes for tags
11
+
12
+ ## v0.0.3
13
+
14
+ * extract helpers includes to railtie
15
+ * extract views folder includes to railtie
16
+ * update install generator
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  [![Bem on Rails](http://habrastorage.org/storage3/551/97d/0c5/55197d0c503e312952195b2ae0e4c337.png)](https://github.com/verybigman/bem-on-rails)
2
2
 
3
- # BEM on Rails
3
+ # BEM on Rails [![Code Climate](https://codeclimate.com/github/verybigman/bem-on-rails.png)](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 adds lines to application_controller.rb, application_helper.rb and creates Thor task with templates.
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
- %div{ bemattrs }
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. Custom tag for block or element.
151
- 2. Add custom classes for blocks and elements.
152
- 3. Flags bem and js.
153
- 4. Mix blocks and elements.
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
- module BemRenderHelper
3
-
4
- include Bemonrails::BemNames
2
+ module BemRenderHelper
3
+ include Bemonrails::BemNames
5
4
 
6
- def render_block(name, builder={})
7
- unless name.blank?
8
- # Generate block paths
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
- def render_element(name, builder={})
24
- unless name.blank?
25
- # Generate element paths
26
- path = File.join build_path_for(:element, builder)
27
- target = File.join path, element(name), element(name)
28
- # Element details
29
- @element_name = name
30
- @element_mods = builder[:elemMods]
31
- @custom_attrs = builder[:attrs]
32
- @custom_class = builder[:cls]
33
- puts @element_mods
34
- @content = builder[:content]
35
- # Render element in block
36
- template_exists?(target) ? render(file: target) : bemempty
37
- end
38
- end
39
- alias :e :render_element
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
- def render_bemattributes
42
- if @block_name && !@element_name
43
- classes_array = [ block(@block_name) ]
44
- # Install mods
45
- if @block_mods
46
- @block_mods.each do |mod|
47
- # Generate mods classes
48
- if mod.kind_of? Hash
49
- mod.each do |mod_name, mod_value|
50
- classes_array.push block(@block_name) + mod(mod_name.to_s) + mod(mod_name.to_s, mod_value)
51
- end
52
- else
53
- classes_array.push block(@block_name) + mod(mod.to_s)
54
- end
55
- # TODO: Find mod with restructure .haml, .erb or etc.
56
- end
57
- end
58
- elsif @element_name
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
- bemclass = classes_array.join(" ")
74
-
75
- # If custom class exist
76
- if @custom_class
77
- bemclass = [bemclass, @custom_class].join(" ")
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
- # String for tag attributes
81
- bemattributes = { class: bemclass }
78
+ bemclass = classes_array.join(" ")
82
79
 
83
- # If custom attributes exist
84
- if @custom_attrs
85
- bemattributes.merge! @custom_attrs
86
- end
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
- bemattributes
89
- end
90
- alias :bemattrs :render_bemattributes
93
+ bemattributes
94
+ end
95
+ alias :bemattrs :render_bemattributes
91
96
 
92
- def render_empty
93
- "<div class=#{ bemclass }></div>".html_safe
94
- end
95
- alias :bemempty :render_empty
97
+ def render_empty
98
+ "<div class=#{ bemclass }></div>".html_safe
99
+ end
100
+ alias :bemempty :render_empty
96
101
 
97
- def render_content
98
- render "bemonrails/essences/content"
99
- end
100
- alias :bemcontent :render_content
101
- end
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
- - @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] }
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
- - elsif essence.kind_of?(Hash) && essence[:block]
10
- = b essence[:block], { content: essence[:content],
11
- mods: essence[:mods],
12
- attrs: essence[:attrs],
13
- cls: essence[:cls] }
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
- - else
16
- = essence
17
+ - else
18
+ = essence
17
19
  - else
18
- = @content
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
- 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')
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
- def generate_names(builder=options)
33
- names = {}
34
- # Generate names for block, his mods and they values
35
- if builder[:block]
32
+ def path_to_block(path)
33
+ BEM[:blocks][:path] + path
34
+ end
36
35
 
37
- names[:klass] = names[:name] = block
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
- if builder[:mod]
40
- names[:name] = mod
41
- names[:klass] = block + names[:name]
42
- end
41
+ names[:klass] = names[:name] = block
43
42
 
44
- if builder[:value]
45
- names[:name] = mod(builder[:value])
46
- names[:klass] = block + mod + names[:name]
47
- end
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
- names[:name] = element
54
- names[:klass] += names[:name]
48
+ if builder[:value]
49
+ names[:name] = mod(builder[:value])
50
+ names[:klass] = block + mod + names[:name]
51
+ end
52
+ end
55
53
 
56
- if builder[:mod]
57
- names[:name] = mod
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
- if builder[:value]
62
- names[:name] = mod(builder[:value])
63
- names[:klass] = block + element + mod + names[:name]
64
- end
65
- end
57
+ names[:name] = element
58
+ names[:klass] += names[:name]
66
59
 
67
- names
60
+ if builder[:mod]
61
+ names[:name] = mod
62
+ names[:klass] = block + element + names[:name]
68
63
  end
69
64
 
70
- def block(name=options[:block])
71
- BEM[:blocks][:prefix] + name
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
- def element_directory
75
- block_name = @block_name ? @block_name : options[:block]
76
- File.join(block(block_name), BEM[:elements][:dir])
77
- end
71
+ names
72
+ end
78
73
 
79
- def element(name=options[:element])
80
- BEM[:elements][:prefix] + name
81
- end
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
- def mod_directory(essence)
84
- case essence
85
- when :block
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
- def mod(name= options[:mod], value=false)
95
- if value
96
- BEM[:mods][:prefix] + value
97
- else
98
- BEM[:mods][:prefix] + name
99
- end
100
- end
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
- def template_exists?(file)
103
- BEM[:techs].each do |tech, extension|
104
- if File.exists? file + extension
105
- return true
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
- end
121
+ end
122
+ end
123
+ end
110
124
  end