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.
@@ -0,0 +1,24 @@
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)
6
+
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
16
+
17
+ puts "#{color + message} \e[0m"
18
+ end
19
+
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
+ end
23
+ end
24
+ end
@@ -1,5 +1,5 @@
1
1
  module Bemonrails
2
- class Engine < Rails::Engine
3
- isolate_namespace Bemonrails
4
- end
5
- end
2
+ class Engine < Rails::Engine
3
+ isolate_namespace Bemonrails
4
+ end
5
+ end
@@ -5,36 +5,20 @@ module Bemonrails
5
5
  class InstallGenerator < ::Rails::Generators::Base
6
6
  source_root File.expand_path("../templates/", __FILE__)
7
7
 
8
- def add_render_helpers
9
- app_helper = 'app/helpers/application_helper.rb'
10
- first_string = "module ApplicationHelper"
11
- bem_render_helpers = "\n\t# Add BEM blocks rendering helpers\n\tinclude Bemonrails::BemRenderHelper\n"
12
-
13
- insert_into_file app_helper, bem_render_helpers, :after => first_string
14
- end
15
-
16
- def add_blocks_folder
17
- app_controller = 'app/controllers/application_controller.rb'
18
- protection_str = "protect_from_forgery\n"
19
- bem_block_folder = "\n\t# Add BEM blocks folder to default views scope\n\tbefore_filter { prepend_view_path(BEM[:blocks][:dir]) }\n"
20
-
21
- insert_into_file app_controller, bem_block_folder, :after => protection_str
22
- end
23
-
24
8
  def add_initializer
25
- template "config/initializer.tt.rb", File.join(Rails.root, "config", "initializers", "bem.rb")
9
+ template "config/initializer.tt.rb", File.join(Rails.root, "config", "initializers", "bem.rb")
26
10
  end
27
11
 
28
12
  def install_bem_tasks
29
- template "thor/bem.tt.rb", File.join(Rails.root, "lib", "tasks", "bem.thor")
13
+ template "thor/bem.tt.rb", File.join(Rails.root, "lib", "tasks", "bem.thor")
30
14
  end
31
15
 
32
16
  def add_blocks_templates
33
- %w(haml.tt coffee.tt md.tt sass.tt).each do |t|
34
- template "techs/#{t}", File.join(Rails.root, "lib", "tasks", "templates", t)
35
- end
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)
19
+ end
36
20
  end
37
21
 
38
22
  end
39
23
  end
40
- end
24
+ end
@@ -2,60 +2,60 @@ BEM = {}
2
2
 
3
3
  # List of known techs.
4
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"
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
18
  }
19
19
 
20
20
  # List of default techs, generating if -T is empty.
21
21
  BEM[:default] = {
22
- haml: BEM[:techs][:haml],
23
- sass: BEM[:techs][:sass],
24
- coffee: BEM[:techs][:coffee],
25
- md: BEM[:techs][:md]
22
+ slim: BEM[:techs][:slim],
23
+ sass: BEM[:techs][:sass],
24
+ coffee: BEM[:techs][:coffee],
25
+ md: BEM[:techs][:md]
26
26
  }
27
27
 
28
28
  # Usage files variants.
29
29
  BEM[:usage] = {
30
- md: BEM[:techs][:md],
31
- wiki: BEM[:techs][:wiki]
30
+ md: BEM[:techs][:md],
31
+ wiki: BEM[:techs][:wiki]
32
32
  }
33
33
 
34
34
  # Default directories, try to customize.
35
35
  # Blocks directory in root of rails app.
36
36
  BEM[:blocks] = {
37
- dir: "blocks",
38
- path: Rails.root.join("blocks"),
39
- prefix: "",
40
- postfix: ""
37
+ dir: "blocks",
38
+ path: Rails.root.join("blocks"),
39
+ prefix: "",
40
+ postfix: ""
41
41
  }
42
42
 
43
43
  # Elements directory in every block directory.
44
44
  # Write 'dir: ""' for creating elements in root of block.
45
45
  BEM[:elements] = {
46
- dir: "elements",
47
- path: BEM[:blocks][:path], # This is individualy for every block
48
- prefix: "__",
49
- postfix: ""
46
+ dir: "elements",
47
+ path: BEM[:blocks][:path], # This is individualy for every block
48
+ prefix: "__",
49
+ postfix: ""
50
50
  }
51
51
 
52
52
  # Mods directory in every block directory.
53
53
  # Write 'dir: ""' for creating mods in root of block.
54
54
  BEM[:mods] = {
55
- dir: "mods",
56
- path: BEM[:blocks][:path], # This is individualy for every block or element
57
- prefix: "_",
58
- postfix: ""
55
+ dir: "mods",
56
+ path: BEM[:blocks][:path], # This is individualy for every block or element
57
+ prefix: "_",
58
+ postfix: ""
59
59
  }
60
60
 
61
61
  # [!] If you work with sass and you want to create blocks, elements and mods in sass,
@@ -75,16 +75,16 @@ BEM[:mods] = {
75
75
  # }
76
76
 
77
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
- }
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
88
  }
89
89
 
90
90
  # You must use application files in
@@ -98,4 +98,4 @@ Rails.application.config.assets.paths << BEM[:blocks][:dir]
98
98
  # gem 'csso-rails'
99
99
 
100
100
  # And uncomment this
101
- # Rails.config.assets.css_compressor = :csso
101
+ # Rails.config.assets.css_compressor = :csso
@@ -1,4 +1,4 @@
1
1
  # CoffeeScript
2
2
  # Example:
3
3
  # $('<%= @css_class %>').click ->
4
- # $('body').hide()
4
+ # $('body').hide()
@@ -1,2 +1,2 @@
1
- %div{ bemattrs }
2
- = bemcontent
1
+ - haml_tag bemtag, bemattrs
2
+ = bemcontent
@@ -0,0 +1,2 @@
1
+ * bemtag, bemattrs
2
+ = bemcontent
@@ -1,291 +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
-
7
- # Templates for techs
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
- # Minimum one param is required for creating
20
- if options[:block] && !options[:element] && !options[:mod]
21
- path = build_path_for(:block)
22
- destination = File.join(path, block)
23
- unless essence_exist?(destination)
24
- create_essence(BEM[:blocks], path)
25
- update_assets(block, path)
26
- end
27
- elsif options[:element] && !options[:mod]
28
- path = build_path_for(:element)
29
- destination = File.join(path, element)
30
- unless essence_exist?(destination)
31
- create_essence(BEM[:elements], path)
32
- update_assets(element, path)
33
- end
34
- elsif options[:mod]
35
- path = build_path_for(:mod)
36
- essence = options[:value] ? options[:value] : options[:mod]
37
- destination = File.join(path, mod(essence))
38
- unless essence_exist?(destination)
39
- create_essence(BEM[:mods], path)
40
- update_assets(mod(essence), path)
41
- end
42
- else
43
- raise print_message("You should set params. Try 'thor help bem:create' for more information", 'red')
44
- 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: "-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)
45
66
  end
46
-
47
-
48
-
49
- desc 'remove', 'Remove block, element or mod'
50
- method_option :block, type: :string, aliases: "-b", desc: "Remove block in default techs."
51
- method_option :element, type: :string, aliases: "-e", desc: "Remove element in default techs. Use with block param."
52
- method_option :mod, type: :string, aliases: "-m", desc: "Remove modificator for block or element."
53
- method_option :value, type: :string, aliases: "-v", desc: "Value for modificator."
54
- method_option :tech, type: :string, aliases: "-T", desc: "Remove essence in spec tech."
55
- method_option :group, type: :string, aliases: "-G", desc: "Remove essence in group. Work for blocks only!"
56
- def remove
57
- # Minimum one param is required for deleting
58
- if options[:block] && !options[:element] && !options[:mod]
59
- path = build_path_for(:block)
60
- destination = File.join(path, block)
61
- if essence_exist?(destination, false)
62
- remove_essence(BEM[:blocks], path)
63
- cut_assets(block, path)
64
- end
65
- elsif options[:element] && !options[:mod]
66
- path = build_path_for(:element)
67
- destination = File.join(path, element)
68
- if essence_exist?(destination, false)
69
- remove_essence(BEM[:elements], path)
70
- cut_assets(element, path)
71
- end
72
- elsif options[:mod]
73
- path = build_path_for(:mod)
74
- essence = options[:value] ? options[:value] : options[:mod]
75
- destination = File.join(path, mod(essence))
76
- if essence_exist?(destination, false)
77
- remove_essence(BEM[:mods], path)
78
- cut_assets(mod(essence), path)
79
- end
80
- else
81
- raise print_message("You should set params. Try 'thor help bem:remove' for more information", 'red')
82
- 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)
83
85
  end
86
+ end
84
87
 
85
-
86
-
87
- desc 'usage', 'Essence usage information'
88
- method_option :block, type: :string, aliases: "-b", desc: "Block usage."
89
- method_option :element, type: :string, aliases: "-e", desc: "Element usage"
90
- method_option :mod, type: :string, aliases: "-m", desc: "Mod usage."
91
- method_option :value, type: :string, aliases: "-v", desc: "Mod value usage."
92
- method_option :group, type: :string, aliases: "-G", desc: "Search essence in group."
93
- def usage
94
- if options[:block] && !options[:element] && !options[:mod]
95
- path = build_path_for(:block)
96
- search_usage_information(block, path)
97
- elsif options[:element] && !options[:mod]
98
- path = build_path_for(:element)
99
- search_usage_information(element, path)
100
- elsif options[:mod]
101
- path = build_path_for(:mod)
102
- essence = options[:value] ? options[:value] : options[:mod]
103
- search_usage_information(mod(essence), path)
104
- else
105
- raise print_message("You should set params. Try 'thor help bem:usage' for more information", 'red')
106
- end
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)
107
91
  end
108
-
109
-
110
-
111
- desc 'list', 'See list of group, block elements, mods and etc.'
112
- method_option :block, type: :string, aliases: "-b", desc: "All block elements, mods and mods values"
113
- method_option :element, type: :string, aliases: "-e", desc: "All element mods and mods values"
114
- method_option :mod, type: :string, aliases: "-m", desc: "All mod values."
115
- method_option :group, type: :string, aliases: "-G", desc: "All blocks in group."
116
- def list
117
- if options[:block] && !options[:element] && !options[:mod]
118
- # Print all block elements and mods
119
- path = build_path_for(:block)
120
- print_elements_list(block, path)
121
- print_mods_list(block, path)
122
- elsif options[:element] && !options[:mod]
123
- # Print all element mods
124
- path = build_path_for(:element)
125
- print_mods_list(element, path)
126
- elsif options[:mod]
127
- # Print all mod values
128
- path = build_path_for(:mod)
129
- print_values_list(element, path)
130
- else
131
- # Print all blocks
132
- path = build_path_for(:block)
133
- print_blocks_list(path)
134
- 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) }
135
109
  end
110
+ end
136
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]}"
137
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
138
123
 
139
- protected
140
-
141
- def essence_exist?(essence_dir, creating=true)
142
- if File.directory?(File.join(BEM[:blocks][:path], essence_dir))
143
- puts print_message("Essence with this name is already exists. Try 'thor help bem:list' or 'thor help bem:usage ", 'red') if creating
144
- true
145
- end
146
- end
147
-
148
- def create_essence(essence_options, path)
149
-
150
- names = generate_names
151
-
152
- @css_class = '.' + names[:klass]
153
-
154
- # [!] Templates exist only for wiki, haml, sass and coffee.
155
- # If you need more templates. Please create them into templates
156
- # directory. Watch existing templates for example.
157
- # What is .tt? It is custom extension for finding templates in other files.
158
- if options[:tech] # Maybe recive from command line
159
- template "#{options[:tech]}.tt", File.join(essence_options[:path], path, names[:name], names[:name] + BEM[:techs][options[:tech].to_sym])
160
- else
161
- # You can customize this list of defaults. See on top of file.
162
- BEM[:default].each do |tech, extension|
163
- template "#{tech}.tt", File.join(essence_options[:path], path, names[:name], names[:name] + extension)
164
- end
165
- end
166
- end
167
-
168
- def remove_essence(essence_options, path)
169
-
170
- names = generate_names
171
-
172
- if options[:tech]
173
- destination = File.join(essence_options[:path], path, names[:name], names[:name] + BEM[:techs][options[:tech].to_sym])
174
- FileUtils.rm(destination)
175
- else
176
- destination = File.join(essence_options[:path], path, names[:name])
177
- FileUtils.rm_rf(destination)
178
- end
179
-
180
- puts "\e[0;31m remove\e[0m " + destination.to_s.gsub(Rails.root.to_s + "/", "")
181
- end
182
-
183
- def update_assets(name, path)
184
- BEM[:assets].each do |type, tech|
185
- asset = File.join(Rails.root, "app", "assets", type.to_s, "application" + tech[:ext])
186
- destination = [path, name, name + tech[:ext]].reject(&:empty?)
187
- line = "#{tech[:import]} #{File.join(destination)}#{tech[:postfix]}"
188
- File.open(asset, "a") do |f|
189
- f.write("\n" + line)
190
- end
191
- end
192
- end
193
-
194
- def cut_assets(name, path)
195
- BEM[:assets].each do |type, tech|
196
- asset = File.join(Rails.root, "app", "assets", type.to_s, "application" + tech[:ext])
197
- destination = [path, name, name + tech[:ext]].reject(&:empty?)
198
- line = "#{tech[:import]} #{File.join(destination)}#{tech[:postfix]}"
199
-
200
- # Open temporary file
201
- tmp = Tempfile.new("temp")
202
- # Write good lines to temporary file.
203
- open(asset, 'r').each do |l|
204
- tmp << l unless l.chomp == line || l.empty?
205
- end
206
- # Close tmp, or troubles ahead.
207
- tmp.close
208
- # Temp to original.
209
- FileUtils.mv(tmp.path, asset)
210
- end
211
- end
212
-
213
- def search_usage_information(essence, path)
214
- BEM[:usage].each do |tech, extension|
215
- file_destination = File.join(BEM[:blocks][:path] + path, essence, essence + extension)
216
- if File.exist?(file_destination)
217
- puts tech.to_s + ": " + file_destination
218
- puts "BEM[:usage]:\t"
219
- File.readlines(file_destination).each do |line|
220
- puts line
221
- end
222
- end
223
- end
224
- end
225
-
226
- def print_blocks_list(essence="", path)
227
- directory_destination = File.join(BEM[:blocks][:path] + path, essence)
228
- puts directory_destination
229
- print_message("BEM[:blocks]:\t", 'green')
230
- Dir[directory_destination + "/*"].each do |name|
231
- # Show only essences. No files. No groups.
232
- # Essences have't ext.
233
- # Get dir name.
234
- name = name.split('/')[-1]
235
- if name.split('.').size == 1
236
- puts " - " + name
237
- end
238
- end
239
- end
240
-
241
- def print_elements_list(essence="", path)
242
- directory_destination = File.join(BEM[:blocks][:path] + path, essence, BEM[:elements][:dir])
243
- print_message("BEM[:elements]:\t", 'purple')
244
- Dir[directory_destination + "/*"].each do |name|
245
- # Get dir name.
246
- name = name.split('/')[-1]
247
- puts " - " + name.split(BEM[:elements][:prefix])[1]
248
- end
249
- end
250
-
251
- def print_mods_list(essence="", path)
252
- directory_destination = File.join(BEM[:blocks][:path] + path, essence, BEM[:mods][:dir])
253
- print_message("BEM[:mods]:\t", 'cyan')
254
- Dir[directory_destination + "/*"].each do |name|
255
- # Get dir name.
256
- name = name.split('/')[-1]
257
- puts " - " + name.split(BEM[:mods][:prefix])[1]
258
- end
259
- end
260
-
261
- def print_values_list(essence="", path)
262
- directory_destination = File.join(BEM[:blocks][:path] + path, essence)
263
- print_message("VALUES:\t", 'yellow')
264
- Dir[directory_destination + "/*"].each do |name|
265
- # Get dir name.
266
- name = name.split('/')[-1]
267
- puts " - " + name.split(BEM[:mods][:prefix])[1]
268
- end
269
- end
270
-
271
- def print_message(message, color)
272
- check_argument_data_type(message, String)
273
- check_argument_data_type(color, String)
274
-
275
- color = case color
276
- when 'green' then "\e[0;32m"
277
- when 'red' then "\e[0;31m"
278
- when 'blue' then "\e[0;34m"
279
- when 'cyan' then "\e[0;36m"
280
- when 'purple' then "\e[0;35m"
281
- when 'yellow' then "\e[1;33m"
282
- else ''
283
- end
124
+ FileUtils.mv(tmp.path, asset)
125
+ end
126
+ end
284
127
 
285
- puts "#{color + message} \e[0m"
286
- end
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
287
186
 
288
- def check_argument_data_type(argument, type)
289
- raise print_message("#{argument} must be a #{type.to_s}", 'red') unless argument.kind_of? type
290
- end
291
- end
187
+ end