Skip to content

Commit

Permalink
move escapeCSS function to mixins
Browse files Browse the repository at this point in the history
  • Loading branch information
tomtjes committed Feb 15, 2024
1 parent b5a2042 commit f34dc4d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 19 deletions.
7 changes: 2 additions & 5 deletions vue/src/components/IngredientComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
</template>

<script>
import {calculateAmount, ResolveUrlMixin, escapeCSS} from "@/utils/utils"
import {calculateAmount, ResolveUrlMixin, EscapeCSSMixin} from "@/utils/utils"
import Vue from "vue"
import VueSanitize from "vue-sanitize"
Expand All @@ -57,7 +57,7 @@ export default {
ingredient_factor: {type: Number, default: 1},
detailed: {type: Boolean, default: true},
},
mixins: [ResolveUrlMixin],
mixins: [ResolveUrlMixin, EscapeCSSMixin],
data() {
return {
checked: false,
Expand Down Expand Up @@ -125,9 +125,6 @@ export default {
// sends parent recipe ingredient to notify complete has been toggled
done: function () {
this.$emit("checked-state-changed", this.ingredient)
},
escapeCSS: function (classname) {
return CSS.escape(escapeCSS(classname))
}
},
}
Expand Down
7 changes: 2 additions & 5 deletions vue/src/components/KeywordsComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@

<script>
import {ResolveUrlMixin, escapeCSS} from "@/utils/utils";
import {ResolveUrlMixin, EscapeCSSMixin} from "@/utils/utils";
export default {
name: 'KeywordsComponent',
mixins: [ResolveUrlMixin],
mixins: [ResolveUrlMixin, EscapeCSSMixin],
props: {
recipe: Object,
limit: Number,
Expand All @@ -36,9 +36,6 @@ export default {
methods: {
keywordClass: function(k) {
return this.escapeCSS('_keywordname-' + k.label)
},
escapeCSS: function (classname) {
return CSS.escape(escapeCSS(classname))
}
}
}
Expand Down
12 changes: 5 additions & 7 deletions vue/src/components/StepComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -122,18 +122,18 @@
</template>

<script>
import {calculateAmount, GettextMixin, getUserPreference, escapeCSS} from "@/utils/utils"
import {calculateAmount, GettextMixin, getUserPreference} from "@/utils/utils"
import CompileComponent from "@/components/CompileComponent"
import IngredientsCard from "@/components/IngredientsCard"
import Vue from "vue"
import moment from "moment"
import {ResolveUrlMixin, calculateHourMinuteSplit} from "@/utils/utils"
import {ResolveUrlMixin, calculateHourMinuteSplit, EscapeCSSMixin} from "@/utils/utils"
Vue.prototype.moment = moment
export default {
name: "StepComponent",
mixins: [GettextMixin, ResolveUrlMixin],
mixins: [GettextMixin, ResolveUrlMixin, EscapeCSSMixin],
components: {CompileComponent, IngredientsCard},
props: {
step: Object,
Expand All @@ -148,7 +148,8 @@ export default {
},
computed: {
step_time: function() {
return calculateHourMinuteSplit(this.step.time)},
return calculateHourMinuteSplit(this.step.time)
},
step_name: function() {
if (this.step.name) {
return this.step.name
Expand Down Expand Up @@ -196,9 +197,6 @@ export default {
},
openPopover: function () {
this.$refs[`id_reactive_popover_${this.step.id}`].$emit("open")
},
escapeCSS: function (classname) {
return CSS.escape(escapeCSS(classname))
}
},
}
Expand Down
9 changes: 7 additions & 2 deletions vue/src/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,13 @@ export function calculateAmount(amount, factor) {
}
}

export function escapeCSS(classname) {
return classname.replace(/\s+/g, "-").toLowerCase()
/* Replace spaces by dashes, then use DOM method to escape special characters. Use for dynamically generated CSS classes*/
export const EscapeCSSMixin = {
methods: {
escapeCSS: function(classname) {
return CSS.escape(classname.replace(/\s+/g, "-").toLowerCase())
}
}
}

export function roundDecimals(num) {
Expand Down

0 comments on commit f34dc4d

Please sign in to comment.