code_writer
Version, currently main branch1 version
- main branchlatestApr 12, 2023
github.com/watzon/code_writer
Easy interface for generating code in Crystal
0 stars
1 dependent
License: MIT
Installation
# Add this to your shard.yml
dependencies:
code_writer:
github: watzon/code_writer
branch: mainmain is a branch, not a release, so this tracks it rather than pinning a version.
Then run:
shards installshard.yml
- Crystal
1.1.0- License
- MIT
- Author
- Chris Watson
Dependencies
Development Dependencies
- spectator~> 0.11.6gitlab: arctic-fox/spectatordev
README
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
Documentation
Built from the current release. The first visit to a release nobody has asked for starts its build.
Links
This branch
- Branch
main- Seen
- Apr 12, 2023
- Crystal
1.1.0- Indexed
- yes
Dependents
Repository
github.com/watzon/code_writer
Metadata
- Created
- Aug 16, 2026
- Updated
- Aug 16, 2026
- Synced
- Aug 16, 2026
- Versions
- 1