jekyll-airtable 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 +12 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +98 -0
- data/LICENSE.txt +21 -0
- data/README.md +44 -0
- data/Rakefile +6 -0
- data/bin/console +42 -0
- data/bin/release +6 -0
- data/bin/setup +8 -0
- data/jekyll-airtable.gemspec +34 -0
- data/lib/jekyll-airtable.rb +27 -0
- data/lib/jekyll-airtable/api.rb +56 -0
- data/lib/jekyll-airtable/client.rb +46 -0
- data/lib/jekyll-airtable/configuration.rb +44 -0
- data/lib/jekyll-airtable/version.rb +5 -0
- data/lib/jekyll/airtable_fetcher.rb +82 -0
- metadata +175 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c8e6718da49e317d34b4dedabca793ec6faa3501
|
4
|
+
data.tar.gz: 752bf11b45a65f6ad9032d650e631020542b97a8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d1343e3d04e8441133112c4c9a212dc278a43affbab021ee5ed228341c6a7f28c6f80e556a8d09675f6b0f07e0d4225c717c67d8c435d251c182ded616972a67
|
7
|
+
data.tar.gz: ab5490a811c43250f19074688972264ba48f8698a8805d8c0a2c76e2623533f94080bc6728d15575d5e7e4b9dd8b139018988ef937467cb296eb8691d83b26cb
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at galih0muhammad@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
jekyll-airtable (0.1.0)
|
5
|
+
faraday (~> 0.11.0)
|
6
|
+
faraday_middleware (~> 0.10.1)
|
7
|
+
jekyll (~> 3.3)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
addressable (2.5.2)
|
13
|
+
public_suffix (>= 2.0.2, < 4.0)
|
14
|
+
byebug (10.0.2)
|
15
|
+
colorator (1.1.0)
|
16
|
+
concurrent-ruby (1.0.5)
|
17
|
+
diff-lcs (1.3)
|
18
|
+
dotenv (2.5.0)
|
19
|
+
em-websocket (0.5.1)
|
20
|
+
eventmachine (>= 0.12.9)
|
21
|
+
http_parser.rb (~> 0.6.0)
|
22
|
+
eventmachine (1.2.7)
|
23
|
+
faraday (0.11.0)
|
24
|
+
multipart-post (>= 1.2, < 3)
|
25
|
+
faraday_middleware (0.10.1)
|
26
|
+
faraday (>= 0.7.4, < 1.0)
|
27
|
+
ffi (1.9.25)
|
28
|
+
forwardable-extended (2.6.0)
|
29
|
+
http_parser.rb (0.6.0)
|
30
|
+
i18n (0.9.5)
|
31
|
+
concurrent-ruby (~> 1.0)
|
32
|
+
jekyll (3.8.3)
|
33
|
+
addressable (~> 2.4)
|
34
|
+
colorator (~> 1.0)
|
35
|
+
em-websocket (~> 0.5)
|
36
|
+
i18n (~> 0.7)
|
37
|
+
jekyll-sass-converter (~> 1.0)
|
38
|
+
jekyll-watch (~> 2.0)
|
39
|
+
kramdown (~> 1.14)
|
40
|
+
liquid (~> 4.0)
|
41
|
+
mercenary (~> 0.3.3)
|
42
|
+
pathutil (~> 0.9)
|
43
|
+
rouge (>= 1.7, < 4)
|
44
|
+
safe_yaml (~> 1.0)
|
45
|
+
jekyll-sass-converter (1.5.2)
|
46
|
+
sass (~> 3.4)
|
47
|
+
jekyll-watch (2.0.0)
|
48
|
+
listen (~> 3.0)
|
49
|
+
kramdown (1.17.0)
|
50
|
+
liquid (4.0.0)
|
51
|
+
listen (3.1.5)
|
52
|
+
rb-fsevent (~> 0.9, >= 0.9.4)
|
53
|
+
rb-inotify (~> 0.9, >= 0.9.7)
|
54
|
+
ruby_dep (~> 1.2)
|
55
|
+
mercenary (0.3.6)
|
56
|
+
multipart-post (2.0.0)
|
57
|
+
pathutil (0.16.1)
|
58
|
+
forwardable-extended (~> 2.6)
|
59
|
+
public_suffix (3.0.3)
|
60
|
+
rake (10.5.0)
|
61
|
+
rb-fsevent (0.10.3)
|
62
|
+
rb-inotify (0.9.10)
|
63
|
+
ffi (>= 0.5.0, < 2)
|
64
|
+
rouge (3.2.1)
|
65
|
+
rspec (3.8.0)
|
66
|
+
rspec-core (~> 3.8.0)
|
67
|
+
rspec-expectations (~> 3.8.0)
|
68
|
+
rspec-mocks (~> 3.8.0)
|
69
|
+
rspec-core (3.8.0)
|
70
|
+
rspec-support (~> 3.8.0)
|
71
|
+
rspec-expectations (3.8.1)
|
72
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
73
|
+
rspec-support (~> 3.8.0)
|
74
|
+
rspec-mocks (3.8.0)
|
75
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
76
|
+
rspec-support (~> 3.8.0)
|
77
|
+
rspec-support (3.8.0)
|
78
|
+
ruby_dep (1.5.0)
|
79
|
+
safe_yaml (1.0.4)
|
80
|
+
sass (3.5.7)
|
81
|
+
sass-listen (~> 4.0.0)
|
82
|
+
sass-listen (4.0.0)
|
83
|
+
rb-fsevent (~> 0.9, >= 0.9.4)
|
84
|
+
rb-inotify (~> 0.9, >= 0.9.7)
|
85
|
+
|
86
|
+
PLATFORMS
|
87
|
+
ruby
|
88
|
+
|
89
|
+
DEPENDENCIES
|
90
|
+
bundler (~> 1.16)
|
91
|
+
byebug
|
92
|
+
dotenv
|
93
|
+
jekyll-airtable!
|
94
|
+
rake (~> 10.0)
|
95
|
+
rspec (~> 3.0)
|
96
|
+
|
97
|
+
BUNDLED WITH
|
98
|
+
1.16.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Galih Muhammad
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# Jekyll::Airtable
|
2
|
+
|
3
|
+
This gem enables you to easily integrate Airtable with Jekyll site and use it as a database. Everytime the Jekyll build is triggered, the gem would automatically send API request to the Airtable base and tables you specify from the environment variable and then store the records as collections, grouped according to the table names.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'jekyll-airtable'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install jekyll-airtable
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
1. Add this gem to the Gemfile
|
24
|
+
2. Run ```sh bundle install ``` on the terminal
|
25
|
+
3. Do not forget to declare it also on the config.yml, below the "gems" or "plugins" YAML key.
|
26
|
+
4. Then you can execute the plugin using ```sh bundle exec jekyll serve ``` or ```sh bundle exec jekyll build ```
|
27
|
+
|
28
|
+
## Development
|
29
|
+
|
30
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
31
|
+
|
32
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
33
|
+
|
34
|
+
## Contributing
|
35
|
+
|
36
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/jekyll-airtable. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
41
|
+
|
42
|
+
## Code of Conduct
|
43
|
+
|
44
|
+
Everyone interacting in the Jekyll::Airtable project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/jekyll-airtable/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
def relative_to_root(path)
|
3
|
+
File.expand_path(path, File.dirname(__dir__))
|
4
|
+
end
|
5
|
+
|
6
|
+
require "bundler/setup"
|
7
|
+
require "jekyll"
|
8
|
+
require_relative("../lib/jekyll-airtable.rb")
|
9
|
+
require 'byebug'
|
10
|
+
|
11
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
12
|
+
# with your gem easier. You can also use a different console, if you like.
|
13
|
+
|
14
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
15
|
+
# require "pry"
|
16
|
+
# Pry.start
|
17
|
+
|
18
|
+
SOURCE_DIR = relative_to_root("spec/fixtures")
|
19
|
+
DEST_DIR = relative_to_root("spec/dest")
|
20
|
+
|
21
|
+
def source_dir(*files)
|
22
|
+
File.join(SOURCE_DIR, *files)
|
23
|
+
end
|
24
|
+
|
25
|
+
def dest_dir(*files)
|
26
|
+
File.join(DEST_DIR, *files)
|
27
|
+
end
|
28
|
+
|
29
|
+
def config(overrides = {})
|
30
|
+
Jekyll.configuration(
|
31
|
+
"source" => source_dir,
|
32
|
+
"destination" => dest_dir,
|
33
|
+
"url" => "http://example.org"
|
34
|
+
).merge(overrides)
|
35
|
+
end
|
36
|
+
|
37
|
+
def site(configuration = config)
|
38
|
+
Jekyll::Site.new(configuration)
|
39
|
+
end
|
40
|
+
|
41
|
+
require "irb"
|
42
|
+
IRB.start(__FILE__)
|
data/bin/release
ADDED
data/bin/setup
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "jekyll-airtable/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "jekyll-airtable"
|
8
|
+
spec.version = Jekyll::Airtable::VERSION
|
9
|
+
spec.authors = ["Galih Muhammad"]
|
10
|
+
spec.email = ["galih0muhammad@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = "Jekyll plugin to integrate Airtable"
|
13
|
+
spec.description = "Airtable support in Jekyll site to easily fetch and store data"
|
14
|
+
spec.homepage = "https://github.com/galliani/jekyll-airtable"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.required_ruby_version = ">= 2.3.0"
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
27
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
29
|
+
spec.add_development_dependency "byebug"
|
30
|
+
spec.add_development_dependency "dotenv"
|
31
|
+
spec.add_dependency 'faraday', '~> 0.11.0'
|
32
|
+
spec.add_dependency 'faraday_middleware', '~> 0.10.1'
|
33
|
+
spec.add_dependency "jekyll", "~> 3.3"
|
34
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "jekyll-airtable/version"
|
2
|
+
require "jekyll-airtable/configuration"
|
3
|
+
require "jekyll-airtable/api"
|
4
|
+
require "jekyll-airtable/client"
|
5
|
+
|
6
|
+
module Jekyll
|
7
|
+
module Airtable
|
8
|
+
extend Configuration
|
9
|
+
|
10
|
+
def self.client(options = {})
|
11
|
+
Jekyll::Airtable::Client.new(options)
|
12
|
+
end
|
13
|
+
|
14
|
+
# Delegate to Airtable::Client
|
15
|
+
def self.method_missing(method, *args, &block)
|
16
|
+
return super unless client.respond_to?(method)
|
17
|
+
client.send(method, *args, &block)
|
18
|
+
end
|
19
|
+
|
20
|
+
# Delegate to Airtable::Client
|
21
|
+
def self.respond_to?(method, include_all=false)
|
22
|
+
return client.respond_to?(method, include_all) || super
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
require "jekyll/airtable_fetcher"
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require_relative "./configuration"
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
module Airtable
|
5
|
+
class API
|
6
|
+
attr_accessor *Configuration::VALID_OPTIONS_KEYS
|
7
|
+
|
8
|
+
# Creates a new API
|
9
|
+
def initialize(options={})
|
10
|
+
options = Airtable.options.merge(options)
|
11
|
+
|
12
|
+
Configuration::VALID_OPTIONS_KEYS.each do |key|
|
13
|
+
send("#{key}=", options[key])
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def config
|
18
|
+
conf = {}
|
19
|
+
|
20
|
+
Configuration::VALID_OPTIONS_KEYS.each do |key|
|
21
|
+
conf[key] = send key
|
22
|
+
end
|
23
|
+
|
24
|
+
conf
|
25
|
+
end
|
26
|
+
|
27
|
+
def versioned_base_endpoint_url
|
28
|
+
config[:endpoint] + config[:api_version] + '/' + config[:base_uid] + '/'
|
29
|
+
end
|
30
|
+
|
31
|
+
def processing_query_params(request_obj, params, params_key)
|
32
|
+
keys = [
|
33
|
+
:fields,
|
34
|
+
:filter_by_formula,
|
35
|
+
:max_records,
|
36
|
+
:page_size,
|
37
|
+
:sort,
|
38
|
+
:view,
|
39
|
+
:cell_format,
|
40
|
+
:time_zone,
|
41
|
+
:user_locale
|
42
|
+
]
|
43
|
+
|
44
|
+
return nil unless keys.include?(params_key) ||
|
45
|
+
params[params_key].nil? ||
|
46
|
+
params[params_key] == ''
|
47
|
+
|
48
|
+
key_string = params_key.to_s.split('_').each_with_index.map do |a, i|
|
49
|
+
if i == 0 then a else a.capitalize end
|
50
|
+
end.join
|
51
|
+
|
52
|
+
request_obj.params[key_string] = params[params_key]
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'uri'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module Jekyll
|
6
|
+
module Airtable
|
7
|
+
class Client < API
|
8
|
+
|
9
|
+
def list_records(table_name:, params: {})
|
10
|
+
@connection = Faraday.new(url: versioned_base_endpoint_url) do |faraday|
|
11
|
+
faraday.response :logger # log requests to STDOUT
|
12
|
+
faraday.request :url_encoded
|
13
|
+
faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
|
14
|
+
end
|
15
|
+
|
16
|
+
@connection.authorization(:Bearer, Airtable.api_key)
|
17
|
+
|
18
|
+
response = @connection.get do |req|
|
19
|
+
req.url URI.escape(table_name)
|
20
|
+
|
21
|
+
default_params = params.merge(max_records: 100) unless params[:max_records]
|
22
|
+
default_params.keys.each do |key|
|
23
|
+
processing_query_params(req, default_params, key)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
response.body
|
28
|
+
end
|
29
|
+
|
30
|
+
def retrieve_record(table_name:, record_uid:)
|
31
|
+
@connection = Faraday.new(url: versioned_base_endpoint_url) do |faraday|
|
32
|
+
faraday.response :logger # log requests to STDOUT
|
33
|
+
faraday.request :url_encoded
|
34
|
+
faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
|
35
|
+
end
|
36
|
+
|
37
|
+
@connection.authorization(:Bearer, Airtable.api_key)
|
38
|
+
|
39
|
+
response = @connection.get(URI.escape(table_name) + '/' + record_uid)
|
40
|
+
|
41
|
+
response.body
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Jekyll
|
2
|
+
module Airtable
|
3
|
+
module Configuration
|
4
|
+
API_URL = 'https://api.airtable.com/'
|
5
|
+
API_VERSION = 'v0'
|
6
|
+
|
7
|
+
# An array of valid keys in the options hash
|
8
|
+
VALID_OPTIONS_KEYS = [
|
9
|
+
:endpoint,
|
10
|
+
:api_version,
|
11
|
+
:api_key,
|
12
|
+
:base_uid
|
13
|
+
].freeze
|
14
|
+
|
15
|
+
attr_accessor *VALID_OPTIONS_KEYS
|
16
|
+
|
17
|
+
# When this module is extended, set all configuration options to their default values
|
18
|
+
def self.extended(base)
|
19
|
+
base.reset
|
20
|
+
end
|
21
|
+
|
22
|
+
# Create a hash of options and their values
|
23
|
+
def options
|
24
|
+
VALID_OPTIONS_KEYS.inject({}) do |option, key|
|
25
|
+
option.merge!(key => send(key))
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# Convenience method to allow configuration options to be set in a block
|
30
|
+
# To be called from the base class
|
31
|
+
def configure
|
32
|
+
yield self
|
33
|
+
end
|
34
|
+
|
35
|
+
# Reset all configuration options to defaults
|
36
|
+
def reset
|
37
|
+
self.endpoint = API_URL
|
38
|
+
self.api_version = API_VERSION
|
39
|
+
self.api_key = nil
|
40
|
+
self.base_uid = ''
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require "json"
|
2
|
+
require 'fileutils'
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
module Jekyll
|
6
|
+
class AirtableFetcher < Jekyll::Generator
|
7
|
+
safe true
|
8
|
+
priority :lowest
|
9
|
+
|
10
|
+
def generate(site)
|
11
|
+
return false if site.config['AIRTABLE_API_KEY'].nil? || site.config['AIRTABLE_API_KEY'] == ''
|
12
|
+
return false if site.config['SYNC_WITH_AIRTABLE'] == 'false'
|
13
|
+
|
14
|
+
Airtable.configure do |config|
|
15
|
+
config.api_key = site.config['AIRTABLE_API_KEY']
|
16
|
+
end
|
17
|
+
|
18
|
+
client = Airtable.client(base_uid: site.config['AIRTABLE_BASE_UID'])
|
19
|
+
|
20
|
+
site.config['AIRTABLE_TABLE_NAMES'].each do |table_name|
|
21
|
+
records = JSON.parse(client.list_records(table_name: table_name, params: {}))
|
22
|
+
next if records.size == 0
|
23
|
+
|
24
|
+
records_as_json = records['records']
|
25
|
+
converted_table_name = to_snake(table_name)
|
26
|
+
directory_name = "collections/_" + converted_table_name
|
27
|
+
|
28
|
+
Dir.mkdir(directory_name) unless File.exists?(directory_name)
|
29
|
+
|
30
|
+
records_as_json.each do |record_hash|
|
31
|
+
slug = record_hash['id']
|
32
|
+
out_file = File.new("#{directory_name}/#{slug}.md", "w")
|
33
|
+
out_file.puts(front_matter_mark)
|
34
|
+
|
35
|
+
# Store the uid
|
36
|
+
out_file.puts("uid: #{slug}")
|
37
|
+
|
38
|
+
fields = record_hash['fields']
|
39
|
+
|
40
|
+
fields.each do |key, value|
|
41
|
+
snake_key = to_snake(key)
|
42
|
+
|
43
|
+
if value.class.name == 'Array'
|
44
|
+
out_file.puts("#{snake_key}:")
|
45
|
+
write_array_values(out_file, value)
|
46
|
+
else
|
47
|
+
value = stringify_value_if_necessary(value)
|
48
|
+
out_file.puts("#{snake_key}: #{value}")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
out_file.puts(front_matter_mark)
|
53
|
+
|
54
|
+
out_file.close
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def front_matter_mark
|
62
|
+
'---'
|
63
|
+
end
|
64
|
+
|
65
|
+
def to_snake(string)
|
66
|
+
string.split(' ').map(&:downcase).join('_')
|
67
|
+
end
|
68
|
+
|
69
|
+
def write_array_values(file, array)
|
70
|
+
array.each do |element|
|
71
|
+
# - { name: 'Low', color: '#306d8c' }
|
72
|
+
value = stringify_value_if_necessary(element)
|
73
|
+
file.puts(" - #{value}")
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def stringify_value_if_necessary(value)
|
78
|
+
return "'#{value}'" if value.include?(':')
|
79
|
+
value
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
metadata
ADDED
@@ -0,0 +1,175 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll-airtable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Galih Muhammad
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-09-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.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
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: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: byebug
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: dotenv
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: faraday
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.11.0
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.11.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: faraday_middleware
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.10.1
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.10.1
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: jekyll
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '3.3'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '3.3'
|
125
|
+
description: Airtable support in Jekyll site to easily fetch and store data
|
126
|
+
email:
|
127
|
+
- galih0muhammad@gmail.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- ".gitignore"
|
133
|
+
- ".rspec"
|
134
|
+
- ".travis.yml"
|
135
|
+
- CODE_OF_CONDUCT.md
|
136
|
+
- Gemfile
|
137
|
+
- Gemfile.lock
|
138
|
+
- LICENSE.txt
|
139
|
+
- README.md
|
140
|
+
- Rakefile
|
141
|
+
- bin/console
|
142
|
+
- bin/release
|
143
|
+
- bin/setup
|
144
|
+
- jekyll-airtable.gemspec
|
145
|
+
- lib/jekyll-airtable.rb
|
146
|
+
- lib/jekyll-airtable/api.rb
|
147
|
+
- lib/jekyll-airtable/client.rb
|
148
|
+
- lib/jekyll-airtable/configuration.rb
|
149
|
+
- lib/jekyll-airtable/version.rb
|
150
|
+
- lib/jekyll/airtable_fetcher.rb
|
151
|
+
homepage: https://github.com/galliani/jekyll-airtable
|
152
|
+
licenses:
|
153
|
+
- MIT
|
154
|
+
metadata: {}
|
155
|
+
post_install_message:
|
156
|
+
rdoc_options: []
|
157
|
+
require_paths:
|
158
|
+
- lib
|
159
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
160
|
+
requirements:
|
161
|
+
- - ">="
|
162
|
+
- !ruby/object:Gem::Version
|
163
|
+
version: 2.3.0
|
164
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
165
|
+
requirements:
|
166
|
+
- - ">="
|
167
|
+
- !ruby/object:Gem::Version
|
168
|
+
version: '0'
|
169
|
+
requirements: []
|
170
|
+
rubyforge_project:
|
171
|
+
rubygems_version: 2.6.13
|
172
|
+
signing_key:
|
173
|
+
specification_version: 4
|
174
|
+
summary: Jekyll plugin to integrate Airtable
|
175
|
+
test_files: []
|