An open API service indexing awesome lists of open source software.

https://github.com/svernidub/plantuml_builder

Gem to build text diagrams with PlantUML
https://github.com/svernidub/plantuml_builder

plantuml plantuml-diagrams plantuml-generator

Last synced: about 1 month ago
JSON representation

Gem to build text diagrams with PlantUML

Awesome Lists containing this project

README

        

# PlantumlBuilder

[![Gem Version](https://badge.fury.io/rb/plantuml_builder.svg)](https://badge.fury.io/rb/plantuml_builder)
[![Build Status](https://travis-ci.com/svernidub/plantuml_builder.svg?branch=master)](https://travis-ci.com/svernidub/plantuml_builder)

Gem to convet [PlantUML](http://plantuml.com) diagrams using plantuml.com or
[local](https://hub.docker.com/r/plantuml/plantuml-server/) PlantUML server

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'plantuml_builder'
```

And then execute:

$ bundle

Or install it yourself as:

$ gem install plantuml_builder

## Usage

PlantUML allows to describe UML (and some other) diagrams in it's own text format.

For example, [sequence diagram](http://plantuml.com/sequence-diagram):
```wsd
@startuml
actor User

User -> MyService : perform
activate MyService
return true
deactivate MyService
@enduml
```

The diagram above will be rendered to:

![](http://www.plantuml.com/plantuml/png/~1UDfJK70eBaaiAYdDpU5I08B4v9By8eNGujGYC1S8G6m5NJi5tyhWrAAopEHK1Ik5WjIYjFoYN9YEpBB4abI40gZEejIIqg8yXPAYKeX8IYfMfGwfUIaWsm5R-2hl)

PlantUML web service expects compression of such diagrams into
it's own format. The diagram above should be converted to

```
~1DfJK70eBaaiAYdDpU5I08B4v9By8eNGujGYC1S8G6m5NJi5tyhWrAAopEHK1Ik5WjIYjFoYN9YEpBB4abI40gZEejIIqg8yXPAYKeX8IYfMfGwfUIaWsm5R-2hl
```

Using `plantuml_builder` you can fetch rendered diagrams from specified server.

Diagrams could be fetched as SVG, PNG, and TXT (ASCII-art) format.

### Using as standalone app

To build one diagram in SVG format from plantuml.com run:

```bash
$ plantuml_build png source_file.wsd destination_file.svg
```

If you need build whole directory, specify `-R` flag before source. To build it into PNG diagrams:

```bash
$ plantuml_build png -R src dest
```

If you want to use local server as endpoint, specify it with `--endpoint`:

```bash
$ plantuml_build txt source_file.wsd destination_file.txt --endpoint=http://localhost:8080
```

### Using as library

First, receive diagram text (from WSD or other file format).

```ruby
wsd = <<-WSD
@startuml
actor User

User -> MyService : perform
activate MyService
return true
deactivate MyService
@enduml
WSD
```

#### SVG

Fetch diagram as SVG:

```ruby
PlantumlBuilder::Formats::SVG.new(wsd).load
=> "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nUser\n\n\n\nUser\n\n\n\n\nMyService\n\n\nMyService\n\n\n\n\nperform\n\n\n\ntrue\n\n\n # diagram in PNG
```

#### TXT (ASCII-art)

```ruby
PlantumlBuilder::Formats::TXT.new(wsd).load
```
Result could be outputed as:

```
┌─┐
║"│
└┬┘
┌┼┐
│ ┌─────────┐
┌┴┐ │MyService│
User └────┬────┘
│ perform ┌┴┐
│ ───────────────>│ │
│ │ │
│ true │ │
│ <─ ─ ─ ─ ─ ─ ─ ─│ │
User ┌───└┬┘───┐
┌─┐ │MyService│
║"│ └─────────┘
└┬┘
┌┼┐

┌┴┐
```

### Using your own server

You can also use PlantUML on your local computer, installed, or using docker image.
You need to specify endpoint:

```ruby
PlantumlBuilder::Formats::TXT.new(wsd, 'http://localhost:8080').load
```

Default endpoint is: `http://www.plantuml.com/plantuml`.

## Development

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.

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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/svernidub/plantuml_builder.

## License

The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).