Middleman extension for using Google spreadsheet as data files. Edit
Add this line to your application's Gemfile:
gem 'middleman-spreadsheet'
And then execute:
$ bundle
- Go to Google API Console and creates your own API credentials.
- Enable Drive API
- Create google credentials json like
{
"client_id": "xxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com",
"client_secret": "xxxxxxxxxxxxxxxxxxxxxxxx"
}
- Activate
:spreadsheet
like below.
activate :spreadsheet do |spreadsheet|
spreadsheet.config = "google_credentials.json"
spreadsheet.spreadsheet_url = "https://docs.google.com/spreadsheets/d/xxxxxxxxxxxxxxxxxxxxx/edit#gid=0"
end
If you want to manage credentials without json, you could to use spreadsheet.credentials
option.
See gimite/google-drive-ruby documentation for more detail authorization information.
Create spreadsheet.
You can specify spreadsheet by spreadsheet_url
spreadsheet.spreadsheet_url = "https://docs.google.com/spreadsheets/d/xxxxxxxxxxxxxxxxxxxxx/edit#gid=0"
or spreadsheet_key
spreadsheet.spreadsheet_key = "xxxxxxxxxxxxxxxxxxxxx"
or spreadsheet_title
.
spreadsheet.spreadsheet_title = "foo bar sheet"
You can use data.spreadsheet.<worksheet_title>
like below.
%ul
- data.spreadsheet.Sheet1.each do |item|
%li #{item.id} #{item.foo} #{item.foo}
You can use app.data.spreadsheet.<worksheet_title>
like below.
app.data.spreadsheet.Sheet1.each do |row|
proxy "/foo/#{row.id}.html", "/items/show.html", locals: { foo: row }
end
Bug reports and pull requests are welcome on GitHub at https://github.com/hogelog/middlmean-spreadsheet.
The gem is available as open source under the terms of the MIT License.