-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
77 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,44 @@ | ||
<script setup lang="ts"> | ||
import { ref } from 'vue' | ||
import PageHeader from './components/PageHeader.vue' | ||
import PageFooter from './components/PageFooter.vue' | ||
import { useEditor } from './composables/useEditor' | ||
import useEditor from './composables/useEditor' | ||
import useGetVariables from './composables/useGetVariables' | ||
useEditor('container') | ||
const { getEditorValue } = useEditor('container') | ||
const { getVariables } = useGetVariables() | ||
const variables = ref<string[]>([]) | ||
async function getEditorContent (): Promise<void> { | ||
const content = getEditorValue() | ||
variables.value = getVariables(content ?? '') | ||
} | ||
</script> | ||
|
||
<template> | ||
<PageHeader /> | ||
<main class="my-5"> | ||
<main class="flex flex-wrap justify-center gap-5 my-5"> | ||
<div | ||
id="container" | ||
class="h-96 w-screen md:w-[43rem]" | ||
/> | ||
<section class="border border-gray-600 p-3 min-w-72 w-fit h-96"> | ||
<button | ||
class="bg-blue-800 text-white px-4 py-2 rounded-md mb-3" | ||
@click="getEditorContent" | ||
> | ||
Get Template Variables | ||
</button> | ||
<ul class="h-72 overflow-y-auto"> | ||
<li | ||
v-for="variable in variables" | ||
:key="variable" | ||
> | ||
{{ variable }} | ||
</li> | ||
</ul> | ||
</section> | ||
</main> | ||
<PageFooter /> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<template> | ||
<header> | ||
<header class="my-5"> | ||
<h1 class="text-4xl text-center font-bold"> | ||
doT.js Editor | ||
</h1> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { type Ref, ref } from 'vue' | ||
|
||
export default function useGetVariables (): { | ||
getVariables: (template: string) => string[] | ||
variables: Ref<string[]> | ||
} { | ||
const regexExpressions = /\{\{.*?\}\}/gs | ||
const regexVariables = /it\.([a-zA-Z_]\w*)/g | ||
const variables = ref<string[]>([]) | ||
|
||
function getVariables (template: string): string[] { | ||
const expressions = template.match(regexExpressions) ?? [] | ||
|
||
const allVariables: string[] = [] | ||
|
||
expressions.forEach(expression => { | ||
const matches = [...expression.matchAll(regexVariables)] | ||
const variables = matches.map(match => match[1]) | ||
allVariables.push(...variables) | ||
}) | ||
|
||
variables.value = [...new Set(allVariables)] | ||
return variables.value | ||
} | ||
|
||
return { | ||
getVariables, | ||
variables | ||
} | ||
} |