lib/cloudcannon-jekyll/reader.rb in cloudcannon-jekyll-0.3.1 vs lib/cloudcannon-jekyll/reader.rb in cloudcannon-jekyll-0.3.2
- old
+ new
@@ -1,12 +1,12 @@
# frozen_string_literal: true
require "jekyll"
-if !Jekyll::VERSION.start_with? "2."
+begin
require_relative "readers/data-reader"
-else
+rescue NameError
require_relative "readers/old-data-reader"
end
module CloudCannonJekyll
# Wraps read functions into one class
@@ -16,29 +16,23 @@
def initialize(site)
@site = site
end
def read_data(dir = "_data")
- if Jekyll::VERSION.start_with? "2."
- CloudCannonJekyll::OldDataReader.new(@site).read(dir)
- else
- CloudCannonJekyll::DataReader.new(@site).read(dir)
- end
+ CloudCannonJekyll::DataReader.new(@site).read(dir)
+ rescue NameError # DataReader doesn't exist in old versions of Jekyll
+ CloudCannonJekyll::OldDataReader.new(@site).read(dir)
end
def read_drafts(dir = "")
- if Jekyll::VERSION.start_with? "2."
- @site.read_content(dir, "_drafts", Jekyll::Draft)
- else
- Jekyll::PostReader.new(@site).read_drafts(dir)
- end
+ Jekyll::PostReader.new(@site).read_drafts(dir)
+ rescue NameError # PostReader doesn't exist in old versions of Jekyll
+ @site.read_content(dir, "_drafts", Jekyll::Draft)
end
def read_posts(dir = "")
- if Jekyll::VERSION.start_with? "2."
- @site.read_content(dir, "_posts", Jekyll::Post)
- else
- Jekyll::PostReader.new(@site).read_posts(dir)
- end
+ Jekyll::PostReader.new(@site).read_posts(dir)
+ rescue NameError # PostReader doesn't exist in old versions of Jekyll
+ @site.read_content(dir, "_posts", Jekyll::Post)
end
end
end