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 ?
<%
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
%>
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 ?
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.
You've picked an interesting way to be generating YAML --with ERB?
Beyond that you'll need to get rid of the initial '---' and then indent
properly. Facets has the #tabto method you can use, though I'm not sure in where
you have to put the code:
require 'facet/string/tabto'
class String
def to_yaml_fragment(n)
self.to_yaml.sub('---','').tabto(n)
end
end
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 ?
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.
You've picked an interesting way to be generating YAML --with ERB?
In Rails, the test fixture files are YAML files that get pre-processed
through ERb.
Beyond that you'll need to get rid of the initial '---' and then indent
properly. Facets has the #tabto method you can use, though I'm not sure in where
you have to put the code:
require 'facet/string/tabto'
class String
def to_yaml_fragment(n)
self.to_yaml.sub('---','').tabto(n)
end
end
On 4/22/06, dblack@wobblini.net <dblack@wobblini.net> wrote:
Hi --
On Sun, 23 Apr 2006, 13 wrote:
>> How about:
>> params:
>> currencies: <%= random_array.inspect %>
>>
>> or something like that.
>>
>> David
>
> Wow. Thanks, David. This is simple and straight forward, just what I need !
>
> # somewhere outside fixture do the initialization of date array
> today = Date.today
> first = Date.new(today.year, today.mon, 1)
> last = (first >> 1) - 1
> dates = (first..last).collect { |d| d.to_s }
>
> Then in *.yml
>
> params:
> <%= dates.rand_subset %> # rand_subset is from facets library
I think you'll want to call .inspect; otherwise it will all be strung
together as a string.