From df3f1e0e88f68c77389cb8a867c6944f5e4cfbd1 Mon Sep 17 00:00:00 2001 From: Jake Worth Date: Tue, 31 May 2016 22:48:11 -0500 Subject: [PATCH 1/5] Move code into lib/ --- jekyll_get.rb | 40 --------------------------------- {_plugins => lib}/jekyll_get.rb | 0 2 files changed, 40 deletions(-) delete mode 100644 jekyll_get.rb rename {_plugins => lib}/jekyll_get.rb (100%) 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 100% rename from _plugins/jekyll_get.rb rename to lib/jekyll_get.rb From 3298ff395ffaa85dc8ce989092977e65dc443e07 Mon Sep 17 00:00:00 2001 From: Jake Worth Date: Tue, 31 May 2016 22:59:07 -0500 Subject: [PATCH 2/5] Add Gemspec and rename module Naming conventions per: http://guides.rubygems.org/name-your-gem/ --- jekyll_get.gemspec | 12 ++++++++++++ lib/jekyll_get.rb | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 jekyll_get.gemspec diff --git a/jekyll_get.gemspec b/jekyll_get.gemspec new file mode 100644 index 0000000..8adda8f --- /dev/null +++ b/jekyll_get.gemspec @@ -0,0 +1,12 @@ +Gem::Specification.new do |s| + s.name = 'jekyll_get' + s.version = '0.1.0' + s.date = '2016-06-01' + s.summary = 'Ruby gem to download data from external JSON sources to use in generating a site' + s.description = 'Downloads data from an external JSON sources' + s.authors = ['Example Dev'] + s.email = 'dev@example.com' + s.files = ['lib/jekyll_get.rb'] + s.homepage = 'http://rubygems.org/gems/jekyll_get' + s.license = 'CC0-1.0' +end diff --git a/lib/jekyll_get.rb b/lib/jekyll_get.rb index f5fb7e3..7407371 100644 --- a/lib/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 From 2e23e87683e77bd853438e04cfeec53c6b1b33bb Mon Sep 17 00:00:00 2001 From: Jake Worth Date: Tue, 31 May 2016 23:21:22 -0500 Subject: [PATCH 3/5] State runtime dependencies --- jekyll_get.gemspec | 3 +++ lib/jekyll_get.rb | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/jekyll_get.gemspec b/jekyll_get.gemspec index 8adda8f..f673472 100644 --- a/jekyll_get.gemspec +++ b/jekyll_get.gemspec @@ -9,4 +9,7 @@ Gem::Specification.new do |s| 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/lib/jekyll_get.rb b/lib/jekyll_get.rb index 7407371..88c98e8 100644 --- a/lib/jekyll_get.rb +++ b/lib/jekyll_get.rb @@ -1,5 +1,6 @@ -require 'json' require 'hash-joiner' +require 'jekyll' +require 'json' require 'open-uri' module JekyllGet From 610c7d335a6dcfd75ee05c5d6250651c468a2ef0 Mon Sep 17 00:00:00 2001 From: Jake Worth Date: Tue, 31 May 2016 23:23:18 -0500 Subject: [PATCH 4/5] Ignore built gems --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .gitignore 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 From 71cf2fe049394287748ebc70d3441d93ad263d0c Mon Sep 17 00:00:00 2001 From: Jake Worth Date: Wed, 1 Jun 2016 08:45:23 -0500 Subject: [PATCH 5/5] Add installation instructions to README --- readme.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index cfb734d..aa329c7 100644 --- a/readme.md +++ b/readme.md @@ -1,10 +1,14 @@ # Install -Add this file to `_plugins` in the root of your Jekyll site. +Add this to your Gemfile: + +```ruby +gem 'jekyll_get' +``` # Configure -This plugin reads settings from the `_config.yml` file. Add settings as attributes or an array of attributes for multiple files. +This gem reads settings from the `_config.yml` file. Add settings as attributes or an array of attributes for multiple files. ## Example