abril / tokamak

template engine for hypermedia resources that provides a single DSL to generate several media types representations
Other
39 stars 11 forks source link

Supporting another version of the dsl (backward compatible) #1

Closed guilhermesilveira closed 13 years ago

guilhermesilveira commented 13 years ago

In this patch, there is another version of the dsl that is backward compatible and gives less noise on the dsl. This approach is Ruby 1.8.7+ compatible. Both json and xml have been changed to support it (applying changes to the builder base). Usage example:

xml = Tokamak::Builder::Xml.build(some_articles) do
    write :id,      "http://example.com/json"
    title   "Feed"
    updated time

    author {
      name  "John Doe"
      email "joedoe@example.com"
    }

    author {
      name  "Foo Bar"
      email "foobar@example.com"
    }

  link("next"    , "http://a.link.com/next")
  link("previous", "http://a.link.com/previous")

  members(:root => "articles") do |member, article|
      write :id,      "uri:#{article[:id]}"
      title   article[:title]
      updated article[:updated]

    link("image", "http://example.com/image/1")
    link("image", "http://example.com/image/2", :type => "application/json")
  end
end

In 1.9.2 the method id has been dropped so it is even simpler.

lfcipriani commented 13 years ago

there is a reason to not implement this: the []= method for adding namespaces to xml output would be impossible to be executed.

lfcipriani commented 13 years ago

closing due to reason posted above and no discussion followed

guilhermesilveira commented 13 years ago

just uploaded the method ns for namespace declaration. branch dsl it also includes the full dsl support discussed on the mailing list