clayallsopp/formotion — pull request #51 by markrickert (2012-11-26 17:15:44+00:00)
Title: Convert values to symbols if necessary when creating the form

This one-liner allows external json files to be used instead of concrete ruby hashes in the code.

I needed to build the form based on some external JSON (either gathered from a server call or stored in the resources directory).

This now allows you to convert a JSON object to a hash and it will symbolize any elements that need to be converted for proper use.

Here's the example hash you use in the documentation, now working as a json object... note the hash symbols are strings that start with ":" such as ```"key": ":email"```

formotion_data.json
```javascript
{
"sections": [{
"title": "Register",
"rows": [{
"title": "Email",
"key": ":email",
"placeholder": "me@mail.com",
"type": ":email",
"auto_correction": ":no",
"auto_capitalization": ":none"
}, {
"title": "Password",
"key": ":password",
"placeholder": "required",
"type": ":string",
"secure": true
}, {
"title": "Password",
"subtitle": "Confirmation",
"key": ":confirm",
"placeholder": "required",
"type": ":string",
"secure": true
}, {
"title": "Remember?",
"key": ":remember",
"type": ":switch",
}]
}, {
"title": "Account Type",
"key": ":account_type",
"select_one": true,
"rows": [{
"title": "Free",
"key": ":free",
"type": ":check",
}, {
"title": "Basic",
"value": true,
"key": ":basic",
"type": ":check",
}, {
"title": "Pro",
"key": ":pro",
"type": ":check",
}]
}, {
"rows": [{
"title": "Sign Up",
"type": ":submit",
}]
}]
}
```