On 4/22/06, 13 <one.three / gmail.com> wrote:
> Hi,
>
> I'm trying to genereate YAML fixtures with ERB, but I can't get it to
> work with nested maps. Here is my code:
>
> $ cat currencies.yml
> first:
>   id: 1
>   filename: dummy1.png
>   params:
>     <%= { :dates => ['2006-04-20'], :currencies => ['USD'] }.to_yaml %>
>
> Here is what i get:
>
> $ erb -r yaml currencies.yml
>
> first:
>   id: 1
>   filename: dummy1.png
>   params:
>     ---
> :currencies:
> - USD
> :dates:
> - "2006-04-20"
>
> In the nested map (params column) only the first line is indented. How
> can I configure  YAML to properly indent other lines too ? I have
> tried to set param :Indent => 4, but without any success. Or maybe
> there ar some other methods how can I generate fixtures such files ?
>
> Help me, please.
>
> --
> Martins
>

Ok. I've managed to create a quick hack:

<%
def fix(lines)
  # strip yaml document separator and pad each line with 4 spaces
  lines.select { |s| s !~ /^---/ }.collect { |s| s.insert(0, '    ') }.join
end
%>

another:
  id: 2
  filename: dummy2.png
  params:
<%= fix({ :dates => ['2006-04-20'], :currencies => ['RUB', 'HKD'] }.to_yaml) %>

I know there are some better ways to solve my problem ...

--
Martins