middleman-google_drive 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/google_drive.rb +36 -14
- data/lib/middleman-google_drive/extension.rb +2 -2
- 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: b55941adf06f492ae066a183856e98b563a03b42
|
4
|
+
data.tar.gz: 20e2056fbdc0114d14c391de431d583fc9d1a88d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 310b40a38b5fb3c452b0e261476552b261ea7aa4a11349bb9f0e6716254323ef6fe92385a41205ec51c32b1642d6cd579fb65fd8e7696e065887616452b2acc3
|
7
|
+
data.tar.gz: 2ed85c7be3f9e6c9fb97bc28ea7bb406d4d4f3eeabf625b1c811e1908d6a41bb6634ec5c5f22838b8036429b2f26dc77a3e39ea6634d3fb913534f6589a408ae
|
data/lib/google_drive.rb
CHANGED
@@ -89,27 +89,49 @@ class GoogleDrive
|
|
89
89
|
# Like tarbell.
|
90
90
|
if %w(microcopy copy).include?(title.downcase) ||
|
91
91
|
title.downcase =~ /[ -_]copy$/
|
92
|
-
data[title] =
|
93
|
-
sheet.extract_data.each do |row|
|
94
|
-
# if the key name is reused, create an array with all the entries
|
95
|
-
if data[title].keys.include? row[0]
|
96
|
-
if data[title][row[0]].is_a? Array
|
97
|
-
data[title][row[0]] << row[1]
|
98
|
-
else
|
99
|
-
data[title][row[0]] = [data[title][row[0]], row[1]]
|
100
|
-
end
|
101
|
-
else
|
102
|
-
data[title][row[0]] = row[1]
|
103
|
-
end
|
104
|
-
end
|
92
|
+
data[title] = load_microcopy(sheet.extract_data)
|
105
93
|
else
|
106
94
|
# otherwise parse the sheet into a hash
|
107
|
-
data[title] = sheet.
|
95
|
+
data[title] = load_table(sheet.extract_data)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
data
|
99
|
+
end
|
100
|
+
|
101
|
+
# Take a two-dimensional array from a spreadsheet and create a hash. The first
|
102
|
+
# column is used as the key, and the second column is the value. If the key
|
103
|
+
# occurs more than once, the value becomes an array to hold all the values
|
104
|
+
# associated with the key.
|
105
|
+
def load_microcopy(table)
|
106
|
+
data = {}
|
107
|
+
table.each_with_index do |row, i|
|
108
|
+
next if i == 0 # skip the header row
|
109
|
+
# Did we already create this key?
|
110
|
+
if data.keys.include? row[0]
|
111
|
+
# if the key name is reused, create an array with all the entries
|
112
|
+
if data[row[0]].is_a? Array
|
113
|
+
data[row[0]] << row[1]
|
114
|
+
else
|
115
|
+
data[row[0]] = [data[row[0]], row[1]]
|
116
|
+
end
|
117
|
+
else
|
118
|
+
# add this row's key and value to the hash
|
119
|
+
data[row[0]] = row[1]
|
108
120
|
end
|
109
121
|
end
|
110
122
|
data
|
111
123
|
end
|
112
124
|
|
125
|
+
# Take a two-dimensional array from a spreadsheet and create an array of hashes.
|
126
|
+
def load_table(table)
|
127
|
+
return [] if table.length < 2
|
128
|
+
header = table.shift # Get the header row
|
129
|
+
table.map do |row|
|
130
|
+
# zip headers with current row, convert it to a hash
|
131
|
+
header.zip(row).to_h unless row.nil?
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
113
135
|
def doc(key, format = 'html')
|
114
136
|
doc = find(key)
|
115
137
|
|
@@ -36,7 +36,7 @@ module Middleman
|
|
36
36
|
else
|
37
37
|
store_data('doc', load_doc(option.to_s, type))
|
38
38
|
end
|
39
|
-
rescue Faraday::ConnectionFailed => exc
|
39
|
+
rescue ::Faraday::ConnectionFailed => exc
|
40
40
|
if @drive.server?
|
41
41
|
puts "== FAILED to load Google Doc \"#{exc.message}\""
|
42
42
|
else
|
@@ -44,7 +44,7 @@ module Middleman
|
|
44
44
|
== Could not connect to Google Drive. Local data will be used.
|
45
45
|
MSG
|
46
46
|
end
|
47
|
-
rescue GoogleDrive::GoogleDriveError => exc
|
47
|
+
rescue ::GoogleDrive::GoogleDriveError => exc
|
48
48
|
if @drive.server?
|
49
49
|
puts "== FAILED to load Google Doc \"#{exc.message}\""
|
50
50
|
else
|