Module: ActionsHelper

Defined in:
app/helpers/actions_helper.rb

Instance Method Summary collapse

Instance Method Details

#_add_white_space(json) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/helpers/actions_helper.rb', line 21

def _add_white_space(json)
  scanner = StringScanner.new(json)
  output = ""
  indent = 0
  until scanner.eos?
    match = scanner.scan(/(?:[\[\]\{\}":,]|[^\[\]\{\}":,]+)/)
    case match
    when "{", "["
      indent += 2
      output << "#{match}\n#{" " * indent}"
    when "}", "]"
      indent -= 2
      output << "\n#{" " * indent}#{match}"
    when "\""
      # hopefully this grabs the entire string
      output << "\"" << scanner.scan(/.*?(?<!\\)"/)
    when ":"
      output << ": "
    when ","
      output << ",\n#{" " * indent}"
    else
      output << match
    end
  end
  output
end

#format_action_params(params) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/helpers/actions_helper.rb', line 3

def format_action_params(params)
  return "<pre>{}</pre>".html_safe if params == {}
  "    <div class=\"action-params-short\">\n      <pre>{ \#{params.keys.map(&:inspect).join(\", \")} }</pre>\n    </div>\n    <div class=\"action-params-full modal\">\n      <div class=\"modal-header\">\n        <button type=\"button\" class=\"close\" data-dismiss=\"modal\" aria-hidden=\"true\">&times;</button>\n        <h3><code>{ \#{params.keys.map(&:inspect).join(\", \")} }</code></h3>\n      </div>\n      <div class=\"modal-body\">\n        <pre>\#{_add_white_space Houston::ParamsSerializer.new.dump(params)}</pre>\n      </div>\n    </div>\n  HTML\nend\n".html_safe

#format_action_state(action) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
# File 'app/helpers/actions_helper.rb', line 48

def format_action_state(action)
  if !action.started?
    '&mdash;'.html_safe
  elsif action.in_progress?
    '<i class="fa fa-spinner fa-pulse"></i>'.html_safe
  elsif action.succeeded?
    '<i class="fa fa-check success"></i>'.html_safe
  else
    '<i class="fa fa-times failure"></i>'.html_safe
  end
end