indented_io 0.8.8 → 0.10.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b429449b90ca605dbcf4f07abaee53a8f2eece7a3131024649c0c2b55775f962
4
- data.tar.gz: eccb5276e5d1356e58809d674a27dc64651bb885c03000e1ac3150b50f989206
3
+ metadata.gz: e7d7b56c7e800172496c55f99f9dc03636488bf6c4129443a68529863dc6a172
4
+ data.tar.gz: 10d967b887989eced95e9fc7f3799d59219e4a76ca926556badf8ebb7e1c49b6
5
5
  SHA512:
6
- metadata.gz: 93fc65e925cad892a1f8cb716ee5064d4a23112930e14ed184072108550e5470834fc97e400011465de1e48a645dbeee3f65883f14e2242fa6a57913bdba51d5
7
- data.tar.gz: 40161650518478d5ad566ceade2274b9900dd651f89bff44246cbd066bdd96d3a5d8cb9da5258d046d324deb1d06feaa608528d46815cce2aa0ed278bdbeeb68
6
+ metadata.gz: 0cb712cf0d9926b09d385db2a37a3d0cb6e136a36f5cbd164dccf49954b93098a4b23b0f4c60548a79267697bbdeb9adf19efd07123762f79ca43ea77860797a
7
+ data.tar.gz: a0986342ecbc58afb912146b30aefbaed2c186df34b4df5dfe8a838cdc631db51eba5524797e101471c1cfd8c5388f42a4a482bc7bbab4fd85cc0bbb765405a5
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- ruby-2.7.1
1
+ ruby-3.1.2
data/Gemfile CHANGED
@@ -4,3 +4,6 @@ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
4
 
5
5
  # Specify your gem's dependencies in indented_io.gemspec
6
6
  gemspec
7
+
8
+ gem "rake", "~>12.0"
9
+ gem "rspec", "~>3.0"
data/TODO CHANGED
@@ -1,5 +1,17 @@
1
1
 
2
2
  TODO
3
+ o Make the folowing wotk
4
+ # Shorthand for
5
+ # puts "Header"
6
+ # indent { puts content }
7
+ #
8
+ puts "Header", indent, content
9
+
10
+ # Shorthand for
11
+ # puts "Header"
12
+ # indent { recurse }
13
+ puts "Header", indent { recurse }
14
+
3
15
  o Fix "goes wrong" in spec/indented_io_spec.rb by making
4
16
  IndentedIOInterface#indent create a IndentedIO object for each level. This
5
17
  may require blocks to pop-off multiple levels
data/indented_io.gemspec CHANGED
@@ -1,7 +1,4 @@
1
-
2
- lib = File.expand_path("../lib", __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "indented_io/version"
1
+ require_relative 'lib/indented_io/version'
5
2
 
6
3
  Gem::Specification.new do |spec|
7
4
  spec.name = "indented_io"
@@ -13,30 +10,22 @@ Gem::Specification.new do |spec|
13
10
  spec.description = %q{
14
11
  IndentedIO extends Kernel, IO, and StringIO with an
15
12
  #indent method that redefines #print, printf, #puts,
16
- and #p to print their output indented. Indentations
13
+ and #p to print their output indented. Indentations
17
14
  are stacked so that each new indentation adds to the
18
15
  previous indendation
19
16
  }
20
17
  spec.homepage = "https://github.com/clrgit/indented_io"
21
18
  spec.license = "MIT"
22
19
 
23
- # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
24
- # to allow pushing to a single host or delete this section to allow pushing to any host.
25
- if spec.respond_to?(:metadata)
26
- spec.metadata["allowed_push_host"] = "https://rubygems.org"
27
- else
28
- raise "RubyGems 2.0 or newer is required to protect against " \
29
- "public gem pushes."
30
- end
31
-
32
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
33
- f.match(%r{^(test|spec|features)/})
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
34
24
  end
35
25
  spec.bindir = "exe"
36
26
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
37
27
  spec.require_paths = ["lib"]
38
28
 
39
- spec.add_development_dependency "bundler", "~> 2.2.10"
40
- spec.add_development_dependency "rake", ">= 12.3.3"
41
- spec.add_development_dependency "rspec", "~> 3.0"
29
+ spec.add_development_dependency "string-text"
30
+
42
31
  end
@@ -13,7 +13,7 @@ module IndentedIO
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
- # but can be used on any IndentedIO object so you can say '$stderr.p value'
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
@@ -22,13 +22,13 @@ module IndentedIO
22
22
  # will pass-through all methods to the underlying device except #print,
23
23
  # #printf, #puts, and #p
24
24
  #
25
- # +level+ is the number of leves to indent and +string+ is the string used
25
+ # +level+ is the number of levels to indent and +string+ is the string used
26
26
  # for indentation. The indentation string can also be given as the keyword
27
27
  # parameter +:string+. Default is the indent string of the outer level or
28
28
  # {::IndentedIO.default_indent} if this is the first level. +:bol+ control the
29
29
  # beginning-of-line status: If true, #indent will begin writing with an
30
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
31
+ # it will only indent after the first newline. Default is true
32
32
  #
33
33
  # If +level+ is negative, #indent will outdent text instead
34
34
  #
@@ -1,6 +1,8 @@
1
1
  require 'indented_io/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
- r = obj
42
+ $stdout = obj
37
43
  end
38
- r
44
+ end
45
+
46
+ def undent
47
+ $stdout = $stdout.send(:parent)
39
48
  end
40
49
  end
41
50
 
@@ -1,4 +1,4 @@
1
1
  module IndentedIO
2
2
  # Version number
3
- VERSION = '0.8.8'
3
+ VERSION = '0.10.0'
4
4
  end
metadata CHANGED
@@ -1,61 +1,32 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: indented_io
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.8
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claus Rasmussen
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2022-03-12 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
- name: bundler
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: 2.2.10
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: 2.2.10
27
- - !ruby/object:Gem::Dependency
28
- name: rake
13
+ name: string-text
29
14
  requirement: !ruby/object:Gem::Requirement
30
15
  requirements:
31
16
  - - ">="
32
17
  - !ruby/object:Gem::Version
33
- version: 12.3.3
18
+ version: '0'
34
19
  type: :development
35
20
  prerelease: false
36
21
  version_requirements: !ruby/object:Gem::Requirement
37
22
  requirements:
38
23
  - - ">="
39
24
  - !ruby/object:Gem::Version
40
- version: 12.3.3
41
- - !ruby/object:Gem::Dependency
42
- name: rspec
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '3.0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '3.0'
25
+ version: '0'
55
26
  description: "\n IndentedIO extends Kernel, IO, and StringIO
56
27
  with an\n #indent method that redefines #print, printf,
57
- #puts,\n and #p to print their output indented. Indentations
58
- \n are stacked so that each new indentation adds to the\n
28
+ #puts,\n and #p to print their output indented. Indentations\n
29
+ \ are stacked so that each new indentation adds to the\n
59
30
  \ previous indendation\n "
60
31
  email:
61
32
  - claus.l.rasmussen@gmail.com
@@ -88,9 +59,7 @@ files:
88
59
  homepage: https://github.com/clrgit/indented_io
89
60
  licenses:
90
61
  - MIT
91
- metadata:
92
- allowed_push_host: https://rubygems.org
93
- post_install_message:
62
+ metadata: {}
94
63
  rdoc_options: []
95
64
  require_paths:
96
65
  - lib
@@ -105,8 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
74
  - !ruby/object:Gem::Version
106
75
  version: '0'
107
76
  requirements: []
108
- rubygems_version: 3.1.4
109
- signing_key:
77
+ rubygems_version: 3.6.9
110
78
  specification_version: 4
111
79
  summary: Print indented text
112
80
  test_files: []