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..f673472 --- /dev/null +++ b/jekyll_get.gemspec @@ -0,0 +1,15 @@ +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' + + 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 96% rename from _plugins/jekyll_get.rb rename to lib/jekyll_get.rb index f5fb7e3..88c98e8 100644 --- a/_plugins/jekyll_get.rb +++ b/lib/jekyll_get.rb @@ -1,8 +1,9 @@ -require 'json' require 'hash-joiner' +require 'jekyll' +require 'json' 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..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