SuffolkLITLab / docassemble-ALDashboard

A frontend to a few common administrative backend functions that aren't built-in to Docassemble
MIT License
8 stars 0 forks source link

Create a simple interview that compiles Bootstrap SCSS #73

Closed nonprofittechy closed 1 year ago

nonprofittechy commented 1 year ago

Maybe it should also give you a template to customize the theme colors, but it should definitely let you upload a full SCSS file.

See: https://suffolklitlab.org/legal-tech-class/docs/practical-guide-docassemble/theming-docassemble#creating-a-custom-theme-from-source-instead-of-with-a-theme-generator

BryceStevenWilley commented 1 year ago

An extremely hacky version that I got to work: likely needs background tasks when downloading and unzipping bootstrap, as well as when compiling the SCSS.

event: done
question: Done!
subquestion: |
  ${ open("/tmp/bootstrap-5.2.3/dist/css/custom.css").read() }
---
code: |
  # Should be a background task
  import requests
  import subprocess
  import os
  from pathlib import Path
  import requests, zipfile, io
  p = Path("/tmp/bootstrap-5.2.3")
  if not p.is_dir():
      r = requests.get("https://github.com/twbs/bootstrap/archive/refs/tags/v5.2.3.zip")
      z = zipfile.ZipFile(io.BytesIO(r.content))
      z.extractall("/tmp/")
      z.close()
      del z
      subprocess.run(["npm", "install", "--prefix", "/tmp/bootstrap-5.2.3"])
  installed = True
---
code: |
  import os
  import shutil
  shutil.copy(uploaded_file.path(), "/tmp/bootstrap-5.2.3/scss/custom.scss")
  vals = subprocess.run(["npm", "run", "css-compile", "--prefix", "/tmp/bootstrap-5.2.3"], capture_output=True)
  compile = True
---
mandatory: True
code: |
  # order block
  start_screen
  installed
  uploaded_file
  compile
  done
---
question: Start
continue button field: start_screen
---
question: What file?
fields:
  - SCSS file: uploaded_file
    datatype: file