Added add_type

This commit is contained in:
Armin Ronacher 2016-01-02 22:14:32 +01:00
parent c18389172f
commit 6fabb41ed1
3 changed files with 30 additions and 2 deletions

View File

@ -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/).

View File

@ -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

View File

@ -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)
```