Sha256: 6e43df95049cdf11d1b87b5c12241d65d8cbc0d111fe015725f825e7a9d65a43

Contents?: true

Size: 1.03 KB

Versions: 5

Compression:

Stored size: 1.03 KB

Contents

module ActionsHelper

  def format_action_params(params)
    return "<pre>{}</pre>".html_safe if params == {}
    <<-HTML.html_safe
      <div class="action-params-short">
        <pre>{ #{params.keys.map(&:inspect).join(", ")} }</pre>
      </div>
      <div class="action-params-full">
        <pre>#{_add_white_space Houston::ParamsSerializer.new.dump(params)}</pre>
      </div>
    HTML
  end

  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

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
houston-core-0.8.1 app/helpers/actions_helper.rb
houston-core-0.8.0 app/helpers/actions_helper.rb
houston-core-0.8.0.pre2 app/helpers/actions_helper.rb
houston-core-0.8.0.pre app/helpers/actions_helper.rb
houston-core-0.7.0 app/helpers/actions_helper.rb