https://github.com/akicho8/html_format
A small library that easily converts various objects to HTML
https://github.com/akicho8/html_format
activerecord converter formatter html ruby
Last synced: 12 months ago
JSON representation
A small library that easily converts various objects to HTML
- Host: GitHub
- URL: https://github.com/akicho8/html_format
- Owner: akicho8
- License: mit
- Created: 2017-09-17T05:16:37.000Z (almost 9 years ago)
- Default Branch: main
- Last Pushed: 2023-04-16T06:51:42.000Z (about 3 years ago)
- Last Synced: 2025-01-12T18:13:18.302Z (over 1 year ago)
- Topics: activerecord, converter, formatter, html, ruby
- Language: Ruby
- Homepage:
- Size: 83 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.org
- License: LICENSE.txt
Awesome Lists containing this project
README
* html_format
- http://github.com/akicho8/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
#+BEGIN_SRC shell-script
$ gem install html_format
#+END_SRC
Or install within application using Gemfile
#+BEGIN_SRC shell-script
$ bundle add html_format
$ bundle install
#+END_SRC
** EXAMPLES
*** Using to_html is easiest
#+BEGIN_SRC ruby
#+BEGIN_SRC ruby
# 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 # => "
idnamecreated_at1alice2000-01-012bob2000-01-023carol2000-01-03"
# Hash
{id: 1, name: "alice", created_at: "2000-01-01"}.to_html # => "
id1namealicecreated_at2000-01-01"
# Array of Array
[
[1, "alice", "2000-01-01"],
[2, "bob", "2000-01-02"],
[3, "carol", "2000-01-03"],
].to_html # => "
1alice2000-01-012bob2000-01-023carol2000-01-03"
# Array
[0, 1, 2, 3].to_html # => "
0123"
#+END_SRC
*** The html_format method feels like simple_format
#+BEGIN_SRC ruby
html_format(1) # => "
1"
#+END_SRC
** How to check by visual inspection during development
#+BEGIN_SRC sh
cd test/dummy
rails s
open http://localhost:3000/
#+END_SRC
** When combined with Rails and bootstrap
app/assets/stylesheets/application.css
#+BEGIN_SRC css
/*
*= require html_format/control
*/
#+END_SRC