class GemTemplate::Engine
Constants
- STRUCT
Public Class Methods
new(params = {})
click to toggle source
# File lib/gem-template/engine.rb, line 79 def initialize(params = {}) # Required params # :rbgem_name => 'mruby-hogehoge', # :license => 'MIT', # :github_user => 'matsumoto-r', # Optional params (auto complete from Required data) # :rbgem_prefix => '.', # :rbgem_type => 'class', # not yet # :class_name => 'Hogehoge', # :author => 'mruby-hogehoge developers', raise "Base is empty" unless params[:base] @base = params[:base] @modname = params[:name].camelize @gemname = params[:name].underscore.to_sym @params = params @params.merge!(mod_name: @modname, gem_name: @gemname) @params.merge!(git_parameters) @render = Render.new(@params) #raise "gem_name is nil" if params[:rbgem_name].nil? end
Public Instance Methods
bin?()
click to toggle source
# File lib/gem-template/engine.rb, line 187 def bin? !!@params[:with_bin] end
bundle?()
click to toggle source
# File lib/gem-template/engine.rb, line 191 def bundle? !@params[:no_bundle] end
cra(lop=STRUCT,path=[])
click to toggle source
# File lib/gem-template/engine.rb, line 104 def cra(lop=STRUCT,path=[]) lop.each do |index| if index[:type] == 'folder' && index.has_key?(:sub) path << index[:name] % @gemname pat = File.join(@base,path) if File.exists?(pat) puts "\033[33mexisting folder: #{pat}\033[0m" else FileUtils.mkdir_p(pat) puts "\033[32mcreating folder: #{pat}\033[0m" end pt = path.dup path = [] cra(index[:sub],pt) unless @deep_skip else if index[:type] == 'folder' path << index[:name] pat = File.join(path) FileUtils.mkdir_p(pat) end if index[:type] == 'file' pch = path.dup pch << index[:name] % @gemname pat = File.join(@base,pch) if File.exist?(pat) puts "\033[33mexisting file: #{pat}\033[0m" else FileUtils.touch(pat) puts "\033[32mcreating file: #{pat}\033[0m" end if File.zero?(pat) puts "\033[32m > filling file\033[0m" File.write(pat, self.send(index[:content])) end if index[:mode] puts "\033[32m > chmod file to #{index[:mode]}\033[0m" File.chmod(index[:mode], pat) end end end end end
create(&block)
click to toggle source
# File lib/gem-template/engine.rb, line 147 def create(&block) cra puts print_next end
ext?()
click to toggle source
# File lib/gem-template/engine.rb, line 184 def ext? !!@params[:with_ext] end
git_exec(cmd)
click to toggle source
# File lib/gem-template/engine.rb, line 171 def git_exec(cmd) `cd #{@base};git #{cmd}` end
git_parameters()
click to toggle source
# File lib/gem-template/engine.rb, line 195 def git_parameters usr = `git config user.name`.chomp mail = `git config user.email`.chomp {git_user: usr, git_mail: mail} end
inprint(text)
click to toggle source
# File lib/gem-template/engine.rb, line 175 def inprint(text) puts "\n\t > #{text}" end
inprintl(text)
click to toggle source
# File lib/gem-template/engine.rb, line 179 def inprintl(text) print "\r" print "\t > #{text}" end
print_next()
click to toggle source
# File lib/gem-template/engine.rb, line 152 def print_next if bundle? inprintl "Running bundler" `cd #{@base} && bundle install` inprintl "\033[32mBundler complete\033[0m" end puts if File.exists?(File.join(@base, '.git')) inprintl "\033[33mNot executing git init\033[0m" else inprintl "\033[32mExecuting git init\033[0m" git_exec("init .") git_exec("add .") git_exec("commit -am 'initial import'") end inprint "Next create a repository on GitHub" end
Private Instance Methods
method_missing(name, *args)
click to toggle source
fill methods
# File lib/gem-template/engine.rb, line 204 def method_missing(name, *args) file = File.expand_path("../templates/#{name}",__FILE__) if File.exists?(file) @render.render(File.read(file)) else if self.respond_to?(name) self.send(name, *args) else raise NoMethodError end end end