• Stars
    star
    137
  • Rank 266,121 (Top 6 %)
  • Language
    Ruby
  • License
    BSD 3-Clause "New...
  • Created over 10 years ago
  • Updated over 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Middleman extension for loading content from Google Drive

Middleman::GoogleDrive

Gem Version

This is an extension for Middleman that allows you to load data from a google spreadsheet into your template data.

Installation

Add this line to your application's Gemfile:

gem 'middleman-google_drive'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install middleman-google_drive

Usage

The extension will get loaded automatically, you just need to activate it.

activate :google_drive

Spreadsheet

There are two ways to load and use spreadsheets. Most the time you just need a single document with multiple worksheets. If you only need a single document...

activate :google_drive, load_sheets: 'mygoogledocumentkey'

You can then use the worksheets in your templates (make sure your worksheets have names that only contain alpha-numeric characters; no spaces or strange things).

<h1>My spreadsheet is called: <%= data.mysheet['title'] %></h1>
<% data.Sheet1.each do [row] %>
    Column one header: <%= row['Column one header'] %>
    Column two header: <%= row['Column two header'] %>
    My column name: <%= row['My column name'] %>
<% end %>

If you would like to load multiple documents from google, you can use a hash when activating the extension:

activate :google_drive, load_sheets: {
    mysheet: google_spreadsheet_key,
    moresheet: another_key
}

Then you can use the data from any of the loaded documents in your templates:

<h1>My spreadsheet is called: <%= data.mysheet['title'] %></h1>
<% data.mysheet['Sheet1'].each do [row] %>
    Column one header: <%= row['Column one header'] %>
    Column two header: <%= row['Column two header'] %>
    My column name: <%= row['My column name'] %>
<% end %>
<% data.moresheet['Sheet1'].each do [row] %>
    Column one header: <%= row['Column one header'] %>
    Column two header: <%= row['Column two header'] %>
    My column name: <%= row['My column name'] %>
<% end %>

Documents

You can load documents similarly to spreadsheets. With documents, you have options: plain text, HTML or ArchieML.

To load a single document as text:

activate :google_drive, load_docs: 'mygoogledocumentkey'

You can now access the text in data.doc. To change the name of the variable name or to load multiple documents, use a hash:

activate :google_drive, load_docs: {
    first_article: 'googledockeyone',
    second_article: 'googledockeytwo'
}
  • To load HTML, use load_docs_html instead of load_docs.
  • For ArchieML, use load_docs_archieml.

The HTML version of a Google doc will be a complete HTML document that includes <html>, <head> and <body> tags. You'll probably wanna use the sanitize gem to clean things up.

You can then access your document in your templates thusly:

<article>
<%=data.first_article %>
</article>

If you are loading ArchieML, the data will come in the form of a hash. Both text and html come as strings.

Setup

The first time you use this extension, you will have to configure the authentication with Google docs. There are two parts to this. First you will have to register a client application with Google and get API keys. Tarbell has a great explanation on how to do this. You will need to copy the client_secrets.json to ~/.google_client_secrets.json. The first time you run middleman, you will be sent to a Google login prompt in order to associate Middleman with your Google account. You should make sure that the account that you choose has access to the spreadsheets you want to use in Middleman.

You need to make sure that the redirect_urls setting for the client secrets is urn:ietf:wg:oauth:2.0:oob and not another URL.

Protip: If somebody in your org has used this extension or something like it, chances are that person has already created a client secrets file that can be shared with you.

Once you authenticate with Google, a new file ~/.google_drive_oauth2.json will be created containing an key for communicating with Google Drive.

You can override the location of the client secrets and oauth2 JSON files with the environment variables GOOGLE_CLIENT_SECRETS and GOOGLE_DRIVE_OAUTH.

If you plan to run Middleman on a server, you can use Google's server to server authentication. This will kick in if you define the environment variables GOOGLE_OAUTH_PERSON, GOOGLE_OAUTH_ISSUER and either GOOGLE_OAUTH_KEYFILE or GOOGLE_OAUTH_PRIVATE_KEY.

Contributing

  1. Fork it ( https://github.com/voxmedia/middleman-google_drive/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

More Repositories

1

meme

Meme generator
JavaScript
1,849
star
2

autotune

Platform for reusable news tools
JavaScript
414
star
3

github-action-slack-notify-build

Report GitHub Actions build status on Slack
JavaScript
252
star
4

data-projects

Scripts and data for various Vox Media stories and news projects
Jupyter Notebook
185
star
5

metronome

JavaScript
170
star
6

verge-50

An example of a Middleman-powered editorial app built by the Vox Media Product Team and published by The Verge.
CSS
129
star
7

accessibility

Vox Product's Accessibility Guidelines
HTML
90
star
8

quiz-generator

JavaScript
88
star
9

lightbike

Asset budget auditing library - for internet site webpages
JavaScript
67
star
10

gliss

Constraint based article layout system
HTML
63
star
11

mapper

A tool for generating world and US-state choropleth maps
JavaScript
51
star
12

Transcriber

NWJS os x desktop based application that given a video/audio file returns a transcription using IBM Watson Speech to text API
HTML
41
star
13

viz-app

GUI for ai2html
HTML
38
star
14

code-of-conduct

HTML
37
star
15

vax-fig

jQuery plugin that downloads and displays the first frame of an animated GIF
JavaScript
35
star
16

tonr

Vax 16 project by Pam, Brittany, Alesha, Scott, and Aidan
JavaScript
27
star
17

sass-theme-template-loader

Themed CSS stylesheet generator for Sass assets
JavaScript
13
star
18

maestro

Maestro - the BigQuery Orchestrator
Go
13
star
19

revenue-hiring

Hiring Guide and Programming Examples
Ruby
11
star
20

pixelpunch

http://pixelpunch.voxmedia.com
HTML
9
star
21

ad-server-proxy

Ruby
8
star
22

captions_burner

NWJS os x desktop app that given a srt and a video burns the captions onto the video. Can also export as gif.
HTML
8
star
23

concert-vast

A simple VAST Library
JavaScript
7
star
24

yobot

Yo.
Ruby
6
star
25

autotune-image-slider

JavaScript
6
star
26

vox-hiring-exercise

Ruby
6
star
27

tap-instagram

Singer Tap for the Instagram Graph API
Python
5
star
28

rich-text-ruby

Format for representing rich text documents and changes, ported from https://github.com/ottypes/rich-text
Ruby
5
star
29

bongo

Bongo is a responsive tool that quickly enables people to make type pairings, color, branding and photo choices in a live, responsive environment without writing any code.
Ruby
4
star
30

autotune-wtfengine

WTFEngine for Autotune
JavaScript
4
star
31

canonical_domain

Ruby
4
star
32

data-privacy-compliance

Vox Media's library for implementing data privacy frameworks for use in revenue
JavaScript
4
star
33

eslint-config-voxproduct

Eslint config for js projects
JavaScript
3
star
34

setup-vox-rig

Script for setting up your Mac OS X system to make Vox Media middleman apps (should be public)
Shell
3
star
35

kinto_box

A ruby client for Kinto(kinto.readthedocs.io)
Ruby
3
star
36

varniphite

Go
3
star
37

voxholder

Ruby
3
star
38

thumbor_varnish_http_loader

Python
2
star
39

ida

Vax project 2016 - Rethinking Visual Narratives
JavaScript
2
star
40

DevOps-Technical-Exercise

Ruby
2
star
41

tap-elasticsearch

meltano extractor for elastic search
Python
2
star
42

tap-twitter

Meltano extractor for organic data from the Twitter API
Python
2
star
43

image_compression_experiments

JavaScript
2
star
44

vc-ikea-minisite

Ikea Minisite 2020
HTML
1
star
45

thumbor_indexed_file_result_storage

Python
1
star
46

nginxplusphite

Puts nginx plus status on graphite
Go
1
star
47

omniauth_service

Ruby
1
star
48

tap-facebook-pages

Singer tap for organic Facebook content insights built using the Meltano SDK
Python
1
star
49

tap-google-sheets

Meltano extractor for Google Sheets
Python
1
star
50

identity-library

Simple JavaScript library to generate private identifiers
TypeScript
1
star
51

iframe-client

Cross-origin iframe messaging client
JavaScript
1
star
52

tap-firestore

Singer Tap for Firestore built with the Meltano SDK
Python
1
star
53

thumbor_rewrite_loader

An HTTP loader which rewrites matches from a list, with a single canonical domain.
Python
1
star
54

attribute_delegator

An ActiveRecord extension that allows you to treat fields from another model/table as local attributes.
Ruby
1
star
55

open-source-contribution-guidelines

Guidelines and code of conduct for contributing to Vox Media open source projects.
1
star