# Author:: Eric Crane (mailto:eric.crane@mac.com) # Copyright:: Copyright (c) 20124 Eric Crane. All rights reserved. # # A helper class used to render HTML tables. # module Gloo module WebSvr class TableRenderer TABLE = 'table'.freeze THEAD = 'thead'.freeze HEAD_CELL = 'head_cell'.freeze ROW = 'row'.freeze CELL = 'cell'.freeze # --------------------------------------------------------------------- # Initialization # --------------------------------------------------------------------- # # Set up the web server. # def initialize( engine ) @engine = engine @log = @engine.log end # --------------------------------------------------------------------- # Container Renderer # --------------------------------------------------------------------- # # Render the query result set to an HTML table. # # params = { # head: head, # cols: result[0], # rows: rows, # styles: self.styles, # cell_renderers: self.cell_renderers # } # def data_to_table params data = params[ :rows ] if data.nil? || ( data.length == 0 ) return "
No data found.
" elsif data.length == 1 return data_to_single_row_table( params ) else return data_to_table_rows( params ) end end # # Show in single-row (form) format. # def data_to_single_row_table( params ) styles = params[ :styles ] str = "#{head[ :title ]} | " str += "#{cell_value} | " str += "
---|
#{head[ :title ]} | " end str << "
---|
#{cell_value} | " end str += "