class JekyllOptionalFrontMatter::Generator
Constants
- CLEANUP_KEY
- CONFIG_KEY
- ENABLED_KEY
Attributes
site[RW]
Public Class Methods
new(site)
click to toggle source
# File lib/jekyll-optional-front-matter/generator.rb, line 14 def initialize(site) @site = site end
Public Instance Methods
generate(site)
click to toggle source
# File lib/jekyll-optional-front-matter/generator.rb, line 18 def generate(site) @site = site return if disabled? site.pages.concat(pages_to_add) site.static_files -= static_files_to_remove if cleanup? end
Private Instance Methods
blacklisted?(page)
click to toggle source
Does the given Jekyll::Page match our filename blacklist?
# File lib/jekyll-optional-front-matter/generator.rb, line 57 def blacklisted?(page) return false if whitelisted?(page) FILENAME_BLACKLIST.include?(page.basename.upcase) end
cleanup?()
click to toggle source
# File lib/jekyll-optional-front-matter/generator.rb, line 85 def cleanup? option(CLEANUP_KEY) == true || site.config["require_front_matter"] end
disabled?()
click to toggle source
# File lib/jekyll-optional-front-matter/generator.rb, line 81 def disabled? option(ENABLED_KEY) == false || site.config["require_front_matter"] end
entry_filter()
click to toggle source
# File lib/jekyll-optional-front-matter/generator.rb, line 73 def entry_filter @entry_filter ||= Jekyll::EntryFilter.new(site) end
markdown_converter()
click to toggle source
# File lib/jekyll-optional-front-matter/generator.rb, line 69 def markdown_converter @markdown_converter ||= site.find_converter_instance(Jekyll::Converters::Markdown) end
markdown_files()
click to toggle source
An array of Jekyll::StaticFile's with a site-defined markdown extension
# File lib/jekyll-optional-front-matter/generator.rb, line 44 def markdown_files site.static_files.select { |file| markdown_converter.matches(file.extname) } end
option(key)
click to toggle source
# File lib/jekyll-optional-front-matter/generator.rb, line 77 def option(key) site.config[CONFIG_KEY] && site.config[CONFIG_KEY][key] end
page_from_static_file(static_file)
click to toggle source
Given a Jekyll::StaticFile, returns the file as a Jekyll::Page
# File lib/jekyll-optional-front-matter/generator.rb, line 49 def page_from_static_file(static_file) base = static_file.instance_variable_get("@base") dir = static_file.instance_variable_get("@dir") name = static_file.instance_variable_get("@name") Jekyll::Page.new(site, base, dir, name) end
pages()
click to toggle source
An array of potential Jekyll::Pages to add, including blacklisted files
# File lib/jekyll-optional-front-matter/generator.rb, line 39 def pages markdown_files.map { |static_file| page_from_static_file(static_file) } end
pages_to_add()
click to toggle source
An array of Jekyll::Pages to add, excluding blacklisted files
# File lib/jekyll-optional-front-matter/generator.rb, line 29 def pages_to_add pages.reject { |page| blacklisted?(page) } end
static_files_to_remove()
click to toggle source
An array of Jekyll::StaticFile's, excluding blacklisted files
# File lib/jekyll-optional-front-matter/generator.rb, line 34 def static_files_to_remove markdown_files.reject { |page| blacklisted?(page) } end
whitelisted?(page)
click to toggle source
# File lib/jekyll-optional-front-matter/generator.rb, line 63 def whitelisted?(page) return false unless site.config["include"].is_a? Array entry_filter.included?(page.relative_path) end