./bin/cli/generate.rb in lux-fw-0.5.37 vs ./bin/cli/generate.rb in lux-fw-0.6.2

- old
+ new

@@ -6,23 +6,20 @@ module LuxGenerate extend self def generate object=nil, objects=nil - unless object - puts "./generate [object singular]".red - exit - end + Cli.die "./generate [object singular]" unless object template_dir = 'config/templates' - exit puts "Lux::View dir #{template_dir} is not accessible" unless Dir.exists?(template_dir) + Cli.die "Lux::Template dir #{template_dir} is not accessible" unless Dir.exist?(template_dir) tpl_desc = { p:'api', m:'model', a:'admin', - c:'cell', + c:'controller', v:'view' } @object = object @objects = objects || @object.pluralize @@ -32,10 +29,11 @@ def parse_vars(data) object = @object objects = @objects klass = @object.classify + klasses = klass.pluralize data.gsub(/\{\{([^\}]+)\}\}/) { eval $1 } end # get all files @@ -55,34 +53,34 @@ templates[type] ||= [] templates[type].push [path, data] end - # # puts "Lux::Views : #{templates.keys.sort.map{ |el| tpl_desc[el.to_sym] ? tpl_desc[el.to_sym].sub(el, el.upcase.yellow) : el.yellow }.join(', ')}" - puts "Lux::Views : #{templates.keys.map{ |el| "#{tpl_desc[el.to_sym]}(#{el.yellow})" }.join(', ')}" + # # puts "Lux::Templates : #{templates.keys.sort.map{ |el| tpl_desc[el.to_sym] ? tpl_desc[el.to_sym].sub(el, el.upcase.yellow) : el.yellow }.join(', ')}" + puts "Templates : #{templates.keys.map{ |el| "#{tpl_desc[el.to_sym]}(#{el.yellow})" }.join(', ')}" print "Execute : " parse_templates = STDIN.gets.chomp for type in templates.keys next unless parse_templates.index(type) for el in templates[type] file, data = *el - if File.exists?(file) + if File.exist?(file) print 'exists'.yellow.rjust(20) else FileUtils.mkdir_p(file.sub(/\/[^\/]+$/,'')) rescue false File.open(file, 'w') { |f| f.write(data) } print 'created'.green.rjust(20) end - puts ": #{file}" + puts " #{file}" end end end end LuxCli.class_eval do desc :generate, 'Genrate models, cells, ...' def generate object, objects=nil LuxGenerate.generate object, objects end -end \ No newline at end of file +end