Module: Momaker
- Defined in:
- lib/momaker.rb,
lib/momaker/version.rb
Constant Summary collapse
- VERSION =
"0.0.4"
Class Method Summary collapse
- .create_module(dir, name) ⇒ Object
- .create_module_directory(path) ⇒ Object
- .hyphenize(str) ⇒ Object
- .start(command, module_type, module_name, remaining_arguments) ⇒ Object
Class Method Details
.create_module(dir, name) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/momaker.rb', line 21 def self.create_module(dir, name) File.open("#{dir}/_#{name}.scss", "w+") do |file| # Block file.write(".#{name} {}" + "\n\n") if @module_submodules.length # Elements @module_submodules.each do |submodule| file.write(".#{name}__#{submodule[:element]} {}") file.write("\n\n") # Modifiers submodule[:modifiers].each do |modifier| file.write(".#{name}__#{submodule[:element]}--#{modifier} {}") file.write("\n\n") end end end end end |
.create_module_directory(path) ⇒ Object
17 18 19 |
# File 'lib/momaker.rb', line 17 def self.create_module_directory(path) FileUtils::mkdir_p(path) end |
.hyphenize(str) ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'lib/momaker.rb', line 7 def self.hyphenize(str) str.gsub(/::/, '/') .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') .gsub(/([a-z\d])([A-Z])/, '\1_\2') .tr("_", "-") .tr(" ", "-") .downcase! str end |
.start(command, module_type, module_name, remaining_arguments) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/momaker.rb', line 43 def self.start(command, module_type, module_name, remaining_arguments) @module_name = hyphenize(module_name) @module_submodules = [] if remaining_arguments remaining_arguments.each do |argument| argument_array = argument.split("+") element = argument_array[0] puts "+ #{element}" if argument_array[1] modifiers = argument_array[1].split(",") modifiers.each { |m| puts " = #{m}" } end puts "\n" @module_submodules.push({ :element => element, :modifiers => modifiers }) end end if command.downcase == "generate" || command.downcase == "g" puts "Create #{module_type} called #{@module_name}? Y/N" print "> " if STDIN.gets.chomp().downcase == "y" module_path = "#{@config_options[:path]}/#{module_type}" if module_path create_module_directory(module_path) if create_module(module_path, @module_name) puts "Generated your new module:" puts "#{module_path}/_#{@module_name}.scss" end end end end end |