Module: StatusCat::StatusHelper
- Defined in:
- app/helpers/status_cat/status_helper.rb
Instance Method Summary collapse
- #status_cell(status) ⇒ Object
-
#status_header ⇒ Object
Constructs an HTML table header.
-
#status_report(checkers) ⇒ Object
Constructs a text status report.
-
#status_report_format(checkers) ⇒ Object
Generate a format string to justify all values.
-
#status_report_header(format = StatusCat::Checkers::Base::FORMAT) ⇒ Object
Generate a header string.
-
#status_row(checker) ⇒ Object
Constructs an HTML table row.
-
#status_style(checker) ⇒ Object
Returns an HTML style for the status table cell.
-
#status_table(checkers) ⇒ Object
Returns an HTML table.
-
#status_title ⇒ Object
Returns an HTML title.
Instance Method Details
#status_cell(status) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'app/helpers/status_cat/status_helper.rb', line 23 def status_cell( status ) if status.kind_of?(Array) list = status.map { |s| content_tag( :li, s ) } status = content_tag( :ul, list.join.html_safe ) end return content_tag( :td, status ) end |
#status_header ⇒ Object
Constructs an HTML table header
5 6 7 8 9 10 11 |
# File 'app/helpers/status_cat/status_helper.rb', line 5 def status_header content_tag( :tr ) do concat content_tag( :th, t( :name, :scope => :status_cat ) ) concat content_tag( :th, t( :value, :scope => :status_cat ) ) concat content_tag( :th, t( :status, :scope => :status_cat ) ) end end |
#status_report(checkers) ⇒ Object
Constructs a text status report
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/helpers/status_cat/status_helper.rb', line 55 def status_report( checkers ) format, format_length = status_report_format( checkers ) header = status_report_header( format ) length = [ format_length, header.length ].max separator = ( '-' * length ) + "\n" result = separator + header + separator checkers.each { |checker| result << checker.to_s( format ) } result << separator return result end |
#status_report_format(checkers) ⇒ Object
Generate a format string to justify all values
70 71 72 73 74 75 76 77 78 79 |
# File 'app/helpers/status_cat/status_helper.rb', line 70 def status_report_format( checkers ) name_max = checkers.map { |c| c.name.to_s.length }.max value_max = checkers.map { |c| c.value.to_s.length }.max status_max = checkers.map { |c| c.status.to_s.length }.max format = "%#{name_max}s | %#{value_max}s | %#{status_max}s\n" length = name_max + 3 + value_max + 3 + status_max return format, length end |
#status_report_header(format = StatusCat::Checkers::Base::FORMAT) ⇒ Object
Generate a header string
83 84 85 86 87 88 |
# File 'app/helpers/status_cat/status_helper.rb', line 83 def status_report_header( format = StatusCat::Checkers::Base::FORMAT ) name = I18n.t( :name, :scope => :status_cat ) value = I18n.t( :value, :scope => :status_cat ) status = I18n.t( :status, :scope => :status_cat ) return sprintf( format, name, value, status ) end |
#status_row(checker) ⇒ Object
Constructs an HTML table row
15 16 17 18 19 20 21 |
# File 'app/helpers/status_cat/status_helper.rb', line 15 def status_row( checker ) content_tag( :tr ) do concat content_tag( :td, checker.name, :style => status_style( checker ) ) concat content_tag( :td, checker.value ) concat status_cell(checker.status || t( :ok, :scope => :status_cat )) end end |
#status_style(checker) ⇒ Object
Returns an HTML style for the status table cell
34 35 36 |
# File 'app/helpers/status_cat/status_helper.rb', line 34 def status_style( checker ) "background-color: #{checker.status.nil? ? :green : :red}" end |
#status_table(checkers) ⇒ Object
Returns an HTML table
40 41 42 43 44 45 |
# File 'app/helpers/status_cat/status_helper.rb', line 40 def status_table( checkers ) content_tag( :table, :border => 1 ) do concat status_header checkers.each { |checker| concat status_row( checker ) } end end |
#status_title ⇒ Object
Returns an HTML title
49 50 51 |
# File 'app/helpers/status_cat/status_helper.rb', line 49 def status_title content_tag( :h1, t( :h1, :scope => :status_cat ) ) end |