0.0
Low commit activity in last 3 years
No release in over a year
A small library that easily converts various objects to HTML.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme

html_format

DESCRIPTION

HTML conversion of various objects easily. Since it is not limited as a helper of Rails, it can be used singly and anywhere.

INSTALL

Install as a standalone gem

$ gem install html_format

Or install within application using Gemfile

$ bundle add html_format
$ bundle install

EXAMPLES

Using to_html is easiest

# Array of Hash
[
  {id: 1, name: "alice", created_at: "2000-01-01"},
  {id: 2, name: "bob",   created_at: "2000-01-02"},
  {id: 3, name: "carol", created_at: "2000-01-03"},
].to_html # => "<div class=\"html_format html_format_depth_0\"><table class=\"table html_format_type_array_of_hash\"><thead><tr><th>id</th><th>name</th><th>created_at</th></tr></thead><tbody><tr><td>1</td><td>alice</td><td>2000-01-01</td></tr><tr><td>2</td><td>bob</td><td>2000-01-02</td></tr><tr><td>3</td><td>carol</td><td>2000-01-03</td></tr></tbody></table></div>"

# Hash
{id: 1, name: "alice", created_at: "2000-01-01"}.to_html # => "<div class=\"html_format html_format_depth_0\"><table class=\"table html_format_type_hash\"><tr><th>id</th><td>1</td></tr><tr><th>name</th><td>alice</td></tr><tr><th>created_at</th><td>2000-01-01</td></tr></table></div>"

# Array of Array
[
  [1, "alice", "2000-01-01"],
  [2, "bob",   "2000-01-02"],
  [3, "carol", "2000-01-03"],
].to_html # => "<div class=\"html_format html_format_depth_0\"><table class=\"table html_format_type_array_of_array\"><tbody><tr><td>1</td><td>alice</td><td>2000-01-01</td></tr><tr><td>2</td><td>bob</td><td>2000-01-02</td></tr><tr><td>3</td><td>carol</td><td>2000-01-03</td></tr></tbody></table></div>"

# Array
[0, 1, 2, 3].to_html # => "<div class=\"html_format html_format_depth_0\"><table class=\"table html_format_type_array\"><tbody><tr><td>0</td><td>1</td><td>2</td><td>3</td></tr></tbody></table></div>"

The html_format method feels like simple_format

html_format(1) # => "<div class=\"html_format html_format_depth_0\"><table class=\"table html_format_type_object\"><tbody><tr><td>1</td></tr></tbody></table></div>"

How to check by visual inspection during development

cd test/dummy
rails s
open http://localhost:3000/

When combined with Rails and bootstrap

app/assets/stylesheets/application.css

/*
 *= require html_format/control
 */