Class: GeditSnippetsTool::Commands
- Inherits:
-
Object
- Object
- GeditSnippetsTool::Commands
- Defined in:
- lib/gedit_snippets_tool.rb
Instance Method Summary collapse
Instance Method Details
#execute(args) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/gedit_snippets_tool.rb', line 10 def execute(args) command = args.shift.strip rescue '--help' if %w(-h --help).include? command show_help elsif %w(-v --version).include? command puts "#{File.basename($0)} #{VERSION}" elsif %w(-cs --cheat-sheet).include? command generate_cheat_sheet args[0] else puts "Unknow command '#{command}'" puts "" show_help end end |
#generate_cheat_sheet(snippet_name = nil) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/gedit_snippets_tool.rb', line 37 def generate_cheat_sheet(snippet_name=nil) hash_of_snippets = Snippet.all(snippet_name) input = File.read(File.(File.dirname(__FILE__) + "/../template/template.eruby")) eruby = Erubis::EscapedEruby.new(input) # create Eruby object ## create context object ## (key means var name, which may be string or symbol.) context = { :hash_of_snippets => hash_of_snippets } puts eruby.evaluate(context) # get result end |
#show_help ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/gedit_snippets_tool.rb', line 26 def show_help puts "Usage: #{File.basename($0)} [OPTION]" puts "Tool to generate cheat sheet of gedit's snippets" puts "" puts "Valid options:" puts "-cs, --cheat-sheet\tcreate cheat sheet of yours gedit's snippets" puts "-h, --help\tshow this help" puts "-v, --version\tshow #{File.basename($0)}'s version" puts "" end |