The Pit is a engine to render pashmak code inside the Html/Text code(PIT: Pashmak in Text).
Pit is something like PHP’s structure to write the code inside other formats(for example Hello <?php echo $name; ?>
).
For example:
{
$name = 'parsa'
}
<html lang="en">
<head>
<title>Document</title>
</head>
<body>
hello
{ println('hello world') }
</body>
</html>
then we can render this code using this command:
$ pashmak @pit myfile.html
output:
<html lang="en">
<head>
<title>Document</title>
</head>
<body>
hello parsa
hello world
</body>
</html>
this system can be used in web development.
Also you can use it in every text format, not only html.
for example:
{ $name = 'someone' }
hello {= $name }
output:
hello someone
Usage of this system is very easy.
We have 2 statements:
{ code }
: runs a pashmak code between { }
OR `{= <value-or-variable> }`: prints the value of between
or {= }
for example:
{
$somevar = 'somevalue'
func somefunc
return 'hello somefunc'
endfunc
}
<h1>Hello {= $somevar }</h1>
<h2>{= somefunc() }</h2>
output:
<h1>Hello somevalue</h1>
<h2>hello somefunc</h2>
You only need to run:
$ pashmak @pit /path/to/file.html
Also you can use this system as a library in your pashmak code.
Example:
import @pit
$output = pit.run_file('/path/to/file.html')
$output = pit.run('<code as string>')
The run_file
function gets file path and runs that and returns the output.
run
function gets code as string and runs that and returns the output.
Also you can pass a Second Argument to them. This argument should be a boolean. if this is True
, this engine runs code directly and shows the output. but if this is False
(default is false), pit runs the code and returns output as string.
for example:
import @pits
$output = pit.run_file('/path/to/file.html', True)
$output = pit.run('<code as string>', True)
{
and }
characters inside codeThe {
and }
chars are special chars that this system do not prints them like normal characters. If you want to use them as a normal character, you should put a \
before them.
For example:
<div>{ println('the \{\}') }</div>
output:
<div>the {}</div>
You can use if
and loop
in this system.
for example:
{ if $age > 18 }
<div class="alert alert-success">
Welcome!
</div>
{ else }
<div class="alert alert-danger">
You cannot access to this Site! :))
</div>
{ endif }
loops:
{
$i = 0
while $i < 10
}<div>hello </div>
{
$i = $i + 1
endwhile
}
output:
<div>hello 0</div>
<div>hello 1</div>
<div>hello 2</div>
<div>hello 3</div>
<div>hello 4</div>
<div>hello 5</div>
<div>hello 6</div>
<div>hello 7</div>
<div>hello 8</div>
<div>hello 9</div>
$__htmldir__
and $__htmlfile__
variablesThe $__htmlfile__
variable contains the current file path.
The $__htmldir__
contains the current file parent directory path.
You can include other html files in your file.
for example, we have foo.html
and bar.html
:
foo.html
:<h1>Hello world</h1>
{
pit.include($__htmldir__ + '/bar.html') # include the bar.html
}
<h3>Good bye</h3>
bar.html
:<div>I am bar</div>
when we run foo.html
, output is this:
<h1>Hello world</h1>
<div>I am bar</div>
<h3>Good bye</h3>
You can include other html files using pit.include
function and pass file path to that.
Also you can send the data while including a file. for example:
{ pit.include('other.html', \{'key1': 'value1', 'key2': 'value2'\}) }
Then that data is accessible in other.html
with $htmldata
variable.
You can write your script and add a shebang for this and make it executable file. For example:
#!/usr/bin/pashmak @pit
{$name = 'parsa'}
<h1>Hello {= $name }</h1>
Then:
$ chmod +x myfile.html
Now you can run it:
$ ./myfile.html
output:
<h1>Hello parsa</h1>