Last active
October 23, 2020 02:27
-
-
Save meirish/3baedbfff42a0e8b68ab94c2a7fa10f4 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 EmberObject from '@ember/object'; | |
import { camelize } from '@ember/string'; | |
export default EmberObject.extend({ | |
model: null, | |
/** | |
* Parse propertyName into ability property | |
* eg: `createProject` will be parsed to `canCreateProject` using default definition | |
* @public | |
* @param {[String]} propertyName [description] | |
* @return {[String]} [description] | |
*/ | |
parseProperty(propertyName) { | |
return camelize(`can-${propertyName}`); | |
}, | |
/** | |
* Get parsed ability value based on propertyName | |
* eg: `createProject` will return a value for `canCreateProject` | |
* using default `parseProperty` definition | |
* @private | |
* @param {String} propertyName property name, eg. `createProject` | |
* @return {*} value of parsed `propertyName` property | |
*/ | |
getAbility(propertyName) { | |
return this.get(this.parseProperty(propertyName)); | |
} | |
}); |
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 Controller from '@ember/controller'; | |
import Resource from '../resource'; | |
export default class ApplicationController extends Controller { | |
appName = 'Ember Twiddle'; | |
resource = Resource.create(); | |
} |
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 Ability from './ability'; | |
export default class Resource extends Ability { | |
get canDelete() { | |
return true; | |
} | |
unknownProperty(key){ | |
// figure out the right key here - maybe we reverse parse it from the can service? | |
// and then call this.permissions.can(stringFromKey); | |
return `${key} is the key`; | |
} | |
} |
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.17.1", | |
"EmberENV": { | |
"FEATURES": {}, | |
"_TEMPLATE_ONLY_GLIMMER_COMPONENTS": false, | |
"_APPLICATION_TEMPLATE_WRAPPER": true, | |
"_JQUERY_INTEGRATION": true | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.js", | |
"ember": "3.18.1", | |
"ember-template-compiler": "3.18.1", | |
"ember-testing": "3.18.1" | |
}, | |
"addons": { | |
"@glimmer/component": "1.0.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment