alucardthefish / CodeNowHere

CLI application to create almost any programming language file!
Other
12 stars 18 forks source link

Migrate to sqlite3 database #9

Open alucardthefish opened 4 years ago

alucardthefish commented 4 years ago

Is your feature request related to a problem? Please describe.

Due that some file extensions can be share between different programming or markup languages, the current system of storing data in files could be very problematic in the future. This can be helpful when the program is supposed to create one file that share any common extension, it should ask user to select the correct type of language.

Describe the solution you'd like

It would be cool to implement a light database such as sqlite3 for storing relevant data of each language. And change the logic to access to its data instead of reading it from files.

Describe alternatives you've considered

Additional context

pm100 commented 1 year ago

This bug is the reason I came to this project (from the up-for-grabs website). I know sqlite very well and liked the idea of adding it here. But I dont think its the correct approach.

I get what you are trying to fix. Today you have

But using a database for all this info is not the right tool. Problem is that you then have to provide a tool to allow editing the contents of the database if users want to tweak the templates.

Alternate proposal.

so a template looks like this

suffix=c++,cpp,cc 
// **************************************************************************************************************
// File: {{ cnh_file }}
// Author: {{ cnh_name }}
// Created: {{ cnh_date }}
{% if exists("description") %}
// Description: {{ description }}
{% endif %}
// **************************************************************************************************************

#include <iostream>

using namespace std;

int main(int argc, char * argv[]) {
    cout << "Hello World" << endl;
    return 0;
}

or

<!DOCTYPE html>
<!-- ************************************************************************************************************** -->
<!-- File: {{ pad(cnh_file, 105) }}-->
<!-- Author: {{ pad(cnh_name, 103) }}-->
<!-- Created: Thu Mar 30 15:04:14 2023                                                                              -->
{% if exists("description") %}
<!-- Description: {{ pad(description, 98) }}-->
{% endif %}
<!-- ************************************************************************************************************** -->

<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>foo</title>
    </head>
    <body>
        <h1>Hello World</h1>
    </body>
</html>

This allows users to put whatever they want in the template. Laid out however they like Their extra variables can be in a json file.

Having typed this is realize this is a big change. Anyway its a suggestion.

alucardthefish commented 1 year ago

That sounds great! I appreciate your suggestion and the time you spent to improve this project. I like your idea on this. I will need to study or learn about inja template engine. Feel free to share any documentation, information or code examples of this approach if you have time.

pm100 commented 1 year ago

inja is here

https://github.com/pantor/inja

I will put up my experimentation app in my own repo

pm100 commented 1 year ago

I have a working demo here

https://github.com/pm100/injatools

It should build and run in visual studio

just add a file name as a cli argument. There are two templates cpp and html

eg

PS C:\work\injatools> .\x64\Debug\injatools.exe foo.html
<!DOCTYPE html>
<!-- ************************************************************************************************************** -->
<!-- File: foo.html                                                                                                 -->
<!-- Author: paulm                                                                                                  -->
<!-- Created: Thu Mar 30 15:04:14 2023                                                                              -->
<!-- Project: fiddly foo                                                                                        -->
<!-- ************************************************************************************************************** -->

<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>foo</title>
    </head>
    <body>
        <h1>Hello World</h1>
    </body>
</html>
</html>
PS C:\work\injatools>

a json file called data.json is automatically loaded for testing

alucardthefish commented 1 year ago

@pm100 Thank you. I will check it