prettier_print 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 94274541967c7d4bb242bbbd4b141e8166d3239c27a03fb28fe606807fa2f302
4
- data.tar.gz: c27c69952f928c0533121941c584bda279966d5b0c04d78671d067d4479c3fbe
3
+ metadata.gz: cd1acc23437a5cf57c8f770a8f6ae6273d14c4716a64566f7966c19fe0f63276
4
+ data.tar.gz: bee4b7fcdd680e7a3747ad025054830426638f166bd14229e1a3386350fd542e
5
5
  SHA512:
6
- metadata.gz: 4d79d0c356c618ba5c89070f708f44993f43efaec89bba478d52c9432b1295dce150555fd1f242d48060ba4cf3152207b8d02d5b3d8121722b71af60b133098c
7
- data.tar.gz: ae5fcfb0885b70c3e1de247da94fedca3d0897a2345efca6f231c3bbdb9565d2ccb2b8b18796c1226d2ede30fdc54bd1baa1d6138d5c1c777e8c6a875574db46
6
+ metadata.gz: e59fb5d9131f40d75e458b45ad069329da4ae83df63f3111f7ffba01347d1ddf1a214f636a4bf5afa08502458c171ed7d17a8e358294ef101c9f1db68a924e20
7
+ data.tar.gz: ae31224da56d3983e6c3fa4329dbaa1bb86a4cf8b500852cfc105cfb01d69b11d61b285860e924768664f652964e300c72dbca141441e3f31222dad7be1545e7
data/CHANGELOG.md CHANGED
@@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [1.2.0] - 2022-12-23
10
+
11
+ ### Added
12
+
13
+ - You can now supply the base indentation level for the output buffer.
14
+
9
15
  ## [1.1.0] - 2022-11-08
10
16
 
11
17
  ### Added
@@ -49,7 +55,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
49
55
 
50
56
  - 🎉 Initial release! 🎉
51
57
 
52
- [unreleased]: https://github.com/ruby-syntax-tree/prettier_print/compare/v1.1.0...HEAD
58
+ [unreleased]: https://github.com/ruby-syntax-tree/prettier_print/compare/v1.2.0...HEAD
59
+ [1.2.0]: https://github.com/ruby-syntax-tree/prettier_print/compare/v1.1.0...v1.2.0
53
60
  [1.1.0]: https://github.com/ruby-syntax-tree/prettier_print/compare/v1.0.2...v1.1.0
54
61
  [1.0.2]: https://github.com/ruby-syntax-tree/prettier_print/compare/v1.0.1...v1.0.2
55
62
  [1.0.1]: https://github.com/ruby-syntax-tree/prettier_print/compare/v1.0.0...v1.0.1
data/Gemfile.lock CHANGED
@@ -1,13 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- prettier_print (1.1.0)
4
+ prettier_print (1.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
9
  docile (1.4.0)
10
- power_assert (2.0.1)
10
+ power_assert (2.0.2)
11
11
  rake (13.0.6)
12
12
  simplecov (0.21.2)
13
13
  docile (~> 1.1)
@@ -15,7 +15,7 @@ GEM
15
15
  simplecov_json_formatter (~> 0.1)
16
16
  simplecov-html (0.12.3)
17
17
  simplecov_json_formatter (0.1.4)
18
- test-unit (3.5.5)
18
+ test-unit (3.5.7)
19
19
  power_assert
20
20
 
21
21
  PLATFORMS
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class PrettierPrint
4
- VERSION = "1.1.0"
4
+ VERSION = "1.2.0"
5
5
  end
@@ -360,6 +360,11 @@ class PrettierPrint
360
360
  # a forced line, or the maximum width.
361
361
  MODE_FLAT = 2
362
362
 
363
+ # The default indentation for printing is zero, assuming that the code starts
364
+ # at the top level. That can be changed if desired to start from a different
365
+ # indentation level.
366
+ DEFAULT_INDENTATION = 0
367
+
363
368
  # This is a convenience method which is same as follows:
364
369
  #
365
370
  # begin
@@ -373,11 +378,12 @@ class PrettierPrint
373
378
  output = "".dup,
374
379
  maxwidth = 80,
375
380
  newline = DEFAULT_NEWLINE,
376
- genspace = DEFAULT_GENSPACE
381
+ genspace = DEFAULT_GENSPACE,
382
+ indentation = DEFAULT_INDENTATION
377
383
  )
378
384
  q = new(output, maxwidth, newline, &genspace)
379
385
  yield q
380
- q.flush
386
+ q.flush(indentation)
381
387
  output
382
388
  end
383
389
 
@@ -481,17 +487,20 @@ class PrettierPrint
481
487
 
482
488
  # Flushes all of the generated print tree onto the output buffer, then clears
483
489
  # the generated tree from memory.
484
- def flush
490
+ def flush(base_indentation = DEFAULT_INDENTATION)
485
491
  # First, get the root group, since we placed one at the top to begin with.
486
492
  doc = groups.first
487
493
 
488
494
  # This represents how far along the current line we are. It gets reset
489
495
  # back to 0 when we encounter a newline.
490
- position = 0
496
+ position = base_indentation
497
+
498
+ # Start the buffer with the base indentation level.
499
+ buffer << genspace.call(base_indentation) if base_indentation > 0
491
500
 
492
501
  # This is our command stack. A command consists of a triplet of an
493
502
  # indentation level, the mode (break or flat), and a doc node.
494
- commands = [[0, MODE_BREAK, doc]]
503
+ commands = [[base_indentation, MODE_BREAK, doc]]
495
504
 
496
505
  # This is a small optimization boolean. It keeps track of whether or not
497
506
  # when we hit a group node we should check if it fits on the same line.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prettier_print
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Newton
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-11-09 00:00:00.000000000 Z
11
+ date: 2022-12-23 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: