lib/cloudcannon-jekyll/reader.rb in cloudcannon-jekyll-1.5.3 vs lib/cloudcannon-jekyll/reader.rb in cloudcannon-jekyll-1.5.4
- old
+ new
@@ -1,38 +1,43 @@
# frozen_string_literal: true
require "jekyll"
+require_relative "readers/old-data-reader"
+require_relative "readers/data-reader"
-begin
- require_relative "readers/data-reader"
-rescue NameError
- require_relative "readers/old-data-reader"
-end
-
module CloudCannonJekyll
# Wraps read functions into one class
class Reader
attr_reader :site
def initialize(site)
@site = site
end
def read_data(dir = "_data")
- CloudCannonJekyll::DataReader.new(@site).read(dir)
- rescue NameError # DataReader doesn't exist in old versions of Jekyll
- CloudCannonJekyll::OldDataReader.new(@site).read(dir)
+ # DataReader doesn't exist in old versions of Jekyll
+ if Jekyll::VERSION.start_with? "2."
+ CloudCannonJekyll::OldDataReader.new(@site).read(dir)
+ else
+ CloudCannonJekyll::DataReader.new(@site).read(dir)
+ end
end
def read_drafts(dir = "")
- 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)
+ # PostReader doesn't exist in old versions of Jekyll
+ if Jekyll::VERSION.start_with? "2."
+ @site.read_content(dir, "_drafts", Jekyll::Draft)
+ else
+ Jekyll::PostReader.new(@site).read_drafts(dir)
+ end
end
def read_posts(dir = "")
- 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)
+ # PostReader doesn't exist in old versions of Jekyll
+ if Jekyll::VERSION.start_with? "2."
+ @site.read_content(dir, "_posts", Jekyll::Post)
+ else
+ Jekyll::PostReader.new(@site).read_posts(dir)
+ end
end
end
end