Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 6521fad

Browse files
committed
Various publishing cleanup
1 parent fc2af57 commit 6521fad

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

.github/workflows/main.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ jobs:
2929
name: AutoMerge
3030
needs:
3131
- ci
32-
- check
3332
runs-on: ubuntu-latest
3433
if: github.event_name == 'pull_request_target' && github.actor == 'dependabot[bot]'
3534
steps:

Gemfile.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ GEM
1313

1414
PLATFORMS
1515
x86_64-darwin-21
16+
x86_64-linux
1617

1718
DEPENDENCIES
1819
prettier_print!

README.md

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Or install it yourself as:
2020

2121
## Usage
2222

23-
To use `PrettierPrint`, you're going to construct a tree that encodes information about how to best print your data, then give the tree a width to print within. The tree will various nodes like `Text` (which wraps actual content to be printed), `Breakable` (a place where a line break could be inserted), `Group` (a set of nodes where if they don't fit on one line they should convert all `Breakable` nodes to line breaks), and others.
23+
To use `PrettierPrint`, you're going to construct a tree that encodes information about how to best print your data, then give the tree a maximum width within which to print. The tree will contain various nodes like `Text` (which wraps actual content to be printed), `Breakable` (a place where a line break could be inserted), `Group` (a set of nodes that the printer should attempt to print on one line), and others.
2424

2525
### Building the printer
2626

@@ -32,8 +32,8 @@ q = PrettierPrint.new(+"", 80, "\n") { |n| " " * n }
3232

3333
By convention, the `PrettierPrint` object is called `q`. The arguments are detailed below.
3434

35-
* This first argument (and the only required argument) is the output object. It can be anything that responds to `<<`, provided that method accepts strings. It's also common to use `[]`.
36-
* The optional second argument is the print width. This defaults to 80. For more information about this see the section below on [print width](#print-width).
35+
* This first argument (and the only required argument) is the output object. It can be anything that responds to `<<`, provided that method accepts strings. Usually this is an unfrozen empty string (`+""`). It's also common to see an empty array (`[]`).
36+
* The optional second argument is the print width. This defaults to `80`. For more information about this see the section below on [print width](#print-width).
3737
* The optional third argument is the newline to use. This defaults to `"\n"`. In some special circumstances, you might want something else like `"\r\n"` or any other newline marker.
3838
* The final optional argument is the block that specifies how to build spaces. It receives a single argument which is the number of spaces to generate. This defaults to printing the specified number of space characters. You would modify this only in special circumstances.
3939

@@ -47,11 +47,11 @@ if some_very_long_condition.some_very_long_method_name(some_very_long_argument)
4747
end
4848
```
4949

50-
In this case you wouldn't want your print width to be set much more than 80, since it would attempt to print this all on one line, which is much less readable.
50+
In this case you wouldn't want your print width to be set much more than `80`, since it would attempt to print this all on one line, which is much less readable.
5151

5252
### Building the tree
5353

54-
Now that you have a printer created, you can start to build out the tree. Each of the nodes of the tree is a small object that you can inspect manually. They each have convenience methods on the print object that should be used to create them. We'll start by talking about the most foundational nodes, then move on to the less commonly-used ones.
54+
Now that you have a printer created, you can start to build out the tree. Each of the nodes of the tree is a small object that you can inspect manually. They each have convenience methods on the printer object that should be used to create them. We'll start by talking about the most foundational nodes, then move on to the less commonly-used ones.
5555

5656
#### `Text`
5757

@@ -99,15 +99,15 @@ There are some times when you want to force a newline into the output and not ch
9999
q.breakable(force: true)
100100
```
101101

102-
There are a few circumstances where you'll want to force the newline into the output but no insert a break parent (because you don't want to necessarily force the groups to break unless they need to). In this case you can pass `force: :skip_break_parent` to this `breakable` and it will not insert a break parent.
102+
There are a few circumstances where you'll want to force the newline into the output but not insert a break parent (because you don't want to necessarily force the groups to break unless they need to). In this case you can pass `force: :skip_break_parent` to breakable and it will not insert a break parent.
103103

104104
```ruby
105105
q.breakable(force: :skip_break_parent)
106106
```
107107

108108
### `Group`
109109

110-
This node marks a group of items which the printer should try to fit on one line. This is the basic command to tell the printer when to break. Groups are usually nested, and the printer will try to fit everything on one line, but if it doesn't fit it will break the outermost group first and try again. It will continue breaking groups until everything fits (or there are no more groups to break).
110+
This node marks a group of items which the printer should try to fit on one line. Groups are usually nested, and the printer will try to fit everything on one line, but if it doesn't fit it will break the outermost group first and try again. It will continue breaking groups until everything fits (or there are no more groups to break).
111111

112112
Breaks are propagated to all parent groups, so if a deeply nested expression has a forced break, everything will break. This only matters for forced breaks, i.e. newlines that are printed no matter what and can be statically analyzed.
113113

@@ -411,14 +411,12 @@ Let's say you wanted to print out a file system like the `tree` command. You wou
411411
```ruby
412412
def print_directory(q, entries)
413413
grouped = entries.group_by { _1.include?("/") ? _1[0..._1.index("/")] : "." }
414-
return if grouped.empty?
415414

416-
q.seplist(grouped["."], -> { q.breakable(force: true) }) do |entry|
415+
q.seplist(grouped["."], -> { q.breakable }) do |entry|
417416
if grouped.key?(entry)
418417
q.text(entry)
419-
420418
q.indent do
421-
q.breakable(force: true)
419+
q.breakable
422420
print_directory(q, grouped[entry].map! { _1[(entry.length + 1)..] })
423421
end
424422
else

0 commit comments

Comments
 (0)