Git Product home page Git Product logo

gdoc.js's Introduction

gDoc.js v1.0.1

Use Google Spreadsheets as your CMS!

Demo Page

Getting Started

Create a Google Spreadsheet containing all the information you will need for your site. After, choose 'Publish to the web...' in the 'File' menu. Then grab the id in the link.

https://docs.google.com/spreadsheets/d/__yourPublicId__/pubhtml

Inside of your HTML document include these two files.

<script src="tabletop.js"></script>
<script src="gDoc.js"></script>

Or just this file

<script src="gDoc.min.js"></script>

Now at the footer of your html page initiate the connection!

By default the sheetName is 'Sheet1'

<script>
    gDoc(yourPublicId, sheetName);
</script>

Example connection

<script>
    // initiating connection
    gDoc('1cfW7dwJkwJq7rqTsftNy3wjCJR3-yDylc5MRmsc0Yw8', 'layout');
</script>

All that's left now is to add gDoc attributes to your html!

Example spreadsheet

title header subheader
My website Welcome, This is my website!

How to insert from example spreadsheet above.

<html>
    <head>
        <title gDoc="title"></title>
        <script src="tabletop.js"></script>
        <script src="gDoc.js"></script>
    </head>
    <body>
        <h1 gDoc="header"></h1>
        <h2 gDoc="subheader"></h2>
    </body>
    <footer>
        <script>
            gDoc(yourPublicId, sheetName);
        </script>               
    </footer>
</html>

And it's that easy!

Setting Parameters

You might want to use gDoc to set link hrefs, img srcs, and set styles.

Here's a quick example of how you would make a red link

my-link my-link:href my-link:style
Example www.mylink.com color: red
<a gDoc="my-link"></a>

Advanced Blocks (Store & Blog)

To iterate over a block of html simply just pass gDoc an object {}.

Let's say you want to export your 4 most recent blog posts

gDoc({
    public: yourPublicId,
    sheet: 'blog',
    gDoc: 'blog-section',
    columns: ['title', 'body', 'link'],
    loop: 4,
    html: function() {
        var html = '<a href="{{link}}">';
        html += '<h1>{{title}}</h1>';
        html += '<p>{{body}}</p>';
        html += '</a>';
        return html;
    }
});

The loop key can be set to false to iterate over all items in the document. Make sure you instantiate all your variables in the 'columns' array, otherwise they won't show up in the mustache syntax.

If you have any other questions just shoot me over an email!

gdoc.js's People

Contributors

jadeallencook avatar stephenradachy avatar

Watchers

Harish 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.