middleman-google_drive 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +63 -0
- data/Rakefile +2 -0
- data/lib/middleman-google_drive/extension.rb +34 -0
- data/lib/middleman-google_drive/version.rb +5 -0
- data/lib/middleman-google_drive.rb +87 -0
- data/lib/middleman_extension.rb +1 -0
- data/middleman-google_drive.gemspec +26 -0
- metadata +126 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: f3a285921b3f9a1cd1315a39ca4adeb5789ff591
|
|
4
|
+
data.tar.gz: 95ea9261a02cfcd9c2e719fb92194a2abb880a04
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 4c674d9893c9f45c9f2ede571ffbe9905989690e50cc7d362ba8387c7953373a36e929c6e64adc2618668f37f2beb3c3c8fe1f981fa45622cbfca546168be94c
|
|
7
|
+
data.tar.gz: 8e88247849e0f5004e08990ece3bcfd0b5c9e5afdbec9bc355e59cf30e7cfef230725f33631aa59580f7df947c393c3b9aecdccaf0e3bc31d82ed5e24e902d45
|
data/.gitignore
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
*.gem
|
|
2
|
+
*.rbc
|
|
3
|
+
.bundle
|
|
4
|
+
.config
|
|
5
|
+
.yardoc
|
|
6
|
+
Gemfile.lock
|
|
7
|
+
InstalledFiles
|
|
8
|
+
_yardoc
|
|
9
|
+
coverage
|
|
10
|
+
doc/
|
|
11
|
+
lib/bundler/man
|
|
12
|
+
pkg
|
|
13
|
+
rdoc
|
|
14
|
+
spec/reports
|
|
15
|
+
test/tmp
|
|
16
|
+
test/version_tmp
|
|
17
|
+
tmp
|
|
18
|
+
*.bundle
|
|
19
|
+
*.so
|
|
20
|
+
*.o
|
|
21
|
+
*.a
|
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2014 Vox Media Inc., Ryan Mark, Pablo Mercado
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# Middleman::GoogleDrive
|
|
2
|
+
|
|
3
|
+
This is an extension for Middleman that allows you to load data from a google
|
|
4
|
+
spreadsheet into your template data.
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
|
|
8
|
+
Add this line to your application's Gemfile:
|
|
9
|
+
|
|
10
|
+
gem 'middleman-google_drive'
|
|
11
|
+
|
|
12
|
+
And then execute:
|
|
13
|
+
|
|
14
|
+
$ bundle install
|
|
15
|
+
|
|
16
|
+
Or install it yourself as:
|
|
17
|
+
|
|
18
|
+
$ gem install middleman-google_drive
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
The extension will get loaded in automatically, you'll just need to activate it.
|
|
23
|
+
|
|
24
|
+
activate :google_drive, load_sheets: {
|
|
25
|
+
mysheet: google_spreadsheet_key,
|
|
26
|
+
moresheet: another_key
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
Then you can use the data in your templates:
|
|
30
|
+
|
|
31
|
+
<h1>My spreadsheet is called: <%= data.mysheet['title'] %></h1>
|
|
32
|
+
<% data.mysheet['Sheet1'].each do [row] %>
|
|
33
|
+
Column one header: <%= row['Column one header'] %>
|
|
34
|
+
Column two header: <%= row['Column two header'] %>
|
|
35
|
+
My column name: <%= row['My column name'] %>
|
|
36
|
+
<% end %>
|
|
37
|
+
|
|
38
|
+
The first time you use this extension, you will have to configure the authentication
|
|
39
|
+
with Google docs. There are two parts to this. First you will have to register
|
|
40
|
+
a client application with Google and get API keys. Tarbell has a [great
|
|
41
|
+
explanation](http://tarbell.readthedocs.org/en/latest/install.html#configure-google-spreadsheet-access-optional) on how to do this. You will need to copy the
|
|
42
|
+
`client_secrets.json` to `~/.google_client_secrets.json`. The first time you
|
|
43
|
+
run middleman, you will be sent to a Google login prompt in order to
|
|
44
|
+
associate Middleman with your Google account. You should make sure that the
|
|
45
|
+
account that you choose has access to the spreadsheets you want to use in
|
|
46
|
+
Middleman. Once you authenticate with Google, a new file
|
|
47
|
+
`~/.google_drive_oauth2.json` will be created containing an key for
|
|
48
|
+
communicating with Google Drive.
|
|
49
|
+
|
|
50
|
+
You can override the location of the client secrets and oauth2 JSON files with
|
|
51
|
+
the environment variables `GOOGLE_CLIENT_SECRETS` and `GOOGLE_DRIVE_OAUTH`.
|
|
52
|
+
|
|
53
|
+
If you plan to run Middleman on a server, you can use Google's server to server
|
|
54
|
+
authentication. This will kick in if you define the environment variables
|
|
55
|
+
`GOOGLE_OAUTH_PERSON`, `GOOGLE_OAUTH_ISSUER` and either `GOOGLE_OAUTH_KEYFILE` or `GOOGLE_OAUTH_PRIVATE_KEY`.
|
|
56
|
+
|
|
57
|
+
## Contributing
|
|
58
|
+
|
|
59
|
+
1. Fork it ( https://github.com/voxmedia/middleman-google_drive/fork )
|
|
60
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
61
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
62
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
63
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
require 'google_drive'
|
|
2
|
+
|
|
3
|
+
module Middleman
|
|
4
|
+
module GoogleDrive
|
|
5
|
+
# Middle man extension that loads the google doc data
|
|
6
|
+
class Extension < Middleman::Extension
|
|
7
|
+
option :load_sheets, {}, 'Hash of google spreadsheets to load. Hash value is the id or slug of the entry to load, hash key is the data attribute to load the sheet data into.'
|
|
8
|
+
|
|
9
|
+
def initialize(app, options_hash = {}, &block)
|
|
10
|
+
super
|
|
11
|
+
|
|
12
|
+
@client = Middleman::GoogleDrive.connect
|
|
13
|
+
@session = ::GoogleDrive.login_with_oauth(
|
|
14
|
+
@client.authorization.access_token)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def after_configuration
|
|
18
|
+
options.load_sheets.each do |k, v|
|
|
19
|
+
app.data.store(k, get_sheet(v))
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def get_sheet(key)
|
|
24
|
+
data = {}
|
|
25
|
+
s = @session.spreadsheet_by_key(key)
|
|
26
|
+
data[:title] = s.title
|
|
27
|
+
s.worksheets.each do |sheet|
|
|
28
|
+
data[sheet.title] = sheet.list.to_hash_array
|
|
29
|
+
end
|
|
30
|
+
data
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
require 'middleman-google_drive/version'
|
|
2
|
+
require 'google/api_client'
|
|
3
|
+
require 'google/api_client/client_secrets'
|
|
4
|
+
require 'google/api_client/auth/file_storage'
|
|
5
|
+
require 'google/api_client/auth/installed_app'
|
|
6
|
+
|
|
7
|
+
module Middleman
|
|
8
|
+
module GoogleDrive
|
|
9
|
+
def self.connect
|
|
10
|
+
credentials = ENV['GOOGLE_DRIVE_OAUTH'] || File.expand_path(
|
|
11
|
+
'~/.google_drive_oauth2.json')
|
|
12
|
+
client_secrets = ENV['GOOGLE_CLIENT_SECRETS'] || File.expand_path(
|
|
13
|
+
'~/.google_client_secrets.json')
|
|
14
|
+
|
|
15
|
+
person = ENV['GOOGLE_OAUTH_PERSON']
|
|
16
|
+
issuer = ENV['GOOGLE_OAUTH_ISSUER']
|
|
17
|
+
key_path = ENV['GOOGLE_OAUTH_KEYFILE']
|
|
18
|
+
private_key = ENV['GOOGLE_OAUTH_PRIVATE_KEY']
|
|
19
|
+
|
|
20
|
+
# try to read the file,
|
|
21
|
+
# throw errors if not readable or not found
|
|
22
|
+
if key_path
|
|
23
|
+
key = Google::APIClient::KeyUtils.load_from_pkcs12(
|
|
24
|
+
key_path, 'notasecret')
|
|
25
|
+
elsif @private_key
|
|
26
|
+
key = OpenSSL::PKey::RSA.new(
|
|
27
|
+
private_key, 'notasecret')
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
if key
|
|
31
|
+
puts 'authenticating with key'
|
|
32
|
+
client = Google::APIClient.new(
|
|
33
|
+
application_name: 'VoxDocs',
|
|
34
|
+
application_version: '0.0.1',
|
|
35
|
+
authorization: Signet::OAuth2::Client.new(
|
|
36
|
+
token_credential_uri: 'https://accounts.google.com/o/oauth2/token',
|
|
37
|
+
audience: 'https://accounts.google.com/o/oauth2/token',
|
|
38
|
+
person: person,
|
|
39
|
+
issuer: issuer,
|
|
40
|
+
signing_key: key,
|
|
41
|
+
scope: [
|
|
42
|
+
'https://www.googleapis.com/auth/drive',
|
|
43
|
+
'https://spreadsheets.google.com/feeds',
|
|
44
|
+
'https://docs.google.com/feeds/',
|
|
45
|
+
'https://docs.googleusercontent.com/'
|
|
46
|
+
]
|
|
47
|
+
)
|
|
48
|
+
)
|
|
49
|
+
client.authorization.fetch_access_token!
|
|
50
|
+
else
|
|
51
|
+
client = Google::APIClient.new(
|
|
52
|
+
application_name: 'Middleman',
|
|
53
|
+
application_version: '1.0.0'
|
|
54
|
+
)
|
|
55
|
+
file_storage = Google::APIClient::FileStorage.new(credentials)
|
|
56
|
+
if file_storage.authorization.nil?
|
|
57
|
+
unless File.exist? client_secrets
|
|
58
|
+
puts 'You need to create a client_secrets.json file and save it to `~/.google_client_secrets.json`. Find instructions here: http://tarbell.readthedocs.org/en/latest/install.html#configure-google-spreadsheet-access-optional'
|
|
59
|
+
exit
|
|
60
|
+
end
|
|
61
|
+
client_secrets = Google::APIClient::ClientSecrets.load(
|
|
62
|
+
client_secrets)
|
|
63
|
+
flow = Google::APIClient::InstalledAppFlow.new(
|
|
64
|
+
client_id: client_secrets.client_id,
|
|
65
|
+
client_secret: client_secrets.client_secret,
|
|
66
|
+
scope: [
|
|
67
|
+
'https://www.googleapis.com/auth/drive',
|
|
68
|
+
'https://spreadsheets.google.com/feeds',
|
|
69
|
+
'https://docs.google.com/feeds/',
|
|
70
|
+
'https://docs.googleusercontent.com/'
|
|
71
|
+
]
|
|
72
|
+
)
|
|
73
|
+
client.authorization = flow.authorize(file_storage)
|
|
74
|
+
else
|
|
75
|
+
client.authorization = file_storage.authorization
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
client
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
require 'middleman-core'
|
|
84
|
+
require 'middleman-google_drive/extension'
|
|
85
|
+
|
|
86
|
+
::Middleman::Extensions.register(
|
|
87
|
+
:google_drive, Middleman::GoogleDrive::Extension)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require 'middleman-google_drive'
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'middleman-google_drive/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = 'middleman-google_drive'
|
|
8
|
+
spec.version = Middleman::GoogleDrive::VERSION
|
|
9
|
+
spec.authors = ['Ryan Mark', 'Pablo Mercado']
|
|
10
|
+
spec.email = ['ryan@mrk.cc', 'pablo@voxmedia.com']
|
|
11
|
+
spec.summary = 'Pull content from a google spreadsheet to use in your middleman site.'
|
|
12
|
+
#spec.description = %q(TODO: Write a longer description. Optional.)
|
|
13
|
+
spec.homepage = 'https://github.com/voxmedia/middleman-google_drive'
|
|
14
|
+
spec.license = 'MIT'
|
|
15
|
+
|
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
|
+
spec.require_paths = ['lib']
|
|
20
|
+
|
|
21
|
+
spec.add_runtime_dependency 'middleman-core', '>= 3.0.0'
|
|
22
|
+
spec.add_runtime_dependency 'google-api-client', '>= 0.7.1'
|
|
23
|
+
spec.add_runtime_dependency 'google_drive', '>= 0.3.9'
|
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.6'
|
|
25
|
+
spec.add_development_dependency 'rake', '>= 10.3.2'
|
|
26
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: middleman-google_drive
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Ryan Mark
|
|
8
|
+
- Pablo Mercado
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2014-06-26 00:00:00.000000000 Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: middleman-core
|
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
|
17
|
+
requirements:
|
|
18
|
+
- - '>='
|
|
19
|
+
- !ruby/object:Gem::Version
|
|
20
|
+
version: 3.0.0
|
|
21
|
+
type: :runtime
|
|
22
|
+
prerelease: false
|
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
24
|
+
requirements:
|
|
25
|
+
- - '>='
|
|
26
|
+
- !ruby/object:Gem::Version
|
|
27
|
+
version: 3.0.0
|
|
28
|
+
- !ruby/object:Gem::Dependency
|
|
29
|
+
name: google-api-client
|
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
|
31
|
+
requirements:
|
|
32
|
+
- - '>='
|
|
33
|
+
- !ruby/object:Gem::Version
|
|
34
|
+
version: 0.7.1
|
|
35
|
+
type: :runtime
|
|
36
|
+
prerelease: false
|
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
38
|
+
requirements:
|
|
39
|
+
- - '>='
|
|
40
|
+
- !ruby/object:Gem::Version
|
|
41
|
+
version: 0.7.1
|
|
42
|
+
- !ruby/object:Gem::Dependency
|
|
43
|
+
name: google_drive
|
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
|
45
|
+
requirements:
|
|
46
|
+
- - '>='
|
|
47
|
+
- !ruby/object:Gem::Version
|
|
48
|
+
version: 0.3.9
|
|
49
|
+
type: :runtime
|
|
50
|
+
prerelease: false
|
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
52
|
+
requirements:
|
|
53
|
+
- - '>='
|
|
54
|
+
- !ruby/object:Gem::Version
|
|
55
|
+
version: 0.3.9
|
|
56
|
+
- !ruby/object:Gem::Dependency
|
|
57
|
+
name: bundler
|
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
|
59
|
+
requirements:
|
|
60
|
+
- - ~>
|
|
61
|
+
- !ruby/object:Gem::Version
|
|
62
|
+
version: '1.6'
|
|
63
|
+
type: :development
|
|
64
|
+
prerelease: false
|
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
66
|
+
requirements:
|
|
67
|
+
- - ~>
|
|
68
|
+
- !ruby/object:Gem::Version
|
|
69
|
+
version: '1.6'
|
|
70
|
+
- !ruby/object:Gem::Dependency
|
|
71
|
+
name: rake
|
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
|
73
|
+
requirements:
|
|
74
|
+
- - '>='
|
|
75
|
+
- !ruby/object:Gem::Version
|
|
76
|
+
version: 10.3.2
|
|
77
|
+
type: :development
|
|
78
|
+
prerelease: false
|
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
80
|
+
requirements:
|
|
81
|
+
- - '>='
|
|
82
|
+
- !ruby/object:Gem::Version
|
|
83
|
+
version: 10.3.2
|
|
84
|
+
description:
|
|
85
|
+
email:
|
|
86
|
+
- ryan@mrk.cc
|
|
87
|
+
- pablo@voxmedia.com
|
|
88
|
+
executables: []
|
|
89
|
+
extensions: []
|
|
90
|
+
extra_rdoc_files: []
|
|
91
|
+
files:
|
|
92
|
+
- .gitignore
|
|
93
|
+
- Gemfile
|
|
94
|
+
- LICENSE.txt
|
|
95
|
+
- README.md
|
|
96
|
+
- Rakefile
|
|
97
|
+
- lib/middleman-google_drive.rb
|
|
98
|
+
- lib/middleman-google_drive/extension.rb
|
|
99
|
+
- lib/middleman-google_drive/version.rb
|
|
100
|
+
- lib/middleman_extension.rb
|
|
101
|
+
- middleman-google_drive.gemspec
|
|
102
|
+
homepage: https://github.com/voxmedia/middleman-google_drive
|
|
103
|
+
licenses:
|
|
104
|
+
- MIT
|
|
105
|
+
metadata: {}
|
|
106
|
+
post_install_message:
|
|
107
|
+
rdoc_options: []
|
|
108
|
+
require_paths:
|
|
109
|
+
- lib
|
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
111
|
+
requirements:
|
|
112
|
+
- - '>='
|
|
113
|
+
- !ruby/object:Gem::Version
|
|
114
|
+
version: '0'
|
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
116
|
+
requirements:
|
|
117
|
+
- - '>='
|
|
118
|
+
- !ruby/object:Gem::Version
|
|
119
|
+
version: '0'
|
|
120
|
+
requirements: []
|
|
121
|
+
rubyforge_project:
|
|
122
|
+
rubygems_version: 2.2.2
|
|
123
|
+
signing_key:
|
|
124
|
+
specification_version: 4
|
|
125
|
+
summary: Pull content from a google spreadsheet to use in your middleman site.
|
|
126
|
+
test_files: []
|