Last active
July 26, 2017 18:17
-
-
Save fivetanley/81c36247d29470e33ed1d5b41b6c3ba8 to your computer and use it in GitHub Desktop.
New Twiddle
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
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
appName: 'Ember Twiddle' | |
}); |
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
import Model from "ember-data/model"; | |
import attr from "ember-data/attr"; | |
import { belongsTo, hasMany } from "ember-data/relationships"; | |
export default Model.extend({ | |
docs: attr(), | |
modules: hasMany('module') | |
}); |
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
import Model from "ember-data/model"; | |
import attr from "ember-data/attr"; | |
import { belongsTo, hasMany } from "ember-data/relationships"; | |
export default Model.extend({ | |
name: attr(), | |
docs: attr(), | |
crate: belongsTo('crate'), | |
child_modules: hasMany('modules', { inverse: 'parent_module'}), | |
parent_module: belongsTo('module', { inverse: 'child_modules'}), | |
}); |
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
import Ember from 'ember'; | |
import config from './config/environment'; | |
const Router = Ember.Router.extend({ | |
location: 'none', | |
rootURL: config.rootURL | |
}); | |
Router.map(function() { | |
this.route('module', {path: ':crate_name/*path'}); | |
}); | |
export default Router; |
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
import Ember from 'ember'; | |
const payload = { | |
"data": { | |
"type": "crate", | |
"id": "example", | |
"attributes": { | |
"docs": " An example crate.\n\n This crate is used to test out the new rustdoc.\n\n It should have an example of almost everything, for testing\n purposes.\n" | |
}, | |
"relationships": { | |
"modules": { | |
"data": [ | |
{ | |
"type": "module", | |
"id": "example::example_module" | |
} | |
] | |
} | |
} | |
}, | |
"included": [ | |
{ | |
"type": "module", | |
"id": "example::example_module", | |
"attributes": { | |
"docs": "a module with a submodule inside", | |
"name": "example_module" | |
}, | |
"relationships": { | |
"child_modules": { | |
"data": [ | |
{ | |
"type": "module", | |
"id": "example::example_module::nested" | |
} | |
] | |
} | |
} | |
}, | |
{ | |
"type": "module", | |
"id": "example::example_module::nested", | |
"attributes": { | |
"docs": "a nested module with a nested module", | |
"name": "nested" | |
}, | |
"relationships": { | |
"child_modules": { | |
"data": [ | |
{ | |
"type": "module", | |
"id": "example::example_module::nested::nested2" | |
} | |
] | |
} | |
} | |
}, | |
{ | |
"type": "module", | |
"id": "example::example_module::nested::nested2", | |
"attributes": { | |
"docs": "a super nested module", | |
"name": "nested2" | |
} | |
} | |
] | |
} | |
export default Ember.Route.extend({ | |
serialize(mod) { | |
// convert :: to / | |
return mod.get('id').replace(/::/g, '/'); | |
}, | |
model(params) { | |
this.store.push(payload); | |
// convert from / to :: // | |
const moduleId = `${params.crate_name}::${params.path.replace(/\//g, '::')}`; | |
return this.store.findRecord('module', moduleId, {reload: false}); | |
} | |
}); | |
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
{ | |
"version": "0.12.1", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "2.12.0", | |
"ember-template-compiler": "2.12.0", | |
"ember-testing": "2.12.0" | |
}, | |
"addons": { | |
"ember-data": "2.12.1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment