反向胡子

时间:2013-01-31 11:10:25

标签: ruby xml mustache

我正在使用小胡子(在ruby中)从散列生成XML文档。

我有办法从XML文档和胡子模板生成哈希吗?

1 个答案:

答案 0 :(得分:0)

考虑到这一段时间后,我意识到这是不可能的。有两个原始哈希的多个实例使用Mustache创建相同的文档,因此这将永远不会合理可行。

其他许多人:

doc = {
  "words": [
    "an",
    "aconda"
  ]
}

template = "here's some words: {{#words}}{{.}}{{/words}}"

out = Mustache.render(template,doc)
# => "here's some words: anaconda"

Mustache.reverse(template,out)
# {'words' => ['anaconda']}