├── LICENSE ├── README.md ├── html_begin.pp └── html_end.pp /LICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | html_inside_cpp 2 | =============== 3 | 4 | Allows inclusion of html pages inside C++ code 5 | 6 | Motivation 7 | =============== 8 | 9 | More and more applications use web-interfaces nowadays. Situations when HTML pages must be returned by C++ program become more common. But embedding pages inside a C++ source file as text strings is not HTML developer friendly, while having bunch of HTML pages with program distribution may be not a nice solution for small programs or programs that do not carry around resources. 10 | 11 | html_inside_cpp allows you to embed HTML page in C++ source, still leaving the HTML page usable and modifiable by HTML developer. 12 | 13 | Example 14 | =============== 15 | Imagine that you have a small HTML file `hello.html`, that must be embedded inside C++ source file: 16 | ``` 17 | 18 | 19 | Hello word! 20 | 21 | ``` 22 | 23 | To do so, slightly modify `hello.html`: 24 | ``` 25 | 29 | 30 | 31 | 32 | 33 | Hello word! 34 | 35 | 36 | 37 | ``` 38 | 39 | now it is ready to be embedded into your `main.cpp` source file: 40 | ``` 41 | #include 42 | 43 | #include "html_begin.pp" // header from this repo 44 | #include "hello.html" // your HTML file 45 | #include "html_end.pp" // header from this repo 46 | 47 | int main() { 48 | std::cout << html_page; // outputs your HTML page content 49 | } 50 | 51 | ``` 52 | Here is what will be outputted by running `main.cpp`: 53 | ``` Hello word! ```. 65 | -------------------------------------------------------------------------------- /html_begin.pp: -------------------------------------------------------------------------------- 1 | /*============================================================================= 2 | Copyright (c) 2013 Antony Polukhin 3 | ==============================================================================*/ 4 | 5 | #define HTML_HELPER \ 6 | html_helper_val); \ 7 | (void)b; \ 8 | } \ 9 | }; /* html_first_commnet_remover */ \ 10 | } /*namespce detail */ 11 | 12 | #define TO_STRING(...) \ 13 | #__VA_ARGS__ 14 | 15 | namespace detail { 16 | struct no_bool_warning; 17 | inline bool operator < (const no_bool_warning&, bool); 18 | 19 | template 20 | struct html_first_commnet_remover; 21 | 22 | template 23 | struct html_first_commnet_remover<__COUNTER__, DelayInstantiation> { 24 | void operator()() { 25 | int html_helper_val = 1; 26 | detail::no_bool_warning nb; 27 | bool b = (nb 28 | -------------------------------------------------------------------------------- /html_end.pp: -------------------------------------------------------------------------------- 1 | /*============================================================================= 2 | Copyright (c) 2009-2013 Antony Polukhin 3 | ==============================================================================*/ 4 | 5 | #undef HTML_HELPER 6 | #undef TO_STRING 7 | --------------------------------------------------------------------------------