nim_websitecreator
nim_websitecreator copied to clipboard
Bug: `title*` is a const, but should be defined in `config.cfg`
title* is defined in the const-file for strings, but the title* should be updated with the value specified by the user in config.cfg. Otherwise title will always be "Nim Website Creator". The plugins needs to be able to use title to represent the user defined title.
https://github.com/ThomasTJdev/nim_websitecreator/blob/d22fc86aa934ee3286b8fa5c4c046f3c90fc4bbe/nimwcpkg/constants/_strings.nim#L48
I was thinking a lot about the config in general, I think this can be changed from INI to JSON Pretty-Printed.
JSON
- Can be done compile-time with std lib.
- Doing it compile-time increases performance and security.
- Code is less verbose less lines of code to do the same.
- Validates config at compile-time.
- Validates config as-you-type.
- Valid config ensured at run-time.
- Minify or Prettify is really easy.
- NPM/Node uses JSON for config, so is not strange to people.
packedjsonoptionally increases performance.- Binary file size is smaller.
- JSON gives you Type-safe config, int is int, bool is bool, etc.
- Plugins need re-compile anyways.
INI
- Can not be done compile-time with std lib.
- Doing it run-time decreases performance.
- Code is more verbose more lines of code to do the same.
- May be Invalid config at compile-time and run-time.
- Can not Validate config as-you-type.
- Minify or Prettify is not posible.
- INI format is more simple than JSON.
- INI empty value is just
key\ninstead of"key": ""that confuses some people. - INI is not Typed, int is string, bool is string, etc you must parse it on each use.
- The more stuff we add to the INI the slower it will become.
How to Validate config as-you-type on the fly?.
- Go to http://argentina-ni.ml
- Switch tab to "file.json".
- Type some JSON on the textarea.
- Check that it says "Valid JSON" or "Invalid JSON" as you type.
- Validation is done Client-side with JavaScript.
- Validation is done Server-side with
parseJson.
Note
- Changing config from INI to JSON may require a NimWC version bump.
- It is an opportunity to Fix this and other stuff.
- This is open to discussion and ideas.
Hi @juancarlospaco
At compile-time
Of course it would benefit performance and security by doing it on compile-time, but it would also limit the users possibility to do quick adjustments. If they get a new mail server, they then need to change the config and re-compile NimWC. I do have have NimWC running on devices, where Nim is not installed. I would like to keep main options as runtime. If we have static elements in the config, a simple macro looping through could do the job:
macro genConfigItems(): void =
var heading: string
loop through config file:
if line.substr(0, 0) == "[":
heading = line
conintue
if heading in ["static", "config", "nochange"]:
source &= "const cfg" & itemName & " = " & itemValue
else:
source &= "let " & itemName & " = dict.getSectionValue(\"" & heading & "\",\"" & itemValue & "\")\n"
result = parseStmt(source)
JSON vs INI
I get the point and I see the benefits. But I'm in doubt about "benefit vs time-to-change"...
Types in config
As you say, the INI does not support types such as bool and int, so it would ease our job as developers to use JSON. But I think our main purpose is to ensure the ease for the end-user.
So I am kinda using webgui as a Mine Field for cool new ideas, and I think people like them,
so maybe in the future stuff from webgui can be steal to here, so few destacable mentions can be:
- getConfig(compileTime = false) with this user can choose
compileTime = trueorcompileTime = false, faster and less code, maybe an overload without requiring aconfigObjectcan be added. - getOpt(), faster and less code, more direct access to values anywhere.
But I wait to see how Fusion evolves, maybe cool stuff can be sent there, and only depend on Fusion and the rest just move it inside NimWC, maybe Fusion becomes a frequently installed package and lots of people will have it installed, looks like a nice idea.
Also: https://github.com/juancarlospaco/nim_packages_security_audit#fully-automated-nim-packages-security-audit :slightly_smiling_face: