diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f0a191a --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/* Ignore built gems */ +*.gem diff --git a/jekyll-get.gemspec b/jekyll-get.gemspec new file mode 100644 index 0000000..adaf812 --- /dev/null +++ b/jekyll-get.gemspec @@ -0,0 +1,16 @@ +Gem::Specification.new do |s| + s.name = 'jekyll-get' + s.version = '1.0.0' + s.date = '2016-06-07' + s.summary = 'Ruby gem to download data from external JSON sources to use in Jekyll site' + s.description = 'Downloads data from external JSON source(s)' + s.authors = ['Allen Kramer & Michael Pell'] + s.email = 'kramer.alleng@gmail.com' + s.files = ['lib/jekyll-get.rb'] + s.homepage = + 'http://rubygems.org/gems/jekyll-get' + s.license = 'CC0-1.0' + + s.add_runtime_dependency 'hash-joiner', '~> 0.0.7' + s.add_runtime_dependency 'jekyll', '~> 3.1', '>= 3.1.6' +end diff --git a/jekyll_get.rb b/jekyll_get.rb deleted file mode 100644 index f5fb7e3..0000000 --- a/jekyll_get.rb +++ /dev/null @@ -1,40 +0,0 @@ -require 'json' -require 'hash-joiner' -require 'open-uri' - -module Jekyll_Get - class Generator < Jekyll::Generator - safe true - priority :highest - - def generate(site) - config = site.config['jekyll_get'] - if !config - return - end - if !config.kind_of?(Array) - config = [config] - end - config.each do |d| - begin - target = site.data[d['data']] - source = JSON.load(open(d['json'])) - if target - HashJoiner.deep_merge target, source - else - site.data[d['data']] = source - end - if d['cache'] - data_source = (site.config['data_source'] || '_data') - path = "#{data_source}/#{d['data']}.json" - open(path, 'wb') do |file| - file << JSON.generate(site.data[d['data']]) - end - end - rescue - next - end - end - end - end -end diff --git a/_plugins/jekyll_get.rb b/lib/jekyll-get.rb similarity index 98% rename from _plugins/jekyll_get.rb rename to lib/jekyll-get.rb index f5fb7e3..7407371 100644 --- a/_plugins/jekyll_get.rb +++ b/lib/jekyll-get.rb @@ -2,7 +2,7 @@ require 'hash-joiner' require 'open-uri' -module Jekyll_Get +module JekyllGet class Generator < Jekyll::Generator safe true priority :highest diff --git a/readme.md b/readme.md index cfb734d..f75845d 100644 --- a/readme.md +++ b/readme.md @@ -1,12 +1,34 @@ -# Install +#Jekyll::Get -Add this file to `_plugins` in the root of your Jekyll site. +Ruby gem to download data from external JSON sources to use in Jekyll site -# Configure +## Install + +In your `_config.yml` file, add a new array with the key ```gems:``` and the value of the gem name you'd like to use. + +```yml +gems: [jekyll-get] +``` + +Then install your gem using ```gem install jekyll-get``` + +or + +Add the this gem to a Bundler group in your Gemfile. + +```yml +group :jekyll_plugins do + gem 'jekyll-get' +end +``` + +Then install by running ```bundle install``` + +## Configure This plugin reads settings from the `_config.yml` file. Add settings as attributes or an array of attributes for multiple files. -## Example +### Example ```yml jekyll_get: