Last active
December 20, 2015 02:49
-
-
Save gcpantazis/6059042 to your computer and use it in GitHub Desktop.
A rough idea for establishing the data models for a module within the module itself, for a future generator with a CMS tie-in.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // schema/killer-thing.json | |
| { | |
| "parents": ["Grid", "Container"], // Grids and Containers can add KillerThing as a submodule. | |
| "model": { | |
| "foo": "String", | |
| "bar": "Integer", | |
| "baz": "Boolean", | |
| "a": ["CoolThing"], // An Array of CoolThing Models. | |
| "b": "RadThing" // A single RadThing Model. | |
| } | |
| } | |
| // schema/cool-thing.json | |
| { | |
| "parents": ["Grid"], // All Grid modules can accept CoolThing as a submodule | |
| "tags": ["String"], | |
| "model": { | |
| "a": "String", | |
| "b": "String", | |
| "c": ["Integer"] | |
| } | |
| } | |
| // schema/rad-thing.json | |
| { | |
| "parents": [], // No modules can automatically use RadThing, must be implicitly required, like in KillerThing. | |
| "model": { | |
| "a": "Boolean", | |
| } | |
| } | |
| // schema/sweet-submodule.json | |
| // An example of a submodule that `KillerThing` and `CoolThing` can require. | |
| { | |
| parents: ['KillerThing, CoolThing'], | |
| model: { | |
| 'a': 'Boolean', | |
| } | |
| } | |
| // routes/cool-route.json | |
| // Expect `a` to be an id matching an existing `CoolThing` model. | |
| // `b`, `bar` are expected to conform to a given test. | |
| // If any assertion fails this 404s. | |
| { | |
| "route": "/cool/:a/:b?querySelectorFoo=:bar", | |
| "layout": "CoolLayout", | |
| "assert": { | |
| "a": "CoolThing", | |
| "b": "[a-zA-Z0-9]", | |
| "bar": "[a-zA-Z0-9]" | |
| } | |
| } | |
| // layouts/cool-layout.jade | |
| // Accesses route data: `route.a`, `route.b`, `route.foo` | |
| // Route data exposed to any included module. | |
| global.tags = getData('CoolModule', route.a).tags | |
| +getModule('header'); | |
| +container | |
| +grid | |
| +getModule('CoolModule', route.a); | |
| +container | |
| +grid | |
| // KillerThing could respond to global.tags for variations based on the incoming route. | |
| // Per jade, one `block` insertion point in each module that we expose as a mixin. | |
| +getModule('KillerThing', 'an-instance-of-killer-thing'); | |
| if route.b | |
| +getModule('SweetSubmodule', route.b); | |
| +getModule('footer'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment