initial commit
This commit is contained in:
commit
b4e2b700b5
|
|
@ -0,0 +1,27 @@
|
|||
# select data from an external source with Ori and close over it
|
||||
Say we have a file somewhere else with all our clients:
|
||||
|
||||
```yaml
|
||||
#clients.yaml
|
||||
client1:
|
||||
name: James Jamm
|
||||
email: james@jamfactory.com
|
||||
client2:
|
||||
name: Sammy Sauk
|
||||
email: sam@sockfactory.com
|
||||
```
|
||||
|
||||
We want to maintain our client database in one place, and get client data for each of their websites without exposing other clients' data.
|
||||
|
||||
We can do this with function in an ori expression file. The function takes a clientid, and returns just that client. Origami's syntax supports passing an argument to a data file as if it were a function.
|
||||
|
||||
```
|
||||
//clientdata.ori
|
||||
(clientid) => /path/to/clients.yaml(clientid)
|
||||
```
|
||||
|
||||
To get just James Jamm's data: `ori 'clientdata.ori("client1")'`
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
(clientid) => clients.yaml(clientid)
|
||||
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
#clients.yaml
|
||||
client1:
|
||||
name: James Jamm
|
||||
email: james@jamfactory.com
|
||||
client2:
|
||||
name: Sammy Sauk
|
||||
email: sam@sockfactory.com
|
||||
|
||||
Loading…
Reference in New Issue