middleman-google_drive 0.2.7 → 0.2.8

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: 9dc8b914f8ecfa175eeebbbf9f523994f377bea2
4
- data.tar.gz: a7cf3b8776134a09304e05e96d38a76c11435d49
3
+ metadata.gz: 2e770a8092ef9c7f93c2bfa87cc5761f734de84a
4
+ data.tar.gz: 70a53a4a60479ca86ab745eeadf419b6e276a366
5
5
  SHA512:
6
- metadata.gz: ebf0e3d4784bdd27b29ad834e4fb188d6f25165c88b36eaf31b6bfbc7d085bbb570e5224110ea4b8d8086b0b1fb85ab371938e2cd3438c262ef912566032d4e1
7
- data.tar.gz: 127a4748dc58952a4edf74862593eaf49b127aae41ac03f399684cd2e22871bb17601ecc96945cb910daefac83e248e8177733706f116b37afc3a3a8c1dcfa75
6
+ metadata.gz: d481a955ea7beb27b5fabb80616e01d54d0c8b7efd25d123c62523b222d98a30de747930d38a1e317eeec4d87201bf4ed5e54635c19c08ff0807d546121b326f
7
+ data.tar.gz: 94273972b78ebc5a254c0f5eeb18e573a73efb03dbaef85f6f4462e60cc1aa18de8516df0f656a248f641365da62a6ca4a488943c1e24e5df63088f648e306a6
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Middleman::GoogleDrive
2
2
 
3
- This is an extension for Middleman that allows you to load data from a google
3
+ This is an extension for Middleman that allows you to load data from a google
4
4
  spreadsheet into your template data.
5
5
 
6
6
  ## Installation
@@ -25,6 +25,8 @@ The extension will get loaded automatically, you just need to activate it.
25
25
  activate :google_drive
26
26
  ```
27
27
 
28
+ ### Spreadsheet
29
+
28
30
  There are two ways to load and use spreadsheets. Most the time you just need a
29
31
  single document with multiple worksheets. If you only need a single document...
30
32
 
@@ -80,65 +82,32 @@ Then you can use the data from any of the loaded documents in your templates:
80
82
  <% end %>
81
83
  ```
82
84
 
83
- You can also use a simplified Google Drive interface from inside your project, via the `drive`
84
- variable. In order to use this functionality, you only have to activate the extension; you do
85
- not have to provide a google docs key:
85
+ ### Documents
86
86
 
87
- ```ruby
88
- # Activate the extension
89
- activate :google_drive
87
+ You can load documents similarly to spreadsheets. With documents, you have a couple
88
+ options: plain text or HTML.
90
89
 
91
- # get metadata for a document
92
- doc_info = drive.find('google_document_key')
90
+ To load a single document as text:
93
91
 
94
- # get the same spreadsheet data without using the load_sheets param above
95
- mysheet = drive.prepared_spreadsheet('google_document_key')
96
-
97
- # get a fancy spreadsheet object
98
- spreadsheet = drive.spreadsheet('google_document_key')
92
+ ```ruby
93
+ activate :google_drive, load_docs: 'mygoogledocumentkey'
99
94
  ```
100
95
 
101
- The fancy spreadsheet object comes from the [roo gem](https://github.com/Empact/roo). Unfortunately documentation is slim. Here is an example from the `roo` readme:
96
+ You can now access the text in `data.doc`. To change the name of the variable name
97
+ or to load multiple documents, use a hash:
102
98
 
103
99
  ```ruby
104
- spreadsheet.sheet('Info').row(1)
105
- spreadsheet.sheet(0).row(1)
106
-
107
- # use this to find the sheet with the most data to parse
108
-
109
- spreadsheet.longest_sheet
110
-
111
- # this file has multiple worksheets, let's iterate through each of them and process
112
-
113
- spreadsheet.each_with_pagename do |name, sheet|
114
- p sheet.row(1)
115
- end
116
-
117
- # pull out a hash of exclusive column data (get rid of useless columns and save memory)
118
-
119
- spreadsheet.each(:id => 'UPC',:qty => 'ATS') {|hash| arr << hash}
120
- #=> hash will appear like {:upc=>727880013358, :qty => 12}
121
-
122
- # NOTE: .parse does the same as .each, except it returns an array (similar to each vs. map)
123
-
124
- # not sure exactly what a column will be named? try a wildcard search with the character *
125
- # regex characters are allowed ('^price\s')
126
- # case insensitive
127
-
128
- spreadsheet.parse(:id => 'UPC*SKU',:qty => 'ATS*\sATP\s*QTY$')
129
-
130
- # if you need to locate the header row and assign the header names themselves,
131
- # use the :header_search option
132
-
133
- spreadsheet.parse(:header_search => ['UPC*SKU','ATS*\sATP\s*QTY$'])
134
- #=> each element will appear in this fashion:
135
- #=> {"UPC" => 123456789012, "STYLE" => "987B0", "COLOR" => "blue", "QTY" => 78}
136
-
137
- # want to strip out annoying unicode characters and surrounding white space?
138
-
139
- spreadsheet.parse(:clean => true)
100
+ activate :google_drive, load_docs: {
101
+ first_article: 'googledockeyone',
102
+ second_article: 'googledockeytwo'
103
+ }
140
104
  ```
141
105
 
106
+ In order to load the google doc as HTML, use `load_docs_html` instead of `load_docs`.
107
+ The HTML version of a Google doc will be a complete HTML document that includes
108
+ `<html>`, `<head>` and `<body>` tags. You'll probably wanna use the sanitize gem
109
+ to clean things up.
110
+
142
111
  ## Setup
143
112
 
144
113
  The first time you use this extension, you will have to configure the authentication
@@ -6,6 +6,8 @@ module Middleman
6
6
  # Middle man extension that loads the google doc data
7
7
  class Extension < Middleman::Extension
8
8
  option :load_sheets, {}, 'Key for a google spreadsheet or a hash of google spreadsheets to load. Hash value is the id or slug of the spreadsheet to load, hash key is the data attribute to load the sheet data into.'
9
+ option :load_docs, {}, 'Key for a google doc or a hash of google docs to load as text. Hash value is the Google key of the spreadsheet to load, hash key is the data attribute to load the sheet data into.'
10
+ option :load_docs_html, {}, 'Key for a google doc or a hash of google docs to load as HTML. Hash value is the Google key of the spreadsheet to load, hash key is the data attribute to load the sheet data into.'
9
11
 
10
12
  def initialize(klass, options_hash = {}, &block)
11
13
  super
@@ -13,19 +15,45 @@ module Middleman
13
15
  @drive = ::GoogleDrive.new
14
16
 
15
17
  app = klass.inst
18
+
16
19
  if options.load_sheets.is_a? Hash
17
20
  options.load_sheets.each do |name, key|
18
- app.data.store(name, load_doc(key.to_s))
21
+ app.data.store(name, load_doc(key.to_s, 'spreadsheet'))
19
22
  end
20
23
  else
21
- load_doc(options.load_sheets.to_s).each do |name, sheet|
24
+ load_doc(options.load_sheets.to_s, 'spreadsheet').each do |name, sheet|
22
25
  app.data.store(name, sheet)
23
26
  end
24
27
  end
28
+
29
+ if options.load_docs.is_a? Hash
30
+ options.load_docs.each do |name, key|
31
+ app.data.store(name, load_doc(key.to_s, 'text'))
32
+ end
33
+ else
34
+ app.data.store(
35
+ 'doc', load_doc(options.load_docs.to_s, 'text'))
36
+ end
37
+
38
+ if options.load_docs_html.is_a? Hash
39
+ options.load_docs_html.each do |name, key|
40
+ app.data.store(name, load_doc(key.to_s, 'html'))
41
+ end
42
+ else
43
+ app.data.store(
44
+ 'doc', load_doc(options.load_docs_html.to_s, 'html'))
45
+ end
25
46
  end
26
47
 
27
- def load_doc(key)
28
- data = @drive.prepared_spreadsheet(key)
48
+ def load_doc(key, type)
49
+ case type.to_s
50
+ when 'spreadsheet'
51
+ data = @drive.prepared_spreadsheet(key)
52
+ when 'html'
53
+ data = @drive.doc(key, 'html')
54
+ else
55
+ data = @drive.doc(key, 'text')
56
+ end
29
57
  doc = @drive.find(key)
30
58
  puts <<-MSG
31
59
  == Loaded data from Google Doc "#{doc['title']}"
@@ -1,5 +1,5 @@
1
1
  module Middleman
2
2
  module GoogleDrive
3
- VERSION = '0.2.7'
3
+ VERSION = '0.2.8'
4
4
  end
5
5
  end
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.add_runtime_dependency 'middleman-core', '~> 3'
23
23
  spec.add_runtime_dependency 'retriable', '~> 1.4'
24
24
  spec.add_runtime_dependency 'google-api-client', '< 0.8'
25
- spec.add_runtime_dependency 'spreadsheet'
25
+ spec.add_runtime_dependency 'roo'
26
26
  spec.add_development_dependency 'bundler', '~> 1.6'
27
27
  spec.add_development_dependency 'rake'
28
28
  spec.add_development_dependency 'minitest'
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.2.7
4
+ version: 0.2.8
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: 2015-03-04 00:00:00.000000000 Z
12
+ date: 2015-03-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: middleman-core
@@ -54,7 +54,7 @@ dependencies:
54
54
  - !ruby/object:Gem::Version
55
55
  version: '0.8'
56
56
  - !ruby/object:Gem::Dependency
57
- name: spreadsheet
57
+ name: roo
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
60
  - - ">="