middleman-spreadsheet 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1259e8e1a1357c6e0a95455117be302b671576a5
4
+ data.tar.gz: 711cc54f680d3a22b7861a6afbccc457ccfa9e3e
5
+ SHA512:
6
+ metadata.gz: 9fcd9eb87f0d5cd21a8a53cb81dc5c1ae70c9810f96cd257421fa98dbd4f445411c84d4952de7e9ec9f5fd793705e835695e76f7f746d24c2e07bee5b6ac72ef
7
+ data.tar.gz: fa3add330bc3a2d9a24b9fa8db8cd8fe100d4647b06eb379c1295870097338c2fc3dc12607c16e88f32908151dad790fa705af9746e870c8a962019013287d37
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ # Ignore bundler lock file
2
+ /Gemfile.lock
3
+
4
+ # Ignore pkg folder
5
+ /pkg
data/Gemfile ADDED
@@ -0,0 +1,18 @@
1
+ # If you do not have OpenSSL installed, update
2
+ # the following line to use "http://" instead
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in middleman-spreadsheet.gemspec
6
+ gemspec
7
+
8
+ group :development do
9
+ gem 'rake'
10
+ gem 'rdoc'
11
+ gem 'yard'
12
+ end
13
+
14
+ group :test do
15
+ gem 'cucumber'
16
+ gem 'aruba'
17
+ gem 'rspec'
18
+ end
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'cucumber/rake/task'
5
+
6
+ Cucumber::Rake::Task.new(:cucumber, 'Run features that should pass') do |t|
7
+ t.cucumber_opts = '--color --tags ~@wip --strict'
8
+ end
9
+
10
+ require 'rake/clean'
11
+
12
+ task test: ['cucumber']
13
+
14
+ task default: :test
@@ -0,0 +1,78 @@
1
+ require 'middleman-core'
2
+
3
+ module Middleman
4
+ module Spreadsheet
5
+ class SpreadsheetNotFound < Exception; end
6
+ class CredentialsNotFound < Exception; end
7
+
8
+ class Extension < ::Middleman::Extension
9
+ option :credentials, nil, 'Google API credentials'
10
+ option :data_name, "spreadsheet", 'Spreadsheet key'
11
+ option :spreadsheet_key, nil, 'Spreadsheet key'
12
+ option :spreadsheet_url, nil, 'Spreadsheet url'
13
+ option :spreadsheet_title, nil, 'Spreadsheet title'
14
+
15
+ def initialize(app, options_hash={}, &block)
16
+ super
17
+
18
+ require "google_drive"
19
+ require "sheet_wrap"
20
+
21
+ session = drive_session(options)
22
+
23
+ if options.spreadsheet_key
24
+ spreadsheet = session.spreadsheet_by_key(options.spreadsheet_key)
25
+ elsif options.spreadsheet_url
26
+ spreadsheet = session.spreadsheet_by_url(options.spreadsheet_url)
27
+ elsif options.spreadsheet_title
28
+ spreadsheet = session.spreadsheet_by_title(options.spreadsheet_title)
29
+ end
30
+
31
+ raise SpreadsheetNotFound, "No spreadsheet specified" unless spreadsheet
32
+
33
+ data = spreadsheet.worksheets.each_with_object({}) do |worksheet, hash|
34
+ sheet_wrap = SheetWrap.wrap(worksheet)
35
+ hash[sheet_wrap.title.to_sym] = sheet_wrap.rows.map(&:to_h)
36
+ end
37
+ @app.data.store(options.data_name.to_sym, data)
38
+ end
39
+
40
+ private
41
+
42
+ def drive_session(options)
43
+ if options.credentials
44
+ credentials = Google::Auth::UserRefreshCredentials.new(
45
+ client_id: options.credentials[:client_id],
46
+ client_secret: options.credentials[:client_secret],
47
+ scope: GoogleDrive::Session::DEFAULT_SCOPE,
48
+ redirect_uri: 'urn:ietf:wg:oauth:2.0:oob',
49
+ )
50
+ if options.credentials[:refresh_token] || self.class.refresh_token
51
+ credentials.refresh_token = options.credentials[:refresh_token] || self.class.refresh_token
52
+ credentials.fetch_access_token!
53
+ else
54
+ STDERR.puts "1. Open this page:\n#{credentials.authorization_uri}"
55
+ STDERR.print "2. Enter the authorization code shown in the page: "
56
+ credentials.code = STDIN.gets.chomp
57
+ credentials.fetch_access_token!
58
+ STDERR.puts "3. Save refresh_token: #{credentials.refresh_token}"
59
+ self.class.refresh_token = credentials.refresh_token
60
+ end
61
+ GoogleDrive::Session.from_credentials(credentials)
62
+ elsif options.config
63
+ GoogleDrive::Session.from_config(options.config)
64
+ else
65
+ raise CredentialsNotFound, "No credentials specified"
66
+ end
67
+ end
68
+
69
+ def self.refresh_token=(token)
70
+ @refresh_token = token
71
+ end
72
+
73
+ def self.refresh_token
74
+ @refresh_token
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,5 @@
1
+ module Middleman
2
+ module Spreadsheet
3
+ VERSION = "0.1.1"
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ require "middleman-core"
2
+
3
+ Middleman::Extensions.register :spreadsheet do
4
+ require "middleman/spreadsheet/extension"
5
+ Middleman::Spreadsheet::Extension
6
+ end
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'middleman/spreadsheet/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "middleman-spreadsheet"
8
+ spec.version = Middleman::Spreadsheet::VERSION
9
+ spec.authors = ["hogelog"]
10
+ spec.email = ["konbu.komuro@gmail.com"]
11
+
12
+ spec.summary = %q{Middleman extension for using Google spreadsheet as data files.}
13
+ spec.homepage = "https://github.com/hogelog/sheet_wrap"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency "sheet_wrap", ">= 0.1.1"
24
+ spec.add_runtime_dependency "middleman-core", ">= 4.2.0"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.14"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ end
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: middleman-spreadsheet
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - hogelog
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-01-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sheet_wrap
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: middleman-core
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 4.2.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 4.2.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.14'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.14'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ description:
70
+ email:
71
+ - konbu.komuro@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - Rakefile
79
+ - lib/middleman-spreadsheet.rb
80
+ - lib/middleman/spreadsheet/extension.rb
81
+ - lib/middleman/spreadsheet/version.rb
82
+ - middleman-spreadsheet.gemspec
83
+ homepage: https://github.com/hogelog/sheet_wrap
84
+ licenses:
85
+ - MIT
86
+ metadata: {}
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubyforge_project:
103
+ rubygems_version: 2.6.10
104
+ signing_key:
105
+ specification_version: 4
106
+ summary: Middleman extension for using Google spreadsheet as data files.
107
+ test_files: []