├── README.md
└── jss.js
/README.md:
--------------------------------------------------------------------------------
1 | This project is not complete, this is just a sketch right now
2 |
JSON Style Sheets
3 | JSON Style Sheets (JSS) is a templating tool for rendering JSON/JavaScript data. JSS
4 | is designed to provide a presentation layer as an extension to CSS, without incurring
5 | the extra overhead and complexity of intermediate HTML generation. CSS is designed
6 | to seperate the visual concerns from semantic data concerns of HTML. However,
7 | with JSON templating, HTML often becomes completely abused, used as a semi-presentation
8 | layer for the JSON data, muddying the separation of concerns and creating excessively
9 | complex relations and indirection between the data and the intended rendering. JSS
10 | extends CSS to provide the necessary facilities to render JSON with minimally sufficient
11 | embedded HTML layout information to properly present data, while still using standard
12 | language syntax and semantics. All valid CSS is valid JSS, and most HTML is valid JSS
13 | as well.
14 |
15 | data.json:
16 | {
17 | "title": "Search for sedans",
18 | "cars": [
19 | {"make": "Honda", "model": "Accord"},
20 | {"make": "Ford", "model": "Taurus"},
21 | ]
22 | }
23 | template.jss:
24 |
25 | /title {
26 | font-size: 24px;
27 | }
28 | /cars {
29 | border: 1px;
30 | }
31 | /cars/#/make {
32 | color: blue;
33 | };
34 |
35 | To apply this template to the data:
36 |
37 | var templateString = loadTemplate();
38 | var compile = require("jss").compile;
39 | var template = compile(templateString);
40 | template.apply(targetDom);
41 |
42 | This would render the JSON with the given styles.
43 |
44 | JSS allows for nested definitions as well:
45 | /cars {
46 | border: 1px;
47 | /make {
48 | color: blue;
49 | };
50 | }
51 |
52 | Or even mixed with standards CSS selectors:
53 | .some-class {
54 | /title {
55 | font-size: 24px;
56 | }
57 | /cars {
58 | border: 1px;
59 | }
60 | }
61 |
62 |
63 | However, when rendering JSON in application, we often need much more control over
64 | the layout, we can utilize HTML directives to add information for layout and interpretation
65 | of semantics directly within our style sheet (no need for a separate file). We can insert
66 | HTML directly into JSS. We can also postpend HTML fragments with selector/rules to
67 | define the styles for that element:
68 |
69 | My App
70 |