Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion sidebar/src/App.svelte
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
<script>
export let name;
export let name;

const insertHelloWorld = () => {
google.script.run.insertText("Hello World.");
}
</script>

<main>
<h1>Hello {name}!</h1>
<p>Visit the <a href="https://svelte.dev/tutorial" target="_blank">Svelte tutorial</a> to learn how to build Svelte apps.</p>
<button on:click={insertHelloWorld} class="blue">Insert Hello World.</button>
</main>

<style>
Expand Down
7 changes: 6 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,9 @@ const showSidebar = () => {
* Parses the file with the given file name. This is used to inject CSS and Javascript
* in an HTML file.
*/
const include = (filename: string) => HtmlService.createHtmlOutputFromFile(filename).getContent();
const include = (filename: string) => HtmlService.createHtmlOutputFromFile(filename).getContent();

/**
* Inserts the given text into the active document.
*/
const insertText = (text: string) => TextInserter.insertText(text);
6 changes: 6 additions & 0 deletions src/text-inserter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace TextInserter {
export const insertText = (text: string) => {
const currentDate = new Date();
DocumentApp.getActiveDocument().getBody().appendParagraph(`${text} It is ${currentDate.toDateString()}`);
}
}