The Hello, World! application

Here is a preview of the famous "Hello, World!" program made with the Atlas toolkit:

Hello World! preview

Like all "Hello, World!" applications, this one focuses on the basics too. For a live demonstration: http://q37.info/runkit/Hello.

Below the source code of this application for the different available languages:

Java source code

import info.q37.atlas.*;
import java.util.HashMap;
import java.nio.file.*;

class Hello extends Atlas {
  public void handle(DOM dom, String action, String id) {
    switch (action) {
    case "":  // Special action launched on each new session.
      try {
        dom.setLayout("", new String(Files.readAllBytes(Paths.get("Main.html"))));
        dom.focus("input");
      } catch (Exception e) {
        System.out.println(e.getStackTrace());
      }
      break;
    case "Typing":
      dom.setContent("name", dom.getContent(id));
      break;
    case "Clear":
      if (dom.confirm("Are you sure ?"))
        dom.setContents(new HashMap<String, String>() {
          {
            put("input", "");
            put("name", "");
          }
        });
      break;
    }
  }

  public static void main(String[] args) throws Exception {
    launch();

    for (;;)
      new Hello();
  }
}

To install this example, among others: http://github.com/epeios-q37/atlas-java/.

JavaScript source code for Node.js

const atlas = require('atlastk');
const fs = require('fs');

const callbacks = {
  "": (dom, id) => dom.setLayout("", fs.readFileSync("Main.html", "utf8"),
    () => dom.focus("input")),
  "Typing": (dom, id) => dom.getContent(id,
    (name) => dom.setContent("name", name)),
  "Clear": (dom, id) => dom.confirm("Are you sure ?",
    (answer) => { if (answer) dom.setContents({ "input": "", "name": "" }) })
};

atlas.launch(() => new atlas.DOM(), callbacks);

To install this example, among others: http://github.com/epeios-q37/atlas-node/.

You can also launch npm install, create a Hello.js file with above source code, or retrieve this file at http://q37.info/download/assets/Hello.js, and then launch node Hello.js.

PHP source code

<?php
require "phar://Atlas.phar/Atlas.php";

class Hello extends Threaded {
 public function handle($dom, $action, $id) {
  switch ($action) {
  case "":  // Special action launched on each new session.
   $dom->setLayout("", file_get_contents("Main.html"));
   $dom->focus("input");
   break;
  case "Typing":
   $dom->setContent("name", $dom->getContent($id));
   break;
  case "Clear":
   if ($dom->confirm("Are you sure?")) {
    $dom->setContents(["input" => "", "name" => ""]);
   }
   break;
  }
 }
}

function hello() {
 return new Hello();
}

Atlas::launch('hello'); // 'hello' refers the above function.
?>

To install this example, among others: http://github.com/epeios-q37/atlas-php/.

Python source code

import Atlas

def acConnect(this, dom, id):
  dom.setLayout("", open("Main.html").read())
  dom.focus("input")

callbacks = {
    "": acConnect,
    "Typing": lambda this, dom, id:
      dom.setContent("name", dom.getContent(id)),
    "Clear": lambda this, dom, id:
      dom.setContents( {  "input": "", "name": ""} )
      if dom.confirm( "Are you sure ?" ) else None
  }

Atlas.launch(Callbacks)

To install this example, among others: http://github.com/epeios-q37/atlas-python/.

HTML file

This is the content of the Main.html file, which content is given as parameter to the setLayout(...) function in above source codes.

<fieldset>
 <label>Name:</label>
 <input id="input" maxlength="20" placeholder="Enter a name here" type="text" data-xdh-onevent="input|Typing" />
 <button data-xdh-onevent="Clear">Clear</button>
 <hr />
 <h1>
  <span>Hello </span>
  <span style="font-style: italic;" id="name"></span>
  <span>!</span>
 </h1>
</fieldset>