module Momaker

Constants

VERSION

Public Class Methods

create_module(dir, name) click to toggle source
# 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) click to toggle source
# File lib/momaker.rb, line 17
def self.create_module_directory(path)
  FileUtils::mkdir_p(path)
end
hyphenize(str) click to toggle source
# 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) click to toggle source
# 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