Boost logo

Boost :

Subject: Re: [boost] Help with the wandbox online C++ compiler REST API please
From: Krzysztof Jusiak (krzysztof_at_[hidden])
Date: 2015-06-19 06:48:08


Yea, Wandbox has some limits for the JSON payload, but I have never checked
it properly, because was working for my library our of the box. Guess it's
small enough.
On the other hand, wasn't working for Hana and, therefore, Louis asked for
the feature to sync whole dirs. The only issue with it is that tabs are
taking almost the whole screen, but it does work nicely.
Anyway, I was experimenting with Wandbox a bit more and noticed they do
allow cross http requests from js.
So, I tried to add edit/compile panel with examples and library taken
directly from github to the main website.
Used CodeMirror (https://codemirror.net/) for syntax highlighting as well
(code below).
This approach gives you the option to compile and modify all code examples
just by clicking a button, a bit like on http://cppreference.com, but with
your library.
They also allow to frame their website, so it may be added to the
documentation like here (
http://krzysztof-jusiak.github.io/di/cpp14/boost/libs/di/doc/html/di/try_it_online.html
).

<-------- index.html
<script src="cm/lib/codemirror.js"></script>
<script src="cm/mode/clike/clike.js"></script>
<script src="try_it_online.js"></script>

<textarea id="code" ></textarea>
<button onclick="compile_an_run()">Compile & Run</button>
<textarea id="result" ></textarea>
------------>

<--------------- try_it_online.js
var di = get_cpp_file("
https://raw.githubusercontent.com/krzysztof-jusiak/di/cpp14/include/boost/di.hpp
");

function get_cpp_file(file) {
     var cpp_file = new XMLHttpRequest();
     cpp_file.open("GET", file, false);
     cpp_file.send();
     return cpp_file.responseText;
}

function compile_and_run() {
var http = new XMLHttpRequest();
http.open("POST", "http://melpon.org/wandbox/api/compile.json", false);
    http.send(
        JSON.stringify({
          "code" : di
        , "codes" : [{
              "file" : "boost/di.hpp"
            , "code" : di
           }]
         , "options":
"warning,cpp-pedantic-errors,optimize,boost-nothing,c++14"
         , "compiler": "clang-head"
    }));

result.value = http.response;
}

function get_examples() {
code.value = get_cpp_file("
https://raw.githubusercontent.com/krzysztof-jusiak/di/cpp14/example/try_it_online/main.cpp
");

    var cpp_code = CodeMirror.fromTextArea(code, {
        lineNumbers: true,
        matchBrackets: true,
        mode: "text/x-c++src"
      });

    cpp_code.setSize(900, 400);

    var cpp_result = CodeMirror.fromTextArea(result, {
        lineNumbers: false,
        matchBrackets: true,
        readOnly: true,
        mode: "text/x-c++src"
      });

    cpp_result.setSize(900, 200);
}
------------->

On Fri, Jun 19, 2015 at 2:54 AM, Niall Douglas <s_sourceforge_at_[hidden]>
wrote:

> On 19 Jun 2015 at 0:59, Louis Dionne wrote:
>
> > Anyway, I totally suck at bash scripting so here's the Python script I
> use
> > to upload my stuff to Wandbox:
> >
> > https://github.com/ldionne/hana/blob/41c9d6e/cmake/wandbox.py
> >
> > It should be generic enough so that you can use it without many
> modifications.
>
> Your script works perfectly. Damn, I wasted many hours on mine.
>
> A *huge* thank you Louis.
>
> Niall
> --
> ned Productions Limited Consulting
> http://www.nedproductions.biz/
> http://ie.linkedin.com/in/nialldouglas/
>
>
>
>
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk