code_writer
CodeWriter
Crystal utility class for generating code.
Installation
-
Add the dependency to your
shard.yml
:dependencies: code_writer: github: watzon/code_writer
-
Run
shards install
Usage
require "code_writer"
# Create a new writer (showing default options)
writer = CodeWriter.new(
buffer: IO::Memory.new,
newline_text: "\n",
tab_count: 4,
indent_style: :spaces,
quote_style: :double,
language_settings: CodeWriter::LANGUAGES["crystal"],
)
# Write code to the buffer
writer.comment do
writer.puts("This is a comment")
writer.puts("This comment is on another line")
end
writer.blank_line
writer.write("class Foo").block do
writer.write("def bar").block do
writer.puts("print \"baz\"")
end
end
# Convert the buffer to a string
writer.to_s
Contributing
- Fork it (https://github.com/watzon/code_writer/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
Contributors
- Chris Watson - creator and maintainer
Repository
code_writer
Owner
Statistic
- 0
- 0
- 0
- 2
- 1
- over 1 year ago
- July 25, 2021
License
MIT License
Links
Synced at
Thu, 07 Nov 2024 11:53:15 GMT
Languages