Skip to content

Instantly share code, notes, and snippets.

@meirish
Last active October 23, 2020 02:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meirish/3baedbfff42a0e8b68ab94c2a7fa10f4 to your computer and use it in GitHub Desktop.
Save meirish/3baedbfff42a0e8b68ab94c2a7fa10f4 to your computer and use it in GitHub Desktop.
New Twiddle
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));
}
});
import Controller from '@ember/controller';
import Resource from '../resource';
export default class ApplicationController extends Controller {
appName = 'Ember Twiddle';
resource = Resource.create();
}
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`;
}
}
<h1>Welcome to {{this.appName}}</h1>
<br>
<br>
{{this.resource.canDelete}}
<br>
{{this.resource.notAKey}}
<br>
{{outlet}}
<br>
<br>
{
"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