bem-on-rails 0.0.3 → 0.0.4

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: 6995691b232fdf4379ed487cfd5e617e160a3eb3
4
- data.tar.gz: b4c0d05d26cd0985fc2cc99d4e586a5e68a8f2aa
3
+ metadata.gz: 0f66d7fdd5df85cb015296b66ec95448402ff0f1
4
+ data.tar.gz: 1f2395fd3b5d51a031e66a4c0c7c2cbaf7462b91
5
5
  SHA512:
6
- metadata.gz: b29fdc8916e7cf7ef078084ff5d399a3633842c3df8978285a5d6e1253ec25dad707fcf3cc53823f64e7fdbc65a1595a2855cd9f7ce5c4960f4291d3e63a6129
7
- data.tar.gz: ee7691bd4bcbc1709c361896e74d6355e32ad9e1d540819c9d78ce73c6c65c28fc91776731a0a56ca982c213c05dcd88afe337e9c2636511bbf0cd03593ac3f3
6
+ metadata.gz: 69bafa47042962c169f8f2ac8c53bb4652736ff6bb7c113a2921575931a37bad1dfc331a3129954f6f924194a42d42cc07ecee3fe3ee0c8c218d344002d80df0
7
+ data.tar.gz: 08f97d4c7e17769d5a5423356b63c80ac6f8833c7f40f0c5c96bb0bef7885faf705bc62b7a373ea7abadef452622d87adafc897535a371b0680c8863ecaac022
data/.rvmrc ADDED
@@ -0,0 +1,62 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
+ # development environment upon cd'ing into the directory
5
+
6
+ # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
7
+ # Only full ruby name is supported here, for short names use:
8
+ # echo "rvm use 2.0.0" > .rvmrc
9
+ environment_id="ruby-2.0.0-p247@bem-on-rails"
10
+
11
+ # Uncomment the following lines if you want to verify rvm version per project
12
+ # rvmrc_rvm_version="1.22.3 (stable)" # 1.10.1 seems like a safe start
13
+ # eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | __rvm_awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
14
+ # echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
15
+ # return 1
16
+ # }
17
+
18
+ # First we attempt to load the desired environment directly from the environment
19
+ # file. This is very fast and efficient compared to running through the entire
20
+ # CLI and selector. If you want feedback on which environment was used then
21
+ # insert the word 'use' after --create as this triggers verbose mode.
22
+ if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
23
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
24
+ then
25
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
26
+ for __hook in "${rvm_path:-$HOME/.rvm}/hooks/after_use"*
27
+ do
28
+ if [[ -f "${__hook}" && -x "${__hook}" && -s "${__hook}" ]]
29
+ then \. "${__hook}" || true
30
+ fi
31
+ done
32
+ unset __hook
33
+ if (( ${rvm_use_flag:=1} >= 1 )) # display automatically
34
+ then
35
+ if [[ $- == *i* ]] # check for interactive shells
36
+ then printf "%b" "Using: \E[32m$GEM_HOME\E[0m
37
+ " # show the user the ruby and gemset they are using in green
38
+ else printf "%b" "Using: $GEM_HOME
39
+ " # don't use colors in non-interactive shells
40
+ fi
41
+ fi
42
+ else
43
+ # If the environment file has not yet been created, use the RVM CLI to select.
44
+ rvm --create use "$environment_id" || {
45
+ echo "Failed to create RVM environment '${environment_id}'."
46
+ return 1
47
+ }
48
+ fi
49
+
50
+ # If you use bundler, this might be useful to you:
51
+ # if [[ -s Gemfile ]] && {
52
+ # ! builtin command -v bundle >/dev/null ||
53
+ # builtin command -v bundle | GREP_OPTIONS="" \grep $rvm_path/bin/bundle >/dev/null
54
+ # }
55
+ # then
56
+ # printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
57
+ # gem install bundler
58
+ # fi
59
+ # if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
60
+ # then
61
+ # bundle install | GREP_OPTIONS="" \grep -vE '^Using|Your bundle is complete'
62
+ # fi
data/CHANGELOG.md CHANGED
@@ -14,3 +14,9 @@
14
14
  * extract helpers includes to railtie
15
15
  * extract views folder includes to railtie
16
16
  * update install generator
17
+
18
+ ## v0.0.4
19
+
20
+ * more refactoring
21
+ * add mix functionality
22
+ * walking to clean code
data/README.md CHANGED
@@ -27,13 +27,12 @@ This generator creates Thor task with templates. You should run to watch your ne
27
27
 
28
28
  $ thor -T
29
29
 
30
- Also generator creates initializer bem.rb with BEM constant. You should restart server after install.
31
- You can customize everythink!
30
+ You should restart server after install.
31
+ You can customize everythink in initializers/bem.rb!
32
32
 
33
33
  ## Usage
34
34
 
35
- You can create blocks, elements, modificators and groups for blocks. It's awesome! Also you can remove them and watch
36
- lists of blocks, block elements, blocks mods and etc. Try thor help for more info.
35
+ 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.
37
36
 
38
37
  Default blocks folder structure:
39
38
  - **blocks**
@@ -136,15 +135,16 @@ Syntax is look like [bemhtml](http://ru.bem.info/articles/bemhtml-reference/).
136
135
  Now templates exists for haml, sass, coffee and md technologies, but you will create your templates in
137
136
  lib/tasks/templates. For example, you can watch haml template:
138
137
  ```haml
139
- - haml_tag bemtag, bemattrs
140
- = bemcontent
138
+ - haml_tag this[:tag], this[:attrs]
139
+ = content
141
140
  ```
142
141
  Or Slim template:
143
142
  ```slim
144
- * bemtag, bemattrs
145
- = bemcontent
143
+ * this[:tag], this[:attrs]
144
+ = content
146
145
  ```
147
- Bemclass and bemcontent is BEM helpers for rendering.
146
+ This and content is BEM helpers for rendering. For access to default essence propeties use 'this' method.
147
+ For access to custom essence properties use 'ctx' method.
148
148
 
149
149
  ### You want more BEM?
150
150
 
@@ -158,10 +158,11 @@ If you want it, please watch [here](https://github.com/Vasfed/csso-rails).
158
158
  ## Tomorrow
159
159
 
160
160
  0. Incapsulate helpers methods and isolate them from project helpers.
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.
161
+ 1. Flag bem.
162
+ 2. i-bem.js for html.
163
+ 3. deps.js
164
+ 4. Mods with restructure. Now you can't use mods with templates(haml, slim and etc.), but they generates.
165
+ 5. Bem exutable. Work with Thor is not convenient.
165
166
 
166
167
  ## Contributing
167
168
 
@@ -2,106 +2,102 @@ module Bemonrails
2
2
  module BemRenderHelper
3
3
  include Bemonrails::BemNames
4
4
 
5
- def bemtag
6
- @custom_tag ||= "div"
7
- end
8
-
9
- def render_block(name, builder={})
5
+ def b(name, builder={})
10
6
  unless name.blank?
11
- # Generate block paths
12
7
  path = File.join BEM[:blocks][:dir], build_path_for(:block, builder)
13
8
  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
9
+ get_bemattributes_from builder
10
+ set_names :block, name
11
+ update_bemattributes
12
+ template_exists?(target) ? render(file: target) : empty
23
13
  end
24
14
  end
25
- alias :b :render_block
26
15
 
27
- def render_element(name, builder={})
16
+ def e(name, builder={})
28
17
  unless name.blank?
29
- # Generate element paths
30
18
  path = File.join build_path_for(:element, builder)
31
19
  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
20
+ get_bemattributes_from builder
21
+ set_names :element, name
22
+ update_bemattributes
23
+ template_exists?(target) ? render(file: target) : empty
42
24
  end
43
25
  end
44
- alias :e :render_element
45
26
 
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)
73
- end
74
- end
27
+ def get_bemattributes_from(builder={})
28
+ @this = {}
29
+ BEM[:attrs].each do |mod|
30
+ if builder[mod]
31
+ @this[mod] = builder[mod]
32
+ builder = builder.except(mod)
75
33
  end
76
34
  end
35
+ @this[:ctx] = builder
36
+ # Set defult attrs, if user not set them.
37
+ @this[:tag] ||= :div
38
+ @this[:attrs] ||= {}
39
+ end
77
40
 
78
- bemclass = classes_array.join(" ")
41
+ def set_names(essence, name)
42
+ case essence
43
+ when :block
44
+ @this[:block] = @block_buffer = name
45
+ when :element
46
+ @this[:block] = @block_buffer
47
+ @this[:elem] = name
48
+ end
49
+ end
79
50
 
80
- # If custom class exist
81
- if @custom_class
82
- bemclass = [bemclass, @custom_class].join(" ")
51
+ def update_bemattributes
52
+ classes_array = []
53
+ generate_class(@this, classes_array)
54
+ install_mix(@this[:mix], classes_array)
55
+ @this[:attrs].merge!({class: [classes_array, @this[:cls]].join(" ").strip!})
56
+ end
57
+
58
+ def install_mods(mods, classes_array, bl, el=false)
59
+ if mods
60
+ el = el ? element(el) : ""
61
+ mods.each do |mod|
62
+ if mod.kind_of? Hash
63
+ mod.each do |mod_name, mod_value|
64
+ classes_array.push(block(bl) + el + mod(mod_name.to_s) + mod(mod_name.to_s, mod_value))
65
+ end
66
+ else
67
+ classes_array.push(block(bl) + el + mod(mod.to_s))
68
+ end
69
+ end
83
70
  end
71
+ end
84
72
 
85
- # String for tag attributes
86
- bemattributes = { class: bemclass }
73
+ def install_mix(mixs, classes_array)
74
+ if mixs
75
+ mixs.each do |mix|
76
+ generate_class(mix, classes_array)
77
+ end
78
+ end
79
+ end
87
80
 
88
- # If custom attributes exist
89
- if @custom_attrs
90
- bemattributes.merge! @custom_attrs
81
+ def generate_class(essence, classes_array)
82
+ if essence[:block] && !essence[:elem]
83
+ classes_array.push(block(essence[:block]))
84
+ install_mods(essence[:mods], classes_array, essence[:block])
85
+ elsif essence[:elem]
86
+ classes_array.push(block(essence[:block]) + element(essence[:elem]))
87
+ install_mods(essence[:elemMods], classes_array, essence[:block], essence[:elem])
91
88
  end
89
+ end
92
90
 
93
- bemattributes
91
+ def empty
92
+ "<div class=#{ @this[:attrs][:class] }></div>".html_safe
94
93
  end
95
- alias :bemattrs :render_bemattributes
96
94
 
97
- def render_empty
98
- "<div class=#{ bemclass }></div>".html_safe
95
+ def this
96
+ @this
99
97
  end
100
- alias :bemempty :render_empty
101
98
 
102
- def render_content
99
+ def content
103
100
  render "bemonrails/essences/content"
104
101
  end
105
- alias :bemcontent :render_content
106
102
  end
107
103
  end
@@ -1,20 +1,12 @@
1
- - if @content.kind_of?(Array)
2
- - @content.each do |essence|
1
+ - if @this[:content].kind_of?(Array)
2
+ - @this[:content].each do |essence|
3
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] }
4
+ = e essence[:elem], essence
9
5
 
10
6
  - 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] }
7
+ = b essence[:block], essence
16
8
 
17
9
  - else
18
10
  = essence
19
11
  - else
20
- = @content
12
+ = @this[:content]
@@ -86,7 +86,7 @@ module Bemonrails
86
86
  end
87
87
 
88
88
  def element_directory
89
- block_name = @block_name ? @block_name : options[:block]
89
+ block_name = @this[:block] ? @this[:block] : options[:block]
90
90
  File.join(block(block_name), BEM[:elements][:dir])
91
91
  end
92
92
 
@@ -14,8 +14,8 @@ module Bemonrails
14
14
  end
15
15
 
16
16
  def add_blocks_templates
17
- %w(slim.tt haml.tt coffee.tt md.tt sass.tt).each do |t|
18
- template "techs/#{t}", File.join(Rails.root, "lib", "tasks", "templates", t)
17
+ %w(haml.tt coffee.tt md.tt sass.tt).each do |t|
18
+ copy_file "techs/#{t}", File.join(Rails.root, "lib", "tasks", "templates", t)
19
19
  end
20
20
  end
21
21
 
@@ -1,101 +1,44 @@
1
- BEM = {}
2
-
3
- # List of known techs.
4
- BEM[:techs] = {
5
- haml: ".html.haml",
6
- slim: ".html.slim",
7
- erb: "html.erb",
8
- jade: ".jade",
9
- sass: ".css.sass",
10
- scss: ".css.scss",
11
- less: ".css.less",
12
- styl: ".css.styl",
13
- css: ".css",
14
- coffee: ".coffee",
15
- js: ".js",
16
- md: ".md",
17
- wiki: ".wiki"
18
- }
1
+ # Update list of known techs.
2
+ # BEM[:techs][:my_tech] = ".ext"
19
3
 
20
4
  # List of default techs, generating if -T is empty.
21
- BEM[:default] = {
22
- slim: BEM[:techs][:slim],
23
- sass: BEM[:techs][:sass],
24
- coffee: BEM[:techs][:coffee],
25
- md: BEM[:techs][:md]
26
- }
5
+ # BEM[:default] << :my_tech
27
6
 
28
- # Usage files variants.
29
- BEM[:usage] = {
30
- md: BEM[:techs][:md],
31
- wiki: BEM[:techs][:wiki]
32
- }
7
+ # Usage files variants. File for Readme about essences.
8
+ # BEM[:usage] << :my_tech
33
9
 
34
10
  # Default directories, try to customize.
35
11
  # Blocks directory in root of rails app.
36
- BEM[:blocks] = {
37
- dir: "blocks",
38
- path: Rails.root.join("blocks"),
39
- prefix: "",
40
- postfix: ""
41
- }
42
-
43
- # Elements directory in every block directory.
12
+ # BEM[:blocks] = {
13
+ # dir: "blocks",
14
+ # path: Rails.root.join("blocks"),
15
+ # prefix: "",
16
+ # postfix: ""
17
+ # }
18
+ # Elements and mods directory in every block. Configure it's like blocks.
44
19
  # Write 'dir: ""' for creating elements in root of block.
45
- BEM[:elements] = {
46
- dir: "elements",
47
- path: BEM[:blocks][:path], # This is individualy for every block
48
- prefix: "__",
49
- postfix: ""
50
- }
51
-
52
- # Mods directory in every block directory.
53
- # Write 'dir: ""' for creating mods in root of block.
54
- BEM[:mods] = {
55
- dir: "mods",
56
- path: BEM[:blocks][:path], # This is individualy for every block or element
57
- prefix: "_",
58
- postfix: ""
59
- }
20
+ # BEM[:elements] = {
21
+ # ...
22
+ # }
23
+ # BEM[:mods] = {
24
+ # ...
25
+ # }
60
26
 
61
27
  # [!] If you work with sass and you want to create blocks, elements and mods in sass,
62
28
  # you should convert 'application.css' to 'application.css.sass'. Because, when
63
- # blocks, elements or mods is created, technology files will be included to application
29
+ # blocks, elements or mods creates, technology files will be included to application
64
30
  # files. This also applies to scss, styl, less and coffee. Customize this for use your
65
31
  # favorite techs. Asset type may have postfix and it's optional.
66
- # Example:
67
- #
68
- # assets = {
69
- # stylesheets:
70
- # {
71
- # ext: BEM[:techs][:scss],
72
- # import: '//= require',
73
- # posfix: ';'
74
- # }
32
+ # BEM[:assets] = {
33
+ # stylesheets: {
34
+ # ext: BEM[:techs][:scss],
35
+ # import: '//= require',
36
+ # posfix: ';'
37
+ # },
38
+ # javascripts: {
39
+ # ...
40
+ # }
75
41
  # }
76
42
 
77
- BEM[:assets] = {
78
- stylesheets:
79
- {
80
- ext: BEM[:techs][:sass],
81
- import: '//= require'
82
- },
83
- javascripts:
84
- {
85
- ext: BEM[:techs][:js],
86
- import: '//= require'
87
- }
88
- }
89
-
90
- # You must use application files in
91
- # assets as a configs, don't write code in them.
92
- # This is need to sprokets includes.
93
- Rails.application.config.assets.paths << BEM[:blocks][:dir]
94
-
95
- # Use CSSO instead of YUI.
96
- # Watch here https://github.com/Vasfed/csso-rails
97
- # Add to gem file:
98
- # gem 'csso-rails'
99
-
100
- # And uncomment this
101
- # Rails.config.assets.css_compressor = :csso
43
+ # [!] Use CSSO instead of YUI.
44
+ # Watch here https://github.com/Vasfed/csso-rails
@@ -1,2 +1,2 @@
1
- - haml_tag bemtag, bemattrs
2
- = bemcontent
1
+ - haml_tag this[:tag], this[:attrs] do
2
+ = content
@@ -1,2 +1,2 @@
1
- * bemtag, bemattrs
2
- = bemcontent
1
+ * this[:tag], this[:attrs]
2
+ = content
@@ -1,187 +1,187 @@
1
1
  require File.expand_path('config/environment.rb')
2
2
 
3
3
  class Bem < Thor
4
- include Thor::Actions
5
- include Bemonrails::BemNames
6
- include Bemonrails::ConsoleMessages
7
-
8
- source_root File.expand_path('../templates', __FILE__)
9
-
10
- desc 'create', 'Create block, element or mod'
11
- method_option :block, type: :string, aliases: "-b", desc: "Create block in default techs."
12
- method_option :element, type: :string, aliases: "-e", desc: "Create element in default techs. Use with block param."
13
- method_option :mod, type: :string, aliases: "-m", desc: "Create modificator for block or element."
14
- method_option :value, type: :string, aliases: "-v", desc: "Value for modificator."
15
- method_option :tech, type: :string, aliases: "-T", desc: "Create essence in spec tech."
16
- method_option :group, type: :string, aliases: "-G", desc: "Create essence in group. Work for blocks only!"
17
- method_option :force, type: :boolean, desc: "Force existing block, element or mod files."
18
- def create
19
- path = build_path_for(essence)
20
- manipulate_essence(:create, essence, path)
21
- end
22
-
23
-
24
- desc 'remove', 'Remove block, element or mod'
25
- method_option :block, type: :string, aliases: "-b", desc: "Remove block in default techs."
26
- method_option :element, type: :string, aliases: "-e", desc: "Remove element in default techs. Use with block param."
27
- method_option :mod, type: :string, aliases: "-m", desc: "Remove modificator for block or element."
28
- method_option :value, type: :string, aliases: "-v", desc: "Value for modificator."
29
- method_option :tech, type: :string, aliases: "-T", desc: "Remove essence in spec tech."
30
- method_option :group, type: :string, aliases: "-G", desc: "Remove essence in group. Work for blocks only!"
31
- def remove
32
- path = build_path_for(essence)
33
- manipulate_essence(:remove, essence, path)
34
- end
35
-
36
-
37
- desc 'usage', 'Essence usage information'
38
- method_option :block, type: :string, aliases: "-b", desc: "Block usage."
39
- method_option :element, type: :string, aliases: "-e", desc: "Element usage"
40
- method_option :mod, type: :string, aliases: "-m", desc: "Mod usage."
41
- method_option :value, type: :string, aliases: "-v", desc: "Mod value usage."
42
- method_option :group, type: :string, aliases: "-G", desc: "Search essence in group."
43
- def usage
44
- path = build_path_for(essence)
45
- manipulate_essence(:usage, essence, path)
46
- end
47
-
48
-
49
- desc 'list', 'See list of group, block elements, mods and etc.'
50
- method_option :block, type: :string, aliases: "-b", desc: "All block elements, mods and mods values"
51
- method_option :element, type: :string, aliases: "-e", desc: "All element mods and mods values"
52
- method_option :mod, type: :string, aliases: "-m", desc: "All mod values."
53
- method_option :group, type: :string, aliases: "-G", desc: "All blocks in group."
54
- def list
55
- path = essence ? build_path_for(essence) : build_path_for(:block)
56
- case essence
57
- when :block
58
- print_elements_list(block, path)
59
- print_mods_list(block, path)
60
- when :element
61
- print_mods_list(element, path)
62
- when :mod
63
- print_values_list(element, path)
64
- else
65
- print_blocks_list(path)
66
- end
67
- end
68
-
69
- protected
70
-
71
- def essence_exist?(essence_dir)
72
- File.directory?(File.join(BEM[:blocks][:path], essence_dir))
73
- end
74
-
75
- def create_essence(essence_options, path)
76
- names = generate_names
77
- @css_class = '.' + names[:klass]
78
- # If you need more templates. Please create them into templates
79
- # directory. Watch existing templates for example.
80
- # What is .tt? It is custom extension for finding templates in other files.
81
- if options[:tech] # Maybe recive from command line
82
- template "#{options[:tech]}.tt", File.join(essence_options[:path], path, names[:name], names[:name] + BEM[:techs][options[:tech].to_sym])
83
- else
84
- create_defaults(essence_options, path, names)
85
- end
86
- end
87
-
88
- def create_defaults(essence_options, path, names)
89
- BEM[:default].each do |tech, extension|
90
- template "#{tech}.tt", File.join(essence_options[:path], path, names[:name], names[:name] + extension)
91
- end
92
- end
93
-
94
- def remove_essence(essence_options, path)
95
- names = generate_names
96
- destination = File.join(essence_options[:path], path, names[:name])
97
- destination = File.join(destination, names[:name] + BEM[:techs][options[:tech].to_sym]) if options[:tech]
98
- FileUtils.rm_rf(destination)
99
-
100
- puts "\e[0;31m remove\e[0m " + destination.to_s.gsub(Rails.root.to_s + "/", "")
101
- end
102
-
103
- def update_assets(name, path)
104
- BEM[:assets].each do |type, tech|
105
- asset = File.join(Rails.root, "app", "assets", type.to_s, "application" + tech[:ext])
106
- destination = [path, name, name + tech[:ext]].reject(&:empty?)
107
- line = "#{tech[:import]} #{File.join(destination)}#{tech[:postfix]}"
108
- File.open(asset, "a") { |f| f.write("\n" + line) }
109
- end
110
- end
111
-
112
- def cut_assets(name, path)
113
- BEM[:assets].each do |type, tech|
114
- asset = File.join(Rails.root, "app", "assets", type.to_s, "application" + tech[:ext])
115
- destination = [path, name, name + tech[:ext]].reject(&:empty?)
116
- line = "#{tech[:import]} #{File.join(destination)}#{tech[:postfix]}"
117
-
118
- tmp = Tempfile.new("temp")
119
- open(asset, 'r').each do |l|
120
- tmp << l unless l.chomp == line || l.empty?
121
- end
122
- tmp.close
123
-
124
- FileUtils.mv(tmp.path, asset)
125
- end
126
- end
127
-
128
- def search_usage_information(essence, path)
129
- BEM[:usage].each do |tech, extension|
130
- file_destination = File.join(path_to_block(path), essence, essence + extension)
131
- read_usage(file_destination) if File.exist?(file_destination)
132
- end
133
- end
134
-
135
- def read_usage(target)
136
- puts "#{ tech }: #{ target }"
137
- puts "BEM[:usage]:\t"
138
- File.readlines(target) { |line| puts line }
139
- end
140
-
141
- def print_blocks_list(essence="", path)
142
- directory_destination = File.join(path_to_block(path), essence)
143
- parse_directory(:blocks, 'green', directory_destination)
144
- end
145
-
146
- def print_elements_list(ess_name="", path)
147
- directory_destination = File.join(path_to_block(path), ess_name, BEM[:elements][:dir])
148
- parse_directory(:elements, 'purple', directory_destination)
149
- end
150
-
151
- def print_mods_list(ess_name="", path)
152
- directory_destination = File.join(path_to_block(path), ess_name, BEM[:mods][:dir])
153
- parse_directory(:mods, 'cyan', directory_destination)
154
- end
155
-
156
- def print_values_list(ess_name="", path)
157
- directory_destination = File.join(path_to_block(path), ess_name)
158
- parse_directory(:mods, 'yellow', directory_destination)
159
- end
160
-
161
- def parse_directory(directory, essence, color)
162
- print_message("BEM[#{ essence }]:\t", color)
163
- Dir[directory + "/*"].each do |name|
164
- name = name.split('/')[-1]
165
- puts " - " + name.split(BEM[essence][:prefix])[1]
166
- end
167
- end
168
-
169
- def manipulate_essence(action, ess, path)
170
- ess_name = send(ess)
171
- ess_name = mod(options[:value] ? options[:value] : options[:mod]) if ess == :mod
172
- destination = File.join(path, ess_name)
173
-
174
- case action
175
- when :create
176
- create_essence(BEM[ess.to_s.pluralize.to_sym], path)
177
- update_assets(ess_name, path)
178
- when :remove
179
- remove_essence(BEM[ess.to_s.pluralize.to_sym], path)
180
- cut_assets(ess_name, path)
181
- when :usage
182
- search_usage_information(ess_name, path) if essence_exist?(destination)
183
- else raise print_message("You should set params. Try 'thor help bem:#{action}' for more information", 'red')
184
- end
185
- end
186
-
187
- end
4
+ include Thor::Actions
5
+ include Bemonrails::BemNames
6
+ include Bemonrails::ConsoleMessages
7
+
8
+ source_root File.expand_path('../templates', __FILE__)
9
+
10
+ desc 'create', 'Create block, element or mod'
11
+ method_option :block, type: :string, aliases: "-b", desc: "Create block in default techs."
12
+ method_option :element, type: :string, aliases: "-e", desc: "Create element in default techs. Use with block param."
13
+ method_option :mod, type: :string, aliases: "-m", desc: "Create modificator for block or element."
14
+ method_option :value, type: :string, aliases: "-v", desc: "Value for modificator."
15
+ method_option :tech, type: :string, aliases: "-T", desc: "Create essence in spec tech."
16
+ method_option :group, type: :string, aliases: "-l", desc: "Create essence in group. Work for blocks only!"
17
+ method_option :force, type: :boolean, desc: "Force existing block, element or mod files."
18
+ def create
19
+ path = build_path_for(essence)
20
+ manipulate_essence(:create, essence, path)
21
+ end
22
+
23
+
24
+ desc 'remove', 'Remove block, element or mod'
25
+ method_option :block, type: :string, aliases: "-b", desc: "Remove block in default techs."
26
+ method_option :element, type: :string, aliases: "-e", desc: "Remove element in default techs. Use with block param."
27
+ method_option :mod, type: :string, aliases: "-m", desc: "Remove modificator for block or element."
28
+ method_option :value, type: :string, aliases: "-v", desc: "Value for modificator."
29
+ method_option :tech, type: :string, aliases: "-T", desc: "Remove essence in spec tech."
30
+ method_option :group, type: :string, aliases: "-l", desc: "Remove essence in group. Work for blocks only!"
31
+ def remove
32
+ path = build_path_for(essence)
33
+ manipulate_essence(:remove, essence, path)
34
+ end
35
+
36
+
37
+ desc 'usage', 'Essence usage information'
38
+ method_option :block, type: :string, aliases: "-b", desc: "Block usage."
39
+ method_option :element, type: :string, aliases: "-e", desc: "Element usage"
40
+ method_option :mod, type: :string, aliases: "-m", desc: "Mod usage."
41
+ method_option :value, type: :string, aliases: "-v", desc: "Mod value usage."
42
+ method_option :group, type: :string, aliases: "-l", desc: "Search essence in group."
43
+ def usage
44
+ path = build_path_for(essence)
45
+ manipulate_essence(:usage, essence, path)
46
+ end
47
+
48
+
49
+ desc 'list', 'See list of group, block elements, mods and etc.'
50
+ method_option :block, type: :string, aliases: "-b", desc: "All block elements, mods and mods values"
51
+ method_option :element, type: :string, aliases: "-e", desc: "All element mods and mods values"
52
+ method_option :mod, type: :string, aliases: "-m", desc: "All mod values."
53
+ method_option :group, type: :string, aliases: "-l", desc: "All blocks in group."
54
+ def list
55
+ path = essence ? build_path_for(essence) : build_path_for(:block)
56
+ case essence
57
+ when :block
58
+ print_elements_list(block, path)
59
+ print_mods_list(block, path)
60
+ when :element
61
+ print_mods_list(element, path)
62
+ when :mod
63
+ print_values_list(element, path)
64
+ else
65
+ print_blocks_list(path)
66
+ end
67
+ end
68
+
69
+ protected
70
+
71
+ def essence_exist?(essence_dir)
72
+ File.directory?(File.join(BEM[:blocks][:path], essence_dir))
73
+ end
74
+
75
+ def create_essence(essence_options, path)
76
+ names = generate_names
77
+ @css_class = '.' + names[:klass]
78
+ # If you need more templates. Please create them into templates
79
+ # directory. Watch existing templates for example.
80
+ # What is .tt? It is custom extension for finding templates in other files.
81
+ if options[:tech] # Maybe recive from command line
82
+ template "#{options[:tech]}.tt", File.join(essence_options[:path], path, names[:name], names[:name] + BEM[:techs][options[:tech].to_sym])
83
+ else
84
+ create_defaults(essence_options, path, names)
85
+ end
86
+ end
87
+
88
+ def create_defaults(essence_options, path, names)
89
+ BEM[:default].each do |tech|
90
+ template "#{tech}.tt", File.join(essence_options[:path], path, names[:name], names[:name] + BEM[:techs][tech])
91
+ end
92
+ end
93
+
94
+ def remove_essence(essence_options, path)
95
+ names = generate_names
96
+ destination = File.join(essence_options[:path], path, names[:name])
97
+ destination = File.join(destination, names[:name] + BEM[:techs][options[:tech].to_sym]) if options[:tech]
98
+ FileUtils.rm_rf(destination)
99
+
100
+ puts "\e[0;31m remove\e[0m " + destination.to_s.gsub(Rails.root.to_s + "/", "")
101
+ end
102
+
103
+ def update_assets(name, path)
104
+ BEM[:assets].each do |type, tech|
105
+ asset = File.join(Rails.root, "app", "assets", type.to_s, "application" + tech[:ext])
106
+ destination = [path, name, name + tech[:ext]].reject(&:empty?)
107
+ line = "#{tech[:import]} #{File.join(destination)}#{tech[:postfix]}"
108
+ File.open(asset, "a") { |f| f.write("\n" + line) }
109
+ end
110
+ end
111
+
112
+ def cut_assets(name, path)
113
+ BEM[:assets].each do |type, tech|
114
+ asset = File.join(Rails.root, "app", "assets", type.to_s, "application" + tech[:ext])
115
+ destination = [path, name, name + tech[:ext]].reject(&:empty?)
116
+ line = "#{tech[:import]} #{File.join(destination)}#{tech[:postfix]}"
117
+
118
+ tmp = Tempfile.new("temp")
119
+ open(asset, 'r').each do |l|
120
+ tmp << l unless l.chomp == line || l.empty?
121
+ end
122
+ tmp.close
123
+
124
+ FileUtils.mv(tmp.path, asset)
125
+ end
126
+ end
127
+
128
+ def search_usage_information(essence, path)
129
+ BEM[:usage].each do |tech|
130
+ file_destination = File.join(path_to_block(path), essence, essence + BEM[:techs][tech])
131
+ read_usage(file_destination) if File.exist?(file_destination)
132
+ end
133
+ end
134
+
135
+ def read_usage(target)
136
+ puts "#{ tech }: #{ target }"
137
+ puts "BEM[:usage]:\t"
138
+ File.readlines(target) { |line| puts line }
139
+ end
140
+
141
+ def print_blocks_list(essence="", path)
142
+ directory_destination = File.join(path_to_block(path), essence)
143
+ parse_directory(:blocks, 'green', directory_destination)
144
+ end
145
+
146
+ def print_elements_list(ess_name="", path)
147
+ directory_destination = File.join(path_to_block(path), ess_name, BEM[:elements][:dir])
148
+ parse_directory(:elements, 'purple', directory_destination)
149
+ end
150
+
151
+ def print_mods_list(ess_name="", path)
152
+ directory_destination = File.join(path_to_block(path), ess_name, BEM[:mods][:dir])
153
+ parse_directory(:mods, 'cyan', directory_destination)
154
+ end
155
+
156
+ def print_values_list(ess_name="", path)
157
+ directory_destination = File.join(path_to_block(path), ess_name)
158
+ parse_directory(:mods, 'yellow', directory_destination)
159
+ end
160
+
161
+ def parse_directory(directory, essence, color)
162
+ print_message("BEM[#{ essence }]:\t", color)
163
+ Dir[directory + "/*"].each do |name|
164
+ name = name.split('/')[-1]
165
+ puts " - " + name.split(BEM[essence][:prefix])[1]
166
+ end
167
+ end
168
+
169
+ def manipulate_essence(action, ess, path)
170
+ ess_name = send(ess)
171
+ ess_name = mod(options[:value] ? options[:value] : options[:mod]) if ess == :mod
172
+ destination = File.join(path, ess_name)
173
+
174
+ case action
175
+ when :create
176
+ create_essence(BEM[ess.to_s.pluralize.to_sym], path)
177
+ update_assets(ess_name, path)
178
+ when :remove
179
+ remove_essence(BEM[ess.to_s.pluralize.to_sym], path)
180
+ cut_assets(ess_name, path)
181
+ when :usage
182
+ search_usage_information(ess_name, path) if essence_exist?(destination)
183
+ else raise print_message("You should set params. Try 'thor help bem:#{action}' for more information", 'red')
184
+ end
185
+ end
186
+
187
+ end
@@ -0,0 +1,79 @@
1
+ BEM = {}
2
+
3
+ BEM[:attrs] = [:block, :elem, :mods, :elemMods, :bem, :js, :jsAttr, :cls, :tag, :mix, :content]
4
+
5
+ # List of known techs.
6
+ BEM[:techs] = {
7
+ haml: ".html.haml",
8
+ slim: ".html.slim",
9
+ erb: "html.erb",
10
+ jade: ".jade",
11
+ sass: ".css.sass",
12
+ scss: ".css.scss",
13
+ less: ".css.less",
14
+ styl: ".css.styl",
15
+ css: ".css",
16
+ coffee: ".coffee",
17
+ js: ".js",
18
+ md: ".md",
19
+ wiki: ".wiki"
20
+ }
21
+ # List of default techs, generating if -T is empty.
22
+ BEM[:default] = [:haml, :sass, :coffee, :md]
23
+ # Usage files variants.
24
+ BEM[:usage] = [:md, :wiki]
25
+ # Default directories, try to customize.
26
+ # Blocks directory in root of rails app.
27
+ BEM[:blocks] = {
28
+ dir: "blocks",
29
+ path: Rails.root.join("blocks"),
30
+ prefix: "",
31
+ postfix: ""
32
+ }
33
+ # Elements directory in every block directory.
34
+ # Write 'dir: ""' for creating elements in root of block.
35
+ BEM[:elements] = {
36
+ dir: "elements",
37
+ path: BEM[:blocks][:path], # This is individualy for every block
38
+ prefix: "__",
39
+ postfix: ""
40
+ }
41
+ # Mods directory in every block directory.
42
+ # Write 'dir: ""' for creating mods in root of block.
43
+ BEM[:mods] = {
44
+ dir: "mods",
45
+ path: BEM[:blocks][:path], # This is individualy for every block or element
46
+ prefix: "_",
47
+ postfix: ""
48
+ }
49
+ # [!] If you work with sass and you want to create blocks, elements and mods in sass,
50
+ # you should convert 'application.css' to 'application.css.sass'. Because, when
51
+ # blocks, elements or mods is created, technology files will be included to application
52
+ # files. This also applies to scss, styl, less and coffee. Customize this for use your
53
+ # favorite techs. Asset type may have postfix and it's optional.
54
+ # Example:
55
+ #
56
+ # assets = {
57
+ # stylesheets:
58
+ # {
59
+ # ext: BEM[:techs][:scss],
60
+ # import: '//= require',
61
+ # posfix: ';'
62
+ # }
63
+ # }
64
+ BEM[:assets] = {
65
+ stylesheets:
66
+ {
67
+ ext: BEM[:techs][:sass],
68
+ import: '//= require'
69
+ },
70
+ javascripts:
71
+ {
72
+ ext: BEM[:techs][:js],
73
+ import: '//= require'
74
+ }
75
+ }
76
+ # You must use application files in
77
+ # assets as a configs, don't write code in them.
78
+ # This is need to sprokets includes.
79
+ Rails.application.config.assets.paths << BEM[:blocks][:dir]
@@ -1,6 +1,9 @@
1
1
  module Bemonrails
2
-
3
2
  class Railtie < Rails::Railtie
3
+ initializer "railtie.configure_rails_initialization" do
4
+ require 'bem-on-rails/initializers/bem'
5
+ end
6
+
4
7
  ActiveSupport.on_load :action_view do
5
8
  include Bemonrails::BemRenderHelper
6
9
  end
@@ -1,3 +1,3 @@
1
1
  module Bemonrails
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
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.3
4
+ version: 0.0.4
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-16 00:00:00.000000000 Z
11
+ date: 2013-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -74,6 +74,7 @@ extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
76
  - .gitignore
77
+ - .rvmrc
77
78
  - CHANGELOG.md
78
79
  - Gemfile
79
80
  - LICENSE
@@ -94,6 +95,7 @@ files:
94
95
  - lib/bem-on-rails/generators/templates/techs/sass.tt
95
96
  - lib/bem-on-rails/generators/templates/techs/slim.tt
96
97
  - lib/bem-on-rails/generators/templates/thor/bem.tt.rb
98
+ - lib/bem-on-rails/initializers/bem.rb
97
99
  - lib/bem-on-rails/railtie.rb
98
100
  - lib/bem-on-rails/version.rb
99
101
  homepage: https://github.com/verybigman/bem-on-rails
@@ -116,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
118
  version: '0'
117
119
  requirements: []
118
120
  rubyforge_project:
119
- rubygems_version: 2.0.3
121
+ rubygems_version: 2.0.7
120
122
  signing_key:
121
123
  specification_version: 4
122
124
  summary: BEM Tools for Rails applications