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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: df94f7285904bfdc980f5c9b41f462419510d229
4
- data.tar.gz: d21820a19625117878fac1a193f31886405cc2b1
3
+ metadata.gz: b55941adf06f492ae066a183856e98b563a03b42
4
+ data.tar.gz: 20e2056fbdc0114d14c391de431d583fc9d1a88d
5
5
  SHA512:
6
- metadata.gz: f0491070a92dac3f1b78bcf9c344505ff85d00e06ced6c3f8483fd549fd0d4793f30198ff327073e8fb7590a06f4a9506fb502f26b707b6e3889f36f1ce425f2
7
- data.tar.gz: 335652541d98d74f3ac22138bbdc2c618c0f11977f22e93fbfd83d33b3f32843cba2aff811ea8c496bb8e137e1cfd9ab5d988ec66d17eaa6a43d07662f622a75
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.get_table[:table]
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
@@ -1,5 +1,5 @@
1
1
  module Middleman
2
2
  module GoogleDrive
3
- VERSION = '0.3.3'
3
+ VERSION = '0.3.4'
4
4
  end
5
5
  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.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Mark