こんにちは!ROOXIM株式会社COO上原です。
今回は、投稿内でUMLを使えるようにしようと思います。
具体的にはPlantUMLでクラス図や、シーケンス図といったダイアグラムを使えるようにします。
PlantUMLとは
PlantUMLは、テキストベースのモデリングツールで、UML(Unified Modeling Language)図を生成するためのオープンソースのツールです。
PlantUMLを使用すると、テキストで UML 図を記述し、自動的にグラフィカルな図に変換することができます。
PlantUMLは以下のようなUML図をサポートしています。
クラス図
シーケンス図
アクティビティ図
コンポーネント図
ステートマシン図
オブジェクト図
ユースケース図
plantumlの出力例
このブログでは実際にPlantuml記法が使えるようになっています。
実際の出力例を示します。
クラス図
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 @startuml class Car { + make: string + model: string + year: int } class Engine { + cylinders: int + displacement: float + horsepower: int } Car *-- Engine : contains @enduml
実際の出力
Car make: string model: string year: int Engine cylinders: int displacement: float horsepower: int contains
シーケンス図
1 2 3 4 5 6 7 8 9 10 11 12 13 @startuml actor User participant "Controller" as Controller participant "Service" as Service participant "Repository" as Repository User -> Controller: Request Controller -> Service: Process Service -> Repository: Query Repository --> Service: Data Service --> Controller: Response Controller --> User: Data @enduml
実際の出力
User User Controller Controller Service Service Repository Repository Request Process Query Data Response Data
アクティビティ図
1 2 3 4 5 6 7 8 9 10 @startuml start :Get Data; if (Data Received?) then (Yes) :Process Data; else (No) :Display Error; endif stop @enduml
実際の出力
Get Data Data Received? Yes No Process Data Display Error
コンポーネント図
1 2 3 4 5 6 7 @startuml package "Example" { [User Interface] --> [Controller] [Controller] --> [Service] [Service] --> [Repository] } @enduml
実際の出力
Example User Interface Controller Service Repository
ステートマシン図
1 2 3 4 5 6 7 8 9 @startuml [*] --> Off Off : Entry/ Do nothing Off --> On : Power On On --> Off : Power Off On --> [*] : Error @enduml
実際の出力
Off Entry/ Do nothing On Power On Power Off Error
オブジェクト図
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 @startuml object Car { make = "Toyota" model = "Camry" year = 2022 } object Engine { cylinders = 4 displacement = 2.5 horsepower = 200 } Car *-- Engine : contains @enduml
実際の出力
Car make = "Toyota" model = "Camry" year = 2022 Engine cylinders = 4 displacement = 2.5 horsepower = 200 contains
ユースケース図
1 2 3 4 5 6 7 @startuml skinparam actorStyle Hollow :User: --> (Use) "Main Admin" as Admin "Use the application" as (Use) Admin --> (Admin the application) @enduml
実際の出力
User Use the application Main Admin Admin the application
Hexoでplantumlを設定
では実際にHexoにPlantumlを設定していきましょう。
hexo-filter-plantumlをインストール
以下のコマンドでhexo-filter-plantuml
をインストールします。
1 npm install hexo-filter-plantuml --save
hexo-filter-plantuml
プラグインの設定
_config.yml
を編集してhexo-filter-plantuml
プラグインの設定をします。
以下の設定をファイルの最後に追加します。
_config.yml 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 plantuml: render: "PlantUMLServer" server: "http://www.plantuml.com/plantuml" link: "inline" outputFormat: "svg" className: "plantuml"
記事にplantumlを追加
サーバを再起動する
プラグインインストール後は以下のコマンドでHexoサーバを再起動します。
ブラウザで確認
ブラウザで http://localhost:4000
にアクセスして編集した記事にUMLが画像として表示されていることを確認します。
実際に表示されていれば完了です。
最後に
技術ブログということもありUMLを使うことは多いと思います。
そこで使うかわからないですがとりあえず設定しておきました。
plantumlは弊社業務でもかなり使うのでガッツリ使っていきたいですね!