Skip to content

Commit 8b57521

Browse files
committed
Update readme
1 parent fdf6ea8 commit 8b57521

File tree

1 file changed

+55
-21
lines changed

1 file changed

+55
-21
lines changed

README.md

+55-21
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,77 @@
1-
# Psych::Comments
1+
# `Psych::Comments` -- brings YAML comment handling
22

3-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/psych/comments`. To experiment with that code, run `bin/console` for an interactive prompt.
4-
5-
TODO: Delete this and the text above, and describe your gem
3+
This gem allows you to manipulate YAML, preserving comment information.
64

75
## Installation
86

9-
Add this line to your application's Gemfile:
10-
117
```ruby
8+
# Gemfile
129
gem 'psych-comments'
1310
```
1411

15-
And then execute:
12+
## Usage
1613

17-
$ bundle install
14+
```ruby
15+
require "psych"
16+
require "psych/comments"
1817

19-
Or install it yourself as:
18+
ast = Psych::Comments.parse_stream(<<YAML)
19+
# foo
20+
- 42
21+
# bar
22+
- 12
23+
YAML
2024

21-
$ gem install psych-comments
25+
ast.children[0].root.children.sort_by! do |node|
26+
node.value.to_i
27+
end
2228

23-
## Usage
29+
puts Psych::Comments.emit_yaml(ast)
30+
```
2431

25-
TODO: Write usage instructions here
32+
## API
2633

27-
## Development
34+
### `Psych::Nodes::Node#leading_comments` -> `Array<String>`
2835

29-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
36+
Returns an array of leading comments. Each comment must start with `#`.
3037

31-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
38+
Extends [Psych::Nodes::Node](https://docs.ruby-lang.org/en/3.1/Psych/Nodes/Node.html).
3239

33-
## Contributing
40+
### `Psych::Nodes::Node#trailing_comments` -> `Array<String>`
3441

35-
Bug reports and pull requests are welcome on GitHub at https://github.com/qnighy/psych-comments. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/qnighy/psych-comments/blob/master/CODE_OF_CONDUCT.md).
42+
Returns an array of leading comments. Each comment must start with `#`.
3643

37-
## License
44+
Extends [Psych::Nodes::Node](https://docs.ruby-lang.org/en/3.1/Psych/Nodes/Node.html).
3845

39-
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
46+
### `Psych::Comments.parse(yaml, filename: nil)`
47+
48+
Parse YAML data with comments. Returns [Psych::Nodes::Document](https://docs.ruby-lang.org/en/3.1/Psych/Nodes/Document.html).
49+
50+
The interface is equivalent to [Psych.parse](https://docs.ruby-lang.org/en/3.1/Psych.html#method-c-parse).
51+
52+
### `Psych::Comments.parse_file(filename)`
4053

41-
## Code of Conduct
54+
Parse YAML data with comments. Returns [Psych::Nodes::Document](https://docs.ruby-lang.org/en/3.1/Psych/Nodes/Document.html).
4255

43-
Everyone interacting in the Psych::Comments project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/qnighy/psych-comments/blob/master/CODE_OF_CONDUCT.md).
56+
The interface is equivalent to [Psych.parse_file](https://docs.ruby-lang.org/en/3.1/Psych.html#method-c-parse).
57+
58+
### `Psych::Comments.parse_stream(yaml, filename: nil, &block)`
59+
60+
Parse YAML stream with comments. Returns [Psych::Nodes::Stream](https://docs.ruby-lang.org/en/3.1/Psych/Nodes/Stream.html).
61+
62+
The interface is equivalent to [Psych.parse_stream](https://docs.ruby-lang.org/en/3.1/Psych.html#method-c-parse_stream).
63+
64+
### `Psych::Comments.emit_yaml(node)` -> `String`
65+
66+
Serializes the event tree into a string.
67+
68+
This method is similar to [`Psych::Nodes::Node#to_yaml`](https://docs.ruby-lang.org/en/3.1/Psych/Nodes/Node.html#method-i-to_yaml),
69+
except that it takes comments into account.
70+
71+
Note that, this is essentially a reimplemention of libyaml's emitter.
72+
The implementation is incomplete and you may observe an incorrect or inconsistent output
73+
if you supply an AST containing unusual constructs.
74+
75+
## License
76+
77+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).

0 commit comments

Comments
 (0)