middleman-google_drive 0.0.6 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/lib/middleman-google_drive/extension.rb +54 -8
- data/lib/middleman-google_drive/version.rb +1 -1
- data/lib/middleman-google_drive.rb +3 -8
- data/middleman-google_drive.gemspec +3 -2
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 16c1bd804f853f95a62015f235fa40dac151a003
|
4
|
+
data.tar.gz: af02439107587b497cfe943fd0499798c6908b3e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1a3ab2878383a99299331cf70bb715e55b4552f5bdc8a58ae9f47fab38035ed36b724da8c69cee9d59a40bd7954d70037c14bc78853bd9385ba5b09f1f0aa4db
|
7
|
+
data.tar.gz: 087b46c200f6556ba3a72e86da8e57f0ad22d75b6641e65b28ec2ef8efc8b82622f85472f33f6f7d563e989239c85c15fc7820fb7e0c17a38cbe25355320c79d
|
data/README.md
CHANGED
@@ -35,6 +35,8 @@ Then you can use the data in your templates:
|
|
35
35
|
My column name: <%= row['My column name'] %>
|
36
36
|
<% end %>
|
37
37
|
|
38
|
+
## Setup
|
39
|
+
|
38
40
|
The first time you use this extension, you will have to configure the authentication
|
39
41
|
with Google docs. There are two parts to this. First you will have to register
|
40
42
|
a client application with Google and get API keys. Tarbell has a [great
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'roo'
|
2
2
|
|
3
3
|
module Middleman
|
4
4
|
module GoogleDrive
|
@@ -10,10 +10,9 @@ module Middleman
|
|
10
10
|
super
|
11
11
|
|
12
12
|
@client = Middleman::GoogleDrive.connect
|
13
|
-
@
|
14
|
-
@client.authorization.access_token)
|
13
|
+
@drive = @client.discovered_api('drive', 'v2')
|
15
14
|
|
16
|
-
app = klass.inst
|
15
|
+
app = klass.inst # this is obviously where you would store the app instance
|
17
16
|
options.load_sheets.each do |k, v|
|
18
17
|
app.data.store(k, get_sheet(v))
|
19
18
|
end
|
@@ -21,11 +20,58 @@ module Middleman
|
|
21
20
|
|
22
21
|
def get_sheet(key)
|
23
22
|
data = {}
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
# we're gonna request the spreadsheet in excel format
|
24
|
+
format = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
25
|
+
|
26
|
+
# get the file metadata
|
27
|
+
list_resp = @client.execute(
|
28
|
+
api_method: @drive.files.get,
|
29
|
+
parameters: { fileId: key })
|
30
|
+
|
31
|
+
# die if there's an error
|
32
|
+
fail list_resp.error_message if list_resp.error?
|
33
|
+
|
34
|
+
# grab the export url
|
35
|
+
uri = list_resp.data['exportLinks'][format]
|
36
|
+
|
37
|
+
# get the export
|
38
|
+
get_resp = @client.execute(uri: uri)
|
39
|
+
|
40
|
+
# die if there's an error
|
41
|
+
fail get_resp.error_message if get_resp.error?
|
42
|
+
|
43
|
+
# get a temporary file. we can't just write to it because ruby's
|
44
|
+
# tempfile tries to be clever and open the file for you, except we
|
45
|
+
# need to open the file in binary mode, so thanks ruby.
|
46
|
+
fp = Tempfile.new(['gdoc', '.xlsx'])
|
47
|
+
filename = fp.path
|
48
|
+
fp.close
|
49
|
+
|
50
|
+
# since the export is binary, reopen the tempfile in write binary mode
|
51
|
+
open(filename, 'wb') do |f|
|
52
|
+
# write the digits
|
53
|
+
f.write get_resp.body
|
54
|
+
end
|
55
|
+
|
56
|
+
# now open the file a third time with Roo. (Roo can't handle an IO
|
57
|
+
# object, it will only take filenames or urls, coulda done this all
|
58
|
+
# in memory, but alas...)
|
59
|
+
xls = Roo::Spreadsheet.open(filename)
|
60
|
+
xls.each_with_pagename do |title, sheet|
|
61
|
+
# if the sheet is called microcopy or copy, we assume the first
|
62
|
+
# column contains keys and the second contains values. Ala tarbell.
|
63
|
+
if %w(microcopy copy).include? title.downcase
|
64
|
+
data[title] = {}
|
65
|
+
sheet.each do |row|
|
66
|
+
data[title][row[0]] = row[1]
|
67
|
+
end
|
68
|
+
else
|
69
|
+
# otherwise parse the sheet into a dict, incorrectly, of course
|
70
|
+
sheet.header_line = 2 # this is stupid. theres a bug in Roo.
|
71
|
+
data[title] = sheet.parse(headers: true)
|
72
|
+
end
|
28
73
|
end
|
74
|
+
fp.unlink # delete our tempfile
|
29
75
|
data
|
30
76
|
end
|
31
77
|
end
|
@@ -39,10 +39,7 @@ module Middleman
|
|
39
39
|
issuer: issuer,
|
40
40
|
signing_key: key,
|
41
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/'
|
42
|
+
'https://www.googleapis.com/auth/drive'
|
46
43
|
]
|
47
44
|
)
|
48
45
|
)
|
@@ -63,16 +60,14 @@ module Middleman
|
|
63
60
|
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'
|
64
61
|
exit
|
65
62
|
end
|
63
|
+
puts 'Please login via your web browser'
|
66
64
|
client_secrets = Google::APIClient::ClientSecrets.load(
|
67
65
|
client_secrets)
|
68
66
|
flow = Google::APIClient::InstalledAppFlow.new(
|
69
67
|
client_id: client_secrets.client_id,
|
70
68
|
client_secret: client_secrets.client_secret,
|
71
69
|
scope: [
|
72
|
-
'https://www.googleapis.com/auth/drive'
|
73
|
-
'https://spreadsheets.google.com/feeds',
|
74
|
-
'https://docs.google.com/feeds/',
|
75
|
-
'https://docs.googleusercontent.com/'
|
70
|
+
'https://www.googleapis.com/auth/drive'
|
76
71
|
]
|
77
72
|
)
|
78
73
|
client.authorization = flow.authorize(file_storage)
|
@@ -6,12 +6,13 @@ require 'middleman-google_drive/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = 'middleman-google_drive'
|
8
8
|
spec.version = Middleman::GoogleDrive::VERSION
|
9
|
+
spec.platform = Gem::Platform::RUBY
|
9
10
|
spec.authors = ['Ryan Mark', 'Pablo Mercado']
|
10
11
|
spec.email = ['ryan@mrk.cc', 'pablo@voxmedia.com']
|
11
12
|
spec.summary = 'Pull content from a google spreadsheet to use in your middleman site.'
|
12
13
|
#spec.description = %q(TODO: Write a longer description. Optional.)
|
13
14
|
spec.homepage = 'https://github.com/voxmedia/middleman-google_drive'
|
14
|
-
spec.license = '
|
15
|
+
spec.license = 'BSD'
|
15
16
|
|
16
17
|
spec.files = `git ls-files -z`.split("\x0")
|
17
18
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
@@ -20,7 +21,7 @@ Gem::Specification.new do |spec|
|
|
20
21
|
|
21
22
|
spec.add_runtime_dependency 'middleman-core', '>= 3.0.0'
|
22
23
|
spec.add_runtime_dependency 'google-api-client', '>= 0.7.1'
|
23
|
-
spec.add_runtime_dependency '
|
24
|
+
spec.add_runtime_dependency 'roo', '~> 1.13.2'
|
24
25
|
spec.add_development_dependency 'bundler', '~> 1.6'
|
25
26
|
spec.add_development_dependency 'rake', '>= 10.3.2'
|
26
27
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: middleman-google_drive
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Mark
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-07-
|
12
|
+
date: 2014-07-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: middleman-core
|
@@ -40,19 +40,19 @@ dependencies:
|
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: 0.7.1
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
|
-
name:
|
43
|
+
name: roo
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
|
-
- -
|
46
|
+
- - ~>
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version:
|
48
|
+
version: 1.13.2
|
49
49
|
type: :runtime
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
|
-
- -
|
53
|
+
- - ~>
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version:
|
55
|
+
version: 1.13.2
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
57
|
name: bundler
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
@@ -101,7 +101,7 @@ files:
|
|
101
101
|
- middleman-google_drive.gemspec
|
102
102
|
homepage: https://github.com/voxmedia/middleman-google_drive
|
103
103
|
licenses:
|
104
|
-
-
|
104
|
+
- BSD
|
105
105
|
metadata: {}
|
106
106
|
post_install_message:
|
107
107
|
rdoc_options: []
|