bem-on-rails 0.0.5 → 1.0.0

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.
@@ -1,124 +1,124 @@
1
1
  module Bemonrails
2
- module BemNames
3
- # Directories paths.
4
- def build_path_for(essence, builder=options, include_level=true)
5
- current_level = builder[:level] ? builder[:level] : BEM[:level]
6
- path = include_level ? [current_level] : []
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')
2
+ module BemNames
3
+
4
+ # Resolve directories
5
+ def path_resolve(essence, builder=options, include_level=true)
6
+ current_level = builder[:level] ? builder[:level] : BEM[:level]
7
+ path = include_level ? [current_level] : []
8
+
9
+ case essence
10
+ when :mod
11
+ # This is for mods with value
12
+ if builder[:block] && builder[:element]
13
+ path.push path_m(:element)
14
+ elsif builder[:block]
15
+ path.push path_m(:block)
16
+ else
17
+ raise print_message("Mods must be for block or element.", 'red')
18
+ end
19
+ when :element
20
+ path.push path_e(builder[:block], builder[:element])
21
+ when :block
22
+ path.push build_b(builder[:block])
23
+ else
24
+ raise print_message("Unknown params. Try 'thor help bem:create'", 'red')
25
+ end
26
+
27
+ File.join path.compact
21
28
  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
29
 
32
- def path_to_block(path, level="")
33
- File.join Rails.root.join(BEM[:root], level + path)
34
- end
30
+ def generate_klass(builder=options)
31
+ names = {}
35
32
 
36
- def generate_names(builder=options)
37
- names = {}
38
- # Generate names for block, his mods and they values
39
- if builder[:block]
33
+ # Generate names for block, his mods and they values
34
+ if builder[:block]
35
+ names[:klass] = build_b(builder[:block])
40
36
 
41
- names[:klass] = names[:name] = block
37
+ # If block have mods
38
+ names[:klass] = build_m(builder[:block], nil, builder[:mod], builder[:value]) if builder[:mod]
39
+ end
42
40
 
43
- if builder[:mod]
44
- names[:name] = mod
45
- names[:klass] = block + names[:name]
46
- end
41
+ # Generate names for elements, they mods and they values
42
+ if builder[:element]
43
+ names[:klass] = build_e(builder[:block], builder[:element])
47
44
 
48
- if builder[:value]
49
- names[:name] = mod(builder[:value])
50
- names[:klass] = block + mod + names[:name]
45
+ # If element have mods
46
+ names[:klass] = build_m(builder[:block], builder[:element], builder[:mod], builder[:value]) if builder[:mod]
47
+ end
48
+
49
+ names
51
50
  end
52
- end
53
51
 
54
- # Generate names for elements, they mods and they values
55
- if builder[:element]
52
+ def resolve_essence
53
+ essence = :block
56
54
 
57
- names[:name] = element
58
- names[:klass] += names[:name]
55
+ if options[:element]
56
+ essence = :element
57
+ if options[:mod]
58
+ essence = :mod
59
+ end
60
+ end
59
61
 
60
- if builder[:mod]
61
- names[:name] = mod
62
- names[:klass] = block + element + names[:name]
62
+ essence
63
63
  end
64
64
 
65
- if builder[:value]
66
- names[:name] = mod(builder[:value])
67
- names[:klass] = block + element + mod + names[:name]
65
+ def build_def(ess)
66
+ case ess
67
+ when :block
68
+ build_b
69
+ when :element
70
+ build_e
71
+ when :mod
72
+ build_m(options[:block], options[:element], options[:mod], options[:value])
73
+ end
68
74
  end
69
- end
70
-
71
- names
72
- end
73
75
 
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
76
+ def path_l(path, level=options[:level])
77
+ File.join Rails.root.join(BEM[:root], level, path)
78
+ end
83
79
 
84
- def block(name=options[:block])
85
- BEM[:blocks][:prefix] + name
86
- end
80
+ # Build block name
81
+ def build_b(b=options[:block])
82
+ BEM[:blocks][:prefix] + b
83
+ end
87
84
 
88
- def element_directory
89
- block_name = @this ? @this[:block] : options[:block]
90
- File.join(block(block_name), BEM[:elements][:dir])
91
- end
85
+ # Build block path
86
+ def path_e(b=options[:block], e=options[:element])
87
+ File.join build_b(b), BEM[:elements][:dir], BEM[:elements][:prefix] + e
88
+ end
92
89
 
93
- def element(name=options[:element])
94
- BEM[:elements][:prefix] + name
95
- end
90
+ # Build element name
91
+ def build_e(b=options[:block], e=options[:element])
92
+ if b
93
+ b + BEM[:elements][:prefix] + e
94
+ else
95
+ BEM[:elements][:prefix] + e
96
+ end
97
+ end
96
98
 
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
99
+ def path_m(essence, m=options[:mod])
100
+ case essence
101
+ when :element
102
+ File.join path_e, build_e, BEM[:mods][:dir], BEM[:mods][:prefix] + m
103
+ else
104
+ File.join build_b, BEM[:mods][:dir], BEM[:mods][:prefix] + m
105
+ end
106
+ end
107
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
108
+ def build_m(b=options[:block], e=options[:element], m=options[:mod], v=options[:value])
109
+ name = build_b(b)
110
+ name = build_e(b, e) if e
111
+ name = name + BEM[:mods][:prefix] + m
112
+ name = name + BEM[:mods][:postfix] + v if v
113
+ name
114
+ end
115
115
 
116
- def template_exists?(file)
117
- BEM[:techs].each do |tech, extension|
118
- if File.exists? file + extension
119
- return true
116
+ def template_exists?(file)
117
+ BEM[:techs].each do |tech, ext|
118
+ return true if File.exists? file + ext
119
+ end
120
120
  end
121
- end
121
+
122
122
  end
123
- end
123
+
124
124
  end
@@ -1,24 +1,27 @@
1
1
  module Bemonrails
2
- module ConsoleMessages
3
- def print_message(message, color)
4
- check_argument_data_type(message, String)
5
- check_argument_data_type(color, String)
2
+ module ConsoleMessages
6
3
 
7
- color = case color
8
- when 'green' then "\e[0;32m"
9
- when 'red' then "\e[0;31m"
10
- when 'blue' then "\e[0;34m"
11
- when 'cyan' then "\e[0;36m"
12
- when 'purple' then "\e[0;35m"
13
- when 'yellow' then "\e[1;33m"
14
- else ''
15
- end
4
+ def print_message(message, color)
5
+ check_argument_data_type(message, String)
6
+ check_argument_data_type(color, String)
16
7
 
17
- puts "#{color + message} \e[0m"
18
- end
8
+ color = case color
9
+ when 'green' then "\e[0;32m"
10
+ when 'red' then "\e[0;31m"
11
+ when 'blue' then "\e[0;34m"
12
+ when 'cyan' then "\e[0;36m"
13
+ when 'purple' then "\e[0;35m"
14
+ when 'yellow' then "\e[1;33m"
15
+ else ''
16
+ end
17
+
18
+ puts "#{color + message} \e[0m"
19
+ end
20
+
21
+ def check_argument_data_type(argument, type)
22
+ raise print_message("#{argument} must be a #{type.to_s}", 'red') unless argument.kind_of? type
23
+ end
19
24
 
20
- def check_argument_data_type(argument, type)
21
- raise print_message("#{argument} must be a #{type.to_s}", 'red') unless argument.kind_of? type
22
25
  end
23
- end
26
+
24
27
  end
@@ -1,10 +1,14 @@
1
1
  module Bemonrails
2
- module Levels
2
+ module Levels
3
+
3
4
  def parse_bem_levels
4
5
  BEM[:levels].each do |level|
5
6
  prepend_view_path File.join(BEM[:root] , level[:name])
6
7
  end
7
- prepend_view_path BEM[:root]
8
+
9
+ prepend_view_path BEM[:root]
8
10
  end
11
+
9
12
  end
10
- end
13
+
14
+ end
@@ -1,5 +1,5 @@
1
1
  module Bemonrails
2
- class Engine < Rails::Engine
3
- isolate_namespace Bemonrails
4
- end
2
+ class Engine < Rails::Engine
3
+ isolate_namespace Bemonrails
4
+ end
5
5
  end
@@ -1,24 +1,27 @@
1
1
  require 'rails/generators'
2
2
 
3
3
  module Bemonrails
4
- module Generators
5
- class InstallGenerator < ::Rails::Generators::Base
6
- source_root File.expand_path("../templates/", __FILE__)
4
+ module Generators
5
+ class InstallGenerator < ::Rails::Generators::Base
7
6
 
8
- def add_initializer
9
- template "config/initializer.tt.rb", File.join(Rails.root, "config", "initializers", "bem.rb")
10
- end
7
+ source_root File.expand_path("../templates/", __FILE__)
11
8
 
12
- def install_bem_tasks
13
- template "thor/bem.tt.rb", File.join(Rails.root, "lib", "tasks", "bem.thor")
14
- end
9
+ def initializers
10
+ template "config/initializer.tt.rb", File.join(Rails.root, "config", "initializers", "bem.rb")
11
+ end
12
+
13
+ def tasks
14
+ template "thor/bem.tt.rb", File.join(Rails.root, "lib", "tasks", "bem.thor")
15
+ end
16
+
17
+ def templates
18
+ %w(haml.tt coffee.tt md.tt sass.tt).each do |t|
19
+ copy_file "techs/#{t}", File.join(Rails.root, "lib", "tasks", "templates", t)
20
+ end
21
+ end
15
22
 
16
- def add_blocks_templates
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
23
  end
20
- end
21
24
 
22
25
  end
23
- end
26
+
24
27
  end
@@ -10,29 +10,15 @@
10
10
  # Default directories, try to customize.
11
11
  # Blocks directory in root of rails app.
12
12
  # BEM[:blocks] = {
13
- # dir: BEM[:root],
14
- # prefix: "",
15
- # postfix: ""
13
+ # dir: BEM[:root],
14
+ # prefix: "",
15
+ # postfix: ""
16
16
  # }
17
+
17
18
  # Elements and mods directory in every block. Configure it's like blocks.
18
19
  # Write 'dir: ""' for creating elements in root of block.
19
- # BEM[:elements] = {
20
- # ...
21
- # }
22
- # BEM[:mods] = {
23
- # ...
24
- # }
25
-
26
- # Work with levels
27
- # Add new level with 'thor bem:levels'
28
- # Require it:
29
- # bem_controls = { name: "bem-controls",
30
- # git: "git@github.com:verybigman/bem-controls.git" }
31
- # Push to levels stack:
32
- # BEM[:levels].push(bem_controls)
33
- # Set it default if you want:
34
- # BEM[:level] = bem_controls[:name]
35
- # After install default level is your app name. Take it by BEM[:app].
20
+ # BEM[:elements] = {}
21
+ # BEM[:mods] = {}
36
22
 
37
23
  # [!] If you work with sass and you want to create blocks, elements and mods in sass,
38
24
  # you should convert 'application.css' to 'application.css.sass'. Because, when
@@ -40,15 +26,12 @@
40
26
  # files. This also applies to scss, styl, less and coffee. Customize this for use your
41
27
  # favorite techs. Asset type may have postfix and it's optional.
42
28
  # BEM[:assets] = {
43
- # stylesheets: {
44
- # ext: BEM[:techs][:scss],
45
- # import: '//= require',
46
- # posfix: ';'
47
- # },
48
- # javascripts: {
49
- # ...
50
- # }
29
+ # stylesheets: {
30
+ # ext: BEM[:techs][:scss],
31
+ # import: '//= require',
32
+ # posfix: ';'
33
+ # },
34
+ # javascripts: {
35
+ # ...
36
+ # }
51
37
  # }
52
-
53
- # [!] Use CSSO instead of YUI.
54
- # Watch here https://github.com/Vasfed/csso-rails
@@ -7,259 +7,81 @@ class Bem < Thor
7
7
 
8
8
  source_root File.expand_path('../templates', __FILE__)
9
9
 
10
+ LEVEL_ASSETS = File.join ".bem", "assets"
11
+
10
12
  desc 'create', 'Create block, element or mod'
11
13
  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."
14
+ method_option :element, type: :string, aliases: "-e", desc: "Create element in default techs."
13
15
  method_option :mod, type: :string, aliases: "-m", desc: "Create modificator for block or element."
14
16
  method_option :value, type: :string, aliases: "-v", desc: "Value for modificator."
15
17
  method_option :tech, type: :string, aliases: "-T", desc: "Create essence in spec tech."
16
- method_option :level, type: :string, aliases: "-l", desc: "Create essence in level. Work for blocks only!"
17
- method_option :force, type: :boolean, desc: "Force existing block, element or mod files."
18
+ method_option :level, type: :string, aliases: "-l", desc: "Create essence in level."
18
19
  def create
19
- path = build_path_for(essence)
20
- manipulate_essence(:create, essence, path)
21
- end
20
+ create_level unless level_exist?
22
21
 
22
+ ess = resolve_essence
23
+ path = path_resolve(ess)
24
+ name = build_def(ess)
25
+ dest = File.join path, name
23
26
 
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 :level, type: :string, aliases: "-l", desc: "Remove essence in level. Work for blocks only!"
31
- def remove
32
- path = build_path_for(essence)
33
- manipulate_essence(:remove, essence, path)
34
- end
27
+ create_essence(BEM[ess.to_s.pluralize.to_sym], path)
35
28
 
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 :level, type: :string, aliases: "-l", desc: "Search essence in level."
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 level, 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 :level, type: :string, aliases: "-l", desc: "All blocks in level."
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
- desc 'levels', 'Manipulating with levels'
70
- method_option :add, type: :boolean, aliases: "-a", desc: "Add new level"
71
- method_option :git, type: :string, aliases: "-g", desc: "From git repository"
72
- method_option :dir, type: :string, aliases: "-d", desc: "From local directory"
73
- method_option :new, type: :string, aliases: "-n", desc: "Create new level"
74
- method_option :default, type: :string, desc: "Create default level tree"
75
- def levels
76
- if options[:add]
77
- level_name = ""
78
- level = ""
79
- if options[:git]
80
- level_name = options[:git].split("/").last.gsub(".git", "")
81
- level = Rails.root.join BEM[:root], level_name
82
- print_message("Cloning blocks into new level: #{ level_name }...", "green")
83
- `git clone #{ options[:git] } #{ level }`
84
- test_level(level) ? level_added : level_error
85
- level_has_assets?(level) ? update_assets_with_level(level_name) : make_level_assets_path(level)
86
- elsif options[:dir]
87
- level_name = options[:git].split("/").last
88
- level = Rails.root.join BEM[:root], level_name
89
- print_message("Copying blocks into new level: #{ level_name }...", "green")
90
- `cp -R #{ options[:dir] } #{ level }`
91
- test_level(level) ? level_added : level_error
92
- level_has_assets?(level) ? update_assets_with_level(level_name) : make_level_assets_path(level)
93
- elsif options[:new]
94
- level_name = options[:new]
95
- level = Rails.root.join BEM[:root], level_name
96
- make_level_assets_path level
97
- update_assets_with_level level_name
98
- test_level(level) ? level_added : level_error
99
- elsif options[:default]
100
- level_name = BEM[:app]
101
- level = Rails.root.join BEM[:root], level_name
102
- make_level_assets_path level
103
- update_assets_with_level level_name
104
- test_level(level) ? level_added : level_error
105
- end
106
- end
29
+ update_assets(name, path)
107
30
  end
108
31
 
109
32
  protected
110
33
 
111
- def test_level(level)
112
- File.directory? level
113
- end
114
-
115
- def level_added
116
- print_message("New level added successfully! Change BEM[:levels] in bem.rb for available levels.", "green")
34
+ def level_exist?(l=options[:level])
35
+ File.directory? Rails.root.join BEM[:root], l
117
36
  end
118
37
 
119
- def level_error
120
- print_message("Error! We have a trouble with connection to repository. Please, try again.", "red")
121
- end
122
-
123
- def level_assets_path
124
- File.join(".bem", "assets")
125
- end
38
+ def create_level(l=options[:level])
39
+ target = Rails.root.join BEM[:root], l
126
40
 
127
- def level_has_assets?(level)
128
- File.directory? File.join level, level_assets_path
129
- end
41
+ # Make files for level assets
42
+ BEM[:assets].each do |type, tech|
43
+ create_file File.join target, LEVEL_ASSETS, type.to_s, "level" + tech[:ext]
44
+ end
130
45
 
131
- def update_assets_with_level(level)
46
+ # Update app assets with levels assets
132
47
  BEM[:assets].each do |type, tech|
133
48
  asset = File.join(Rails.root, "app", "assets", type.to_s, "application" + tech[:ext])
134
- destination = [level, level_assets_path, type.to_s, "level" + tech[:ext]]
135
- create_file asset unless File.exist?(asset)
49
+ destination = [l, LEVEL_ASSETS, type.to_s, "level" + tech[:ext]]
50
+ create_file asset unless File.exist?(asset)
136
51
  append_file asset, "\n#{ tech[:import] } #{ File.join(destination) }#{ tech[:postfix] }"
137
52
  end
138
53
  end
139
54
 
140
- def make_level_assets_path(level)
141
- BEM[:assets].each do |type, tech|
142
- create_file File.join level, level_assets_path, type.to_s, "level" + tech[:ext]
143
- end
144
- end
145
-
146
- def essence_exist?(essence_dir)
147
- File.directory? File.join BEM[:blocks][:path], essence_dir
148
- end
149
-
150
55
  def create_essence(essence_options, path)
151
- names = generate_names
56
+ names = generate_klass
152
57
  @css_class = '.' + names[:klass]
153
58
  # If you need more templates. Please create them into templates
154
59
  # directory. Watch existing templates for example.
155
60
  # What is .tt? It is custom extension for finding templates in other files.
156
61
  if options[:tech] # Maybe recive from command line
157
- template "#{ options[:tech] }.tt", File.join(essence_options[:dir], path, names[:name], names[:name] + BEM[:techs][options[:tech].to_sym])
62
+ template "#{ options[:tech] }.tt", File.join(BEM[:root], path, names[:klass] + BEM[:techs][options[:tech].to_sym])
158
63
  else
159
- create_defaults(essence_options, path, names)
64
+ defaults(essence_options, path, names)
160
65
  end
161
66
  end
162
67
 
163
- def create_defaults(essence_options, path, names)
68
+ def defaults(essence_options, path, names)
164
69
  BEM[:default].each do |tech|
165
- template "#{ tech }.tt", File.join(essence_options[:dir], path, names[:name], names[:name] + BEM[:techs][tech])
70
+ template "#{ tech }.tt", File.join(BEM[:root], path, names[:klass] + BEM[:techs][tech])
166
71
  end
167
72
  end
168
73
 
169
- def remove_essence(essence_options, path)
170
- names = generate_names
171
- destination = File.join(essence_options[:dir], path, names[:name])
172
- destination = File.join(destination, names[:name] + BEM[:techs][options[:tech].to_sym]) if options[:tech]
173
- remove_dir destination
174
- end
175
-
176
74
  def update_assets(name, path)
177
- level = BEM[:level]
178
- level ||= options[:level]
75
+ level = BEM[:level] || options[:level]
76
+
179
77
  BEM[:assets].each do |type, tech|
180
- asset = File.join(Rails.root, BEM[:root], level, level_assets_path, type.to_s, "level" + tech[:ext])
78
+ asset = File.join(Rails.root, BEM[:root], level, LEVEL_ASSETS, type.to_s, "level" + tech[:ext])
181
79
  # BEM[:root] > level > .bem > assets
182
80
  # 4 ../
183
- destination = ["../../../../", path, name, name + tech[:ext]].reject(&:empty?)
184
- create_file asset unless File.exist?(asset)
81
+ destination = ["../../../../", path, name + tech[:ext]].reject(&:empty?)
82
+ create_file asset unless File.exist?(asset)
185
83
  append_file asset, "\n#{ tech[:import] } #{ File.join(destination) }#{ tech[:postfix] }"
186
84
  end
187
85
  end
188
86
 
189
- def cut_assets(name, path)
190
- level = BEM[:level]
191
- level ||= options[:level]
192
- BEM[:assets].each do |type, tech|
193
- asset = File.join(Rails.root, BEM[:root], level, level_assets_path, type.to_s, "level" + tech[:ext])
194
- destination = ["../../../../", path, name, name + tech[:ext]].reject(&:empty?)
195
- line = "#{ tech[:import] } #{ File.join(destination) }#{ tech[:postfix] }"
196
-
197
- tmp = Tempfile.new("temp")
198
- open(asset, 'r').each do |l|
199
- tmp << l unless l.chomp == line || l.empty?
200
- end
201
- tmp.close
202
-
203
- FileUtils.mv(tmp.path, asset)
204
- end
205
- end
206
-
207
- def search_usage_information(essence, path)
208
- BEM[:usage].each do |tech|
209
- file_destination = File.join(path_to_block(path), essence, essence + BEM[:techs][tech])
210
- read_usage(file_destination) if File.exist?(file_destination)
211
- end
212
- end
213
-
214
- def read_usage(target)
215
- puts "#{ tech }: #{ target }"
216
- puts "BEM[:usage]:\t"
217
- File.readlines(target) { |line| puts line }
218
- end
219
-
220
- def print_blocks_list(essence="", path)
221
- directory_destination = File.join(path_to_block(path), essence)
222
- parse_directory(:blocks, 'green', directory_destination)
223
- end
224
-
225
- def print_elements_list(ess_name="", path)
226
- directory_destination = File.join(path_to_block(path), ess_name, BEM[:elements][:dir])
227
- parse_directory(:elements, 'purple', directory_destination)
228
- end
229
-
230
- def print_mods_list(ess_name="", path)
231
- directory_destination = File.join(path_to_block(path), ess_name, BEM[:mods][:dir])
232
- parse_directory(:mods, 'cyan', directory_destination)
233
- end
234
-
235
- def print_values_list(ess_name="", path)
236
- directory_destination = File.join(path_to_block(path), ess_name)
237
- parse_directory(:mods, 'yellow', directory_destination)
238
- end
239
-
240
- def parse_directory(directory, essence, color)
241
- print_message("BEM[#{ essence }]:\t", color)
242
- Dir[directory + "/*"].each do |name|
243
- name = name.split('/')[-1]
244
- puts " - " + name.split(BEM[essence][:prefix])[1]
245
- end
246
- end
247
-
248
- def manipulate_essence(action, ess, path)
249
- ess_name = send(ess)
250
- ess_name = mod(options[:value] ? options[:value] : options[:mod]) if ess == :mod
251
- destination = File.join(path, ess_name)
252
-
253
- case action
254
- when :create
255
- create_essence(BEM[ess.to_s.pluralize.to_sym], path)
256
- update_assets(ess_name, path)
257
- when :remove
258
- remove_essence(BEM[ess.to_s.pluralize.to_sym], path)
259
- cut_assets(ess_name, path)
260
- when :usage
261
- search_usage_information(ess_name, path) if essence_exist?(destination)
262
- else raise print_message("You should set params. Try 'thor help bem:#{ action }' for more information", 'red')
263
- end
264
- end
265
- end
87
+ end