4 ms·
I'm working on a JSON based website layout and component system. For example: a component that lists blog posts could be represented by: { options:{
by SolarUpNote 13y ago
I'm working on a JSON based website layout and component system.
For example: a component that lists blog posts could be represented by:
{
options:{
elements:[image, title, author, date]
},
criteria:{
sort:date.desc,
published:true,
limit:10
},
request_vars:{page:3}
}
That would show the last 10 posts that are published, ordered by date, on page 3 of the results.
That's a simple example, this site: volumeone.org is built almost entirely this way.
Since it's in JSON format, JavaScript can be used to build UIs that build the components and layouts.
- meowface 13y agoI might suggest using YAML too, either as an alternative or as a complete replacement. YAML (when written in a certain way) is basically JSON without any line noise, and optimized for human reading and writing. You will be able to parse it exactly the same.
- SolarUpNote 13y agoI tried that too, but sometimes the nesting level is too deep for YAML. There were also some difficulties when escaping special characters in YAML.
- meowface 13y agoIn regards to the nesting level: what do you mean? There shouldn't be any technical limit on the nesting depth. As for escaping special characters: I've run into that a lot, and I agree it is very annoying. God help you if you want to specify regexes on lines. So for a lot of my YAML-ish applications, where YAML is used for user templating or configuration, I run everything through a really simple postprocessor (often by encapsulating non-digit lines with single quotes, and a few other tweaks) and that seems to work well for me. That way the user only has to type the bare minimum (no double quotes, no curly braces, no/fewer commas), and what they write "just works."
- solnyshok 13y agoHow do you implement it in browser?
- SolarUpNote 13y agoIt's server-side. There's a record for each page/component in a database where the JSON is stored. It converts the "criteria" part into SQL, and the "options" part into HTML, and returns the resulting HTML for each component.
- JesseObrien 13y agoMight I suggest something like redis* for storing this data? Or is that what you mean by database? * http://redis.io/ http://redis.io/
- SolarUpNote 13y agoThanks for the suggestion. I've been meaning to try that out, maybe it's time to look into Redis.
- kolev 13y agoYour example is a JavaScript array, not a JSON object. Just saying.