Sha256: 5dbf8981e8caac4af06f6cfb35824c4e8917c20bd566910c9ee47590f9a667b5

Contents?: true

Size: 832 Bytes

Versions: 14

Compression:

Stored size: 832 Bytes

Contents

#!/usr/bin/env ruby

require 'rubygems'
require 'json'

def tag(name, content)
  "<#{name}>#{content}</#{name}>"
end

def row(name, array)
  array.map do |value|
    tag(name, value)
  end * ' '
end

table_header = false

puts '
<style>
tr:nth-child(even) {
  background-color: whitesmoke;
}
th {
    background: darkgray;
    font-color: white;
    padding: 1mm;
}
td {
    padding: 1mm;
}
</style>
'

STDIN.each_line do |line|
  begin
    object           = JSON.parse(line)
    unless table_header
      puts '<table>'
      table_header_row = row('th', object.keys.sort)
      puts tag('tr', table_header_row)
      table_header = true
    end
    copy = object.keys.sort.map do |key|
      object[key]
    end
    table_body_row = row('td', copy)
    puts tag('tr', table_body_row)
  rescue => error
  end
end

puts '</table>'

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
ix-cli-0.0.27 bin/ix-json-to-html-table-2
ix-cli-0.0.26 bin/ix-json-to-html-table-2
ix-cli-0.0.25 bin/ix-json-to-html-table-2
ix-cli-0.0.24 bin/ix-json-to-html-table-2
ix-cli-0.0.23 bin/ix-json-to-html-table-2
ix-cli-0.0.22 bin/ix-json-to-html-table-2
ix-cli-0.0.21 bin/ix-json-to-html-table-2
ix-cli-0.0.20 bin/ix-json-to-html-table-2
ix-cli-0.0.19 bin/ix-json-to-html-table-2
ix-cli-0.0.18 bin/ix-json-to-html-table-2
ix-cli-0.0.17 bin/ix-json-to-html-table-2
ix-cli-0.0.16 bin/ix-json-to-html-table-2
ix-cli-0.0.15 bin/ix-json-to-html-table-2
ix-cli-0.0.14 bin/ix-json-to-html-table-2