|
1 | | -# Aa2img |
2 | | - |
3 | | -TODO: Delete this and the text below, and describe your gem |
4 | | - |
5 | | -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/aa2img`. To experiment with that code, run `bin/console` for an interactive prompt. |
| 1 | +<h1 align="center">aa2img</h1> |
| 2 | +<p align="center"> |
| 3 | + <strong>Convert ASCII/Unicode diagrams into clean SVG and PNG images</strong> |
| 4 | +</p> |
| 5 | +<p align="center"> |
| 6 | + <img src="https://img.shields.io/badge/ruby-%3E%3D%203.2-red.svg" alt="Ruby 3.2+"> |
| 7 | + <img src="https://img.shields.io/badge/output-SVG%20%2F%20PNG-2f855a.svg" alt="Output SVG/PNG"> |
| 8 | + <img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="License MIT"> |
| 9 | + <a href="https://github.com/ydah/aa2img/actions/workflows/main.yml"> |
| 10 | + <img src="https://github.com/ydah/aa2img/actions/workflows/main.yml/badge.svg" alt="CI"> |
| 11 | + </a> |
| 12 | +</p> |
| 13 | + |
| 14 | +<p align="center"> |
| 15 | + <a href="#features">Features</a> • |
| 16 | + <a href="#installation">Installation</a> • |
| 17 | + <a href="#usage">Usage</a> • |
| 18 | + <a href="#diagram-syntax">Diagram Syntax</a> • |
| 19 | + <a href="#themes">Themes</a> |
| 20 | +</p> |
| 21 | + |
| 22 | +--- |
| 23 | + |
| 24 | +`aa2img` parses text-based box diagrams and renders them as themed images. |
| 25 | +It is useful for docs, README files, and architecture notes where you want to keep diagrams editable as plain text. |
| 26 | + |
| 27 | +## Features |
| 28 | + |
| 29 | +- Parses both Unicode and ASCII box-drawing styles (`┌─┐ │ └─┘` and `+--+ | | +--+`) |
| 30 | +- Detects section separators (`├──┤`) inside boxes |
| 31 | +- Detects nested parent-child box structures |
| 32 | +- Renders right-side annotations in `← note` format |
| 33 | +- Handles full-width characters, including Japanese labels |
| 34 | +- Supports `SVG` and `PNG` output |
| 35 | +- Ships with 3 built-in themes: `default`, `blueprint`, `monochrome` |
| 36 | +- Supports vertical label alignment: `top`, `center`, `bottom` |
6 | 37 |
|
7 | 38 | ## Installation |
8 | 39 |
|
9 | | -TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org. |
| 40 | +### Requirements |
10 | 41 |
|
11 | | -Install the gem and add to the application's Gemfile by executing: |
| 42 | +- Ruby `3.2+` |
| 43 | +- ImageMagick (required only for PNG output) |
12 | 44 |
|
13 | 45 | ```bash |
14 | | -bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG |
| 46 | +# macOS |
| 47 | +brew install imagemagick |
| 48 | + |
| 49 | +# Ubuntu / Debian |
| 50 | +sudo apt install imagemagick |
| 51 | +``` |
| 52 | + |
| 53 | +### Add to Gemfile |
| 54 | + |
| 55 | +```ruby |
| 56 | +gem "aa2img", github: "ydah/aa2img" |
15 | 57 | ``` |
16 | 58 |
|
17 | | -If bundler is not being used to manage dependencies, install the gem by executing: |
| 59 | +After the gem is published to RubyGems, you can also install it with: |
18 | 60 |
|
19 | 61 | ```bash |
20 | | -gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG |
| 62 | +gem install aa2img |
21 | 63 | ``` |
22 | 64 |
|
23 | 65 | ## Usage |
24 | 66 |
|
25 | | -TODO: Write usage instructions here |
| 67 | +### Quick Start (CLI) |
| 68 | + |
| 69 | +1. Create a text diagram file: |
| 70 | + |
| 71 | +```txt |
| 72 | +┌────────────────────────────┐ |
| 73 | +│ API Gateway │ |
| 74 | +├────────────────────────────┤ |
| 75 | +│ Application │ |
| 76 | +│ ┌──────────────────────┐ │ |
| 77 | +│ │ Database │ │ |
| 78 | +│ └──────────────────────┘ │ |
| 79 | +└────────────────────────────┘ |
| 80 | +``` |
| 81 | + |
| 82 | +2. Convert to SVG: |
| 83 | + |
| 84 | +```bash |
| 85 | +aa2img convert diagram.txt output.svg |
| 86 | +``` |
| 87 | + |
| 88 | +3. Convert to PNG: |
| 89 | + |
| 90 | +```bash |
| 91 | +aa2img convert diagram.txt output.png --scale 3 |
| 92 | +``` |
| 93 | + |
| 94 | +### Commands |
| 95 | + |
| 96 | +| Command | Description | |
| 97 | +|---|---| |
| 98 | +| `aa2img convert INPUT_FILE OUTPUT_FILE` | Convert text diagram to image (format inferred from extension) | |
| 99 | +| `aa2img themes` | List available themes | |
| 100 | +| `aa2img preview INPUT_FILE` | Show parsed AST tree for debugging | |
| 101 | +| `aa2img version` | Show version | |
| 102 | + |
| 103 | +### `convert` Options |
| 104 | + |
| 105 | +| Option | Description | |
| 106 | +|---|---| |
| 107 | +| `--theme NAME` | Theme name (`default`, `blueprint`, `monochrome`) | |
| 108 | +| `--scale N` | Scale factor for PNG output (default: `2`) | |
| 109 | +| `--valign POS` | Vertical label alignment (`top`, `center`, `bottom`) | |
| 110 | + |
| 111 | +Notes: |
| 112 | +- Use `-` as `INPUT_FILE` to read from stdin. |
| 113 | +- Output format is inferred from `OUTPUT_FILE` extension (`.svg` or `.png`). |
| 114 | + |
| 115 | +```bash |
| 116 | +# Read from stdin |
| 117 | +cat diagram.txt | aa2img convert - output.svg |
| 118 | + |
| 119 | +# Use blueprint theme |
| 120 | +aa2img convert diagram.txt blueprint.svg --theme blueprint |
| 121 | + |
| 122 | +# Center label alignment |
| 123 | +aa2img convert diagram.txt centered.svg --valign center |
| 124 | +``` |
| 125 | + |
| 126 | +### Ruby API |
| 127 | + |
| 128 | +```ruby |
| 129 | +require "aa2img" |
| 130 | + |
| 131 | +aa = <<~AA |
| 132 | + ┌──────┐ |
| 133 | + │ Test │ |
| 134 | + └──────┘ |
| 135 | +AA |
| 136 | + |
| 137 | +# Get SVG string |
| 138 | +svg = Aa2Img.convert(aa, format: :svg, theme: "default", valign: :center) |
| 139 | + |
| 140 | +# Write to file (format inferred from extension) |
| 141 | +Aa2Img.convert_to_file(aa, "diagram.png", theme: "monochrome", scale: 2, valign: :top) |
| 142 | +``` |
| 143 | + |
| 144 | +## Diagram Syntax |
| 145 | + |
| 146 | +### Basic Boxes |
| 147 | + |
| 148 | +Unicode: |
| 149 | + |
| 150 | +```txt |
| 151 | +┌──────┐ |
| 152 | +│ API │ |
| 153 | +└──────┘ |
| 154 | +``` |
| 155 | + |
| 156 | +ASCII: |
| 157 | + |
| 158 | +```txt |
| 159 | ++------+ |
| 160 | +| API | |
| 161 | ++------+ |
| 162 | +``` |
| 163 | + |
| 164 | +### Sectioned Boxes |
| 165 | + |
| 166 | +```txt |
| 167 | +┌────────────────┐ |
| 168 | +│ Presentation │ |
| 169 | +├────────────────┤ |
| 170 | +│ Application │ |
| 171 | +├────────────────┤ |
| 172 | +│ Infrastructure │ |
| 173 | +└────────────────┘ |
| 174 | +``` |
| 175 | + |
| 176 | +### Annotations |
| 177 | + |
| 178 | +```txt |
| 179 | +┌──────────┐ ← user input |
| 180 | +│ REPL │ |
| 181 | +└──────────┘ |
| 182 | +``` |
| 183 | + |
| 184 | +## Themes |
| 185 | + |
| 186 | +Built-in themes: |
| 187 | + |
| 188 | +- `default`: balanced light theme |
| 189 | +- `blueprint`: deep-blue blueprint-like style |
| 190 | +- `monochrome`: print-friendly grayscale style |
| 191 | + |
| 192 | +```bash |
| 193 | +aa2img themes |
| 194 | +``` |
| 195 | + |
| 196 | +You can also pass a custom theme hash from Ruby: |
| 197 | + |
| 198 | +```ruby |
| 199 | +custom_theme = { |
| 200 | + "background_color" => "#ffffff", |
| 201 | + "box_fill" => "#f8fafc", |
| 202 | + "box_stroke" => "#334155", |
| 203 | + "text_color" => "#0f172a", |
| 204 | + "font_family" => "'Noto Sans JP', sans-serif" |
| 205 | +} |
| 206 | + |
| 207 | +svg = Aa2Img.convert(aa, format: :svg, theme: custom_theme) |
| 208 | +``` |
| 209 | + |
| 210 | +## Notes |
| 211 | + |
| 212 | +- Current parser behavior is optimized for box/layer diagrams. |
| 213 | +- Annotation detection currently supports right-side `←` markers. |
| 214 | +- `preview --format` is reserved for future expansion; current output is tree-style. |
26 | 215 |
|
27 | 216 | ## Development |
28 | 217 |
|
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. |
| 218 | +```bash |
| 219 | +git clone https://github.com/ydah/aa2img.git |
| 220 | +cd aa2img |
| 221 | +bin/setup |
| 222 | +bundle exec rspec |
| 223 | +``` |
| 224 | + |
| 225 | +Run the example script: |
30 | 226 |
|
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). |
| 227 | +```bash |
| 228 | +bundle exec ruby examples/basic_usage.rb |
| 229 | +``` |
32 | 230 |
|
33 | 231 | ## Contributing |
34 | 232 |
|
35 | | -Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/aa2img. |
| 233 | +Issues and pull requests are welcome at `https://github.com/ydah/aa2img`. |
36 | 234 |
|
37 | 235 | ## License |
38 | 236 |
|
39 | | -The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). |
| 237 | +[MIT License](LICENSE.txt) |
0 commit comments