Merge pull request #1625 from iamtabrezkhan/issue-1507
FEAT: add syntax highlighting in Code Generator Modal
This commit is contained in:
@@ -11,7 +11,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div slot="body" class="flex flex-col">
|
<div slot="body" class="flex flex-col">
|
||||||
<label for="requestType">{{ $t("request_type") }}</label>
|
<label for="requestType">{{ $t("choose_language") }}</label>
|
||||||
<span class="select-wrapper">
|
<span class="select-wrapper">
|
||||||
<v-popover>
|
<v-popover>
|
||||||
<pre v-if="requestType">{{ codegens.find((x) => x.id === requestType).name }}</pre>
|
<pre v-if="requestType">{{ codegens.find((x) => x.id === requestType).name }}</pre>
|
||||||
@@ -46,15 +46,22 @@
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<textarea
|
<SmartAceEditor
|
||||||
id="generatedCode"
|
v-if="requestType"
|
||||||
|
:value="requestCode"
|
||||||
|
:lang="codegens.find((x) => x.id === requestType).language"
|
||||||
|
:options="{
|
||||||
|
maxLines: '10',
|
||||||
|
minLines: '10',
|
||||||
|
fontSize: '16px',
|
||||||
|
autoScrollEditorIntoView: true,
|
||||||
|
readOnly: true,
|
||||||
|
showPrintMargin: false,
|
||||||
|
useWorker: false,
|
||||||
|
}"
|
||||||
|
styles="rounded-b-lg"
|
||||||
ref="generatedCode"
|
ref="generatedCode"
|
||||||
name="generatedCode"
|
/>
|
||||||
rows="8"
|
|
||||||
v-model="requestCode"
|
|
||||||
readonly
|
|
||||||
class="rounded-b-lg"
|
|
||||||
></textarea>
|
|
||||||
</div>
|
</div>
|
||||||
</SmartModal>
|
</SmartModal>
|
||||||
</template>
|
</template>
|
||||||
@@ -66,7 +73,7 @@ export default {
|
|||||||
props: {
|
props: {
|
||||||
show: Boolean,
|
show: Boolean,
|
||||||
requestCode: String,
|
requestCode: String,
|
||||||
requestTypeProp: { type: String, default: "" },
|
requestTypeProp: { type: String, default: "curl" },
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
@@ -97,7 +104,8 @@ export default {
|
|||||||
this.$toast.success(this.$t("copied_to_clipboard"), {
|
this.$toast.success(this.$t("copied_to_clipboard"), {
|
||||||
icon: "done",
|
icon: "done",
|
||||||
})
|
})
|
||||||
this.$refs.generatedCode.select()
|
this.$refs.generatedCode.editor.selectAll()
|
||||||
|
this.$refs.generatedCode.editor.focus()
|
||||||
document.execCommand("copy")
|
document.execCommand("copy")
|
||||||
setTimeout(() => (this.$refs.copyRequestCode.innerHTML = this.copyButton), 1000)
|
setTimeout(() => (this.$refs.copyRequestCode.innerHTML = this.copyButton), 1000)
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ import { ShellWgetCodegen } from "./generators/shell-wget"
|
|||||||
*
|
*
|
||||||
* id: string
|
* id: string
|
||||||
* name: 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
|
* generator: (ctx) => string
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
export const CLibcurlCodegen = {
|
export const CLibcurlCodegen = {
|
||||||
id: "c-libcurl",
|
id: "c-libcurl",
|
||||||
name: "C libcurl",
|
name: "C libcurl",
|
||||||
|
language: "c_cpp",
|
||||||
generator: ({
|
generator: ({
|
||||||
auth,
|
auth,
|
||||||
httpUser,
|
httpUser,
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { isJSONContentType } from "~/helpers/utils/contenttypes"
|
|||||||
export const CsRestsharpCodegen = {
|
export const CsRestsharpCodegen = {
|
||||||
id: "cs-restsharp",
|
id: "cs-restsharp",
|
||||||
name: "C# RestSharp",
|
name: "C# RestSharp",
|
||||||
|
language: "csharp",
|
||||||
generator: ({
|
generator: ({
|
||||||
url,
|
url,
|
||||||
pathName,
|
pathName,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
export const CurlCodegen = {
|
export const CurlCodegen = {
|
||||||
id: "curl",
|
id: "curl",
|
||||||
name: "cURL",
|
name: "cURL",
|
||||||
|
language: "sh",
|
||||||
generator: ({
|
generator: ({
|
||||||
url,
|
url,
|
||||||
pathName,
|
pathName,
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { isJSONContentType } from "~/helpers/utils/contenttypes"
|
|||||||
export const GoNativeCodegen = {
|
export const GoNativeCodegen = {
|
||||||
id: "go-native",
|
id: "go-native",
|
||||||
name: "Go Native",
|
name: "Go Native",
|
||||||
|
language: "golang",
|
||||||
generator: ({
|
generator: ({
|
||||||
url,
|
url,
|
||||||
pathName,
|
pathName,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
export const JavaOkhttpCodegen = {
|
export const JavaOkhttpCodegen = {
|
||||||
id: "java-okhttp",
|
id: "java-okhttp",
|
||||||
name: "Java OkHttp",
|
name: "Java OkHttp",
|
||||||
|
language: "java",
|
||||||
generator: ({
|
generator: ({
|
||||||
auth,
|
auth,
|
||||||
httpUser,
|
httpUser,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
export const JavaUnirestCodegen = {
|
export const JavaUnirestCodegen = {
|
||||||
id: "java-unirest",
|
id: "java-unirest",
|
||||||
name: "Java Unirest",
|
name: "Java Unirest",
|
||||||
|
language: "java",
|
||||||
generator: ({
|
generator: ({
|
||||||
url,
|
url,
|
||||||
pathName,
|
pathName,
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { isJSONContentType } from "~/helpers/utils/contenttypes"
|
|||||||
export const JavascriptFetchCodegen = {
|
export const JavascriptFetchCodegen = {
|
||||||
id: "js-fetch",
|
id: "js-fetch",
|
||||||
name: "JavaScript Fetch",
|
name: "JavaScript Fetch",
|
||||||
|
language: "javascript",
|
||||||
generator: ({
|
generator: ({
|
||||||
url,
|
url,
|
||||||
pathName,
|
pathName,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
export const JavascriptJqueryCodegen = {
|
export const JavascriptJqueryCodegen = {
|
||||||
id: "js-jquery",
|
id: "js-jquery",
|
||||||
name: "JavaScript jQuery",
|
name: "JavaScript jQuery",
|
||||||
|
language: "javascript",
|
||||||
generator: ({
|
generator: ({
|
||||||
url,
|
url,
|
||||||
pathName,
|
pathName,
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { isJSONContentType } from "~/helpers/utils/contenttypes"
|
|||||||
export const JavascriptXhrCodegen = {
|
export const JavascriptXhrCodegen = {
|
||||||
id: "js-xhr",
|
id: "js-xhr",
|
||||||
name: "JavaScript XHR",
|
name: "JavaScript XHR",
|
||||||
|
language: "javascript",
|
||||||
generator: ({
|
generator: ({
|
||||||
auth,
|
auth,
|
||||||
httpUser,
|
httpUser,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
export const NodejsAxiosCodegen = {
|
export const NodejsAxiosCodegen = {
|
||||||
id: "nodejs-axios",
|
id: "nodejs-axios",
|
||||||
name: "NodeJs Axios",
|
name: "NodeJs Axios",
|
||||||
|
language: "javascript",
|
||||||
generator: ({
|
generator: ({
|
||||||
url,
|
url,
|
||||||
pathName,
|
pathName,
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { isJSONContentType } from "~/helpers/utils/contenttypes"
|
|||||||
export const NodejsNativeCodegen = {
|
export const NodejsNativeCodegen = {
|
||||||
id: "nodejs-native",
|
id: "nodejs-native",
|
||||||
name: "NodeJs Native",
|
name: "NodeJs Native",
|
||||||
|
language: "javascript",
|
||||||
generator: ({
|
generator: ({
|
||||||
url,
|
url,
|
||||||
pathName,
|
pathName,
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { isJSONContentType } from "~/helpers/utils/contenttypes"
|
|||||||
export const NodejsRequestCodegen = {
|
export const NodejsRequestCodegen = {
|
||||||
id: "nodejs-request",
|
id: "nodejs-request",
|
||||||
name: "NodeJs Request",
|
name: "NodeJs Request",
|
||||||
|
language: "javascript",
|
||||||
generator: ({
|
generator: ({
|
||||||
url,
|
url,
|
||||||
pathName,
|
pathName,
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { isJSONContentType } from "~/helpers/utils/contenttypes"
|
|||||||
export const NodejsUnirestCodegen = {
|
export const NodejsUnirestCodegen = {
|
||||||
id: "nodejs-unirest",
|
id: "nodejs-unirest",
|
||||||
name: "NodeJs Unirest",
|
name: "NodeJs Unirest",
|
||||||
|
language: "javascript",
|
||||||
generator: ({
|
generator: ({
|
||||||
url,
|
url,
|
||||||
pathName,
|
pathName,
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { isJSONContentType } from "~/helpers/utils/contenttypes"
|
|||||||
export const PhpCurlCodegen = {
|
export const PhpCurlCodegen = {
|
||||||
id: "php-curl",
|
id: "php-curl",
|
||||||
name: "PHP cURL",
|
name: "PHP cURL",
|
||||||
|
language: "php",
|
||||||
generator: ({
|
generator: ({
|
||||||
url,
|
url,
|
||||||
pathName,
|
pathName,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
export const PowershellRestmethodCodegen = {
|
export const PowershellRestmethodCodegen = {
|
||||||
id: "powershell-restmethod",
|
id: "powershell-restmethod",
|
||||||
name: "PowerShell RestMethod",
|
name: "PowerShell RestMethod",
|
||||||
|
language: "powershell",
|
||||||
generator: ({
|
generator: ({
|
||||||
url,
|
url,
|
||||||
pathName,
|
pathName,
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ const printHeaders = (headers) => {
|
|||||||
export const PythonHttpClientCodegen = {
|
export const PythonHttpClientCodegen = {
|
||||||
id: "python-http-client",
|
id: "python-http-client",
|
||||||
name: "Python http.client",
|
name: "Python http.client",
|
||||||
|
language: "python",
|
||||||
generator: ({
|
generator: ({
|
||||||
url,
|
url,
|
||||||
pathName,
|
pathName,
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ const printHeaders = (headers) => {
|
|||||||
export const PythonRequestsCodegen = {
|
export const PythonRequestsCodegen = {
|
||||||
id: "python-requests",
|
id: "python-requests",
|
||||||
name: "Python Requests",
|
name: "Python Requests",
|
||||||
|
language: "python",
|
||||||
generator: ({
|
generator: ({
|
||||||
url,
|
url,
|
||||||
pathName,
|
pathName,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
export const RubyNetHttpCodeGen = {
|
export const RubyNetHttpCodeGen = {
|
||||||
id: "ruby-net-http",
|
id: "ruby-net-http",
|
||||||
name: "Ruby Net::HTTP",
|
name: "Ruby Net::HTTP",
|
||||||
|
language: "ruby",
|
||||||
generator: ({
|
generator: ({
|
||||||
url,
|
url,
|
||||||
pathName,
|
pathName,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
export const SalesforceApexCodegen = {
|
export const SalesforceApexCodegen = {
|
||||||
id: "salesforce-apex",
|
id: "salesforce-apex",
|
||||||
name: "Salesforce Apex",
|
name: "Salesforce Apex",
|
||||||
|
language: "apex",
|
||||||
generator: ({
|
generator: ({
|
||||||
url,
|
url,
|
||||||
pathName,
|
pathName,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
export const ShellHttpieCodegen = {
|
export const ShellHttpieCodegen = {
|
||||||
id: "shell-httpie",
|
id: "shell-httpie",
|
||||||
name: "Shell HTTPie",
|
name: "Shell HTTPie",
|
||||||
|
language: "sh",
|
||||||
generator: ({
|
generator: ({
|
||||||
url,
|
url,
|
||||||
pathName,
|
pathName,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
export const ShellWgetCodegen = {
|
export const ShellWgetCodegen = {
|
||||||
id: "shell-wget",
|
id: "shell-wget",
|
||||||
name: "Shell wget",
|
name: "Shell wget",
|
||||||
|
language: "sh",
|
||||||
generator: ({
|
generator: ({
|
||||||
url,
|
url,
|
||||||
pathName,
|
pathName,
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ export default () => ({
|
|||||||
bodyParams: [],
|
bodyParams: [],
|
||||||
rawParams: "",
|
rawParams: "",
|
||||||
rawInput: false,
|
rawInput: false,
|
||||||
requestType: "",
|
requestType: "curl",
|
||||||
contentType: "",
|
contentType: "",
|
||||||
},
|
},
|
||||||
gql: {
|
gql: {
|
||||||
|
|||||||
Reference in New Issue
Block a user