import { TextEditor , Uri , ViewColumn } from "vscode" ; import * as pug from "pug" ; import { DocumentContentManagerInterface } from "./documentContentManagerInterface" ; import { HtmlPreview } from "../util/htmlPreview" ; export class PugDocumentContentManager implements DocumentContentManagerInterface { private _editor : TextEditor ; public constructor ( editor ) { this . _editor = editor ; return this ; } public editor ( ) { return this . _editor ; } public async createContentSnippet ( ) { let editor = this . _editor ; if ( ! editor ) { return HtmlPreview . errorSnippet ( this . getWindowErrorMessage ( ) ) ; } return this . generatePreviewSnippet ( editor ) ; } public sendPreviewCommand ( previewUri , displayColumn ) { return HtmlPreview . sendPreviewCommand ( previewUri , displayColumn ) ; } private getWindowErrorMessage ( ) { return `No Active editor - no properties to preview.` ; } private pugSrcSnippetWithNodeModules ( pugContent ) { var options = { pretty : true } ; var fn = pug . compile ( pugContent , options ) ; var html = fn ( ) ; return html ; } private pugSrcSnippet ( editor ) { if ( ! editor ) { return Promise . resolve ( HtmlPreview . errorSnippet ( this . getWindowErrorMessage ( ) ) ) ; } return Promise . resolve ( this . pugSrcSnippetWithNodeModules ( editor . document . getText ( ) ) ) ; } private generatePreviewSnippet ( editor ) { if ( ! editor || ! editor . document ) { return Promise . resolve ( HtmlPreview . errorSnippet ( this . getWindowErrorMessage ( ) ) ) ; } let doc = editor . document ; return this . pugSrcSnippet ( editor ) . then ( function ( pugSrc ) { return HtmlPreview . fixNoneNetLinks ( pugSrc , doc . fileName ) ; } ) ; } }