0

仲買人アプリのテンプレートを動的にループしたい yaml ファイルにプロジェクトのリストがありますが、より動的に実行できる/すべきかどうか、またはその方法がわかりません。

私は持っている:

data.projects.each do |f|
  proxy "/work/#{f[:name].parameterize}.html", "/work/template.html", 
    :locals => { name: f[:name], client: f[:client], ... } #would like to dynamically pull in keys as locals.
end

ignore "/work/template.html"

ヤムル:

-  name: Acme Website
   client: Acme Inc
   overview: "Cupcake ipsum dolor sit amet wafer gummi bears pudding applicake. Jujubes brownie powder. Sweet roll powder gingerbread gummies. Cupcake ice cream sweet roll pie lollipop. Jelly-o jelly-o apple pie chupa chups jelly jujubes gingerbread. Icing carrot cake powder chupa chups. Pudding sweet roll jelly-o muffin faworki biscuit. Marzipan marshmallow cake tiramisu caramels bear claw carrot cake cotton candy. Toffee danish sweet roll. Cookie topping powder toffee ice cream muffin dragée. Soufflé caramels apple pie chocolate cake cookie cake. Macaroon tiramisu halvah soufflé. Dessert toffee halvah chocolate cake bear claw."
   skills:
   - design
   - development
   - branding
   - ecommerce
   stack:
   - middleman
   - branding
   - design
4

2 に答える 2

1

projectテンプレート内で完全なオブジェクトを使用できますか?

data.projects.each do |p|
  proxy "/work/#{p[:name].parameterize}.html", "work/template.html",
    :locals => { :p => p }
end

...内のプロジェクトへのアクセスを許可する必要がありますhttp://0.0.0.0:4567/work/acme-website.html

<ul>
 <li><%= p.name %></li>
 <li><%= p.client %></li>
</ul>

結果:

  • アクメのウェブサイト
  • アクメ株式会社
于 2013-06-27T06:57:06.190 に答える
0

最初に、YAML を解析して Ruby オブジェクトに戻してから、そこから移動する必要があります。

require 'yaml'

doc = YAML.load(<<EOT)
---
-  name: Acme Website
  client: Acme Inc
  overview: "Cupcake ipsum dolor sit amet wafer gummi bears pudding applicake. Jujubes brownie powder. Sweet roll powder gingerbread gummies. Cupcake ice cream sweet roll pie lollipop. Jelly-o jelly-o apple pie chupa chups jelly jujubes gingerbread. Icing carrot cake powder chupa chups. Pudding sweet roll jelly-o muffin faworki biscuit. Marzipan marshmallow cake tiramisu caramels bear claw carrot cake cotton candy. Toffee danish sweet roll. Cookie topping powder toffee ice cream muffin dragée. Soufflé caramels apple pie chocolate cake cookie cake. Macaroon tiramisu halvah soufflé. Dessert toffee halvah chocolate cake bear claw."
  skills:
  - design
  - development
  - branding
  - ecommerce
  stack:
  - middleman
  - branding
  - design
EOT

require 'pp'
pp doc

どの出力:

[{"name"=>"Acme Website",
  "client"=>"Acme Inc",
  "overview"=>
  "Cupcake ipsum dolor sit amet wafer gummi bears pudding applicake. Jujubes brownie powder. Sweet roll powder gingerbread gummies. Cupcake ice cream sweet roll pie lollipop. Jelly-o jelly-o apple pie chupa chups jelly jujubes gingerbread. Icing carrot cake powder chupa chups. Pudding sweet roll jelly-o muffin faworki biscuit. Marzipan marshmallow cake tiramisu caramels bear claw carrot cake cotton candy. Toffee danish sweet roll. Cookie topping powder toffee ice cream muffin dragée. Soufflé caramels apple pie chocolate cake cookie cake. Macaroon tiramisu halvah soufflé. Dessert toffee halvah chocolate cake bear claw.",
  "skills"=>["design", "development", "branding", "ecommerce"],
  "stack"=>["middleman", "branding", "design"]}]

それはハッシュの配列です。返された配列を反復処理し、埋め込まれたハッシュを抽出して通常どおり処理できます。

doc.each { |h|
  puts h['name']
  puts h['client']
}
于 2013-02-26T15:43:27.387 に答える