Class: Lhj::Command::CodeTemplate

Inherits:
Lhj::Command
  • Object
show all
Defined in:
lib/lhj/command/code/code_template.rb

Constant Summary collapse

CODE_TEMPLATE_INDEX =
[{ name: 'dispatch Source 模板', template: 'dispatch_source.erb' },
{ name: '消息队列', template: 'message_query.erb' },
{ name: '代码模板', template: 'test.erb' }].freeze

Instance Method Summary collapse

Methods inherited from Lhj::Command

#auto_spin, #begin_title, #run, #stop

Constructor Details

#initialize(argv) ⇒ CodeTemplate

Returns a new instance of CodeTemplate.



11
12
13
14
# File 'lib/lhj/command/code/code_template.rb', line 11

def initialize(argv)
  @cli = HighLine.new
  super
end

Instance Method Details

#handleObject



16
17
18
19
20
21
22
23
24
25
# File 'lib/lhj/command/code/code_template.rb', line 16

def handle
  CODE_TEMPLATE_INDEX.each_index do |i|
    puts "#{i}.#{CODE_TEMPLATE_INDEX[i][:name]}".yellow
  end
  idx = @cli.ask('请选择查看代码模板: '.green).strip.to_i
  item = CODE_TEMPLATE_INDEX[idx]
  template_name = item[:template]
  template_str = render_template(template_name)
  puts template_str
end

#render_template(template_name) ⇒ Object



27
28
29
30
# File 'lib/lhj/command/code/code_template.rb', line 27

def render_template(template_name)
  temp = File.read(File.join(File.dirname(__FILE__), 'template', template_name))
  Lhj::ErbTemplateHelper.render(temp, nil, nil)
end