Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add usage samples #31

Open
1 of 2 tasks
flexferrum opened this issue Jul 19, 2018 · 5 comments
Open
1 of 2 tasks

Add usage samples #31

flexferrum opened this issue Jul 19, 2018 · 5 comments
Labels
enhancement New feature or request

Comments

@flexferrum
Copy link
Collaborator

flexferrum commented Jul 19, 2018

Add usage samples for:

  • Web (based on boost.beast)
  • Code generation (based on cppast)
@flexferrum flexferrum added the enhancement New feature or request label Jul 19, 2018
@flexferrum flexferrum added this to the Release 1.0 milestone Jul 19, 2018
@flexferrum flexferrum added this to To Do in Jinja2Cpp standard features via automation Jul 19, 2018
@flexferrum
Copy link
Collaborator Author

@Manu343726 , would you like to add your cppast/tinyrefl template examples here?

@Manu343726
Copy link
Contributor

Whenever I make it work, sure ;)

@flexferrum
Copy link
Collaborator Author

Thanks!

@Manu343726
Copy link
Contributor

Manu343726 commented Oct 1, 2018

BTW something like this should work right now:

#include <cppast/libclang_parser.hpp>
#include <tinyrefl/tool/model/cppast/jinja2reflection.hpp>
#include <jinja2cpp/template.h>

using namespace tinyrefl::tool::model;

int main()
{
    using parser_t = cppast::simple_file_parser<cppast::libclang_parser>;
    cppast::cpp_entity_index index;
    parser_t                 parser{type_safe::ref(index)};
    parser_t::config         config;
    config.set_flags(cppast::cpp_standard::cpp_11);

    auto file = parser.parse("my_enum.hpp", config);
    jinja2::ValuesMap variables{
        {"file", jinja2::Reflect(make_entity_ref(index, file.value()))}};

        jinja2::Template tmpl;
    tmpl.Load(R"(
{% for enum in file.enums %}
{{enum.fullname}} from_string(const std::string& str)
{
{% for value in enum.values %}
    if((str == "{{value.name}}") ||
       (str == "{{value.qualifiedname}}") ||
       (str == "{{value.fullname}}"))
    {
        return {{value.fullname}};
    }
{% endfor %}

    throw std::logic_error{"Invalid {{enum.fullname}} value name"};
}
{% endfor %}
)");
    std::ofstream output{"my_enum_from_string.cpp"};
    tmpl.Render(output, variables);
}

@flexferrum
Copy link
Collaborator Author

Contemporary classics. :D

@flexferrum flexferrum modified the milestones: Release 1.0, Release 0.9.2 Feb 24, 2019
@flexferrum flexferrum modified the milestones: Release 0.9.2, Release 1.0 May 11, 2019
@flexferrum flexferrum moved this from To do to In progress in Jinja2Cpp enhancements May 15, 2019
@flexferrum flexferrum moved this from In progress to To do in Jinja2Cpp enhancements May 15, 2019
@flexferrum flexferrum moved this from To do to In progress in Jinja2Cpp enhancements Oct 1, 2019
@flexferrum flexferrum removed this from the Release 1.2 milestone Mar 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Jinja2Cpp enhancements
  
In progress
Development

No branches or pull requests

2 participants