Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // http://baussprojects.comlu.com/projects.php#daweb
- import std.array : replace, join;
- import std.conv : to;
- import std.string : isNumeric;
- /**
- * Class test.
- * HelloCreator creates a specific amount of lines with Hello and a number.
- */
- class HelloCreator {
- int amount;
- this(int amount) {
- this.amount = amount;
- }
- string create() {
- string hello;
- foreach (i; 0 .. amount)
- hello ~= "Hello " ~ to!string(i) ~ "!<br />\r\n";
- return hello;
- }
- }
- if (post) {
- // If POST do this
- // Attempts to get "number" from the post data. Gives an empty string if not found.
- string number = postData.get("number", "");
- if (!isNumeric(number)) {
- // If the input is not a number print an error message
- html = replace(html, "@VALUE", "Please type a number! '" ~ number ~ "' is not valid!");
- }
- else {
- // If the input is a number do this
- // Creates a new instance of HelloCreator with the amount of Hello's to be the input number
- auto hello = new HelloCreator(to!int(number));
- // Replaces "@VALUE" within the html with the return value of create()
- html = replace(html, "@VALUE", hello.create());
- }
- }
- else {
- // if GET do this
- // Creates a new instance of HelloCreator with the amount of Hello's to be 10
- auto hello = new HelloCreator(10);
- // Replaces "@VALUE" within the html with the return value of create()
- html = replace(html, "@VALUE", hello.create());
- }
- if (queryString) {
- // If there is a query string do this
- // Joins all the query string keys into a string with ", " as a separator
- html = replace(html, "@QUERIES", join(queryString.keys, ", "));
- }
- else {
- // If there is no query string just type N/A
- html = replace(html, "@QUERIES", "N/A");
- }
- <html>
- <head>
- <title>Index</title>
- </head>
- <body>
- @QUERIES
- <p>
- <span style="color: #ffffff; background-color: #000000;">
- @VALUE
- </span>
- </p>
- <form action="index.d" method="POST">
- Type a number:<br />
- <input type="text" name="number" /><br />
- <input type="submit" value="Submit" />
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement