bem-on-rails 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fff2737501c065e32082282035389196d6c04ff6
4
- data.tar.gz: 21b73fe7f203438ec35752ac6b39e47b51c25b6b
3
+ metadata.gz: db5b4a9a59a618f6262eccc08032c9d2ef7d9778
4
+ data.tar.gz: 3f1f5738a05779c041f1debcad85651616af34f5
5
5
  SHA512:
6
- metadata.gz: 6bb146bef1547d553da012d8ae3c1376902e503bd034d4ae6e8071745b0b5ac2fa65125d2ef18fcd0af310e1e195959b58522e9e67ede62e095e58f6baa4b8d3
7
- data.tar.gz: b5fcfb9413c4cff5d583f25cccfa7f48e490d55c2f8c99fc7f9cafe1a10b3fc9b6e4ce4572e3791bde0ae3d906e58f6bab4a23bd2331a3bf8aeaca89b9a40991
6
+ metadata.gz: f5bc8f7d40d5c28a7e7dc8f83a313526e1ee15705e91bdff65458972bdc164253aaa578451b784789caa03a8c034a3597e7b61da2242c7958c36e78b0f7b9d26
7
+ data.tar.gz: 1e4e04663d0d743042146ff533d1b7890cb6d82d3cf14e74a749b6762e123c0c462c583628dbff95c5660f2bbf2bf9eda05d771a77c93d667fe345b2a6faa641
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ .idea
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
1
  ## v0.0.1
2
2
 
3
- * first release with small functionality
3
+ * first release with small functionality
4
+
5
+ ## v0.0.2
6
+
7
+ * rendering blocks in block
8
+ * fix trubles with mods without value
9
+ * add custom attributes for tags
10
+ * add custom classes for tags
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
- # BEM On Rails
1
+ [![Bem on Rails](http://habrastorage.org/storage3/551/97d/0c5/55197d0c503e312952195b2ae0e4c337.png)](https://github.com/verybigman/bem-on-rails)
2
2
 
3
- Work with BEM methodology in Rails applications. BEM On Rails is ruby copy from bem-tools.
3
+ # BEM on Rails
4
+
5
+ Work with BEM methodology in Rails applications. BEM on Rails is ruby copy from bem-tools.
4
6
  You can read about bem-tools [here](http://bem.info/tools/bem/) and BEM methodology [here](http://bem.info/method/).
5
7
 
6
8
  ## Installation
@@ -26,11 +28,13 @@ You should run to watch your new instruments:
26
28
 
27
29
  $ thor -T
28
30
 
29
- Also generator creates initializer bem.rb with BEM constant. You can customize everythink!
31
+ Also generator creates initializer bem.rb with BEM constant. You should restart server after install.
32
+ You can customize everythink!
30
33
 
31
34
  ## Usage
32
35
 
33
- You can create blocks, elements, modificators and groups for blocks. It's awesome! Also you can remove them and watch lists of blocks, block elements, blocks mods and etc. Try thor help for more info.
36
+ You can create blocks, elements, modificators and groups for blocks. It's awesome! Also you can remove them and watch
37
+ lists of blocks, block elements, blocks mods and etc. Try thor help for more info.
34
38
 
35
39
  Default blocks folder structure:
36
40
  - **blocks**
@@ -98,12 +102,27 @@ Use them like configs, for require only. This involves using Sprockets.
98
102
 
99
103
  In your view you should write this:
100
104
  ```ruby
101
- = b "test", mods: {color: "red"}, content: [{ elem: "icon", elemMods: {size: "small"} }]
105
+ = b "test", mods: [{color: "red"}], content: [{ elem: "icon", elemMods: [{size: "small"}] }]
102
106
  ```
103
107
 
104
108
  If block in group:
105
109
  ```ruby
106
- = b "test", group: "name", mods: {color: "red"}, content: []
110
+ = b "test", group: "name", mods: [{color: "red"}], content: []
111
+ ```
112
+
113
+ Block with mods without value:
114
+ ```ruby
115
+ = b "test", mods: [:super, {color: "red"}], content: []
116
+ ```
117
+
118
+ Block with custom attributes for tag:
119
+ ```ruby
120
+ = b "test", attrs: {src: "/img.png"}, content: []
121
+ ```
122
+
123
+ Block with custom class for tag:
124
+ ```ruby
125
+ = b "test", cls: "custom", content: []
107
126
  ```
108
127
 
109
128
  Syntax is look like [bemhtml](http://ru.bem.info/articles/bemhtml-reference/).
@@ -113,7 +132,7 @@ Syntax is look like [bemhtml](http://ru.bem.info/articles/bemhtml-reference/).
113
132
  Now templates exists for haml, sass, coffee and md technologies, but you will create your templates in
114
133
  lib/tasks/templates. For example, you can watch haml template:
115
134
  ```haml
116
- %div{ bemclass }
135
+ %div{ bemattrs }
117
136
  = bemcontent
118
137
  ```
119
138
  Bemclass and bemcontent is BEM helpers for rendering.
@@ -127,14 +146,13 @@ If you want it, please watch [here](https://github.com/Vasfed/csso-rails).
127
146
 
128
147
  ## Tomorrow
129
148
 
130
- 1. Rendering blocks in block.
131
- 2. Custom tag for block or element.
132
- 3. Add attrs for blocks and elements.
133
- 4. Add custom classes for blocks and elements.
134
- 5. Flags bem and js.
135
- 6. Mix blocks and elements.
136
- 7. Mods with restructure. Now you can't use mods with templates(haml, slim and etc.), but they generates.
137
- 8. Bem exutable. Work with Thor is not convenient.
149
+ 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.
138
156
 
139
157
  ## Contributing
140
158
 
@@ -11,6 +11,8 @@ module Bemonrails
11
11
  # Block details
12
12
  @block_name = name
13
13
  @block_mods = builder[:mods]
14
+ @custom_attrs = builder[:attrs]
15
+ @custom_class = builder[:cls]
14
16
  @content = builder[:content]
15
17
  # Render block in view
16
18
  template_exists?(target) ? render(file: target) : bemempty
@@ -26,6 +28,8 @@ module Bemonrails
26
28
  # Element details
27
29
  @element_name = name
28
30
  @element_mods = builder[:elemMods]
31
+ @custom_attrs = builder[:attrs]
32
+ @custom_class = builder[:cls]
29
33
  puts @element_mods
30
34
  @content = builder[:content]
31
35
  # Render element in block
@@ -34,19 +38,20 @@ module Bemonrails
34
38
  end
35
39
  alias :e :render_element
36
40
 
37
- def render_class
41
+ def render_bemattributes
38
42
  if @block_name && !@element_name
39
43
  classes_array = [ block(@block_name) ]
40
44
  # Install mods
41
45
  if @block_mods
42
- @block_mods.each do |mod_name, mod_value|
46
+ @block_mods.each do |mod|
43
47
  # Generate mods classes
44
- if mod_value
45
- classes_array.push block(@block_name) + mod(mod_name.to_s) + mod(mod_name.to_s, mod_value)
46
- else
47
- classes_array.push block(@block_name) + mod(mod_name.to_s)
48
- end
49
-
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
50
55
  # TODO: Find mod with restructure .haml, .erb or etc.
51
56
  end
52
57
  end
@@ -65,9 +70,24 @@ module Bemonrails
65
70
  end
66
71
  end
67
72
 
68
- { class: classes_array.join(" ") }
73
+ bemclass = classes_array.join(" ")
74
+
75
+ # If custom class exist
76
+ if @custom_class
77
+ bemclass = [bemclass, @custom_class].join(" ")
78
+ end
79
+
80
+ # String for tag attributes
81
+ bemattributes = { class: bemclass }
82
+
83
+ # If custom attributes exist
84
+ if @custom_attrs
85
+ bemattributes.merge! @custom_attrs
86
+ end
87
+
88
+ bemattributes
69
89
  end
70
- alias :bemclass :render_class
90
+ alias :bemattrs :render_bemattributes
71
91
 
72
92
  def render_empty
73
93
  "<div class=#{ bemclass }></div>".html_safe
@@ -1,7 +1,17 @@
1
1
  - if @content.kind_of?(Array)
2
2
  - @content.each do |essence|
3
3
  - if essence.kind_of?(Hash) && essence[:elem]
4
- = e essence[:elem], { content: essence[:content], mods: essence[:elemMods] }
4
+ = e essence[:elem], { content: essence[:content],
5
+ mods: essence[:elemMods],
6
+ attrs: essence[:attrs],
7
+ cls: essence[:cls] }
8
+
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] }
14
+
5
15
  - else
6
16
  = essence
7
17
  - else
@@ -22,16 +22,16 @@ module Bemonrails
22
22
  end
23
23
 
24
24
  def add_initializer
25
- template "initializer.tt", File.join(Rails.root, "config", "initializers", "bem.rb")
25
+ template "config/initializer.tt.rb", File.join(Rails.root, "config", "initializers", "bem.rb")
26
26
  end
27
27
 
28
28
  def install_bem_tasks
29
- template "bem.tt", File.join(Rails.root, "lib", "tasks", "bem.thor")
29
+ template "thor/bem.tt.rb", File.join(Rails.root, "lib", "tasks", "bem.thor")
30
30
  end
31
31
 
32
32
  def add_blocks_templates
33
33
  %w(haml.tt coffee.tt md.tt sass.tt).each do |t|
34
- template t, File.join(Rails.root, "lib", "tasks", "templates", t)
34
+ template "techs/#{t}", File.join(Rails.root, "lib", "tasks", "templates", t)
35
35
  end
36
36
  end
37
37
 
@@ -0,0 +1,2 @@
1
+ %div{ bemattrs }
2
+ = bemcontent
@@ -1,3 +1,3 @@
1
1
  module Bemonrails
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bem-on-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton Winogradov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-08 00:00:00.000000000 Z
11
+ date: 2013-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -86,12 +86,12 @@ files:
86
86
  - lib/bem-on-rails/build/bem_names.rb
87
87
  - lib/bem-on-rails/engine.rb
88
88
  - lib/bem-on-rails/generators/install_generator.rb
89
- - lib/bem-on-rails/generators/templates/bem.tt
90
- - lib/bem-on-rails/generators/templates/coffee.tt
91
- - lib/bem-on-rails/generators/templates/haml.tt
92
- - lib/bem-on-rails/generators/templates/initializer.tt
93
- - lib/bem-on-rails/generators/templates/md.tt
94
- - lib/bem-on-rails/generators/templates/sass.tt
89
+ - lib/bem-on-rails/generators/templates/config/initializer.tt.rb
90
+ - lib/bem-on-rails/generators/templates/techs/coffee.tt
91
+ - lib/bem-on-rails/generators/templates/techs/haml.tt
92
+ - lib/bem-on-rails/generators/templates/techs/md.tt
93
+ - lib/bem-on-rails/generators/templates/techs/sass.tt
94
+ - lib/bem-on-rails/generators/templates/thor/bem.tt.rb
95
95
  - lib/bem-on-rails/version.rb
96
96
  homepage: https://github.com/verybigman/bem-on-rails
97
97
  licenses:
@@ -113,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
113
  version: '0'
114
114
  requirements: []
115
115
  rubyforge_project:
116
- rubygems_version: 2.0.7
116
+ rubygems_version: 2.0.3
117
117
  signing_key:
118
118
  specification_version: 4
119
119
  summary: BEM Tools for Rails applications
@@ -1,2 +0,0 @@
1
- %div{ bemclass }
2
- = bemcontent