jekyll-gdrive 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +71 -0
- data/Rakefile +2 -0
- data/jekyll-gdrive.gemspec +26 -0
- data/lib/jekyll/commands/gdrive.rb +64 -0
- data/lib/jekyll/gdrive/generator.rb +34 -0
- data/lib/jekyll/gdrive/version.rb +5 -0
- data/lib/jekyll/gdrive.rb +12 -0
- metadata +111 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1f1017a6e52a15259bd35f142d8cbe0efd0547c3
|
4
|
+
data.tar.gz: 1e8ea2c9a0e9809b16ced3a082fa77b4f316673e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 59d34f4e30f694a0db9e92854153accd6b38ddc1eb1a1c880a0e17424b1fa2489a6fe90533a332de2ba7bf52dd0cdeb709e7b24932c4d0d50078d52d7d86eeb5
|
7
|
+
data.tar.gz: 74e32fef80068e5eda3a613683cee6d85133629ff3e264b1f873232420495ed2c0d74ae6c50ef3372b151d4a7d718fc1d54d8e203d1f3abc925b04c34d41a0c7
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Mathias Biilmann Christensen
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
# Jekyll Gdrive Plugin
|
2
|
+
|
3
|
+
Access data from a Google Drvie Spreadsheet in your Jekyll sites
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add these lines to your Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
group :jekyll_plugins do
|
11
|
+
gem 'jekyll-gdrive'
|
12
|
+
end
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Before you can access any data from GDrive you need to get an access token. After installing the plugin, run:
|
22
|
+
|
23
|
+
$ bundle exec jekyll gdrive
|
24
|
+
|
25
|
+
And follow the instructions to create an application in Google's developer console and generate an access token.
|
26
|
+
|
27
|
+
Once you have to token, you need to set it up as an environment variable before running `jekyll build`.
|
28
|
+
|
29
|
+
$ export GDRIVE_TOKEN=<your ned gdrive token>
|
30
|
+
|
31
|
+
You'll also need to configure the plugin to use the right spreadsheet.
|
32
|
+
|
33
|
+
Add this to your `_config.yml`:
|
34
|
+
|
35
|
+
```yaml
|
36
|
+
gdrive:
|
37
|
+
sheet: "title of my spreadsheey"
|
38
|
+
```
|
39
|
+
|
40
|
+
## Accessing your Google Sheet data
|
41
|
+
|
42
|
+
In any Liquid template you can now use: `site.data.google_sheet` to access your sheet data.
|
43
|
+
|
44
|
+
Example:
|
45
|
+
|
46
|
+
```html
|
47
|
+
<table>
|
48
|
+
<thead>
|
49
|
+
{% for row in site.data.google_sheet limit: 1 %}
|
50
|
+
<tr>
|
51
|
+
{% for col in row %}<th>{{col}}</th>{% endfor %}
|
52
|
+
</tr>
|
53
|
+
{% endfor %}
|
54
|
+
</thead>
|
55
|
+
<tbody>
|
56
|
+
{% for row in site.data.google_sheet offset: 1 %}
|
57
|
+
<tr>
|
58
|
+
{% for col in row %}<td>{{col}}</td>{% endfor %}
|
59
|
+
</tr>
|
60
|
+
{% endfor %}
|
61
|
+
</tbody>
|
62
|
+
</table>
|
63
|
+
```
|
64
|
+
|
65
|
+
## Contributing
|
66
|
+
|
67
|
+
1. Fork it ( https://github.com/[my-github-username]/jekyll-gdrive/fork )
|
68
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
69
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
70
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
71
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'jekyll/gdrive/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "jekyll-gdrive"
|
8
|
+
spec.version = Jekyll::Gdrive::VERSION
|
9
|
+
spec.authors = ["Mathias Biilmann Christensen"]
|
10
|
+
spec.email = ["mathias@netlify.com"]
|
11
|
+
spec.summary = %q{Google Sheets access from your Jekyll sites}
|
12
|
+
spec.description = %q{Access Data from a Google Sheet through the GDrive API in your Jekyll sites}
|
13
|
+
spec.homepage = "https://github.com/netlify/jekyll-gdrive"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
|
24
|
+
spec.add_runtime_dependency "google_drive"
|
25
|
+
spec.add_runtime_dependency "highline"
|
26
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module Jekyll
|
2
|
+
module Commands
|
3
|
+
class Gdrive < Jekyll::Command
|
4
|
+
class << self
|
5
|
+
def init_with_program(prog)
|
6
|
+
prog.command(:gdrive) do |c|
|
7
|
+
c.syntax "gdrive"
|
8
|
+
c.description "Create a new Google Drive Access Token"
|
9
|
+
|
10
|
+
c.action do |args, options|
|
11
|
+
generate_access_token
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def generate_access_token
|
17
|
+
require "highline/import"
|
18
|
+
|
19
|
+
puts "To use data from Google drive:"
|
20
|
+
puts "Create a new project with Google's Developer Platform:"
|
21
|
+
puts "https://console.developers.google.com/project"
|
22
|
+
puts
|
23
|
+
puts "Go to the project, select APIs & Auth > Credentials from left menu"
|
24
|
+
puts "Create new OAuth Client ID"
|
25
|
+
puts "Pick 'Installed Application' and fill out information"
|
26
|
+
|
27
|
+
client = Google::APIClient.new(:application_name => "Jekyll GDrive", :application_version => Jekyll::Gdrive::VERSION)
|
28
|
+
auth = client.authorization
|
29
|
+
auth.client_id = ask "Enter your Google Drive API Client ID: "
|
30
|
+
auth.client_secret = ask "Enter your Google Drive API Client Secret: "
|
31
|
+
auth.scope =
|
32
|
+
"https://www.googleapis.com/auth/drive " +
|
33
|
+
"https://docs.google.com/feeds/ " +
|
34
|
+
"https://docs.googleusercontent.com/ " +
|
35
|
+
"https://spreadsheets.google.com/feeds/"
|
36
|
+
|
37
|
+
auth.redirect_uri = "urn:ietf:wg:oauth:2.0:oob"
|
38
|
+
|
39
|
+
unless system("open '#{auth.authorization_uri}'")
|
40
|
+
puts "Open this page in your browser:"
|
41
|
+
puts auth.authorization_uri
|
42
|
+
puts
|
43
|
+
end
|
44
|
+
auth.code = ask "Enter he authorization code shown in the page: "
|
45
|
+
auth.fetch_access_token!
|
46
|
+
access_token = auth.access_token
|
47
|
+
|
48
|
+
puts
|
49
|
+
puts "You now have a Google Drive Access token:"
|
50
|
+
puts
|
51
|
+
puts access_token
|
52
|
+
puts
|
53
|
+
puts "Remember, this token gives access to all the files in your drive"
|
54
|
+
puts "So keep it safe"
|
55
|
+
puts "To use with the Jekyll GDrive plugin:"
|
56
|
+
puts "Set a GDRIVE_TOKEN environment variable"
|
57
|
+
puts
|
58
|
+
puts "export GDRIVE_TOKEN=#{access_token}"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Jekyll
|
2
|
+
module Gdrive
|
3
|
+
class Generator < Jekyll::Generator
|
4
|
+
def generate(site)
|
5
|
+
sheet_name = site.config['gdrive'] && site.config['gdrive']['sheet']
|
6
|
+
access_token = ENV['GDRIVE_TOKEN']
|
7
|
+
|
8
|
+
raise "No sheet specified for the GDrive Data Plugin\nSet 'gdrive.sheet' in your '_config.yml'" unless sheet_name
|
9
|
+
raise "No access token specified for the GDrive Data Plugin\nSet it in a GRDIVE_TOKEN environment variable\nEg.: export GDRIVE_TOKEN=my-long-token\nRun 'jekyll gdrive' to get an access token" unless access_token
|
10
|
+
|
11
|
+
session = GoogleDrive.login_with_oauth(access_token)
|
12
|
+
|
13
|
+
sheet = session.file_by_title(sheet_name).worksheets.first
|
14
|
+
|
15
|
+
data = []
|
16
|
+
|
17
|
+
(0..sheet.num_rows).each do |row|
|
18
|
+
data[row] = []
|
19
|
+
(0..sheet.num_cols).each do |col|
|
20
|
+
data[row][col] = sheet[row+1, col+1]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# remove empty rows
|
25
|
+
while data.last.all? {|c| c == "" || c.nil? }
|
26
|
+
data.pop
|
27
|
+
end
|
28
|
+
|
29
|
+
puts "Site data for google sheet: #{data}"
|
30
|
+
site.data['google_sheet'] = data
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll-gdrive
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mathias Biilmann Christensen
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-12-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: google_drive
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: highline
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Access Data from a Google Sheet through the GDrive API in your Jekyll
|
70
|
+
sites
|
71
|
+
email:
|
72
|
+
- mathias@netlify.com
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- jekyll-gdrive.gemspec
|
83
|
+
- lib/jekyll/commands/gdrive.rb
|
84
|
+
- lib/jekyll/gdrive.rb
|
85
|
+
- lib/jekyll/gdrive/generator.rb
|
86
|
+
- lib/jekyll/gdrive/version.rb
|
87
|
+
homepage: https://github.com/netlify/jekyll-gdrive
|
88
|
+
licenses:
|
89
|
+
- MIT
|
90
|
+
metadata: {}
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 2.2.2
|
108
|
+
signing_key:
|
109
|
+
specification_version: 4
|
110
|
+
summary: Google Sheets access from your Jekyll sites
|
111
|
+
test_files: []
|