class JekyllJsonFeed::Generator

Constants

MINIFY_REGEX

Matches all whitespace that follows

1. A '>', which closes an XML tag or
2. A '}', which closes a Liquid tag

We will strip all of this whitespace to minify the template

Public Instance Methods

generate(site) click to toggle source

Main plugin action, called by Jekyll-core

# File lib/jekyll-json-feed/generator.rb, line 7
def generate(site)
  @site = site
  return if file_exists?(feed_path)
  @site.pages << content_for_file(feed_path, feed_source_path)
end

Private Instance Methods

content_for_file(file_path, file_source_path) click to toggle source

Generates contents for a file

# File lib/jekyll-json-feed/generator.rb, line 45
def content_for_file(file_path, file_source_path)
  file = PageWithoutAFile.new(@site, File.dirname(__FILE__), "", file_path)
  file.content = File.read(file_source_path).gsub(MINIFY_REGEX, "")
  file.data["layout"] = nil
  file.data["sitemap"] = false
  file.output
  file
end
feed_path() click to toggle source

Path to feed from config, or feed.json for default

# File lib/jekyll-json-feed/generator.rb, line 22
def feed_path
  if @site.config["json_feed"] && @site.config["json_feed"]["path"]
    @site.config["json_feed"]["path"]
  else
    "feed.json"
  end
end
feed_source_path() click to toggle source

Path to feed.json template file

# File lib/jekyll-json-feed/generator.rb, line 31
def feed_source_path
  File.expand_path "./feed.json", File.dirname(__FILE__)
end
file_exists?(file_path) click to toggle source

Checks if a file already exists in the site source

# File lib/jekyll-json-feed/generator.rb, line 36
def file_exists?(file_path)
  if @site.respond_to?(:in_source_dir)
    File.exist? @site.in_source_dir(file_path)
  else
    File.exist? Jekyll.sanitized_path(@site.source, file_path)
  end
end