indented_io 0.9.0 → 0.11.0
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 +4 -4
- data/indented_io.gemspec +4 -1
- data/lib/indented_io/indented_io.rb +14 -8
- data/lib/indented_io/indented_io_interface.rb +14 -9
- data/lib/indented_io/io.rb +1 -1
- data/lib/indented_io/kernel.rb +12 -3
- data/lib/indented_io/stringio.rb +2 -2
- data/lib/indented_io/tempfile.rb +1 -1
- data/lib/indented_io/version.rb +1 -1
- data/lib/indented_io.rb +9 -9
- metadata +20 -9
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1ca4010d40987e7fcf41ef261e382d9c4dbd46aedf28b14b1b492e2d89514e69
|
|
4
|
+
data.tar.gz: 9ecb56b410ed532c145b438f1f08ab380ebd6f4003f38c9c851cfeba27c9f4f1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1f3b9df5ccba732b79eefac135faa6a79a580e50bd954e7a1cea46d6a8f97adb2a116c4d63eb38f33cce17d096b35a008ac3b0e5c9f7bdc674615ea4b7951017
|
|
7
|
+
data.tar.gz: 5f54172ed68dfa74eea22303f283dce696d40db0f33fb21719e38c06d93db70626596571ff89822fed4e0ac59351d06bfb1a748a5434a94ae5104a238a0c747e
|
data/indented_io.gemspec
CHANGED
|
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
|
10
10
|
spec.description = %q{
|
|
11
11
|
IndentedIO extends Kernel, IO, and StringIO with an
|
|
12
12
|
#indent method that redefines #print, printf, #puts,
|
|
13
|
-
and #p to print their output indented. Indentations
|
|
13
|
+
and #p to print their output indented. Indentations
|
|
14
14
|
are stacked so that each new indentation adds to the
|
|
15
15
|
previous indendation
|
|
16
16
|
}
|
|
@@ -25,4 +25,7 @@ Gem::Specification.new do |spec|
|
|
|
25
25
|
spec.bindir = "exe"
|
|
26
26
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
27
27
|
spec.require_paths = ["lib"]
|
|
28
|
+
|
|
29
|
+
spec.add_development_dependency "string-text"
|
|
30
|
+
|
|
28
31
|
end
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
require_relative 'indented_io_interface'
|
|
2
2
|
|
|
3
3
|
module IndentedIO
|
|
4
4
|
# An IO device that writes indented text by reimplementing #write, #print,
|
|
@@ -6,14 +6,14 @@ module IndentedIO
|
|
|
6
6
|
#
|
|
7
7
|
# IndentedIO objects forms a chain that acts as a stack. The lowest element
|
|
8
8
|
# in the stack is always a "pure" IO object (eg. $stdout). IndentedIO object
|
|
9
|
-
# are
|
|
9
|
+
# are then moved on and off the stack as indentation levels rise or fall
|
|
10
10
|
#
|
|
11
11
|
# Note that #new is private. The only way to create a IndentedIO object is to
|
|
12
12
|
# call #indent on an object that supports it ({Kernel}, {IO}, or {StringIO})
|
|
13
13
|
class IndentedIO
|
|
14
14
|
include IndentedIOInterface
|
|
15
15
|
|
|
16
|
-
# @!visibility private
|
|
16
|
+
# @!visibility private
|
|
17
17
|
alias :interface_indent :indent
|
|
18
18
|
|
|
19
19
|
# (see IndentedIO::IndentedIOInterface#indent)
|
|
@@ -21,6 +21,10 @@ module IndentedIO
|
|
|
21
21
|
interface_indent(depth, string, bol: bol, &block)
|
|
22
22
|
end
|
|
23
23
|
|
|
24
|
+
def undent
|
|
25
|
+
@parent
|
|
26
|
+
end
|
|
27
|
+
|
|
24
28
|
# Indent and print args to the underlying device. #write has the same semantic
|
|
25
29
|
# as IO#write
|
|
26
30
|
def write(*args)
|
|
@@ -54,8 +58,10 @@ module IndentedIO
|
|
|
54
58
|
end
|
|
55
59
|
|
|
56
60
|
# Indent and print args to the underlying device. #p has the same semantic
|
|
57
|
-
# as Kernel#p. Please note that even though #p is only defined on Kernel
|
|
58
|
-
#
|
|
61
|
+
# as Kernel#p. Please note that even though #p is only defined on Kernel it
|
|
62
|
+
# can also be used on any IndentedIO object so you can say '$stderr.p
|
|
63
|
+
# value'. This also deviates from the standard ruby $stderr object that
|
|
64
|
+
# doesn't have a #p method defined
|
|
59
65
|
def p(*args)
|
|
60
66
|
if bol
|
|
61
67
|
args.each { |arg| write(arg.inspect, "\n") }
|
|
@@ -70,13 +76,13 @@ module IndentedIO
|
|
|
70
76
|
# Make IndentedIO behave like the underlying @device by only searching for
|
|
71
77
|
# methods in the device
|
|
72
78
|
#
|
|
73
|
-
# @!visibility private
|
|
79
|
+
# @!visibility private
|
|
74
80
|
def respond_to?(method, include_all = false)
|
|
75
81
|
[:indent, :depth, :tab, :p].include?(method) || device.respond_to?(method, include_all)
|
|
76
82
|
end
|
|
77
83
|
|
|
78
84
|
# Make IndentedIO behave like the underlying @device
|
|
79
|
-
# @!visibility private
|
|
85
|
+
# @!visibility private
|
|
80
86
|
def method_missing(method, *args)
|
|
81
87
|
device.send(method, *args)
|
|
82
88
|
end
|
|
@@ -131,7 +137,7 @@ module IndentedIO
|
|
|
131
137
|
def initialize(parent, levels, this_indent, bol)
|
|
132
138
|
if levels < 0
|
|
133
139
|
parent.is_a?(::IndentedIO::IndentedIO) or raise ::IndentedIO::Error.new "Negative levels argument"
|
|
134
|
-
parent.levels + levels >= 0 or raise ::IndentedIO::Error.new "
|
|
140
|
+
parent.levels + levels >= 0 or raise ::IndentedIO::Error.new "Levels out of range"
|
|
135
141
|
sibling = parent
|
|
136
142
|
while parent.is_a?(::IndentedIO::IndentedIO) && levels < 0
|
|
137
143
|
levels += parent.levels
|
|
@@ -20,19 +20,24 @@ module IndentedIO
|
|
|
20
20
|
module IndentedIOInterface
|
|
21
21
|
# Returns a IndentedIO object that can be used for printing. The IO object
|
|
22
22
|
# will pass-through all methods to the underlying device except #print,
|
|
23
|
-
# #printf, #puts, and #p
|
|
23
|
+
# #printf, #puts, and #p that extends the default to output indented text
|
|
24
24
|
#
|
|
25
|
-
# +level+ is the number of
|
|
26
|
-
#
|
|
27
|
-
#
|
|
28
|
-
# {::IndentedIO.default_indent} if this is the first level. +:bol+ control the
|
|
29
|
-
# beginning-of-line status: If true, #indent will begin writing with an
|
|
30
|
-
# indentation string as if it was at the beginning of the line. If false,
|
|
31
|
-
# it will only indent after the next newline. Default is true
|
|
25
|
+
# +level+ is the number of levels to indent the following text. If +level+
|
|
26
|
+
# is negative, #indent will outdent text instead. +level' can also be true
|
|
27
|
+
# or false: true sets the level to 1 and false sets it to 0
|
|
32
28
|
#
|
|
33
|
-
#
|
|
29
|
+
# +string+ is the string used for indentation. The indentation string can
|
|
30
|
+
# also be given as the keyword parameter +:string+. Default is the indent
|
|
31
|
+
# string of the outer level or {::IndentedIO.default_indent} if this is the
|
|
32
|
+
# first level
|
|
33
|
+
#
|
|
34
|
+
# +:bol+ controls the beginning-of-line status: If true, #indent will begin
|
|
35
|
+
# writing with an indentation string as if it was at the beginning of the
|
|
36
|
+
# line. If false, it will only indent after the first newline. Default is
|
|
37
|
+
# true
|
|
34
38
|
#
|
|
35
39
|
def indent(levels = 1, string_ = ::IndentedIO.default_indent, string: string_, bol: nil, &block)
|
|
40
|
+
levels = levels.is_a?(Integer) ? levels : (levels && 1 || 0)
|
|
36
41
|
block.nil? || block.arity == 1 or raise ::IndentedIO::Error.new "Wrong number of block parameters"
|
|
37
42
|
@indented_io_object = ::IndentedIO::IndentedIO.send(:new, self, levels, string, bol)
|
|
38
43
|
block_given? ? yield(@indented_io_object) : @indented_io_object
|
data/lib/indented_io/io.rb
CHANGED
data/lib/indented_io/kernel.rb
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
require_relative 'indented_io_interface'
|
|
2
2
|
|
|
3
3
|
module Kernel
|
|
4
|
+
@@INDENT_STACK = []
|
|
5
|
+
|
|
4
6
|
# Like {IndentedIO::IndentedIOInterface#indent} except the underlying device is
|
|
5
7
|
# not the receiver (Kernel) but $stdout. Kernel#indent also allows a block without
|
|
6
8
|
# an argument. In that case it manipulates $stdout to print indented:
|
|
@@ -17,6 +19,9 @@ module Kernel
|
|
|
17
19
|
# # Indented
|
|
18
20
|
# # Even more indented
|
|
19
21
|
#
|
|
22
|
+
# It called without a block, it indents $stdout. It should then be matched
|
|
23
|
+
# with a corresponding #undent
|
|
24
|
+
#
|
|
20
25
|
def indent(levels = 1, string_ = IndentedIO.default_indent, string: string_, bol: nil, &block)
|
|
21
26
|
block.nil? || block.arity <= 1 or raise IndentedIO::Error.new "Wrong number of parameters"
|
|
22
27
|
obj = IndentedIO::IndentedIO.send(:new, $stdout, levels, string, bol)
|
|
@@ -32,10 +37,14 @@ module Kernel
|
|
|
32
37
|
$stdout = saved_stdout
|
|
33
38
|
end
|
|
34
39
|
end
|
|
40
|
+
r
|
|
35
41
|
else
|
|
36
|
-
|
|
42
|
+
$stdout = obj
|
|
37
43
|
end
|
|
38
|
-
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def undent
|
|
47
|
+
$stdout = $stdout.send(:parent)
|
|
39
48
|
end
|
|
40
49
|
end
|
|
41
50
|
|
data/lib/indented_io/stringio.rb
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
require_relative 'stringio' # Required to avoid 'superclass mismatch' errors in other modules
|
|
2
|
+
require_relative 'indented_io_interface'
|
|
3
3
|
|
|
4
4
|
# Includes the IndentedIOInterface that define the #indent method
|
|
5
5
|
class StringIO
|
data/lib/indented_io/tempfile.rb
CHANGED
data/lib/indented_io/version.rb
CHANGED
data/lib/indented_io.rb
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
require_relative 'indented_io/version'
|
|
3
|
+
require_relative 'indented_io/error'
|
|
4
|
+
require_relative 'indented_io/indented_io'
|
|
5
|
+
require_relative 'indented_io/indented_io_interface'
|
|
6
|
+
require_relative 'indented_io/kernel'
|
|
7
|
+
require_relative 'indented_io/io'
|
|
8
|
+
require_relative 'indented_io/stringio'
|
|
9
|
+
require_relative 'indented_io/tempfile'
|
|
10
10
|
|
|
11
|
-
# IndentedIO module. See {IndentedIO::IndentedIO} for documentation on how to
|
|
11
|
+
# IndentedIO module. See {IndentedIO::IndentedIO} for documentation on how to
|
|
12
12
|
# use this module
|
|
13
13
|
#
|
|
14
14
|
module IndentedIO
|
metadata
CHANGED
|
@@ -1,19 +1,32 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: indented_io
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.11.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Claus Rasmussen
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: exe
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
12
|
-
dependencies:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: string-text
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '0'
|
|
19
|
+
type: :development
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '0'
|
|
13
26
|
description: "\n IndentedIO extends Kernel, IO, and StringIO
|
|
14
27
|
with an\n #indent method that redefines #print, printf,
|
|
15
|
-
#puts,\n and #p to print their output indented. Indentations
|
|
16
|
-
\
|
|
28
|
+
#puts,\n and #p to print their output indented. Indentations\n
|
|
29
|
+
\ are stacked so that each new indentation adds to the\n
|
|
17
30
|
\ previous indendation\n "
|
|
18
31
|
email:
|
|
19
32
|
- claus.l.rasmussen@gmail.com
|
|
@@ -47,7 +60,6 @@ homepage: https://github.com/clrgit/indented_io
|
|
|
47
60
|
licenses:
|
|
48
61
|
- MIT
|
|
49
62
|
metadata: {}
|
|
50
|
-
post_install_message:
|
|
51
63
|
rdoc_options: []
|
|
52
64
|
require_paths:
|
|
53
65
|
- lib
|
|
@@ -62,8 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
62
74
|
- !ruby/object:Gem::Version
|
|
63
75
|
version: '0'
|
|
64
76
|
requirements: []
|
|
65
|
-
rubygems_version: 3.
|
|
66
|
-
signing_key:
|
|
77
|
+
rubygems_version: 3.6.9
|
|
67
78
|
specification_version: 4
|
|
68
79
|
summary: Print indented text
|
|
69
80
|
test_files: []
|