lino.utils.jsgen¶
A framework for generating Javascript from Python.
See also Utilities for generating Javascript code.
Example:
>>> class TextField(Component):
... declare_type = DECLARE_VAR
>>> class Panel(Component):
... declare_type = DECLARE_VAR
>>> fld1 = TextField(fieldLabel="Field 1", name='fld1', xtype='textfield')
>>> fld2 = TextField(fieldLabel="Field 2", name='fld2', xtype='textfield')
>>> fld3 = TextField(fieldLabel="Field 3", name='fld3', xtype='textfield')
>>> p1 = Panel(title="Panel",name='p1', xtype='panel', items=[fld2, fld3])
>>> main = Component(title="Main", name='main', xtype='form', items=[fld1, p1])
>>> d = dict(main=main, wc=[1, 2, 3])
>>> for ln in declare_vars(d):
... print(ln)
var fld11 = { "fieldLabel": "Field 1", "xtype": "textfield" };
var fld22 = { "fieldLabel": "Field 2", "xtype": "textfield" };
var fld33 = { "fieldLabel": "Field 3", "xtype": "textfield" };
var p14 = { "items": [ fld22, fld33 ], "title": "Panel", "xtype": "panel" };
>>> print(py2js(d))
{ "main": { "items": [ fld11, p14 ], "title": "Main", "xtype": "form" }, "wc": [ 1, 2, 3 ] }
(This module's source code is available here.)
Functions
|
|
|
Yields the Javascript lines that declare the given |
|
|
|
|
|
|
|
|
|
Note that None values are rendered as |
|
Classes
|
A Component is a Variable whose value is a dict of options. |
|
|
|
|
|
A visible component |
|
A string that py2js will represent as is, not between quotes. |
-
lino.utils.jsgen.
obj2dict
(o, attrs)¶ - Parameters
o -- object
attrs -- space seperated string or list of strings of wanted attrs
kws -- existing dict of values
- Returns
dict with key:value pairs that match the object[arrts] if arrts exist in object
-
class
lino.utils.jsgen.
js_code
(s)¶ Bases:
object
A string that py2js will represent as is, not between quotes.
-
class
lino.utils.jsgen.
Component
(name=None, **options)¶ Bases:
lino.utils.jsgen.Variable
A Component is a Variable whose value is a dict of options. Deserves more documentation.
-
walk
()¶ Walk over this component and its children.
-
-
class
lino.utils.jsgen.
VisibleComponent
(name, **kwargs)¶ Bases:
lino.utils.jsgen.Component
,lino.core.permissions.Permittable
A visible component
-
install_permission_handler
()¶ Define the allow_read handler used by
get_view_permission()
. This must be done only once, but after having configureddebug_permissions
andrequired_roles
.
-
-
lino.utils.jsgen.
declare_vars
(v)¶ Yields the Javascript lines that declare the given
Variable
v. If v is aComponent
, list, tuple or dict which contains other variables, recursively yields also the lines to declare these.
-
lino.utils.jsgen.
py2js
(v, compact=True)¶ Note that None values are rendered as
null
(notundefined
.