Skip to content
This repository was archived by the owner on May 6, 2025. It is now read-only.
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 10 additions & 50 deletions src/components/files/Editor.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
<template>
<form id="editor" :class="req.language">
<div v-if="hasMetadata" id="metadata">
<h2>{{ $t('files.metadata') }}</h2>
</div>

<h2 v-if="hasMetadata">{{ $t('files.body') }}</h2>
</form>
</template>

Expand All @@ -17,10 +13,7 @@ import buttons from '@/utils/buttons'
export default {
name: 'editor',
computed: {
...mapState(['req', 'schedule']),
hasMetadata: function () {
return (this.req.metadata !== undefined && this.req.metadata !== null)
}
...mapState(['req', 'schedule'])
},
data: function () {
return {
Expand Down Expand Up @@ -52,36 +45,22 @@ export default {
this.req.content = ''
}

const language = this.req.extension.slice(1)
const isMarkdown = language === '.markdown' ||
language === '.md'

// Set up the main content editor.
this.content = CodeMirror(document.getElementById('editor'), {
value: this.req.content,
lineNumbers: (this.req.language !== 'markdown'),
lineNumbers: !isMarkdown,
viewportMargin: 500,
autofocus: true,
mode: this.req.language,
theme: (this.req.language === 'markdown') ? 'markdown' : 'ttcn',
lineWrapping: (this.req.language === 'markdown')
})

CodeMirror.autoLoadMode(this.content, this.req.language)

// Prevent of going on if there is no metadata.
if (!this.hasMetadata) {
return
}

this.parseMetadata()

// Set up metadata editor.
this.metadata = CodeMirror(document.getElementById('metadata'), {
value: this.req.metadata,
viewportMargin: Infinity,
lineWrapping: true,
theme: 'markdown',
mode: this.metalang
mode: language,
theme: isMarkdown ? 'markdown' : 'ttcn',
lineWrapping: isMarkdown
})

CodeMirror.autoLoadMode(this.metadata, this.metalang)
CodeMirror.autoLoadMode(this.content, language)
},
methods: {
// Saves the content when the user presses CTRL-S.
Expand All @@ -97,21 +76,6 @@ export default {
event.preventDefault()
this.save()
},
// Parses the metadata and gets the language in which
// it is written.
parseMetadata () {
if (this.req.metadata.startsWith('{')) {
this.metalang = 'json'
}

if (this.req.metadata.startsWith('---')) {
this.metalang = 'yaml'
}

if (this.req.metadata.startsWith('+++')) {
this.metalang = 'toml'
}
},
// Publishes the file.
publish (event) {
this.save(event, true)
Expand All @@ -123,10 +87,6 @@ export default {
let content = this.content.getValue()
buttons.loading(button)

if (this.hasMetadata) {
content = this.metadata.getValue() + '\n\n' + content
}

api.put(this.$route.path, content, regenerate, this.schedule)
.then(() => {
buttons.success(button)
Expand Down