middleman-google_drive 0.1.0 → 0.1.1

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: 16c1bd804f853f95a62015f235fa40dac151a003
4
- data.tar.gz: af02439107587b497cfe943fd0499798c6908b3e
3
+ metadata.gz: b3b6e4fdd59f38f10e195f07fefbf4bf1a536529
4
+ data.tar.gz: bd0feb9fd0e999dad48eb87795ea11a334cd72b9
5
5
  SHA512:
6
- metadata.gz: 1a3ab2878383a99299331cf70bb715e55b4552f5bdc8a58ae9f47fab38035ed36b724da8c69cee9d59a40bd7954d70037c14bc78853bd9385ba5b09f1f0aa4db
7
- data.tar.gz: 087b46c200f6556ba3a72e86da8e57f0ad22d75b6641e65b28ec2ef8efc8b82622f85472f33f6f7d563e989239c85c15fc7820fb7e0c17a38cbe25355320c79d
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 # this is obviously where you would store the app instance
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
- # grab the export url
35
- uri = list_resp.data['exportLinks'][format]
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 the first
62
- # column contains keys and the second contains values. Ala tarbell.
63
- if %w(microcopy copy).include? title.downcase
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
- data[title][row[0]] = row[1]
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 dict, incorrectly, of course
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
@@ -1,5 +1,5 @@
1
1
  module Middleman
2
2
  module GoogleDrive
3
- VERSION = '0.1.0'
3
+ VERSION = '0.1.1'
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.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Mark