Sha256: c6a1a6c92fb5ed474b70e5344fc506f4dd93f64e058b8375d90fd3531f81b015

Contents?: true

Size: 1.99 KB

Versions: 5

Compression:

Stored size: 1.99 KB

Contents

module RailsDb
  module Helpers
    # TODO check styles
    STYLES = {
      default: {
        table: 'table',
        tr: 'table_tr',
        th: 'table_th',
        td: 'table_td',
        thead: 'table_thead',
        tfoot: 'table_tfoot'
      },
      bootstrap: {
        table: 'table table-bordered table-striped table-hover',
        tr: 'table_tr',
        th: 'table_th',
        td: 'table_td',
        thead: 'table_thead',
        tfoot: 'table_tfoot'
      },
      foundation: {
        table: 'table',
        tr: 'table_tr',
        th: 'table_th',
        td: 'table_td',
        thead: 'table_thead',
        tfoot: 'table_tfoot'
      }
    }

    def rails_db_data_table(table_name, options = {})
      options.reverse_merge!(
        style: :default,
        header: true,
        footer: false,
        columns: [],
        limit: nil,
        order_by: nil,
        order: :asc
      )
      table = RailsDb::Table.new(table_name)
        .limit(options[:limit])
        .order_by(options[:order_by])
        .select(options[:columns])
        .order(options[:order])

      render '/rails_db/shared/data_table', table: table,
                                            header: options[:header],
                                            footer: options[:footer],
                                            style:  options[:style]
    end

    def rails_db_data_table_sql(sql, options = {})
      options.reverse_merge!(
        style: :default,
        header: true,
        footer: false,
      )
      sql        = "#{sql}".strip
      sql_query  = RailsDb::SqlQuery.new(sql, false).execute

      render '/rails_db/shared/sql_result', sql_query: sql_query,
                                            header: options[:header],
                                            footer: options[:footer],
                                            style:  options[:style]
    end

    def rails_db_table_style(tag, style)
      style = STYLES[style] || STYLES[:default]
      style[tag.to_sym]
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rails_db-2.4.5 lib/rails_db/helpers.rb
rails_db-2.4.4 lib/rails_db/helpers.rb
rails_db-2.4.3 lib/rails_db/helpers.rb
rails_db-2.4.2 lib/rails_db/helpers.rb
rails_db-2.4.1 lib/rails_db/helpers.rb