structurizr / java

Structurizr for Java
https://docs.structurizr.com/java
Apache License 2.0
1.01k stars 288 forks source link

Use local file as theme #331

Closed Lenormju closed 1 month ago

Lenormju commented 2 months ago

Description

Add support for providing theme by a file.

The !include keyword allows for 3 different types of resources : !include <file|directory|url> While the theme keyword allows for only 1 type of resource : theme <default|url> (default being a shorthand for an hardcoded URL).

I was uncertain between the Priority "no rush" and "willing to open a PR". I think I can solve this issue myself, but I'd like to know if you are okay with the goal before to start working on it.

Priority

I'm willing to add this feature myself and raise a PR (please confirm approach first)

More information

I don't want to have to store my own theme file on a file server somewhere, to be picked up by Structurizr, while it can already use local files for all kinds of purposes. I had to use Docker Compose with a Python Simple HTTP Server to be able to have a self-contained build step :

name: build-structurizr
services:
  serve-theme:
    image: "python:3.10.8-slim-bullseye"
    working_dir: /www/data/
    command: "python -m http.server 8000"
    ports:
      - 8000:8000
    volumes:
      - type: bind
        source: ./docs/theme/
        target: /www/data/
        read_only: true

  build-docs:
    image: ghcr.io/avisi-cloud/structurizr-site-generatr:latest
    command: generate-site -w workspace.dsl
    volumes:
      - type: bind
        source: ./docs/
        target: /var/model/
        read_only: false
    depends_on:
      - serve-theme

which made possible to provide the theme as an URL :

        theme http://serve-theme:8000/theme.json
simonbrowndotje commented 1 month ago

The browser-based Structurizr UI loads themes via an XHR request, which is why they need to be URLs. Since you're using Site Generatr, this restriction doesn't apply, so I've added the ability to specify a theme file, relative to the DSL file; for example:

theme theme.json

This will inline all styles defined in theme.json and override any styles that already exist in your workspace.