rzeldent / micro-moustache

Minimal moustache implementation for micro controllers
MIT License
8 stars 0 forks source link

Extensions for the Arduino #3

Open fletchjp opened 1 year ago

fletchjp commented 1 year ago

Hi. Thank you for micro-moustache. I am attaching a file with a modified version for your information.

  1. I have added a library.properties file for use by the Arduino IDE.
  2. I have changed the include directory to src.
  3. There is an extra header file called moustach_code.h which adds new capabilities.

I can also send you some examples using the extensions if you wish.

I am running code on an Arduino UNO.

Happy New Year

John Fletcher micro-moustache.zip

rzeldent commented 1 year ago

Hi John,

Great you like it! This was something really missing...

If you want I can incorporate the changes in the library. I can make a branch/pull request but think you should take the credit for your work. I suggest you make a pull request (with the new examples?) and I can incorporate it in the library... That way you'll be the co-author.

Kind regards,

Rene

On Wed, Jan 4, 2023 at 7:47 PM John Fletcher @.***> wrote:

Hi. Thank you for micro-moustache. I am attaching a file with a modified version for your information.

  1. I have added a library.properties file for use by the Arduino IDE.
  2. I have changed the include directory to src.
  3. There is an extra header file called moustach_code.h which adds new capabilities.

I can also send you some examples using the extensions if you wish.

Happy New Year

John Fletcher micro-moustache.zip https://github.com/rzeldent/micro-moustache/files/10346714/micro-moustache.zip

— Reply to this email directly, view it on GitHub https://github.com/rzeldent/micro-moustache/issues/3, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB2ENBYPBC5H7P3N2Y4FYDDWQXAVPANCNFSM6AAAAAATRDJKTQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

fletchjp commented 1 year ago

Rene

Thank you, I will do that. It will take a few days as I have a talk to give on Sunday. I will make some examples. I suggest I bump the version number. Shall I make it 1.1.0 as I have not changed your interface?

rzeldent commented 1 year ago

Hi John,

That's fine, there's no hurry. Changing the version number is fine (and required). Looking forward!

Rene

On Thu, Jan 5, 2023 at 11:58 PM John Fletcher @.***> wrote:

Rene

Thank you, I will do that. It will take a few days as I have a talk to give on Sunday. I will make some examples. I suggest I bump the version number. Shall I make it 1.1.0 as I have not changed your interface?

— Reply to this email directly, view it on GitHub https://github.com/rzeldent/micro-moustache/issues/3#issuecomment-1372897947, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB2ENBYUUEWHMTI34FPQOULWQ5GYRANCNFSM6AAAAAATRDJKTQ . You are receiving this because you commented.Message ID: @.***>

fletchjp commented 1 year ago

Rene

I have now made an example for my extra functions which are in a separate header file. I have changed the version number to 1.1.0 as the interface is not changed. I have added new material to the README file to describe how to use the new functions.

I do need to change the name of the folder holding the headers from 'include' to 'src' and I don't know whether that will break use on other hardware than a UNO.

I can make this into a pull request although I am not sure how best to do this.

In the meantime I am attaching a ZIP file with a copy of the library as I now have it configured. Please let me know whether this makes sense to you.

Best wishes

John micro-moustache.zip

rzeldent commented 1 year ago

Hi John,

I made a branch for the modifications: /feature/john_fletcher and incorporated it in the build. rzeldent/micro-moustache at feature/john_fletcher (github.com) https://github.com/rzeldent/micro-moustache/tree/feature/john_fletcher However, while compiling the example I keep running into compiler issues because the value of the moustache_variable_t is const and thus cannot be changed. So, for example the code at line 48: number_value[0].value = String(number); is not allowed. I commented out some assignments but to no avail. See for example the output of job https://github.com/rzeldent/micro-moustache/actions/runs/3920169050/jobs/6701626391

What am I missing?

Kind regards,

Rene

On Sat, Jan 14, 2023 at 2:07 PM John Fletcher @.***> wrote:

Rene

I have now made an example for my extra functions which are in a separate header file. I have changed the version number to 1.1.0 as the interface is not changed. I have added new material to the README file to describe how to use the new functions.

I do need to change the name of the folder holding the headers from 'include' to 'src' and I don't know whether that will break use on other hardware than a UNO.

I can make this into a pull request although I am not sure how best to do this.

In the meantime I am attaching a ZIP file with a copy of the library as I now have it configured. Please let me know whether this makes sense to you.

Best wishes

John micro-moustache.zip https://github.com/rzeldent/micro-moustache/files/10417360/micro-moustache.zip

— Reply to this email directly, view it on GitHub https://github.com/rzeldent/micro-moustache/issues/3#issuecomment-1382733620, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB2ENBYU76ECMKAZ57O7VATWSKQHXANCNFSM6AAAAAATRDJKTQ . You are receiving this because you commented.Message ID: @.***>

fletchjp commented 1 year ago

Rene

The difference is that I am running on an Arduino UNO where the messages are regarded as warnings because of the use of -fpermissive in the Arduino IDE setup. This applies on both the Arduino IDE 1.8.19 and 2.0.3 which use the same configuration file, for example

C:\Users\john\Documents\Arduino\examples\moustache_values\moustache_values.ino:49:40: warning: passing 'const String' as 'this' argument discards qualifiers [-fpermissive] number_value[0].value = String(number);

I think you are working on a different system which provides different settings.

I have tried compiling the example for an Arduino DUE and that fails. The message is the same except that it is an error.

The reason it fails for the DUE is that -fpermissive is not defined. When I add it to the line compiler.cpp.flags in platform.txt then the errors become warnings and it compiles.

platform.txt is hidden away in the user's AppData\Local\Arduino15\packages on a Windows computer

I have tried in the past to find out just what -fpermissive does allow on different systems without success,

It may be that you can change the settings on your system, or just label my work for Arduino UNOs etc. I can now use a DUE as a test system to see if I can get around this.

I have taken the other approach and looked for a work around for the error and not found one (yet).

What do you think?

John

fletchjp commented 1 year ago

I have had a look at ways to work around this problem without using -fpermissive. I have not found a solution.

I don't know what you think. Perhaps I should abandon this idea, except for the example for error messages.

John

rzeldent commented 1 year ago

Hi John,

Have been busy the last few days. I'll take a look at it. However, compiling with -permissive is not an option. Just a quick email to let you know I've not forgotten to do something with your suggestions!

Rene

On Mon, Jan 16, 2023 at 1:54 PM John Fletcher @.***> wrote:

I have had a look at ways to work around this problem without using -fpermissive. I have not found a solution.

I don't know what you think. Perhaps I should abandon this idea, except for the example for error messages.

John

— Reply to this email directly, view it on GitHub https://github.com/rzeldent/micro-moustache/issues/3#issuecomment-1384014412, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB2ENBZIYHPN3MFRMJX7VKLWSVAILANCNFSM6AAAAAATRDJKTQ . You are receiving this because you commented.Message ID: @.***>

rzeldent commented 1 year ago

Hi John,

I looked again at you extensions and basically what you want to do is not recreate the array but be able to update a particular value. This makes a lot of sense if you have a single/global instance. So, maybe the const is too strict when using the moustache values. To overcome this I made the moustache_variable_t's value parameter not const, so it is posible to change it. I think this will make it easier to work with this library.

When using this version, the array is no longer allowed to be const. So below an example how to use it. You can use your templates to change the values and then just call render.

Please give it a go and let me know what you think about this change see branch: feature/no_const.

Kind regards,

Rene

void setup()
{
    const char *taxes =
        "Hello {{name}}\n"
        "You have just won {{value}} dollars!\n"
        "{{#in_ca}}"
        "Well, {{taxed_value}} dollars, after taxes.\n"
        "{{/in_ca}}"
        "{{^in_ca}}"
        "And no taxes paid!\n"
        "{{/in_ca}}";

    moustache_variable_t substitutions[] = {
        {"name", "Chris"},
        {"value", String(10000)},
        {"taxed_value", String(10000 - (10000 * 0.4))},
        {"in_ca", String(true)}};

    auto result = moustache_render(taxes, substitutions);
    Serial.println(result);

    substitutions[3].value = String(false);
    result = moustache_render(taxes, substitutions);
    Serial.println(result);
}