Added markdown support to features
This commit is contained in:
@@ -27,7 +27,7 @@
|
|||||||
import { insertFeature } from '/imports/api/creature/properties/Features.js';
|
import { insertFeature } from '/imports/api/creature/properties/Features.js';
|
||||||
import ColumnLayout from '/imports/ui/components/ColumnLayout.vue';
|
import ColumnLayout from '/imports/ui/components/ColumnLayout.vue';
|
||||||
import FeatureCard from '/imports/ui/components/features/FeatureCard.vue';
|
import FeatureCard from '/imports/ui/components/features/FeatureCard.vue';
|
||||||
import { evaluateComputation, evaluateString } from '/imports/ui/utility/evaluate.js';
|
import { evaluateComputation, evaluateStringWithVariables } from '/imports/ui/utility/evaluate.js';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
props: {
|
props: {
|
||||||
@@ -47,7 +47,7 @@
|
|||||||
}, {
|
}, {
|
||||||
sort: {order: 1},
|
sort: {order: 1},
|
||||||
}).map(f => {
|
}).map(f => {
|
||||||
f.description = evaluateString(f.description, vars);
|
f.description = evaluateStringWithVariables(f.description, vars);
|
||||||
return f;
|
return f;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
20
app/imports/ui/components/MarkdownText.vue
Normal file
20
app/imports/ui/components/MarkdownText.vue
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<template lang="html">
|
||||||
|
<div v-html="compiledMarkdown">
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import marked from 'marked';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
props: {
|
||||||
|
markdown: String,
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
compiledMarkdown() {
|
||||||
|
if (!this.markdown) return;
|
||||||
|
return marked(this.markdown, { sanitize: true });
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
</script>
|
||||||
@@ -13,13 +13,14 @@
|
|||||||
@click.stop="$emit('update', {_id, update: {enabled: !enabled}})"
|
@click.stop="$emit('update', {_id, update: {enabled: !enabled}})"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
<v-card-text>
|
<v-card-text v-if="description">
|
||||||
{{description}}
|
<markdown-text :markdown="description"/>
|
||||||
</v-card-text>
|
</v-card-text>
|
||||||
</toolbar-card>
|
</toolbar-card>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import MarkdownText from '/imports/ui/components/MarkdownText.vue';
|
||||||
import ToolbarCard from '/imports/ui/components/ToolbarCard.vue';
|
import ToolbarCard from '/imports/ui/components/ToolbarCard.vue';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@@ -33,9 +34,9 @@
|
|||||||
alwaysEnabled: Boolean,
|
alwaysEnabled: Boolean,
|
||||||
},
|
},
|
||||||
components: {
|
components: {
|
||||||
|
MarkdownText,
|
||||||
ToolbarCard,
|
ToolbarCard,
|
||||||
},
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -1,25 +1,27 @@
|
|||||||
<template lang="html">
|
<template lang="html">
|
||||||
<property-dialog :doc="feature" collection="features" @remove="$emit('remove')">
|
<property-dialog :doc="feature" collection="features" @remove="$emit('remove')">
|
||||||
<div>
|
<div>
|
||||||
{{feature.description}}
|
<markdown-text :markdown="feature.computedDescription || feature.description"/>
|
||||||
<!--
|
<!--
|
||||||
<child-lists
|
<child-lists
|
||||||
:parent="feature"
|
:parent="feature"
|
||||||
/>
|
/>
|
||||||
-->
|
-->
|
||||||
</div>
|
</div>
|
||||||
<feature-foremovet="form" :feature="feature" @update="(update, ack) => $emit('update', update, ack)"/>
|
<feature-form slot="form" :feature="feature" @update="(update, ack) => $emit('update', update, ack)"/>
|
||||||
</property-dialog>
|
</property-dialog>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import PropertyDialog from '/imports/ui/components/properties/PropertyDialog.vue';
|
import PropertyDialog from '/imports/ui/components/properties/PropertyDialog.vue';
|
||||||
import FeatureForm from '/imports/ui/components/features/FeatureForm.vue';
|
import FeatureForm from '/imports/ui/components/features/FeatureForm.vue';
|
||||||
|
import MarkdownText from '/imports/ui/components/MarkdownText.vue';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
PropertyDialog,
|
PropertyDialog,
|
||||||
FeatureForm,
|
FeatureForm,
|
||||||
|
MarkdownText,
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
feature: Object,
|
feature: Object,
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
<script>
|
<script>
|
||||||
import Features, {updateFeature} from '/imports/api/creature/properties/Features.js';
|
import Features, {updateFeature} from '/imports/api/creature/properties/Features.js';
|
||||||
import FeatureDialog from '/imports/ui/components/features/FeatureDialog.vue';
|
import FeatureDialog from '/imports/ui/components/features/FeatureDialog.vue';
|
||||||
|
import {evaluateStringForCharId} from '/imports/ui/utility/evaluate.js';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
@@ -19,7 +20,11 @@
|
|||||||
},
|
},
|
||||||
meteor: {
|
meteor: {
|
||||||
feature(){
|
feature(){
|
||||||
return Features.findOne(this._id);
|
let feature = Features.findOne(this._id);
|
||||||
|
feature.computedDescription = evaluateStringForCharId(
|
||||||
|
feature.description, feature.charId
|
||||||
|
);
|
||||||
|
return feature;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
|||||||
@@ -12,7 +12,6 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import propertyUpdateMethods from '/imports/api/creature/properties/propertyUpdateMethods.js';
|
|
||||||
import DialogBase from '/imports/ui/dialogStack/DialogBase.vue';
|
import DialogBase from '/imports/ui/dialogStack/DialogBase.vue';
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
|
import Creatures from '/imports/api/creature/Creatures.js';
|
||||||
|
|
||||||
// Computations resolve to numbers
|
// Computations resolve to numbers
|
||||||
// vars is a dict of variables to substitute
|
// vars is a dict of variables to substitute
|
||||||
function evaluateComputation(string, vars){
|
export function evaluateComputation(string, vars){
|
||||||
if (!string) return string;
|
if (!string) return string;
|
||||||
// Replace all the string variables with numbers if possible
|
// Replace all the string variables with numbers if possible
|
||||||
let substitutedString = string.replace(
|
let substitutedString = string.replace(
|
||||||
@@ -14,11 +16,11 @@ function evaluateComputation(string, vars){
|
|||||||
} catch (e){
|
} catch (e){
|
||||||
return substitutedString;
|
return substitutedString;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
// Strings can have computations in bracers like so: {computation}
|
// Strings can have computations in bracers like so: {computation}
|
||||||
// vars is a dict of variables to substitute
|
// vars is a dict of variables to substitute
|
||||||
function evaluateString(string, vars){
|
export function evaluateStringWithVariables(string, vars){
|
||||||
if (!string) return string;
|
if (!string) return string;
|
||||||
// Compute everything inside bracers
|
// Compute everything inside bracers
|
||||||
return string.replace(/\{([^\{\}]*)\}/g, function(match, p1){
|
return string.replace(/\{([^\{\}]*)\}/g, function(match, p1){
|
||||||
@@ -26,4 +28,8 @@ function evaluateString(string, vars){
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export { evaluateComputation, evaluateString };
|
export function evaluateStringForCharId(string, charId){
|
||||||
|
let char = Creatures.findOne(charId, {fields: {variables: 1}});
|
||||||
|
let vars = char ? char.variables : {};
|
||||||
|
return evaluateStringWithVariables(string, vars);
|
||||||
|
}
|
||||||
|
|||||||
5
app/package-lock.json
generated
5
app/package-lock.json
generated
@@ -830,6 +830,11 @@
|
|||||||
"p-defer": "^1.0.0"
|
"p-defer": "^1.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"marked": {
|
||||||
|
"version": "0.6.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/marked/-/marked-0.6.1.tgz",
|
||||||
|
"integrity": "sha512-+H0L3ibcWhAZE02SKMqmvYsErLo4EAVJxu5h3bHBBDvvjeWXtl92rGUSBYHL2++5Y+RSNgl8dYOAXcYe7lp1fA=="
|
||||||
|
},
|
||||||
"mathjs": {
|
"mathjs": {
|
||||||
"version": "5.5.0",
|
"version": "5.5.0",
|
||||||
"resolved": "https://registry.npmjs.org/mathjs/-/mathjs-5.5.0.tgz",
|
"resolved": "https://registry.npmjs.org/mathjs/-/mathjs-5.5.0.tgz",
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
"css-box-shadow": "^1.0.0-3",
|
"css-box-shadow": "^1.0.0-3",
|
||||||
"fibers": "^2.0.2",
|
"fibers": "^2.0.2",
|
||||||
"lodash": "^4.17.11",
|
"lodash": "^4.17.11",
|
||||||
|
"marked": "^0.6.1",
|
||||||
"mathjs": "^5.5.0",
|
"mathjs": "^5.5.0",
|
||||||
"meteor-node-stubs": "^0.3.3",
|
"meteor-node-stubs": "^0.3.3",
|
||||||
"moo": "^0.5.0",
|
"moo": "^0.5.0",
|
||||||
|
|||||||
Reference in New Issue
Block a user