Added add_type
This commit is contained in:
parent
c18389172f
commit
6fabb41ed1
|
@ -37,7 +37,7 @@ class MyThingType(Type):
|
||||||
return raw.value
|
return raw.value
|
||||||
|
|
||||||
def setup_env(self, **extra):
|
def setup_env(self, **extra):
|
||||||
self.env.types['mything'] = MyThingType
|
self.env.add_type(MyThingType)
|
||||||
```
|
```
|
||||||
|
|
||||||
For more information see [value_from_raw :ref](value-from-raw/).
|
For more information see [value_from_raw :ref](value-from-raw/).
|
||||||
|
|
|
@ -36,7 +36,7 @@ class LocationType(Type):
|
||||||
return (lng, lat)
|
return (lng, lat)
|
||||||
|
|
||||||
def setup_env(self, **extra):
|
def setup_env(self, **extra):
|
||||||
self.env.types['location'] = LocationType
|
self.env.add_type(LocationType)
|
||||||
```
|
```
|
||||||
|
|
||||||
## Raw Value
|
## Raw Value
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
title: add_type
|
||||||
|
---
|
||||||
|
signature: type
|
||||||
|
---
|
||||||
|
summary: Adds a new field type to the environment.
|
||||||
|
---
|
||||||
|
type: method
|
||||||
|
---
|
||||||
|
version_added: 2.0
|
||||||
|
---
|
||||||
|
body:
|
||||||
|
|
||||||
|
This registers a new [Field Type :ref](../../db/type/) with the environment
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
```python
|
||||||
|
from lektor.types import Type
|
||||||
|
|
||||||
|
class MyThingType(Type):
|
||||||
|
widget = 'singleline-text'
|
||||||
|
|
||||||
|
def value_from_raw(self, raw):
|
||||||
|
return raw.value
|
||||||
|
|
||||||
|
def setup_env(self, **extra):
|
||||||
|
self.env.add_type(MyThingType)
|
||||||
|
```
|
Loading…
Reference in New Issue