Skip to content

Commit

Permalink
Merge pull request #1 from AlchemyCMS/rename-element_type
Browse files Browse the repository at this point in the history
Rename element type
  • Loading branch information
tvdeyen authored Nov 6, 2020
2 parents 00f5c05 + 7bd4d7c commit a4a817b
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ export default {
}
```

You now have acces to the `page` prop and its `elements`. Also you have access to the `elementType()` method that you can use to dynamically render element components.
You now have acces to the `page` prop and its `elements`. Also you have access to the `componentName()` method that you can use to dynamically render element components.

```html
<template>
<div :class="page.page_layout">
<component
:is="elementType(element)"
:is="componentName(element)"
v-for="element in page.elements"
:key="element.id"
:element="element"
Expand Down
2 changes: 1 addition & 1 deletion src/components/FallbackElement.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div class="alchemy-fallback-element">
<h2>I am a dummy {{ element.element_type }} Alchemy element component</h2>
<h2>I am a dummy {{ element.name }} Alchemy element component</h2>
<p>
To replace me put a Vue component into
<kbd>~/components/Alchemy/Elements/</kbd>
Expand Down
4 changes: 2 additions & 2 deletions src/components/__tests__/fallback-element.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ function getComponent() {
return shallowMount(FallbackElement, {
propsData: {
element: {
element_type: "main_header",
name: "main_header",
essences: [
{
role: "headline",
},
],
nested_elements: [
{
element_type: "header",
name: "header",
},
],
},
Expand Down
10 changes: 5 additions & 5 deletions src/mixins/__tests__/element.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const AlchemyElementComponent = {
describe("Alchemy element mixin", () => {
it("has access to the element", () => {
const element = {
element_type: "content_page",
name: "content_page",
essences: [],
}
const comp = shallowMount(AlchemyElementComponent, {
Expand All @@ -26,7 +26,7 @@ describe("Alchemy element mixin", () => {
const comp = shallowMount(AlchemyElementComponent, {
propsData: {
element: {
element_type: "content_page",
name: "content_page",
essences: [],
},
},
Expand All @@ -41,7 +41,7 @@ describe("Alchemy element mixin", () => {
const comp = shallowMount(AlchemyElementComponent, {
propsData: {
element: {
element_type: "content_page",
name: "content_page",
essences: [headline],
},
},
Expand All @@ -57,7 +57,7 @@ describe("Alchemy element mixin", () => {
const comp = shallowMount(AlchemyElementComponent, {
propsData: {
element: {
element_type: "content_page",
name: "content_page",
essences: [],
},
},
Expand All @@ -72,7 +72,7 @@ describe("Alchemy element mixin", () => {
const comp = shallowMount(AlchemyElementComponent, {
propsData: {
element: {
element_type: "content_page",
name: "content_page",
essences: [headline],
},
},
Expand Down
12 changes: 6 additions & 6 deletions src/mixins/__tests__/page.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const AlchemyPageComponent = {
template: `
<div class="alchemy-page">
<component
:is="elementType(element)"
:is="componentName(element)"
v-for="element in page.elements"
:key="element.id"
:element="element"
Expand Down Expand Up @@ -40,7 +40,7 @@ describe("Alchemy page mixin", () => {
describe("elementByName", () => {
describe("if element exists", () =>{
it("returns element", () => {
const element = { element_type: "header" }
const element = { name: "header" }
const component = shallowMount(AlchemyPageComponent, {
propsData: {
page: {
Expand Down Expand Up @@ -70,7 +70,7 @@ describe("Alchemy page mixin", () => {
describe("elementsByName", () => {
describe("if element exists", () =>{
it("returns element", () => {
const elements = [{ element_type: "header" }]
const elements = [{ name: "header" }]
const component = shallowMount(AlchemyPageComponent, {
propsData: {
page: {
Expand All @@ -97,13 +97,13 @@ describe("Alchemy page mixin", () => {
})
})

describe("elementType", () => {
describe("componentName", () => {
describe("if element component has been registered", () => {
it("returns the component name", () => {
const component = shallowMount(AlchemyPageComponent, {
propsData: {
page: {
elements: [{ element_type: "element_component" }],
elements: [{ name: "element_component" }],
},
},
})
Expand All @@ -118,7 +118,7 @@ describe("Alchemy page mixin", () => {
const component = shallowMount(AlchemyPageComponent, {
propsData: {
page: {
elements: [{ element_type: "something" }],
elements: [{ name: "something" }],
},
},
})
Expand Down
6 changes: 3 additions & 3 deletions src/mixins/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export default {
},
},
methods: {
elementType(element) {
const name = element.element_type
componentName(element) {
const name = element.name
if (this.$options.components[name]) {
return name
}
Expand All @@ -20,7 +20,7 @@ export default {
return this.elementsByName(name)[0]
},
elementsByName(name) {
return this.page.elements.filter((e) => e.element_type === name)
return this.page.elements.filter((e) => e.name === name)
},
},
}

0 comments on commit a4a817b

Please sign in to comment.