Rewrite
This commit is contained in:
@@ -1 +0,0 @@
|
||||
<!-- This is a comment. Comments have no effect! -->
|
||||
@@ -1,45 +0,0 @@
|
||||
<!--
|
||||
You can have regular HTML elements in WL.
|
||||
-->
|
||||
|
||||
<a head="some_page.html">I'm a link</a>
|
||||
|
||||
<!--
|
||||
You can declare variables and use them in the HTML by
|
||||
escaping the name
|
||||
-->
|
||||
|
||||
let name = "cozis"
|
||||
|
||||
<p>Hello from \name</p>
|
||||
|
||||
<!--
|
||||
HTML attributes are evaluated as WL expressions.
|
||||
|
||||
The following evaluates to
|
||||
|
||||
<p A=Some value B=7></p>
|
||||
|
||||
which, to be fair, isn't right. There shoud be quotes
|
||||
around "Some value"
|
||||
-->
|
||||
|
||||
let valueA = "Some value"
|
||||
|
||||
<p A=valueA B=1+2*3></p>
|
||||
|
||||
<!--
|
||||
HTML attributes are just expressions, and therefore
|
||||
can be assigned to variables
|
||||
-->
|
||||
|
||||
let link = <a href="page.html">Click me</a>
|
||||
|
||||
<!--
|
||||
And then can be printed by simply stating the name
|
||||
of the variable or by embedding it in a lager element
|
||||
-->
|
||||
|
||||
link
|
||||
|
||||
<p>You should click this link: \link</p>
|
||||
@@ -1,58 +0,0 @@
|
||||
<!--
|
||||
You can embed elements based on conditions
|
||||
using plain if-else statements
|
||||
-->
|
||||
|
||||
let a = 2
|
||||
|
||||
if a == 1: {
|
||||
<a>The condition is true</a>
|
||||
} else {
|
||||
<a>It is false</a>
|
||||
}
|
||||
|
||||
<!--
|
||||
If the branch occurs inside an HTML element,
|
||||
you must escape the if keyword with a backslash
|
||||
-->
|
||||
|
||||
<p>
|
||||
\if a == 1: {
|
||||
<a>The condition is true</a>
|
||||
} else {
|
||||
<a>It is false</a>
|
||||
}
|
||||
</p>
|
||||
|
||||
<!--
|
||||
Similarly, you can execute code multiple times
|
||||
based on a condition using a while statement.
|
||||
|
||||
The following loop generates the output
|
||||
|
||||
<a>I'm link number 1</a>
|
||||
<a>I'm link number 2</a>
|
||||
<a>I'm link number 3</a>
|
||||
|
||||
Note how the i variable is printed after adding
|
||||
1 to it.
|
||||
-->
|
||||
|
||||
let i = 0
|
||||
while i < 3: {
|
||||
<a>I'm link number \i + 1</a>
|
||||
i = i + 1
|
||||
}
|
||||
|
||||
<!--
|
||||
To insert the loop in an HTML element, you need
|
||||
to escape it
|
||||
-->
|
||||
|
||||
i = 0
|
||||
<ul>
|
||||
\while i < 3: {
|
||||
<li>I'm link number \i + 1</li>
|
||||
i = i + 1
|
||||
}
|
||||
</ul>
|
||||
@@ -1,83 +0,0 @@
|
||||
|
||||
<!--
|
||||
WL supports integers, floats, strings, array and map
|
||||
values. Arrays are what you expect. They allow one to
|
||||
store sequences of elements.
|
||||
|
||||
The following snippet prints
|
||||
|
||||
123
|
||||
|
||||
which is the string obtained by concatenating all
|
||||
the elements
|
||||
-->
|
||||
|
||||
let my_var = [1, 2, 3]
|
||||
|
||||
my_var
|
||||
|
||||
<!--
|
||||
Maps are similar to Python dicts and Javascript
|
||||
objects. They store associations between values
|
||||
|
||||
The following prints
|
||||
|
||||
Second
|
||||
-->
|
||||
|
||||
let my_map = { 1: "First", 2: "Second", 3: "Third" }
|
||||
|
||||
my_map[2]
|
||||
|
||||
<!--
|
||||
You can have any type as a map key, and if the
|
||||
key is a string that is also a valid variable
|
||||
name, you can drop the double quotes
|
||||
-->
|
||||
|
||||
let person = { "name": "Cozis" }
|
||||
let person_no_quotes = { name: "Cozis" }
|
||||
|
||||
<!--
|
||||
You can iterate over the keys of a map using the
|
||||
for loop. The following prints the string
|
||||
|
||||
ABC
|
||||
|
||||
-->
|
||||
|
||||
for key in { A: 1, B: 2, C: 3 }: {
|
||||
key
|
||||
}
|
||||
|
||||
for key, i in { A: 1, B: 2, C: 3 }: {
|
||||
<!--
|
||||
You can keep track of the current index by adding
|
||||
a second interation variable
|
||||
-->
|
||||
}
|
||||
|
||||
<!--
|
||||
When using a for loop over a map, the first
|
||||
iteration variable holds its keys. When the
|
||||
iterated value is an array, the first variable
|
||||
returns its values
|
||||
-->
|
||||
|
||||
for val in [5, 3, 7]:
|
||||
val
|
||||
|
||||
for val, i in [5, 3, 7]:
|
||||
i
|
||||
|
||||
<!--
|
||||
As usual, you can have for statements in HTML
|
||||
by escaping them
|
||||
-->
|
||||
|
||||
let links = ["http://github.com", "http://reddit.com"]
|
||||
|
||||
<ul>
|
||||
\for link, i in links:
|
||||
<li><a href=link>I'm link number \i</a></li>
|
||||
</ul>
|
||||
@@ -1,26 +0,0 @@
|
||||
|
||||
<!--
|
||||
You can declare functions too.
|
||||
|
||||
Unlike the global scope, expressions
|
||||
are not printed by default, so you need
|
||||
to use the print statement to do so.
|
||||
-->
|
||||
|
||||
fun say_hello(name) {
|
||||
print "Hello to "
|
||||
print name
|
||||
}
|
||||
|
||||
say_hello("cozis")
|
||||
|
||||
<!--
|
||||
If a function is implemented with a single
|
||||
expression, you can omit the curly braces
|
||||
to return it
|
||||
-->
|
||||
|
||||
fun say_hello_2(name)
|
||||
<a>Hello, \name!</a>
|
||||
|
||||
say_hello_2("cozis")
|
||||
Reference in New Issue
Block a user