Module: RedmineCLI::Helpers::Output

Overview

Helpers for output

Instance Method Summary collapse

Instance Method Details

#erb(template, vars = {}) ⇒ Object

Alias for TemplateRenderer#render



31
32
33
# File 'lib/redmine_cli/helpers/output.rb', line 31

def erb(template, vars = {})
  RedmineCLI::TemplateRenderer.render(template, vars)
end

#message(name, params = {}) ⇒ Object Also known as: m

Gets text from I18n and replaces params e.g.

I18n.t(:hello) => 'Hello, {{ user }}'
message(:hello, user: 'Vasya') => 'Hello, Vasya'

Parameters:

  • name (Symbol)
  • params (Hash) (defaults to: {})

    optional



44
45
46
47
48
# File 'lib/redmine_cli/helpers/output.rb', line 44

def message(name, params = {})
  result = I18n.t name
  params.each { |k, e| result.gsub!("{{ #{k} }}", e.to_s) }
  result
end

for Helpers::Input.

Prints keys of ‘list` and `value.name`

Parameters:

  • list (Hash)


14
15
16
17
# File 'lib/redmine_cli/helpers/output.rb', line 14

def print_object_list(list)
  key_max_len = list.keys.map { |key| key.to_s.size }.max
  list.each { |k, v| puts "#{k.to_s.ljust(key_max_len)} - #{v.name}" }
end

for Helpers::Input



22
23
24
25
26
# File 'lib/redmine_cli/helpers/output.rb', line 22

def print_prompt_message(text, params = {})
  print text
  print "[#{params[:default]}] " if params.key? :default
  print "(#{params[:limited_to].join(', ')}) " if params[:limited_to].is_a? Array
end