bem-on-rails 0.0.5 → 1.0.0

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: 528efc9c4ee0620d95e5923c59b8ab349d27cf3f
4
- data.tar.gz: 094484ca8182ccb9d9e519a65a6868a093e804cb
3
+ metadata.gz: 34fc7f94fc556482ce63533af0fad010a4317cbc
4
+ data.tar.gz: 4b63348acd65d33a4644afdf7abf16d884781e6e
5
5
  SHA512:
6
- metadata.gz: aefa6d3c4ce10fa5823245a77db22ca88d48d5a5bf2b91b105ad7c8bb575b569cd235c563e54f1266a71f9be63e0b4f7168d2a32560bb3050ea956efff92b2d9
7
- data.tar.gz: 365656e97e01dd2654133f1fc68efde5a21e8fdf4328309a63605b3ed27277ed7595903b14f9e5fe050905288fe559390e68e329bd17ecf5121ba820a5df783c
6
+ metadata.gz: ba198e429ab748f4abd633fced46c991ba867862ebd66b38c615942298cc912eb996e3852f5e27b389e4a0449f5db7e42daa952ee50bb7085d96bf1bb5fbb3df
7
+ data.tar.gz: 47c0b1de4f323e6b9e3eb35d6b3da4fbf065b2f3b2c54ed254c814aaece8f81c881739ff9b45360fd220141ba7020671ba3b7b4de905c6abf8cea3e7e6a55c89
@@ -1,13 +1,21 @@
1
- ## v0.0.1
1
+ ## v1.0.0
2
2
 
3
- * first release with small functionality
3
+ * remove unneeded thor tasks
4
+ * use canonical BEM naming
5
+ * use compatibility filesystem structure with another BEM libraries
6
+ * use compatibility with BEMSJON renderer methods
7
+ * errors fixes and optimize
4
8
 
5
- ## v0.0.2
9
+ ## v0.0.5
6
10
 
7
- * rendering blocks in block
8
- * fix trubles with mods without value
9
- * add custom attributes for tags
10
- * add custom classes for tags
11
+ * work with levels
12
+ * errors fixes
13
+
14
+ ## v0.0.4
15
+
16
+ * more refactoring
17
+ * add mix functionality
18
+ * walking to clean code
11
19
 
12
20
  ## v0.0.3
13
21
 
@@ -15,13 +23,13 @@
15
23
  * extract views folder includes to railtie
16
24
  * update install generator
17
25
 
18
- ## v0.0.4
26
+ ## v0.0.2
19
27
 
20
- * more refactoring
21
- * add mix functionality
22
- * walking to clean code
28
+ * rendering blocks in block
29
+ * fix trubles with mods without value
30
+ * add custom attributes for tags
31
+ * add custom classes for tags
23
32
 
24
- ## v0.0.5
33
+ ## v0.0.1
25
34
 
26
- * work with levels
27
- * errors fixes
35
+ * first release with small functionality
data/README.md CHANGED
@@ -1,9 +1,8 @@
1
- [![Bem on Rails](http://habrastorage.org/storage3/551/97d/0c5/55197d0c503e312952195b2ae0e4c337.png)](https://github.com/verybigman/bem-on-rails)
1
+ # BEM on Rails
2
2
 
3
- # BEM on Rails [![Code Climate](https://codeclimate.com/github/verybigman/bem-on-rails.png)](https://codeclimate.com/github/verybigman/bem-on-rails)
3
+ This README also available in [russian](https://github.com/verybigman/bem-on-rails/blob/master/README.ru.md).
4
4
 
5
- Work with BEM methodology in Rails applications. BEM on Rails is ruby copy from bem-tools.
6
- You can read about bem-tools [here](http://bem.info/tools/bem/) and BEM methodology [here](http://bem.info/method/).
5
+ Work with BEM methodology in Rails applications. BEM on Rails is ruby fork of bem-tools. You can read about bem-tools [here](http://bem.info/tools/bem/) and BEM methodology [here](http://bem.info/method/). Also i talk about this gem in russian on YaC 2013, you can watch this [here](http://tech.yandex.ru/events/bemup/yac-bemup/talks/1349/).
7
6
 
8
7
  ## Installation
9
8
 
@@ -18,140 +17,91 @@ And then execute:
18
17
  Or install it yourself as:
19
18
 
20
19
  $ gem install bem-on-rails
21
-
20
+
22
21
  Then you should run install generator:
23
22
 
24
23
  $ rails g bemonrails:install
25
24
 
26
- This generator creates Thor task with templates. You should run to watch your new instruments:
27
-
28
- $ thor -T
29
-
30
- If you want use default level, you must be create folders tree for it:
31
-
32
- $ thor bem:levels -a --default
33
-
34
- You should restart server after install.
35
- You can customize everythink in initializers/bem.rb!
25
+ You should restart server after install.
36
26
 
37
27
  ## Usage
38
28
 
39
- 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.
40
-
41
- Default blocks folder structure:
29
+ You can create blocks, elements and them modificators on levels. Default folder structure:
42
30
 
43
31
  - **bem**
44
32
  - **level_name**
45
33
  - **block_name**
46
- - **elements**
47
- - **__element_name**
48
- - __element_name.html.haml
49
- - __element_name.css.sass
50
- - __element_name.coffee
51
- - __element_name.md
52
- - **mods**
53
- - **_mod_name**
54
- - **_mod_value**
55
- - _mod_name.css.sass
56
- - _mod_name.coffee
57
- - _mod_name.md
34
+ - **__element_name**
35
+ - block-name__element_name.html.haml
36
+ - block-name__element_name.css.sass
37
+ - block-name__element_name.coffee
38
+ - block-name__element_name.md
39
+ - **_mod_name**
40
+ - block-name_mod_name.css.sass
41
+ - block-name_mod_name.coffee
42
+ - block-name_mod_name.md
58
43
  - block_name.html.haml
59
44
  - block_name.css.sass
60
45
  - block_name.coffee
61
46
  - block_name.md
62
47
 
63
- You can specify all prefixes for blocks, elements and mods in bem.rb initializer.
64
-
65
- **All blocks now creates on levels.**
66
-
67
- ### Levels
68
-
69
- Create new level:
70
-
71
- $ thor bem:levels -a -n level_name
72
-
73
- Get from git:
74
-
75
- $ thor bem:levels -a -g git@github.com:verybigman/bem-controls.git
76
-
77
- Copy from directory:
78
-
79
- $ thor bem:levels -a -d ~/path/to/level_name
48
+ You can read more about folders structure [here](http://bem.info/method/filesystem/). Also specify all prefixes for blocks, elements and mods in bem.rb initializer.
80
49
 
81
50
  ### Creating
82
51
 
83
52
  Easy block creating look like:
84
53
 
85
- $ thor bem:create -b test
86
-
54
+ $ thor bem:create -l level-name -b test
55
+
87
56
  Block with mod:
88
57
 
89
- $ thor bem:create -b test -m large
58
+ $ thor bem:create -l level-name -b test -m large
90
59
 
91
60
  Block with pretty mod with value:
92
-
93
- $ thor bem:create -b test -m color -v red
61
+
62
+ $ thor bem:create -l level-name -b test -m color -v red
94
63
 
95
64
  Create element:
96
65
 
97
- $ thor bem:create -b test -e icon
98
-
66
+ $ thor bem:create -l level-name -b test -e icon
67
+
99
68
  Element with mod:
100
69
 
101
- $ thor bem:create -b test -e icon -m large
102
-
70
+ $ thor bem:create -l level-name -b test -e icon -m large
71
+
103
72
  Element with pretty mod:
104
73
 
105
- $ thor bem:create -b test -e icon -m size -v small
74
+ $ thor bem:create -l level-name -b test -e icon -m size -v small
106
75
 
107
76
  Block in special technolody:
108
- $ thor bem:create -b test -T sass
77
+ $ thor bem:create -l level-name -b test -T sass
109
78
 
110
79
  Element in special tehcnology creates like block. List of know technologies you can see in bem.rb initializer. You can customize it. After block, element or mod creating generator adds to level assets (level_name/.bem/assets) main file (level) require string. Ex:
111
80
  ```sass
112
- //= require ../../../../test/elements/__field/__field.css.sass
81
+ //= require ../../../../test/__field/test__field.css.sass
113
82
  ```
114
- You should remember! You are not in any case should not be writing styles and scripts in assets levels and application files.
115
- Use them like configuration files, for require only. This involves using Sprockets.
83
+ You should remember! You are not in any case should not be writing styles and scripts in assets levels and application files. Use them like configuration files, for require only. This involves using Sprockets.
116
84
 
117
85
  ### Rendering
118
86
 
119
87
  In your view you should write this:
120
88
  ```ruby
121
- = b "test", mods: [{color: "red"}], content: [{ elem: "icon", elemMods: [{size: "small"}] }]
122
- ```
89
+ = block "test", mods: [{color: "red"}], content: [{ elem: "icon", elemMods: [{size: "small"}] }]
123
90
 
124
- If block in group:
125
- ```ruby
126
- = b "test", group: "name", mods: [{color: "red"}], content: []
127
- ```
128
-
129
- Block with mods without value:
130
- ```ruby
131
- = b "test", mods: [:super, {color: "red"}], content: []
132
- ```
91
+ = block "test", mods: [:super, {color: "red"}], content: []
133
92
 
134
- Block with custom attributes for tag:
135
- ```ruby
136
- = b "test", attrs: {src: "/img.png"}, content: []
137
- ```
93
+ = block "test", attrs: {src: "/img.png"}, content: []
138
94
 
139
- Block with custom class for tag:
140
- ```ruby
141
- = b "test", cls: "custom", content: []
142
- ```
95
+ = block "test", cls: "custom", content: []
143
96
 
144
- Block with custom tag for block( 'div' is default ):
145
- ```ruby
146
97
  = b "test", tag: "article", content: []
147
98
  ```
148
99
 
149
- Syntax is look like [bemhtml](http://ru.bem.info/articles/bemhtml-reference/).
100
+ Syntax is look like original [BEMJSON](http://ru.bem.info/technology/bemjson/v2/bemjson/).
150
101
 
151
102
  ### Templates
152
103
 
153
- Now templates exists for haml, sass, coffee and md technologies, but you will create your templates in
154
- lib/tasks/templates. For example, you can watch haml template:
104
+ Now templates exists for haml, sass, coffee and md technologies, but you will create your templates in lib/tasks/templates. For example, you can watch haml template:
155
105
  ```haml
156
106
  - haml_tag this[:tag], this[:attrs]
157
107
  = content
@@ -161,29 +111,18 @@ Or Slim template:
161
111
  * this[:tag], this[:attrs]
162
112
  = content
163
113
  ```
164
- This and content is BEM helpers for rendering. For access to default essence propeties use 'this' method.
165
- For access to custom essence properties use 'ctx' method.
114
+ `this` and `content` is BEM helpers for rendering. `this` is access to default essence propeties, `content` is access to context properties.
166
115
 
167
116
  ### You want more BEM?
168
117
 
169
- You can use CSSO instead of YUI compressor for precompile assets.
170
- Read [here](http://habrahabr.ru/post/181880/) about it.
171
-
172
- If you want it, please watch [here](https://github.com/Vasfed/csso-rails).
173
-
174
- *__Stay BEMed!__*
175
-
176
- ## Tomorrow
177
-
178
- 0. Incapsulate helpers methods and isolate them from project helpers.
179
- 1. i-bem.js for html.
180
- 2. deps.js
181
- 3. Mods with restructure. Now you can't use mods with templates(haml, slim and etc.), but they generates.
182
-
183
- ## Contributing
184
-
185
- 1. Fork it
186
- 2. Create your feature branch (`git checkout -b my-new-feature`)
187
- 3. Commit your changes (`git commit -am 'Add some feature'`)
188
- 4. Push to the branch (`git push origin my-new-feature`)
189
- 5. Create new Pull Request
118
+ More information you can find on [official site of BEM](http://bem.info)
119
+
120
+ ### Authors
121
+
122
+ - Anton Winogradov ([verybigman](https://github.com/verybigman)) @awinogradov
123
+
124
+ ### Ideas
125
+
126
+ Please, talk about your ideas by GitHub [issues](https://github.com/verybigman/bem-on-rails/issues).
127
+
128
+ ### [MIT](http://en.wikipedia.org/wiki/MIT_License) License
@@ -0,0 +1,115 @@
1
+ # BEM on Rails
2
+
3
+ Позволяет использовать БЭМ методологию в Rails приложениях. BEM on Rails это Ruby форк частичного функционала bem-tools. Узнать, что такое bem-tools можно здесь [здесь](http://bem.info/tools/bem/), а о самой БЭМ методологии [здесь](http://bem.info/method/). Кроме того, я выступал с докладом об этом геме на YaC 2013, который можно найти [здесь](http://tech.yandex.ru/events/bemup/yac-bemup/talks/1349/).
4
+
5
+ ## Установка
6
+
7
+ Добавьте эту строку в Gemfile:
8
+
9
+ gem 'bem-on-rails'
10
+
11
+ Затем запустите бандлер:
12
+
13
+ $ bundle
14
+
15
+ Далее запускаем генератор:
16
+
17
+ $ rails g bemonrails:install
18
+
19
+ Если сервер запущен, его надо бы перезапустить.
20
+
21
+ ## Использование
22
+
23
+ Вы можете создавать блоки, элементы и их модификаторы на разных уровнях. Так выглядит стандартная структура директорий:
24
+
25
+ - **bem**
26
+ - **level_name**
27
+ - **block_name**
28
+ - **__element_name**
29
+ - block-name__element_name.html.haml
30
+ - block-name__element_name.css.sass
31
+ - block-name__element_name.coffee
32
+ - block-name__element_name.md
33
+ - **_mod_name**
34
+ - block-name_mod_name.css.sass
35
+ - block-name_mod_name.coffee
36
+ - block-name_mod_name.md
37
+ - block_name.html.haml
38
+ - block_name.css.sass
39
+ - block_name.coffee
40
+ - block_name.md
41
+
42
+ Больше информации об организации файловой системы можно найти [здесь](http://bem.info/method/filesystem/).
43
+
44
+ ### Создание новых блоков
45
+
46
+ Простой пример:
47
+
48
+ $ thor bem:create -l level-name -b test
49
+
50
+ Блок с булевым модификатором:
51
+
52
+ $ thor bem:create -l level-name -b test -m large
53
+
54
+ Блок с модификатором и его значением:
55
+
56
+ $ thor bem:create -l level-name -b test -m color -v red
57
+
58
+ Создание элемента:
59
+
60
+ $ thor bem:create -l level-name -b test -e icon
61
+
62
+ Создание сущности в необходимой технологии:
63
+
64
+ $ thor bem:create -l level-name -b test -T sass
65
+
66
+ Список используюмых технологий находится в bem.rb initializer. Во время создания сущностей создаются записи в файлах ассетов (level_name/.bem/assets). Например:
67
+ ```sass
68
+ //= require ../../../../test/__field/test__field.css.sass
69
+ ```
70
+ Пожалуйста, не пишите ничего самостоятельно в этих файлах.
71
+
72
+ ### Вьюхи
73
+
74
+ Haml:
75
+ ```ruby
76
+ = block "test", mods: [{color: "red"}], content: [{ elem: "icon", elemMods: [{size: "small"}] }]
77
+
78
+ = block "test", mods: [:super, {color: "red"}], content: []
79
+
80
+ = block "test", attrs: {src: "/img.png"}, content: []
81
+
82
+ = block "test", cls: "custom", content: []
83
+
84
+ = block "test", tag: "article", content: []
85
+ ```
86
+
87
+ Синтаксис схож с ориганльным из [BEMJSON](http://ru.bem.info/technology/bemjson/v2/bemjson/).
88
+
89
+ ### Шаблоны
90
+
91
+ По умолчанию шаблоны можно писать на haml, sass, coffee и md, но вы можете создать свои технологии, какие вам только будут необходимы по примеру со стандартными из lib/tasks/templates. Например так выглядит шаблон для haml:
92
+ ```haml
93
+ - haml_tag this[:tag], this[:attrs]
94
+ = content
95
+ ```
96
+ А вот так для Slim:
97
+ ```slim
98
+ * this[:tag], this[:attrs]
99
+ = content
100
+ ```
101
+ `this` и `content` это БЭМ помощники для рендеринга. `this` используется для доступа к стандартным полям сущности, а 'ctx' для доступа к полям контекста.
102
+
103
+ ### Хотите больше информации о БЭМ?
104
+
105
+ Много полезных статей на [официальном БЭМ сайте](http://bem.info)
106
+
107
+ ### Авторы
108
+
109
+ - Антон Виноградов ([verybigman](https://github.com/verybigman)) @awinogradov
110
+
111
+ ### Идеи, замечания и пожелания
112
+
113
+ Все это можно оформить в виде [issues](https://github.com/verybigman/bem-on-rails/issues) на GitHub.
114
+
115
+ ### [MIT](http://en.wikipedia.org/wiki/MIT_License) Лицензия
@@ -0,0 +1,107 @@
1
+ module Bemonrails
2
+ module BemRenderHelper
3
+ include Bemonrails::BemNames
4
+
5
+ def block(b_name, builder={})
6
+ unless b_name.blank?
7
+ builder[:block] = b_name
8
+ path = File.join path_resolve(:block, builder, false)
9
+ target = File.join path, build_b(b_name)
10
+ create_ctx builder
11
+ update_ctx :block, b_name
12
+ resolve_ctx
13
+ template_exists?(target) ? render(file: target) : empty
14
+ end
15
+ end
16
+
17
+ def elem(e_name, builder={})
18
+ unless e_name.blank?
19
+ builder[:block] = this[:block]
20
+ builder[:element] = e_name
21
+ path = File.join path_resolve(:element, builder, false)
22
+ target = File.join path, build_e(this[:block], e_name)
23
+ create_ctx builder
24
+ update_ctx :element, e_name
25
+ resolve_ctx
26
+ template_exists?(target) ? render(file: target) : empty
27
+ end
28
+ end
29
+
30
+ def create_ctx(builder={})
31
+ @this = {}
32
+
33
+ BEM[:attrs].each do |mod|
34
+ if builder[mod]
35
+ @this[mod] = builder[mod]
36
+ builder = builder.except(mod)
37
+ end
38
+ end
39
+
40
+ @this[:ctx] = builder
41
+ @this[:bem] ||= true
42
+ @this[:attrs] ||= {}
43
+ @this[:tag] ||= :div
44
+ end
45
+
46
+ def update_ctx(essence, name)
47
+ case essence
48
+ when :block
49
+ @this[:block] = @block_buffer = name
50
+ when :element
51
+ @this[:block] = @block_buffer
52
+ @this[:elem] = name
53
+ end
54
+ end
55
+
56
+ def resolve_ctx
57
+ classes_array = []
58
+
59
+ if this[:bem]
60
+ dom_class(this, classes_array)
61
+ resolve_mixes(this[:mix], classes_array)
62
+ else
63
+ classes_array.push(this[:elem] ? this[:elem] : this[:block])
64
+ end
65
+
66
+ this[:attrs].merge!({class: [classes_array, this[:cls]].join(" ").strip!})
67
+ end
68
+
69
+ def resolve_mods(mods, classes_array, bl, el=false)
70
+ mods = mods || {}
71
+ mods.each do |m, v|
72
+ classes_array.push(build_m(build_b(bl), el ? build_e(bl, el) : nil, m.to_s, v))
73
+ end
74
+ end
75
+
76
+ def resolve_mixes(mixs, classes_array)
77
+ mixs = mixs || {}
78
+ mixs.each do |mix|
79
+ generate_class(mix, classes_array)
80
+ end
81
+ end
82
+
83
+ def dom_class(essence, classes_array)
84
+ if essence[:block] && essence[:elem]
85
+ classes_array.push(build_e(essence[:block], essence[:elem]))
86
+ resolve_mods(essence[:elemMods], classes_array, essence[:block], essence[:elem])
87
+ elsif essence[:block]
88
+ classes_array.push(build_b(essence[:block]))
89
+ resolve_mods(essence[:mods], classes_array, essence[:block])
90
+ end
91
+ end
92
+
93
+ def empty
94
+ "<div class=#{ @this[:attrs][:class] }></div>".html_safe
95
+ end
96
+
97
+ def this
98
+ @this
99
+ end
100
+
101
+ def content
102
+ render "bemonrails/essences/content"
103
+ end
104
+
105
+ end
106
+
107
+ end