Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Bug: title* is a const, but should be defined in config.cfg #127

Open
ThomasTJdev opened this issue Feb 25, 2020 · 3 comments
Open

Bug: title* is a const, but should be defined in config.cfg #127

ThomasTJdev opened this issue Feb 25, 2020 · 3 comments

Comments

@ThomasTJdev
Copy link
Owner

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.

title* = "Nim Website Creator"

@juancarlospaco
Copy link
Collaborator

juancarlospaco commented Feb 29, 2020

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.
  • packedjson optionally 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\n instead 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.

@ThomasTJdev
Copy link
Owner Author

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.

@juancarlospaco
Copy link
Collaborator

juancarlospaco commented Apr 22, 2020

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 = true or compileTime = false, faster and less code, maybe an overload without requiring a configObject can 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
🙂

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants