org_tp 0.0.9 → 0.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e57f2468252f682a1338ee3683762c47bc6885c8
4
- data.tar.gz: faa6355e08d36b09c233cdd9feb9d24fcac2a8c4
3
+ metadata.gz: 24a89757969e7d697fd02316826d970741ca7e86
4
+ data.tar.gz: b3defd4248ab8857dee375c8bbe9292ba0710962
5
5
  SHA512:
6
- metadata.gz: cf37326c8506fbb181552144cd87ec26eebf62078cf668fcc584a88c1b9aa098c12ef37a462e32a851102ab75d248a6e5858c5449779b6f5e9fe1ccd6617a940
7
- data.tar.gz: 7992e2f0d622b37f9142a8bc7a4451e1b895b19d9402782d4c55f126a78c84852172ec832930a32dbc3095e48e2cc6756acfc5d030209f9c90085c78745e2f2a
6
+ metadata.gz: 8bd700c2a93cf23059da0a34cead03da4d94635e397ae395e81e167f32e48be163c0f750a2fd274843ea47b952d2513df8d2dab9bff6242dec42c6ad59d707f4
7
+ data.tar.gz: 1d3ca465fd0aa29815399d37295ecda1ac23063b030d144c80e6aa87f07a636bc93858888cd24519d36c46d57ffe9b75f16ffb50378a3a2ffde76c9220ec2998
data/README.org CHANGED
@@ -151,6 +151,16 @@ tp 1, intersection_both: '+'
151
151
 
152
152
  *** Markdown format example
153
153
 
154
+ `markdown: true` has the same meaning as `intersection: '|', cover: false`
155
+
156
+ #+BEGIN_SRC ruby
157
+ tp [{id: 1, name: 'alice'}, {id: 2, name: 'bob'}], markdown: true
158
+ # >> | id | name |
159
+ # >> |----|-------|
160
+ # >> | 1 | alice |
161
+ # >> | 2 | bob |
162
+ #+END_SRC
163
+
154
164
  #+BEGIN_SRC ruby
155
165
  tp [{id: 1, name: 'alice'}, {id: 2, name: 'bob'}], intersection: '|', cover: false
156
166
  # >> | id | name |
@@ -164,7 +174,9 @@ tp [{id: 1, name: 'alice'}, {id: 2, name: 'bob'}], intersection: '|', cover: fal
164
174
  #+BEGIN_SRC ruby
165
175
  tp OrgTp.default_options
166
176
  # >> |-------------------+-------|
177
+ # >> | markdown | false |
167
178
  # >> | header | |
179
+ # >> | cover | true |
168
180
  # >> | vertical | | |
169
181
  # >> | intersection | + |
170
182
  # >> | intersection_both | | |
@@ -192,7 +204,7 @@ tp 1
192
204
  require 'tapp'
193
205
  require 'org_tp'
194
206
 
195
- "Hello".reverse.tapp.reverse.tapp
207
+ "Hello".reverse.tapp(:tp).reverse.tapp(:tp)
196
208
  # >> |-------|
197
209
  # >> | olleH |
198
210
  # >> |-------|
@@ -19,6 +19,8 @@ tp User
19
19
  tp User.first
20
20
  tp User.limit(1)
21
21
  tp ActiveRecord::Base.connection.select_all('SELECT * FROM users')
22
+ tp ActiveRecord::Base.connection.select_one('SELECT * FROM users')
23
+ tp ActiveRecord::Base.connection.select_value('SELECT 1 + 2')
22
24
  # >> |----+-------|
23
25
  # >> | id | name |
24
26
  # >> |----+-------|
@@ -42,3 +44,10 @@ tp ActiveRecord::Base.connection.select_all('SELECT * FROM users')
42
44
  # >> | 2 | bob |
43
45
  # >> | 3 | carol |
44
46
  # >> |----+-------|
47
+ # >> |------+-------|
48
+ # >> | id | 1 |
49
+ # >> | name | alice |
50
+ # >> |------+-------|
51
+ # >> |---|
52
+ # >> | 3 |
53
+ # >> |---|
@@ -11,7 +11,9 @@ tp OrgTp.default_options
11
11
  # >> | 1 |
12
12
  # >> +---+
13
13
  # >> |-------------------+-------|
14
+ # >> | markdown | false |
14
15
  # >> | header | |
16
+ # >> | cover | true |
15
17
  # >> | vertical | | |
16
18
  # >> | intersection | + |
17
19
  # >> | intersection_both | | |
@@ -20,7 +22,9 @@ tp OrgTp.default_options
20
22
  # >> | in_code | UTF-8 |
21
23
  # >> |-------------------+-------|
22
24
  # >> +-------------------+-------+
25
+ # >> | markdown | false |
23
26
  # >> | header | |
27
+ # >> | cover | true |
24
28
  # >> | vertical | | |
25
29
  # >> | intersection | + |
26
30
  # >> | intersection_both | + |
@@ -20,16 +20,16 @@ tp User.limit(1)
20
20
  # >> |--------------------------+-------|
21
21
  # >> | _id | name |
22
22
  # >> |--------------------------+-------|
23
- # >> | 598d9d05f6453f404a7a4c74 | alice |
24
- # >> | 598d9d06f6453f404a7a4c75 | bob |
25
- # >> | 598d9d06f6453f404a7a4c76 | carol |
23
+ # >> | 59bb8090f6453f365f93ddc3 | alice |
24
+ # >> | 59bb8090f6453f365f93ddc4 | bob |
25
+ # >> | 59bb8090f6453f365f93ddc5 | carol |
26
26
  # >> |--------------------------+-------|
27
27
  # >> |------+--------------------------|
28
- # >> | _id | 598d9d05f6453f404a7a4c74 |
28
+ # >> | _id | 59bb8090f6453f365f93ddc3 |
29
29
  # >> | name | alice |
30
30
  # >> |------+--------------------------|
31
31
  # >> |--------------------------+-------|
32
32
  # >> | _id | name |
33
33
  # >> |--------------------------+-------|
34
- # >> | 598d9d05f6453f404a7a4c74 | alice |
34
+ # >> | 59bb8090f6453f365f93ddc3 | alice |
35
35
  # >> |--------------------------+-------|
@@ -2,7 +2,7 @@ $LOAD_PATH << '../lib'
2
2
  require 'tapp'
3
3
  require 'org_tp'
4
4
 
5
- "Hello".reverse.tapp.reverse.tapp
5
+ "Hello".reverse.tapp(:tp).reverse.tapp(:tp)
6
6
  # >> |-------|
7
7
  # >> | olleH |
8
8
  # >> |-------|
@@ -17,11 +17,34 @@ puts
17
17
  # set global options
18
18
  OrgTp.default_options.update(intersection: '|', cover: false)
19
19
  tp array
20
+
21
+ ######################################## markdown option
22
+
23
+ # tp with options # !> `*' interpreted as argument prefix
24
+ tp array, markdown: true
25
+
26
+ # to_t with options
27
+ array.to_t(markdown: true) # => "| id | name |\n|----|-------|\n| 1 | alice |\n| 2 | bob |\n"
28
+
29
+ puts
30
+
31
+ # set global options
32
+ OrgTp.default_options.update(markdown: true)
33
+ tp array
34
+ # >> | id | name |
35
+ # >> |----|-------|
36
+ # >> | 1 | alice |
37
+ # >> | 2 | bob |
38
+ # >>
39
+ # >> | id | name |
40
+ # >> |----|-------|
41
+ # >> | 1 | alice |
42
+ # >> | 2 | bob |
20
43
  # >> | id | name |
21
44
  # >> |----|-------|
22
45
  # >> | 1 | alice |
23
46
  # >> | 2 | bob |
24
- # >>
47
+ # >>
25
48
  # >> | id | name |
26
49
  # >> |----|-------|
27
50
  # >> | 1 | alice |
@@ -12,6 +12,12 @@ module OrgTp
12
12
  OrgTp.generate(attributes, options)
13
13
  end
14
14
  end
15
+
16
+ concern :ActiveRecordResult do
17
+ def to_t(**options)
18
+ OrgTp.generate(collect(&:to_h), options)
19
+ end
20
+ end
15
21
  end
16
22
 
17
23
  Kernel.class_eval do
@@ -6,6 +6,7 @@ require 'kconv'
6
6
  module OrgTp
7
7
  mattr_accessor :default_options do
8
8
  {
9
+ markdown: false,
9
10
  header: nil,
10
11
  cover: true,
11
12
  vertical: '|',
@@ -29,6 +30,12 @@ module OrgTp
29
30
 
30
31
  def initialize(rows, **options)
31
32
  @options = OrgTp.default_options.merge(options)
33
+
34
+ if @options[:markdown]
35
+ @options[:intersection] = '|'
36
+ @options[:cover] = false
37
+ end
38
+
32
39
  @rows = rows
33
40
  @column_names = nil
34
41
  end
@@ -177,7 +184,6 @@ module OrgTp
177
184
  end
178
185
  },
179
186
  },
180
-
181
187
  ]
182
188
  end
183
189
  end
@@ -3,12 +3,7 @@ module OrgTp
3
3
  initializer 'org_tp' do
4
4
  ActiveSupport.on_load(:active_record) do
5
5
  include OrgTp::ActiveRecord
6
-
7
- ::ActiveRecord::Result.class_eval do
8
- def to_t(**options)
9
- OrgTp.generate(collect(&:to_h), options)
10
- end
11
- end
6
+ ::ActiveRecord::Result.include OrgTp::ActiveRecordResult
12
7
  end
13
8
 
14
9
  if defined?(Mongoid::Document)
@@ -1,3 +1,3 @@
1
1
  module OrgTp
2
- VERSION = '0.0.9'
2
+ VERSION = '0.0.10'
3
3
  end
data/lib/org_tp.rb CHANGED
@@ -8,12 +8,7 @@ else
8
8
  if defined?(ActiveSupport)
9
9
  ActiveSupport.on_load(:active_record) do
10
10
  include OrgTp::ActiveRecord
11
-
12
- ActiveRecord::Result.class_eval do
13
- def to_t(**options)
14
- OrgTp.generate(collect(&:to_h), options)
15
- end
16
- end
11
+ ::ActiveRecord::Result.include OrgTp::ActiveRecordResult
17
12
  end
18
13
  end
19
14
  if defined?(Mongoid::Document)
@@ -32,7 +27,8 @@ if defined?(Tapp)
32
27
  register :tp, Tp
33
28
  end
34
29
 
35
- Tapp.configure do |config|
36
- config.default_printer = :tp
37
- end
30
+ # # When tapp defaults to tp
31
+ # Tapp.configure do |config|
32
+ # config.default_printer = :tp
33
+ # end
38
34
  end
data/spec/org_tp_spec.rb CHANGED
@@ -54,6 +54,14 @@ EOT
54
54
  | 1 | alice | 0123456789 |
55
55
  | 2 | bob | あいうえお |
56
56
  | 3 | bob | |
57
+ EOT
58
+
59
+ OrgTp.generate(@rows, markdown: true).should == <<~EOT
60
+ | id | name | description |
61
+ |----|-------|-------------|
62
+ | 1 | alice | 0123456789 |
63
+ | 2 | bob | あいうえお |
64
+ | 3 | bob | |
57
65
  EOT
58
66
  end
59
67
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: org_tp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - akicho8
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-10 00:00:00.000000000 Z
11
+ date: 2017-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport