Re: templates in yaml

"Makoto Kuwata" <[email protected]>
Newsgroups gmane.text.yaml.general
Message-ID <[email protected]>
How about Erubis if you are a ruby user?
http://www.kuwata-lab.com/erubis/


---- template.ryaml ----
<% for item in @list %>
<%= item['name'] %>:
  - tel: <%= item['tel'] %>
  - address: <%= item['address'] %>
<% end %>


---- data.yaml ----
list:
  - name:    Adam
    tel:     '000000'
    address: some street
  - name:    Eve
    tel:     11111
    address: some other street
  - name:    Peter
    tel:     22222
    address: other


---- result ----
$ erubis -f data.yaml template.ryaml
Adam:
  - tel: 000000
  - address: some street
Eve:
  - tel: 11111
  - address: some other street
Peter:
  - tel: 22222
  - address: other



Or:


---- data.rb ----
table = [
  [ "Adam",  "000000", "some street", ],
  [ "Eve",   "111111", "some other street", ],
  [ "Peter", "222222", "other", ],
]
@list = table.collect { |e| {"name"=>e[0], "tel"=>e[1], "address"=>e[2]} }


---- result ----
$ erubis -f data.rb template.ryaml
Adam:
  - tel: 000000
  - address: some street
Eve:
  - tel: 111111
  - address: some other street
Peter:
  - tel: 222222
  - address: other



--
[email protected]


On 6/10/07, Clark C. Evans <[email protected]> wrote:
> on Fri, 08 Jun 2007 23:04:54 +0200, Konto na WP wrote:
> |
> | In YAML I write:
> |
> | Adam:
> |  -tel: 000000
> |  -adress: some street
> | Eve:
> |  -tel: 11111
> |  -adress: some other street
> | Peter:
> |  -tel: 22222
> |  -adress: other
> |
> | Is there some templates, so I don't have
> | to repeat "tel", "adress"?
> |
> | The doc would look like this:
> |
> | Adam:
> |  -00000
> |  -some street
> |
> | etc.
> |
> | and I could use ['adam']['tel'].
>
> It seems that you could do this quite easily with a program in
> your language of choice that "pre-processes" the YAML.  However,
> there isn't a general macro-processing language like that and
> I'd be hesitant to try and invent one -- a general purpose
> programming language will do just as well.
>
> Cheers,
>
> Clark
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by DB2 Express
> Download DB2 Express C - the FREE version of DB2 express and take
> control of your XML. No limits. Just data. Click to get it now.
> http://sourceforge.net/powerbar/db2/
> _______________________________________________
> Yaml-core mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/yaml-core
>
>

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.