From 15b5513af150be6d7477b1ecd77d31489dec0732 Mon Sep 17 00:00:00 2001 From: XVincentX Date: Sat, 5 Nov 2016 12:39:31 +0100 Subject: [PATCH 1/5] Create command skeleton for Apiary preview --- client/package.json | 6 ++++++ client/src/commands.ts | 24 ++++++++++++++++++++++++ client/src/extension.ts | 3 ++- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/client/package.json b/client/package.json index 0bef267..b047385 100644 --- a/client/package.json +++ b/client/package.json @@ -173,6 +173,12 @@ "title": "Browses the current API on Apiary documentation", "category": "API Elements - Apiary", "icon": "./resources/apiary.ico" + }, + { + "command": "apiElements.apiary.preview", + "title": "Previews the current API on Apiary documentation", + "category": "API Elements - Apiary", + "icon": "./resources/apiary.ico" } ] }, diff --git a/client/src/commands.ts b/client/src/commands.ts index 1024be1..5dfe2d5 100644 --- a/client/src/commands.ts +++ b/client/src/commands.ts @@ -82,6 +82,30 @@ export function publishApi(context: ExtensionContext, textEditor: TextEditor) { ); } +export function previewApi(context: ExtensionContext, textEditor: TextEditor) { + const code = textEditor.document.getText(); + const preview = + ` + + + + Nasino pariosino + + + + + + `; + + fs.writeFileSync('./tmp.html', preview, 'utf8'); + + return commands.executeCommand('vscode.previewHtml', Uri.parse('file://tmp.html')); +} + export function logout(context: ExtensionContext) { const tokenFilePath = path.join(context.extensionPath, '.apiaryToken'); if (fs.existsSync(path.join(context.extensionPath, '.apiaryToken'))) { diff --git a/client/src/extension.ts b/client/src/extension.ts index 1beeb12..e8481b4 100644 --- a/client/src/extension.ts +++ b/client/src/extension.ts @@ -15,7 +15,8 @@ function registerCommands(client: LanguageClient, context: ExtensionContext) { commands.registerCommand('apiElements.apiary.fetchApi', Commands.fetchApi.bind(this, context)), commands.registerCommand('apiElements.apiary.logout', Commands.logout.bind(this, context)), commands.registerTextEditorCommand('apiElements.apiary.publishApi', Commands.publishApi.bind(this, context)), - commands.registerTextEditorCommand('apiElements.apiary.browse', Commands.browse.bind(this, context)) + commands.registerTextEditorCommand('apiElements.apiary.browse', Commands.browse.bind(this, context)), + commands.registerTextEditorCommand('apiElements.apiary.preview', Commands.previewApi.bind(this, context)) ); } From aa3d38fbeee2e5fb645d28634da828e9240c5f87 Mon Sep 17 00:00:00 2001 From: XVincentX Date: Sat, 5 Nov 2016 15:23:53 +0100 Subject: [PATCH 2/5] Show a side by side column --- client/src/commands.ts | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/client/src/commands.ts b/client/src/commands.ts index 5dfe2d5..96f7add 100644 --- a/client/src/commands.ts +++ b/client/src/commands.ts @@ -4,7 +4,7 @@ import * as path from 'path'; import {killCurrentApiaryClient, requestApiaryClient} from './requestApiaryClient'; import {showMessage} from './showMessage'; import {showUntitledWindow} from './showUntitledWindow'; -import {ExtensionContext, Position, QuickPickItem, Range, TextEditor, Uri, commands, window} from 'vscode'; +import {ExtensionContext, Position, QuickPickItem, Range, TextEditor, Uri, ViewColumn, commands, window} from 'vscode'; import {LanguageClient} from 'vscode-languageclient'; import axios from 'axios'; @@ -89,7 +89,7 @@ export function previewApi(context: ExtensionContext, textEditor: TextEditor) { - Nasino pariosino + API Preview @@ -101,9 +101,10 @@ export function previewApi(context: ExtensionContext, textEditor: TextEditor) { `; - fs.writeFileSync('./tmp.html', preview, 'utf8'); + const filePath = path.join(context.extensionPath, 'preview.html'); + fs.writeFileSync(filePath, preview, 'utf8'); - return commands.executeCommand('vscode.previewHtml', Uri.parse('file://tmp.html')); + return commands.executeCommand('vscode.previewHtml', Uri.parse(`file:${filePath}`), getViewColumn()); } export function logout(context: ExtensionContext) { @@ -131,3 +132,23 @@ export function browse(context: ExtensionContext, textEditor: TextEditor) { }) .then(uri => commands.executeCommand('vscode.open', uri), showMessage); } + +function getViewColumn(sideBySide = true): ViewColumn { + const active = window.activeTextEditor; + if (!active) { + return ViewColumn.One; + } + + if (!sideBySide) { + return active.viewColumn; + } + + switch (active.viewColumn) { + case ViewColumn.One: + return ViewColumn.Two; + case ViewColumn.Two: + return ViewColumn.Three; + default: + return active.viewColumn; + } +} From 63ab5d9818a789bfbf147a238ae10d8da7b6914b Mon Sep 17 00:00:00 2001 From: XVincentX Date: Sat, 12 Nov 2016 11:21:13 +0100 Subject: [PATCH 3/5] Update to latest VSCode --- client/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/package.json b/client/package.json index b047385..691a160 100644 --- a/client/package.json +++ b/client/package.json @@ -17,7 +17,7 @@ }, "publisher": "vncz", "engines": { - "vscode": "^1.5.0" + "vscode": "^1.7.0" }, "categories": [ "Languages", From 5c51bb548666b085ff7282e9ef7d4b32958dfd30 Mon Sep 17 00:00:00 2001 From: XVincentX Date: Sat, 12 Nov 2016 11:25:24 +0100 Subject: [PATCH 4/5] Escape the provided code --- client/package.json | 1 + client/src/commands.ts | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/client/package.json b/client/package.json index 691a160..713b54d 100644 --- a/client/package.json +++ b/client/package.json @@ -194,6 +194,7 @@ }, "dependencies": { "axios": "^0.14.0", + "lodash.escape": "^4.0.1", "vscode-languageclient": "^2.4.2" } } diff --git a/client/src/commands.ts b/client/src/commands.ts index 96f7add..d40cd5c 100644 --- a/client/src/commands.ts +++ b/client/src/commands.ts @@ -9,6 +9,8 @@ import {LanguageClient} from 'vscode-languageclient'; import axios from 'axios'; +const escape = require('lodash.escape'); + function selectApi(context: ExtensionContext) { return requestApiaryClient(context) .then(client => Promise.all([client.getApiList(), client])) @@ -83,7 +85,7 @@ export function publishApi(context: ExtensionContext, textEditor: TextEditor) { } export function previewApi(context: ExtensionContext, textEditor: TextEditor) { - const code = textEditor.document.getText(); + const code = escape(textEditor.document.getText()); const preview = ` From c4f57bc2a38c82cf5ea4265943d9d9c75689c71b Mon Sep 17 00:00:00 2001 From: XVincentX Date: Sat, 12 Nov 2016 11:44:04 +0100 Subject: [PATCH 5/5] Finalise the thinghy --- client/CHANGELOG.md | 4 ++++ client/src/commands.ts | 8 +++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/client/CHANGELOG.md b/client/CHANGELOG.md index 9c4f849..d026e13 100644 --- a/client/CHANGELOG.md +++ b/client/CHANGELOG.md @@ -2,6 +2,10 @@ This changelog tracks changes starting from first public release. +## v0.5.1 + +- It is now possible to preview the documentation you're working now currently in Apiary using the appropriate feature. Just look for Apiary: Preview command. + ## v0.5.0 - It is now possible to configure what you think it's a Symbol to report and not. All of them are extension parameters and are enabled by default. diff --git a/client/src/commands.ts b/client/src/commands.ts index d40cd5c..2ca10a9 100644 --- a/client/src/commands.ts +++ b/client/src/commands.ts @@ -4,7 +4,8 @@ import * as path from 'path'; import {killCurrentApiaryClient, requestApiaryClient} from './requestApiaryClient'; import {showMessage} from './showMessage'; import {showUntitledWindow} from './showUntitledWindow'; -import {ExtensionContext, Position, QuickPickItem, Range, TextEditor, Uri, ViewColumn, commands, window} from 'vscode'; +import {ExtensionContext, Position, QuickPickItem, Range, TextEditor, Uri, + ViewColumn, commands, window, workspace} from 'vscode'; import {LanguageClient} from 'vscode-languageclient'; import axios from 'axios'; @@ -103,10 +104,11 @@ export function previewApi(context: ExtensionContext, textEditor: TextEditor) { `; - const filePath = path.join(context.extensionPath, 'preview.html'); + const filePath = path.join(workspace.rootPath || context.extensionPath, 'preview.html'); fs.writeFileSync(filePath, preview, 'utf8'); - return commands.executeCommand('vscode.previewHtml', Uri.parse(`file:${filePath}`), getViewColumn()); + return commands.executeCommand('vscode.previewHtml', Uri.parse(`file:${filePath}`), getViewColumn()) + .then(() => fs.unlinkSync(filePath)); } export function logout(context: ExtensionContext) {