├── CMakeLists.txt ├── LICENSE ├── README.md ├── cpp.html.h └── hello.html.cpp /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.11) 2 | project(cpp-html CXX) 3 | 4 | function(ADD_COMPILE_FLAG value) 5 | message(STATUS "Building with ${value}") 6 | foreach(variable CMAKE_C_FLAGS CMAKE_CXX_FLAGS) 7 | set(${variable} "${${variable}} ${value}" PARENT_SCOPE) 8 | endforeach(variable) 9 | endfunction() 10 | 11 | add_compile_flag("-Wno-unicode-homoglyph") 12 | add_compile_flag("-std=c++1z") 13 | 14 | add_executable(hello "hello.html.cpp") 15 | add_test(hello hello) 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 JF Bastien 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | C++ ﹤HTML﹥ 2 | ========== 3 | 4 | The Web is all about frameworks. You can't go a week without a new hot thing 5 | coming out. C++ is really missing on this trend, and that's a shame. 😔 6 | 7 | After having worked on 8 | [NaCl / PNaCl](https://en.wikipedia.org/wiki/Google_Native_Client), 9 | [WebAssembly](https://en.wikipedia.org/wiki/WebAssembly), I've determined that 10 | we should try something new and interesting. Instead of putting C++ into the 11 | browser, let's put HTML into the C++. 12 | 13 | This is a personal project and I've only outlined the basic idea. I'm sure that 14 | the amazing thing that is 🕺 Open Source 💃 will bring me many amazing pull 15 | requests. I can see this framework going far. 16 | 17 | [Here](https://github.com/jfbastien/cpp-html/blob/master/hello.html.cpp)'s the 18 | classic `Hello, World!` example in C++ ﹤HTML﹥: 19 | 20 | ```cpp 21 | #include "cpp.html.h" 22 | 23 | ﹤html﹥ 24 | ﹤head﹥ 25 | ﹤/head﹥ 26 | ﹤body﹥ 27 | ﹤p﹥(Hello, World!)﹤/p﹥ 28 | ﹤/body﹥ 29 | ﹤/html﹥ 30 | ``` 31 | 32 | Want to contribute but not sure where to start? Check out 33 | [the issues](https://github.com/jfbastien/cpp-html/issues)! 34 | -------------------------------------------------------------------------------- /cpp.html.h: -------------------------------------------------------------------------------- 1 | #ifndef __﹤html﹥__ 2 | #define __﹤html﹥__ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | struct indent { 9 | inline static int indentation = 0; 10 | 11 | indent() 12 | { 13 | ++indentation; 14 | } 15 | 16 | ~indent() 17 | { 18 | --indentation; 19 | } 20 | 21 | static void print_indent() 22 | { 23 | for(auto i = indentation; i > 0; --i) { 24 | fputs(" ", stdout); 25 | } 26 | } 27 | }; 28 | 29 | 30 | struct list_item { 31 | template 32 | list_item(const char* thing) 33 | : text{thing} 34 | { 35 | } 36 | 37 | void print(std::string s) 38 | { 39 | indent::print_indent(); 40 | printf("%s\t%s", s.c_str(), text.c_str()); 41 | } 42 | 43 | std::string text; 44 | }; 45 | 46 | struct ignore_me_t {}; 47 | auto ignore_me = ignore_me_t{}; 48 | 49 | struct ordered_list { 50 | std::vector items; 51 | indent ind; 52 | 53 | template 54 | ordered_list(ignore_me_t, ListItems... listItemsPack) 55 | : items{listItemsPack...} 56 | { 57 | for(int i{}; i != items.size(); ++i) { 58 | items[i].print(std::to_string(i + 1)); 59 | puts(""); 60 | } 61 | puts(""); 62 | } 63 | }; 64 | 65 | struct unordered_list { 66 | std::vector items; 67 | indent ind; 68 | 69 | template 70 | unordered_list(ignore_me_t, ListItems... listItemsPack) 71 | : items{listItemsPack...} 72 | { 73 | for(int i{}; i != items.size(); ++i) { 74 | items[i].print("*"); 75 | puts(""); 76 | } 77 | puts(""); 78 | } 79 | }; 80 | 81 | #define ﹤html﹥ int main() { 82 | #define ﹤/html﹥ return 0; } 83 | #define ﹤head﹥ 84 | #define ﹤/head﹥ 85 | #define ﹤body﹥ 86 | #define ﹤/body﹥ 87 | #define ﹤p﹥(...) puts(#__VA_ARGS__ 88 | #define ﹤/p﹥ ); 89 | #define ﹤ol﹥ ordered_list {ignore_me 90 | #define ﹤/ol﹥ }; 91 | #define ﹤ul﹥ unordered_list {ignore_me 92 | #define ﹤/ul﹥ }; 93 | #define ﹤li﹥(...) , list_item{#__VA_ARGS__ 94 | #define ﹤/li﹥ } 95 | 96 | #endif 97 | -------------------------------------------------------------------------------- /hello.html.cpp: -------------------------------------------------------------------------------- 1 | #include "cpp.html.h" 2 | 3 | ﹤html﹥ 4 | ﹤head﹥ 5 | ﹤/head﹥ 6 | ﹤body﹥ 7 | ﹤p﹥(Hello, World!)﹤/p﹥ 8 | ﹤ol﹥ 9 | ﹤li﹥(This is an item in an ordered list!)﹤/li﹥ 10 | ﹤li﹥(Pretty coolˎ huh?)﹤/li﹥ 11 | ﹤li﹥(This is the last item!)﹤/li﹥ 12 | ﹤/ol﹥ 13 | 14 | ﹤ul﹥ 15 | ﹤li﹥(This is an item in an unordered list!)﹤/li﹥ 16 | ﹤li﹥(Also cool!)﹤/li﹥ 17 | ﹤/ul﹥ 18 | ﹤/body﹥ 19 | ﹤/html﹥ 20 | --------------------------------------------------------------------------------