Skip to content

Commit

Permalink
improve default generated plugin
Browse files Browse the repository at this point in the history
plugin matches 'hello', fixed some typo's
  • Loading branch information
nvdk committed Apr 23, 2018
1 parent d6a12f3 commit 65ce242
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ export default Component.extend({
actions: {
insert(){
let mappedLocation = this.get('hintsRegistry').updateLocationToCurrentIndex(this.get('hrId'), this.get('location'));
this.get('hintsRegistry').removeHintsAtLocation(this.get('location'), this.get('hrId'), 'editor-plugins/date-card');
this.get('editor').replaceTextWithHTML(...mappedLocation, this.get('info').value);
this.get('hintsRegistry').removeHintsAtLocation(this.get('location'), this.get('hrId'), 'editor-plugins/<%= dasherizedModuleName %>-card');
this.get('editor').replaceTextWithHTML(...mappedLocation, this.get('info').htmlString);
}
}
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { getOwner } from '@ember/application';
import Service from '@ember/service';
import EmberObject, { computed } from '@ember/object';
import moment from 'moment';
import { task } from 'ember-concurrency';

/**
Expand Down Expand Up @@ -34,12 +33,18 @@ const RdfaEditor<%= classifiedModuleName %>Plugin = Service.extend({
execute: task(function * (hrId, contexts, hintsRegistry, editor) {
if (contexts.length === 0) return [];

const hints = contexts.filter((context) => detectRelevantContext).forEach((context) => {
return generateHintsForContext(context);
const hints = [];
contexts.forEach((context) => {
let relevantContext = this.detectRelevantContext(context)
if (relevantContext) {
hintsRegistry.removeHintsInRegion(context.region, hrId, this.get('who'));
hints.pushObjects(this.generateHintsForContext(context));
}
});


return hints.forEach( (hint) => generateCard(hint));
const cards = hints.map( (hint) => this.generateCard(hrId, hintsRegistry, editor, hint));
if(cards.length > 0){
hintsRegistry.addHints(hrId, this.get('who'), cards);
}
}).restartable(),

/**
Expand All @@ -54,7 +59,7 @@ const RdfaEditor<%= classifiedModuleName %>Plugin = Service.extend({
* @private
*/
detectRelevantContext(context){
return true;
return context.text.toLowerCase().indexOf('hello') >= 0;
},


Expand All @@ -81,7 +86,6 @@ const RdfaEditor<%= classifiedModuleName %>Plugin = Service.extend({
* @method generateCard
*
* @param {string} hrId Unique identifier of the event in the hintsRegistry
* @param {Object} rdfaAnnotation object
* @param {Object} hintsRegistry Registry of hints in the editor
* @param {Object} editor The RDFa editor instance
* @param {Object} hint containing the hinted string and the location of this string
Expand All @@ -90,11 +94,12 @@ const RdfaEditor<%= classifiedModuleName %>Plugin = Service.extend({
*
* @private
*/
generateCard(hrId, rdfaAnnotation, hintsRegistry, editor, hint){
generateCard(hrId, hintsRegistry, editor, hint){
return EmberObject.create({
info: {
label: this.get('who'),
plainValue: hint.text,
htmlString: '<b>hello world</b>',
location: hint.location,
hrId, hintsRegistry, editor
},
Expand All @@ -116,15 +121,15 @@ const RdfaEditor<%= classifiedModuleName %>Plugin = Service.extend({
*/
generateHintsForContext(context){
const hints = [];
const text = context.text;
const location = this.normalizeLocation([0, stringToScan.length], context.region);
hints.push({text, location})
const index = context.text.toLowerCase().indexOf('hello');
const text = context.text.slice(index, index+5);
const location = this.normalizeLocation([index, index + 5], context.region);
hints.push({text, location});
return hints;
}
});

RdfaEditor<%= classifiedModuleName %>Plugin.reopen({
who: 'editor-plugins/<%= dasherizedModuleName %>-card',

who: 'editor-plugins/<%= dasherizedModuleName %>-card'
});
export default RdfaEditor<%= classifiedModuleName %>Plugin;
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { default } from '@lblod/ember-rdfa-editor<%= dasherizedModuleName %>-plugin/services/rdfa-editor-<%= dasherizedModuleName %>-plugin';
export { default } from '@lblod/ember-rdfa-editor-<%= dasherizedModuleName %>-plugin/services/rdfa-editor-<%= dasherizedModuleName %>-plugin';

0 comments on commit 65ce242

Please sign in to comment.