-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for binding to constant values (#37)
- Loading branch information
Showing
14 changed files
with
101 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
.. py:module:: rolumns | ||
:noindex: | ||
|
||
Constants | ||
========= | ||
|
||
The Problem | ||
----------- | ||
|
||
Sometimes you want to bind a column to a static constant that doesn't exist within your source data. | ||
|
||
We'll achieve this by binding the constant to the column's :class:`Source`. | ||
|
||
Code Sample | ||
----------- | ||
|
||
.. testcode:: | ||
|
||
from rolumns import Columns, Source | ||
from rolumns.renderers import RowsRenderer | ||
|
||
data = [ | ||
{ | ||
"name": "Robert Pringles", | ||
"address": { | ||
"planet": "Earth" | ||
} | ||
}, | ||
{ | ||
"name": "Daniel Sausage", | ||
"address": { | ||
"planet": "Mars" | ||
} | ||
}, | ||
{ | ||
"name": "Charlie Marmalade", | ||
"address": { | ||
"planet": "Pluto" | ||
} | ||
} | ||
] | ||
|
||
columns = Columns() | ||
columns.add("Name", "name") | ||
columns.add("Address", "address.planet") | ||
columns.add("Lives on a Planet?", Source(constant="Yes")) | ||
|
||
renderer = RowsRenderer(columns) | ||
rows = renderer.render(data) | ||
|
||
print(list(rows)) | ||
|
||
Result | ||
------ | ||
|
||
.. testoutput:: | ||
:options: +NORMALIZE_WHITESPACE | ||
|
||
[['Name', 'Address', 'Lives on a Planet?'], | ||
['Robert Pringles', 'Earth', 'Yes'], | ||
['Daniel Sausage', 'Mars', 'Yes'], | ||
['Charlie Marmalade', 'Pluto', 'Yes']] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[ | ||
["Name", "Favourite Colour", "Delightful?"], | ||
["alice", "green", "Yes"], | ||
["bob", "magenta", "Yes"], | ||
["charlie", "orange", "Yes"] | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters