Code Monkey home page Code Monkey logo

htmlbuilder's Introduction

HtmlBuilder

license Travis CI Linux Build Status AppVeyor Windows Build status

A simple C++ header-only HTML 5 Generator library, using a Document Object Model (DOM).

Copyright (c) 2017-2021 Sébastien Rombauts ([email protected])

Current status

Deployed in production in a small application.

Support

  • Windows 10 - VS2015 / 2017 / 2019
  • Linux Ubuntu 16.04 Clang 7 / GCC 5.4

Features

  1. DOM Model
  2. Example featuring Bootstrap's navigation bar

Missing features

  1. Encoding of HTML Entities (special chars)
  2. Support for HTML Comments
  3. Support for CSS inline style (this is probably easy)

Javascript inline script is currently out of scope.

Example

The following example is provided in src/Main.cpp.

Source Code

    HTML::Document document("Welcome to HTML");
    document.addAttribute("lang", "en");
    document << HTML::Header2("Generated HTML") << HTML::Break() << HTML::Break();
    document.body() << "Which results in the following HTML page (truncated to fit in this README): ";
    document << HTML::Text("Text directly in the body. ") << HTML::Text("Text directly in the body.") << HTML::Break()
        << HTML::Text("Text directly in the body.");
    document << HTML::Paragraph("This is the way to go for a big text in a multi-line paragraph.");
    document << HTML::Link("Google", "http://google.com").cls("my_style");
    document << (HTML::Paragraph("A paragraph. ").addAttribute("style", "font-family:arial")
        << HTML::Text("Text child.") << HTML::Break() << HTML::Text("And more text."));

    document << (HTML::List()
        << (HTML::ListItem("Text item"))
        << (HTML::ListItem() << HTML::Link("Github Link", "http://srombauts.github.io").title("SRombaut's Github home page"))
        << (HTML::ListItem() << (HTML::List()
                << HTML::ListItem("val1")
                << HTML::ListItem("val2"))));

    document << (HTML::Table()
        << (HTML::Row() << HTML::ColHeader("A") << HTML::ColHeader("B"))
        << (HTML::Row() << HTML::Col("Cell_11") << HTML::Col("Cell_12"))
        << (HTML::Row() << HTML::Col("Cell_21") << HTML::Col("Cell_22"))
        << (HTML::Row() << HTML::Col("") << HTML::Col("Cell_32")));

Generated HTML

Which results in the following HTML page (truncated to fit in this README):

Text directly in the body. Text directly in the body.
Text directly in the body.

This is the way to go for a big text in a multi-line paragraph.

Google

A paragraph. Text child.
And more text.

A B
Cell_11 Cell_12
Cell_21 Cell_22
Cell_32

Building with CMake

This is a header only library, so just include the include folder and go on.

Get cpplint submodule

git submodule init
git submodule update

Typical generic build (see also "build.bat" or "./build.sh")

mkdir build
cd build
cmake ..        # cmake .. -G "Visual Studio 10"    # for Visual Studio 2010
cmake --build . # make

Debug build for Unix Makefiles

mkdir Debug
cd Debug
cmake .. -DCMAKE_BUILD_TYPE=Debug   # -G "Unix Makefiles"
cmake --build . # make

Release build

mkdir Release
cd Release
cmake .. -DCMAKE_BUILD_TYPE=Release  # -G "Unix Makefiles"
cmake --build . # make

htmlbuilder's People

Contributors

srombauts avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.