Skip to content

Commit b5d5875

Browse files
committed
improved documentation
1 parent 08ae618 commit b5d5875

5 files changed

Lines changed: 50 additions & 42 deletions

File tree

doc/foundation/static/css/app.css

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,27 @@ h1, h2, h3, h4, h5, .top-bar .name h1 a {
4141

4242
.container .row {
4343
background-color: rgba(0, 0, 0, 0.3);
44+
}
45+
46+
.note {
47+
border: 1px solid #2BA6CB;
48+
background-color: rgba(46, 166, 203, 0.3);
49+
}
50+
51+
.hightlight {
52+
margin-bottom: 1em;
53+
}
54+
55+
.versionchanged {
56+
border: 1px solid white;
57+
background-color: rgba(255, 255, 255, 0.3);
58+
padding: 5px;
59+
}
60+
61+
.versionmodified {
62+
font-weight: bold;
63+
}
64+
65+
.pre {
66+
color: #E44D26;
4467
}
-26 Bytes
Loading

doc/source/howtos.rst

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,30 @@ How to write Python in PythonScript
44
How to use PythonScript ?
55
-------------------------
66

7-
Install PythonScriptTranslator::
7+
Install PythonScriptTranslator:
8+
9+
.. code-block:: sh
810
911
pip install PythonScriptTranslator
1012
1113
And download the latest version on the master branch of `pythonscript.js <https://raw.github.com/amirouche/PythonScript/master/pythonscript.js>`_.
1214

13-
Prepare a app.html file that can look like the following:
15+
Prepare a ``app.html`` file that can look like the following:
1416

1517
.. code-block:: html
1618

1719
<script src="pythonscript.js" type="text/javascript" charset="utf-8"></script>
1820
<script src="app.py.js" type="text/javascript" charset="utf-8"></script>
1921

20-
That is all, ``app.py.js`` is the result of the compilation of a ``app.py`` with the following command::
22+
That is all, ``app.py.js`` is the result of the compilation of a ``app.py`` with the following command:
2123

22-
pythonscript < app.py > app.py.js
24+
.. code-block:: sh
2325
26+
pythonscript < app.py > app.py.js
2427
2528
.. note:: The following tests can be done in the `online editor <http://apppyjs.appspot.com/>`_.
2629

27-
.. note:: Or you can use the mini `deli Django project <https://github.com/amirouche/PythonScript/tree/master/django-demo>`_.
30+
.. note:: Or you can use the mini `demo Django project <https://github.com/amirouche/PythonScript/tree/master/django-demo>`_.
2831

2932
.. note:: Whatever route you go you will need `firebug <https://addons.mozilla.org/fr/firefox/addon/firebug/>`_.
3033

@@ -36,7 +39,7 @@ The old ``print`` statement will be converted to Javascript ``console.log`` whic
3639
Dealing with variables
3740
----------------------
3841

39-
This is very important! Just like in Javascript you **must** «declare» the variables using the ``var`` function. For instance ``var(spam)``. It can take several arguments ``var(spam, egg, bottle)``. This is because PythonScript use the underlying Javascript variable scope and in Javascript a variable is by default global. The partical consequence is that you **must** declare every usage of a variable *except* if you want to use a global (which seldom happens). Typical code in PythonScript looks like:
42+
This is very important! Just like in Javascript you **must** «declare» the variables using the ``var`` function. For instance ``var(spam)``. It can take several arguments ``var(spam, egg, bottle)``. This is because PythonScript use the underlying Javascript variable scope and in Javascript a variable is by default global. The pratical consequence is that you **must** declare every usage of a variable *except* if you want to use a global (which seldom happens). Typical code in PythonScript looks like:
4043

4144
.. code-block:: python
4245
@@ -58,7 +61,9 @@ A function is defined just like in Python:
5861
5962
my_function(1,2,3,4,5,spam=6,egg=7)
6063
61-
The above code will print in a browser console the following::
64+
The above code will print in a browser console the following:
65+
66+
.. code-block:: javascript
6267
6368
1 2 3 Object { __class__={...}, __dict__={...}} Object { __class__={...}, __dict__={...}}
6469
@@ -81,7 +86,9 @@ Let's define a function that is more verbose:
8186
8287
my_function(1,2,3,4,5,spam=6,egg=7)
8388
84-
It will print in the browser console the following::
89+
It will print in the browser console the following:
90+
91+
.. code-block:: javascript
8592
8693
foo
8794
@@ -111,23 +118,15 @@ What we expected.
111118

112119
Also, as in Python, functions are objects so you can use them as such.
113120

114-
**Becarful**, ``*args`` and ``**kwargs`` are supported in definition but not in calling, this means that the following:
115-
116-
.. code-block:: python
117-
118-
args = list()
119-
kwargs = dict()
120-
my_function(*args, **kwargs)
121-
122-
Will **not** work.
123-
121+
.. versionchanged:: 0.7
122+
Added support for ``*`` and ``**`` in calling, pratically it means that given ``args`` a ``list`` and ``kwargs`` a ``dict`` you can use the following call ``function(*args, **kwargs)``.
124123

125124
How to work with classes?
126125
-------------------------
127126

128127
Once functions are done, classes are just a piece of cake, except there is yet no ``__get_attribute__`` or ``__getattr__`` hook it similar to CPython. Data descriptors works the same way. And metaclass is explained in the following paragraph.
129128

130-
.. warning:: You don't have to inherit ``object`` actually there is no ``object`` object in PythonScript yet.
129+
.. warning:: You don't have to inherit ``object`` actually there is no ``object`` object in PythonScript.
131130

132131

133132
How to use ``__metaclass__`` property?

doc/source/internals.rst

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ Compilation
1818
JSGenerator -> "Javascript" [folded];
1919
}
2020

21-
This is the description of ``pythonscript`` command. Mind the fact that there is no actual ``pythontopythonjs`` command this is done on the fly.
21+
This is the description of ``pythonscript`` command.
22+
23+
.. versionchanged:: 0.7
24+
There is now ``python_to_pythonjs`` command that allow you to review the python code generated before it's converted to javascript
25+
2226

2327
Execution
2428
---------
@@ -50,12 +54,12 @@ In the following we will see in order:
5054
``pythonjs``
5155
------------
5256

53-
``pythonjs`` knows how to translate:
57+
``pythonjs`` command knows how to translate:
5458

55-
- Python functions to Javascript ones
59+
- Restricted Python functions to Javascript
5660
- It handles attribute access e.g. ``spam.egg.foobarbaz``
5761
- Add brackets and semi-colons
58-
- ``print(*args)`` are converted to ``console.log(*args)``
62+
- ``print(foo, bar, flower)`` are converted to ``console.log(foo, bar, flower)``
5963
- ``for i in jsrange(int)`` are converted to Javascript for loops
6064

6165
It also support two special functions ``JS(str)`` and ``var(*args)``:
@@ -78,7 +82,7 @@ Will be translated to the following Javascript code:
7882
d = new Array();
7983
d.push(1)
8084
81-
This makes it possible to:
85+
This makes possible to:
8286

8387
- Support Javascript syntax that is not supported by Python.
8488
- Bypass translation process as it will be shown later.
@@ -128,7 +132,6 @@ Create an array of integers that can be iterated over by the ``for`` loop genera
128132
``create_array`` will create a Javascript array with ``args``. This function circunvent a behavior in Javascript where ``new Array(42)`` and ``new Array(42, 24)`` behaves differently.
129133

130134

131-
132135
``adapt_arguments()``
133136
~~~~~~~~~~~~~~~~~~~~~
134137

pythonscript/main.py

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)