FEAT: add syntax highlighting in Code Generator Modal

USE: SmartAceEditor componenent
This commit is contained in:
Tabrez Khan
2021-05-03 14:46:41 +05:30
parent d676b5a68d
commit 3f743b4f61
23 changed files with 38 additions and 9 deletions

View File

@@ -46,15 +46,20 @@
</button>
</div>
</div>
<textarea
id="generatedCode"
<SmartAceEditor
:value="requestCode"
:lang="codegens.find((x) => x.id === requestType).language"
:options="{
maxLines: '16',
minLines: '10',
fontSize: '16px',
autoScrollEditorIntoView: true,
readOnly: true,
showPrintMargin: false,
useWorker: false,
}"
ref="generatedCode"
name="generatedCode"
rows="8"
v-model="requestCode"
readonly
class="rounded-b-lg"
></textarea>
/>
</div>
</SmartModal>
</template>
@@ -97,7 +102,8 @@ export default {
this.$toast.success(this.$t("copied_to_clipboard"), {
icon: "done",
})
this.$refs.generatedCode.select()
this.$refs.generatedCode.editor.selectAll()
this.$refs.generatedCode.editor.focus()
document.execCommand("copy")
setTimeout(() => (this.$refs.copyRequestCode.innerHTML = this.copyButton), 1000)
},

View File

@@ -25,6 +25,8 @@ import { ShellWgetCodegen } from "./generators/shell-wget"
*
* id: string
* name: string
* language: string // a string identifier used in ace editor for syntax highlighting
* // see node_modules/ace-builds/src-noconflict/mode-** files for valid value
* generator: (ctx) => string
*
*/

View File

@@ -1,6 +1,7 @@
export const CLibcurlCodegen = {
id: "c-libcurl",
name: "C libcurl",
language: "c_cpp",
generator: ({
auth,
httpUser,

View File

@@ -3,6 +3,7 @@ import { isJSONContentType } from "~/helpers/utils/contenttypes"
export const CsRestsharpCodegen = {
id: "cs-restsharp",
name: "C# RestSharp",
language: "csharp",
generator: ({
url,
pathName,

View File

@@ -1,6 +1,7 @@
export const CurlCodegen = {
id: "curl",
name: "cURL",
language: "sh",
generator: ({
url,
pathName,

View File

@@ -3,6 +3,7 @@ import { isJSONContentType } from "~/helpers/utils/contenttypes"
export const GoNativeCodegen = {
id: "go-native",
name: "Go Native",
language: "golang",
generator: ({
url,
pathName,

View File

@@ -1,6 +1,7 @@
export const JavaOkhttpCodegen = {
id: "java-okhttp",
name: "Java OkHttp",
language: "java",
generator: ({
auth,
httpUser,

View File

@@ -1,6 +1,7 @@
export const JavaUnirestCodegen = {
id: "java-unirest",
name: "Java Unirest",
language: "java",
generator: ({
url,
pathName,

View File

@@ -3,6 +3,7 @@ import { isJSONContentType } from "~/helpers/utils/contenttypes"
export const JavascriptFetchCodegen = {
id: "js-fetch",
name: "JavaScript Fetch",
language: "javascript",
generator: ({
url,
pathName,

View File

@@ -1,6 +1,7 @@
export const JavascriptJqueryCodegen = {
id: "js-jquery",
name: "JavaScript jQuery",
language: "javascript",
generator: ({
url,
pathName,

View File

@@ -3,6 +3,7 @@ import { isJSONContentType } from "~/helpers/utils/contenttypes"
export const JavascriptXhrCodegen = {
id: "js-xhr",
name: "JavaScript XHR",
language: "javascript",
generator: ({
auth,
httpUser,

View File

@@ -1,6 +1,7 @@
export const NodejsAxiosCodegen = {
id: "nodejs-axios",
name: "NodeJs Axios",
language: "javascript",
generator: ({
url,
pathName,

View File

@@ -3,6 +3,7 @@ import { isJSONContentType } from "~/helpers/utils/contenttypes"
export const NodejsNativeCodegen = {
id: "nodejs-native",
name: "NodeJs Native",
language: "javascript",
generator: ({
url,
pathName,

View File

@@ -3,6 +3,7 @@ import { isJSONContentType } from "~/helpers/utils/contenttypes"
export const NodejsRequestCodegen = {
id: "nodejs-request",
name: "NodeJs Request",
language: "javascript",
generator: ({
url,
pathName,

View File

@@ -3,6 +3,7 @@ import { isJSONContentType } from "~/helpers/utils/contenttypes"
export const NodejsUnirestCodegen = {
id: "nodejs-unirest",
name: "NodeJs Unirest",
language: "javascript",
generator: ({
url,
pathName,

View File

@@ -3,6 +3,7 @@ import { isJSONContentType } from "~/helpers/utils/contenttypes"
export const PhpCurlCodegen = {
id: "php-curl",
name: "PHP cURL",
language: "php",
generator: ({
url,
pathName,

View File

@@ -1,6 +1,7 @@
export const PowershellRestmethodCodegen = {
id: "powershell-restmethod",
name: "PowerShell RestMethod",
language: "powershell",
generator: ({
url,
pathName,

View File

@@ -11,6 +11,7 @@ const printHeaders = (headers) => {
export const PythonHttpClientCodegen = {
id: "python-http-client",
name: "Python http.client",
language: "python",
generator: ({
url,
pathName,

View File

@@ -11,6 +11,7 @@ const printHeaders = (headers) => {
export const PythonRequestsCodegen = {
id: "python-requests",
name: "Python Requests",
language: "python",
generator: ({
url,
pathName,

View File

@@ -1,6 +1,7 @@
export const RubyNetHttpCodeGen = {
id: "ruby-net-http",
name: "Ruby Net::HTTP",
language: "ruby",
generator: ({
url,
pathName,

View File

@@ -1,6 +1,7 @@
export const SalesforceApexCodegen = {
id: "salesforce-apex",
name: "Salesforce Apex",
language: "apex",
generator: ({
url,
pathName,

View File

@@ -1,6 +1,7 @@
export const ShellHttpieCodegen = {
id: "shell-httpie",
name: "Shell HTTPie",
language: "sh",
generator: ({
url,
pathName,

View File

@@ -1,6 +1,7 @@
export const ShellWgetCodegen = {
id: "shell-wget",
name: "Shell wget",
language: "sh",
generator: ({
url,
pathName,