middleman-google_drive 0.1.0 → 0.1.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 +4 -4
- data/lib/middleman-google_drive/extension.rb +22 -10
- data/lib/middleman-google_drive/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b3b6e4fdd59f38f10e195f07fefbf4bf1a536529
|
4
|
+
data.tar.gz: bd0feb9fd0e999dad48eb87795ea11a334cd72b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e6402cbecf78bd7a0d26aef9842beb4e8e2b2a60add73a27a7dad65902eac6279c5f92c84f33af7efa910aa7005f3bcd9907a90de259f079edc27c5ebd56f977
|
7
|
+
data.tar.gz: c544df48fd31fbd38a7dcd7668d1d42b0bae5ee4fbc09142656e7c3b638de3d0b80e254e96e2b179eaef31842bde96a04d614b07b67ec20d048bca7ec57efab6
|
@@ -12,16 +12,15 @@ module Middleman
|
|
12
12
|
@client = Middleman::GoogleDrive.connect
|
13
13
|
@drive = @client.discovered_api('drive', 'v2')
|
14
14
|
|
15
|
-
app = klass.inst #
|
15
|
+
app = klass.inst # where would you store the app instance?
|
16
16
|
options.load_sheets.each do |k, v|
|
17
17
|
app.data.store(k, get_sheet(v))
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
21
|
def get_sheet(key)
|
22
|
+
# setup the hash that we will eventually return
|
22
23
|
data = {}
|
23
|
-
# we're gonna request the spreadsheet in excel format
|
24
|
-
format = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
25
24
|
|
26
25
|
# get the file metadata
|
27
26
|
list_resp = @client.execute(
|
@@ -31,8 +30,10 @@ module Middleman
|
|
31
30
|
# die if there's an error
|
32
31
|
fail list_resp.error_message if list_resp.error?
|
33
32
|
|
34
|
-
#
|
35
|
-
|
33
|
+
# Grab the export url. We're gonna request the spreadsheet
|
34
|
+
# in excel format. Because it includes all the worksheets.
|
35
|
+
uri = list_resp.data['exportLinks'][
|
36
|
+
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']
|
36
37
|
|
37
38
|
# get the export
|
38
39
|
get_resp = @client.execute(uri: uri)
|
@@ -58,15 +59,26 @@ module Middleman
|
|
58
59
|
# in memory, but alas...)
|
59
60
|
xls = Roo::Spreadsheet.open(filename)
|
60
61
|
xls.each_with_pagename do |title, sheet|
|
61
|
-
# if the sheet is called microcopy or copy, we assume
|
62
|
-
# column contains keys and the second contains values.
|
63
|
-
|
62
|
+
# if the sheet is called microcopy, copy or ends with copy, we assume
|
63
|
+
# the first column contains keys and the second contains values.
|
64
|
+
# Like tarbell.
|
65
|
+
if %w(microcopy copy).include?(title.downcase) ||
|
66
|
+
title.downcase =~ /[ -_]copy$/
|
64
67
|
data[title] = {}
|
65
68
|
sheet.each do |row|
|
66
|
-
|
69
|
+
# if the key name is reused, create an array with all the entries
|
70
|
+
if data[title].keys.include? row[0]
|
71
|
+
if data[title][row[0]].is_a? Array
|
72
|
+
data[title][row[0]] << row[1]
|
73
|
+
else
|
74
|
+
data[title][row[0]] = [data[title][row[0]], row[1]]
|
75
|
+
end
|
76
|
+
else
|
77
|
+
data[title][row[0]] = row[1]
|
78
|
+
end
|
67
79
|
end
|
68
80
|
else
|
69
|
-
# otherwise parse the sheet into a
|
81
|
+
# otherwise parse the sheet into a hash
|
70
82
|
sheet.header_line = 2 # this is stupid. theres a bug in Roo.
|
71
83
|
data[title] = sheet.parse(headers: true)
|
72
84
|
end
|