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_format_max_length(checkers, column) ⇒ Object
-
#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
24 25 26 27 28 29 30 31 |
# File 'app/helpers/status_cat/status_helper.rb', line 24 def status_cell(status) if status.is_a?(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
6 7 8 9 10 11 12 |
# File 'app/helpers/status_cat/status_helper.rb', line 6 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
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/helpers/status_cat/status_helper.rb', line 56 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
71 72 73 74 75 76 77 78 79 80 |
# File 'app/helpers/status_cat/status_helper.rb', line 71 def status_report_format(checkers) name_max = status_report_format_max_length(checkers, :name) value_max = status_report_format_max_length(checkers, :value) status_max = status_report_format_max_length(checkers, :status) 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_format_max_length(checkers, column) ⇒ Object
82 83 84 |
# File 'app/helpers/status_cat/status_helper.rb', line 82 def status_report_format_max_length(checkers, column) return checkers.map { |c| c.send(column).to_s.length }.max end |
#status_report_header(format = StatusCat::Checkers::Base::FORMAT) ⇒ Object
Generate a header string
88 89 90 91 92 93 |
# File 'app/helpers/status_cat/status_helper.rb', line 88 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 format(format, name, value, status) end |
#status_row(checker) ⇒ Object
Constructs an HTML table row
16 17 18 19 20 21 22 |
# File 'app/helpers/status_cat/status_helper.rb', line 16 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
35 36 37 |
# File 'app/helpers/status_cat/status_helper.rb', line 35 def status_style(checker) "background-color: #{checker.status.nil? ? :green : :red}" end |
#status_table(checkers) ⇒ Object
Returns an HTML table
41 42 43 44 45 46 |
# File 'app/helpers/status_cat/status_helper.rb', line 41 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
50 51 52 |
# File 'app/helpers/status_cat/status_helper.rb', line 50 def status_title content_tag(:h1, t(:h1, scope: :status_cat)) end |