Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

easy_table

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

easy_table

  • 0.0.10
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

EasyTable

Gem Version Build Status endorse

EasyTable provides a helper for building HTML tables in Rails applications.

It is inspired by simple_form gem: https://github.com/plataformatec/simple_form

Installation

Add this line to your application's Gemfile:

gem "easy_table"

And then execute:

$ bundle

Usage

For a working Rails 4.2 sample code see: cthulhu666/easy_table_sample

All examples below assume that You are using Haml. Please, use Haml !

Simplest example

= table_for(@people) do |t|
  - t.column :name
  - t.column :surname

This produces:

%table
  %thead
    %tr
      %th name
      %th surname
  %tbody
    %tr#person-1
      %td John
      %td Doe

Assuming @people is a collection consisting of one record, person with id = 1, John Doe

Simple example

= table_for(@people, class: 'people') do |t|
  - t.column :name, class: 'name' do |person|
    - person.name.downcase 
  - t.column :surname, class: lambda { |person| ['surname', person.surname.length > 5 && 'long'].compact } do |person|
    - person.surname.upcase

This produces:

%table.people
  %thead
    %tr
      %th name
      %th surname
  %tbody
    %tr#person-1
      %td.name john
      %td.surname DOE
    %tr#person-2
      %td.name alice
      %td.surname.long COOPER

Assuming @people is a collection consisting of two records:

  • person with id = 1, John Doe
  • person with id = 2, Alice Cooper

Example with more complex table structure

= table_for(@people) do |t|
  - t.span 'personal data' do |s|
    - s.column :name
    - s.colunm :surname
  - t.span 'contact data' do |s|
    - s.column :email
    - s.column :phone

This produces:

%table
  %thead
    %tr
      %th{colspan: 2, scope: 'col'} personal data
      %th{colspan: 2, scope: 'col'} contact data
    %tr
      %th name
      %th surname
      %th email
      %th phone
  %tbody
    %tr#person-1
      %td John
      %td Doe
      %td john.doe@gmail.com
      %td 123456789    

I18n and column headers

en:
  easy_table:
    person: # this is matched based on controller_name.singularize
      name: 'Name'
      surname: 'Surname'

With following form definition

= table_for(@people) do |t|
  - t.column :name
  - t.column :surname

It will use 'Name' and 'Surname' as column header labels:

%table
  %thead
    %tr
      %th Name
      %th Surname

You can also explicitly set column header passing it as a second argument to column and span methods:

= table_for(@people) do |t|
  - t.column :name, 'Name'
  - t.column :surname, 'Surname'

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

FAQs

Package last updated on 18 Jul 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc