https://github.com/akicho8/org_tp
OrgTp shows text table like emacs org-table for easy reading.
https://github.com/akicho8/org_tp
debug emacs formatter org-table ruby table
Last synced: 9 months ago
JSON representation
OrgTp shows text table like emacs org-table for easy reading.
- Host: GitHub
- URL: https://github.com/akicho8/org_tp
- Owner: akicho8
- Archived: true
- Created: 2017-08-05T13:23:46.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2018-06-27T08:08:47.000Z (almost 8 years ago)
- Last Synced: 2024-04-25T16:43:18.298Z (about 2 years ago)
- Topics: debug, emacs, formatter, org-table, ruby, table
- Language: Ruby
- Homepage:
- Size: 67.4 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.org
Awesome Lists containing this project
README
* OrgTp
OrgTp shows text table like emacs org-table for easy reading.
#+BEGIN_SRC ruby
tp Object.constants.grep(/RUBY_/).map { |e| [e, Object.const_get(e)] }.to_h
# >> |---------------------+------------------------------------------------------------|
# >> | RUBY_VERSION | 2.5.0 |
# >> | RUBY_RELEASE_DATE | 2017-12-25 |
# >> | RUBY_PLATFORM | x86_64-darwin16 |
# >> | RUBY_PATCHLEVEL | 0 |
# >> | RUBY_DESCRIPTION | ruby 2.5.0p0 (2017-12-25 revision 61468) [x86_64-darwin16] |
# >> | RUBY_ENGINE | ruby |
# >> | RUBY_REVISION | 61468 |
# >> | RUBY_ENGINE_VERSION | 2.5.0 |
# >> | RUBY_COPYRIGHT | ruby - Copyright (C) 1993-2017 Yukihiro Matsumoto |
# >> |---------------------+------------------------------------------------------------|
#+END_SRC
** Installation
Install as a standalone gem
#+BEGIN_SRC shell-script
$ gem install org_tp
#+END_SRC
Or install within application using Gemfile
#+BEGIN_SRC shell-script
$ bundle add org_tp
$ bundle install
#+END_SRC
** Examples
*** Array of hash
#+BEGIN_SRC ruby
tp [{id: 1, name: 'alice'}, {id: 2, name: 'bob'}]
# >> |----+-------|
# >> | id | name |
# >> |----+-------|
# >> | 1 | alice |
# >> | 2 | bob |
# >> |----+-------|
#+END_SRC
*** Hash
#+BEGIN_SRC ruby
tp({id: 1, name: 'alice'})
# >> |------+-------|
# >> | id | 1 |
# >> | name | alice |
# >> |------+-------|
#+END_SRC
*** Array
#+BEGIN_SRC ruby
tp [:alice, :bob]
# >> |-------|
# >> | alice |
# >> | bob |
# >> |-------|
#+END_SRC
*** ActiveRecord or Mongoid
#+BEGIN_SRC ruby
['alice', 'bob'].each { |e| User.create!(name: e) }
#+END_SRC
#+BEGIN_SRC ruby
tp User
# >> |----+-------|
# >> | id | name |
# >> |----+-------|
# >> | 1 | alice |
# >> | 2 | bob |
# >> |----+-------|
#+END_SRC
#+BEGIN_SRC ruby
tp User.limit(1)
# >> |----+-------|
# >> | id | name |
# >> |----+-------|
# >> | 1 | alice |
# >> |----+-------|
#+END_SRC
#+BEGIN_SRC ruby
tp User.first
# >> |------+-------|
# >> | id | 1 |
# >> | name | alice |
# >> |------+-------|
#+END_SRC
**** ActiveRecord::Result
#+BEGIN_SRC ruby
tp ActiveRecord::Base.connection.select_all('SELECT * FROM users')
# >> |----+-------|
# >> | id | name |
# >> |----+-------|
# >> | 1 | alice |
# >> | 2 | bob |
# >> |----+-------|
#+END_SRC
** How to table as string
Use to_t method.
#+BEGIN_SRC ruby
puts [{id: 1, name: 'alice'}, {id: 2, name: 'bob'}].to_t
# >> |----+-------|
# >> | id | name |
# >> |----+-------|
# >> | 1 | alice |
# >> | 2 | bob |
# >> |----+-------|
#+END_SRC
** Options
Pass as the second argument to tp or the first argument to to_t.
#+BEGIN_SRC ruby
tp 1
# >> |---|
# >> | 1 |
# >> |---|
tp 1, intersection_both: '+'
# >> +---+
# >> | 1 |
# >> +---+
#+END_SRC
*** Markdown format example
=markdown: true= has the same meaning as =intersection: '|', cover: false=
#+BEGIN_SRC ruby
tp [{id: 1, name: 'alice'}, {id: 2, name: 'bob'}], markdown: true
# >> | id | name |
# >> |----|-------|
# >> | 1 | alice |
# >> | 2 | bob |
#+END_SRC
#+BEGIN_SRC ruby
tp [{id: 1, name: 'alice'}, {id: 2, name: 'bob'}], intersection: '|', cover: false
# >> | id | name |
# >> |----|-------|
# >> | 1 | alice |
# >> | 2 | bob |
#+END_SRC
** Global Options
#+BEGIN_SRC ruby
tp OrgTp.default_options
# >> |-------------------+-------|
# >> | markdown | false |
# >> | header | |
# >> | cover | true |
# >> | vertical | | |
# >> | intersection | + |
# >> | intersection_both | | |
# >> | horizon | - |
# >> | padding | |
# >> | in_code | UTF-8 |
# >> |-------------------+-------|
tp 1
# >> |---|
# >> | 1 |
# >> |---|
OrgTp.default_options[:intersection_both] = '+'
tp 1
# >> +---+
# >> | 1 |
# >> +---+
#+END_SRC