liquid_feedback_frontend
view app/main/style/style.css.lua @ 1852:e593570a23c5
More efficient algorithm
| author | bsw | 
|---|---|
| date | Tue Mar 22 10:35:44 2022 +0100 (2022-03-22) | 
| parents | 85ca5a7e46ec | 
| children | 
 line source
     1 slot.set_layout(nil, "text/css")
     3 local style = execute.chunk{ module = "style", chunk = "_style", params = { style = config.style } }
     5 local scss = [[
     6 @import "../style/mdl/color-definitions";
     7 $color-primary: ]] .. style.color.primary .. [[;
     8 $color-primary-dark: ]] .. style.color.primary .. [[;
     9 $color-primary-contrast: ]] .. style.color.primary_contrast .. [[;
    10 $color-accent: ]] .. style.color.accent .. [[;
    11 $color-accent-contrast: ]] .. style.color.accent_contrast .. [[;
    12 $image-path: "]] .. request.get_absolute_baseurl() .. "static/mdl" .. [[";
    13 @import "../style/mdl/material-design-lite"
    14 ]]
    16 local key = extos.crypt(json.export(style.color), "$1$12345678") -- TODO hash function
    17 local filename_scss = encode.file_path(WEBMCP_BASE_PATH, 'tmp', "style-" .. key .. ".scss")
    18 local filename_css = encode.file_path(WEBMCP_BASE_PATH, 'tmp', "style-" .. key .. ".css")
    20 local css_file = io.open(filename_css, "r")
    22 if not config.css then
    23   config.css = {}
    24 end
    26 if not config.css[key] then
    27   if css_file then
    28     config.css[key] = css_file:read("*a")
    29   else
    30     local scss_file = assert(io.open(filename_scss, "w"))
    31     scss_file:write(scss)
    32     scss_file:write("\n")
    33     scss_file:close()
    35     local output, err, status = extos.pfilter(nil, "sassc", filename_scss)
    36     if status ~= 0 then
    37       error(err)
    38     end
    39     config.css[key] = output
    40     local css_file = assert(io.open(filename_css, "w"))
    41     css_file:write(config.css[key])
    42     css_file:close()
    43   end
    44 end
    46 slot.put_into("data", config.css[key])
