-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
91 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#ifndef BOOST_MUSTACHE_RENDER_HPP_INCLUDED | ||
#define BOOST_MUSTACHE_RENDER_HPP_INCLUDED | ||
|
||
// Copyright 2022 Peter Dimov | ||
// Distributed under the Boost Software License, Version 1.0. | ||
// https://www.boost.org/LICENSE_1_0.txt | ||
|
||
#include <boost/mustache/renderer.hpp> | ||
|
||
namespace boost | ||
{ | ||
namespace mustache | ||
{ | ||
|
||
template<class T1 = json::value, class T2 = json::value> void render( core::string_view tmpl, output_ref out, T1 const& data, T2 const& partials, json::storage_ptr sp = {} ) | ||
{ | ||
mustache::renderer rd( data, partials, sp ); | ||
|
||
rd.render( tmpl, out ); | ||
rd.finish( out ); | ||
} | ||
|
||
} // namespace mustache | ||
} // namespace boost | ||
|
||
#endif // #ifndef BOOST_MUSTACHE_RENDER_HPP_INCLUDED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#ifndef BOOST_MUSTACHE_RENDERER_HPP_INCLUDED | ||
#define BOOST_MUSTACHE_RENDERER_HPP_INCLUDED | ||
|
||
// Copyright 2022 Peter Dimov | ||
// Distributed under the Boost Software License, Version 1.0. | ||
// https://www.boost.org/LICENSE_1_0.txt | ||
|
||
#include <boost/mustache/output_ref.hpp> | ||
#include <boost/json/value.hpp> | ||
#include <boost/json/array.hpp> | ||
#include <boost/json/object.hpp> | ||
#include <boost/json/storage_ptr.hpp> | ||
#include <boost/json/value_from.hpp> | ||
#include <boost/core/detail/string_view.hpp> | ||
|
||
namespace boost | ||
{ | ||
namespace mustache | ||
{ | ||
|
||
class renderer | ||
{ | ||
private: | ||
|
||
json::array context_stack_; | ||
json::object partials_; | ||
|
||
public: | ||
|
||
renderer( json::value const& data, json::value const& partials ); | ||
|
||
template<class T1, class T2> explicit renderer( T1 const& data, T2 const& partials, json::storage_ptr sp = {} ): | ||
renderer( json::value_from( data, sp ), json::value_from( partials, sp ) ) | ||
{ | ||
} | ||
|
||
void render( core::string_view tmpl, output_ref out ); | ||
void finish( output_ref out ); | ||
}; | ||
|
||
} // namespace mustache | ||
} // namespace boost | ||
|
||
#endif // #ifndef BOOST_MUSTACHE_RENDERER_HPP_INCLUDED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,5 @@ run quick.cpp ; | |
|
||
run output_ref.cpp ; | ||
run output_ref2.cpp ; | ||
|
||
run render_literal.cpp ; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright 2022 Peter Dimov | ||
// Distributed under the Boost Software License, Version 1.0. | ||
// https://www.boost.org/LICENSE_1_0.txt | ||
|
||
#include <boost/mustache/render.hpp> | ||
#include <boost/core/lightweight_test.hpp> | ||
#include <string> | ||
|
||
int main() | ||
{ | ||
std::string st; | ||
|
||
boost::mustache::render( "no-tags", st, {}, {} ); | ||
|
||
BOOST_TEST_EQ( st, std::string( "no-tags" ) ); | ||
|
||
return boost::report_errors(); | ||
} |