Giter Site home page Giter Site logo

ytolun / dtl Goto Github PK

View Code? Open in Web Editor NEW
8.0 1.0 0.0 404 KB

An Apps Script project for Google Docs. It allows you to create flexible templates and generate instances of them using a sidebar GUI

License: MIT License

JavaScript 59.00% HTML 41.00%
google-docs apps-script clasp templating-language

dtl's Introduction


Docs Templating Language

clasp GitHub package.json dynamic GitHub package.json version GitHub

Twitter Follow

Create flexible templates for Google Docs and generate instances of your templates using a sidebar GUI. See the demo video here

Docs Templating Language Demo

Table of Contents

Features

πŸ”€ Variables: Define variables and replace them with strings using text inputs in the GUI

βœ… If Statements: Define conditional blocks of content in your document and show/hide them using checkboxes in the GUI

πŸ’± Switch Statements: Define conditional blocks of content for more than two scenarios and show/hide them using dropdowns in the GUI

πŸ–‡Nesting: You can use variables inside of if or switch statements

πŸ’« Flexible: DTL can be used to create anytype of document template you want

Usage

As of now, DTL isn't published as an add-on. So you need to create your own Apps Script project by copying this file.

Clone the project

git clone https://github.com/YTolun/dtl.git

Create a Google Doc file

Create a Google Doc file in youy Drive and open the Script Editor by going to Tools > Script Editor

Change Script Id in the cloned project

To learn the Script Id of your newly created Google Doc, open the Script Editor and go to File > Project Properties

Copy the Script Id of your Google Doc and change /.clasp.json accordingly.

Install clasp

Please follow the instructions on clasp README to install clasp, log into it and turn on your Apps Script API.

Push the code to your project

Run

clasp push

Now when you open your Google Doc, you'll see the DTL item on the menu.

Syntax

You can use this JSX-inspired syntax anywhere in your document to manipulate your template using the generated sidebar UI.

Variables

Variables control string values and they're represented by text inputs in the GUI. There are two ways of defining a variable in DTL.

Regular print tag:

<dtl:print={variableName} />

Shorthand tag (better suited for inline usage):

<dtl={variableName} />

If Statements

If statements control blocks of elements that you wish to show or hide depending on a boolean variable. If statements are represented by checkboxes in the GUI.

If statement syntax:

<dtl:if={booleanName}>
    This block of text will only be included in the generated copy of the document
    if the booleanName is set to true βœ”
</dtl:if>

Currently, DTL doesn't support using inline if statements.

Switch Statements

Switch statements are used to include one of two or more blocks of elements based on a case choice. Switch statements are represented by dropdowns of possible case values in the GUI.

Swtich statement syntax:

<dtl:switch={switchName}>
    <dtl:case={optionOne}>
        This block of text will only be included in the generated copy of the document
        if optionOne is selected as switchName
    </dtl:case>
    <dtl:case={optionTwo}>
        This block of text will only be included in the generated copy of the document
        if optionTwo is selected as switchName
    </dtl:case>
    <dtl:case={optionThree}>
        This block of text will only be included in the generated copy of the document
        if optionThree is selected as switchName
    </dtl:case>
</dtl:switch>

Currently, DTL doesn't support using inline switch statements.

Known Issues

Last element of a document can't be a variable, an if statement or a switch statement

You need at least one empty line or a line of regulat text (that doesn't use DTL) at the end of your document. This issue is caused by an Apps Script limitation.

License

This project is licensed under the MIT License. For further information, please check the LICENSE file.

dtl's People

Contributors

ytolun avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.