Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Prototyping 3 — Data

Prototyping 3 — Data

Brief overview over YAML and how to use it within a prototype for I18n and other purposes.

Florian Plank

June 12, 2012
Tweet

More Decks by Florian Plank

Other Decks in Programming

Transcript

  1. XML

  2. <?xml version="1.0" encoding="UTF-8" ?> <books> <book id="1"> <title>Pride and Prejudice</title>

    <author>Jane Austen</author> </book> <book id="2"> <title>Brave New World</title> <author>Aldous Huxley</author> </book> </books>
  3. <?xml version="1.0" encoding="UTF-8" ?> <books> <book id="1"> <title>Pride and Prejudice</title>

    <author>Jane Austen</author> </book> <book id="2"> <title>Brave New World</title> <author>Aldous Huxley</author> </book> </books>
  4. “XML is like violence. — If it hasn’t solved your

    problem, you’re not using enough of it.”
  5. <?xml version="1.0" encoding="UTF-8" ?> <books> <book id="1"> <title>Pride and Prejudice</title>

    <author>Jane Austen</author> </book> <book id="2"> <title>Brave New World</title> <author>Aldous Huxley</author> </book> </books>
  6. <?xml version="1.0" encoding="UTF-8" ?> <books> <book id="1"> <title>Pride and Prejudice</title>

    <author>Jane Austen</author> </book> <book id="2"> <title>Brave New World</title> <author>Aldous Huxley</author> </book> </books>
  7. { "books": { "book": [ { "id": 1, "title ":

    " Pride and Prejudice", "author ": " Jane Austen" }, { "id": 2, "title": "Brave New World", "author": "Aldous Huxley" } ] } }
  8. { "books": { "book": [ { "id": 1, "title ":

    "Pride and Prejudice", "author ": "Jane Austen" }, { "id": 2, "title": "Brave New World", "author": "Aldous Huxley" } ] } }
  9. --- books: - id: 1 title: Pride and Prejudice author:

    Jane Austen - id: 2 title: Brave New World author: Aldous Huxley
  10. --- books: - id: 1 title: Pride and Prejudice author:

    Jane Austen - id: 2 title: Brave New World author: Aldous Huxley
  11. module ViewHelpers # … def list(key, &block) data = t(key).clone

    rescue {} raise data if data =~ /translation missing/ data = NestedOstruct.import(data) raise data unless data.is_a? Array data.each {|i| yield i } end def t(key, args={}) I18n.t(key, args) end end
  12. --- books: - id: 1 title: Pride and Prejudice author:

    Jane Austen - id: 2 title: Brave New World author: Aldous Huxley