class Jekyll::TidyJSON::Processor
Public Class Methods
new(config)
click to toggle source
# File lib/jekyll/tidy_json.rb, line 9 def initialize(config) parse_plugin_config config.fetch("tidy_json", {}) end
Public Instance Methods
continue_on_error?()
click to toggle source
# File lib/jekyll/tidy_json.rb, line 40 def continue_on_error? !!@continue_on_error end
enabled?()
click to toggle source
# File lib/jekyll/tidy_json.rb, line 48 def enabled? !!@enabled end
pretty?()
click to toggle source
# File lib/jekyll/tidy_json.rb, line 44 def pretty? !!@pretty end
should_tidy?(path)
click to toggle source
# File lib/jekyll/tidy_json.rb, line 13 def should_tidy?(path) enabled? && File.extname(path).downcase == ".json" end
tidy_page_or_document(page_or_document)
click to toggle source
# File lib/jekyll/tidy_json.rb, line 17 def tidy_page_or_document(page_or_document) if should_tidy?(page_or_document.relative_path) tidy_page_or_document!(page_or_document) end end
tidy_page_or_document!(page_or_document)
click to toggle source
# File lib/jekyll/tidy_json.rb, line 23 def tidy_page_or_document!(page_or_document) path = page_or_document.relative_path Jekyll.logger.debug("Tidy up JSON:", path) page_or_document.output = tidy_string(page_or_document.output) rescue JSON::ParserError print_parse_error(!continue_on_error?, $!, path) raise unless continue_on_error? end
tidy_string(string)
click to toggle source
# File lib/jekyll/tidy_json.rb, line 33 def tidy_string(string) json = JSON.parse(string) meth = self.pretty? ? :pretty_generate : :fast_generate JSON.public_send meth, json end
Private Instance Methods
parse_plugin_config(pc)
click to toggle source
# File lib/jekyll/tidy_json.rb, line 54 def parse_plugin_config(pc) @continue_on_error = pc.fetch("continue_on_error", false) @enabled = pc.fetch("enabled", true) @pretty = pc.fetch("pretty", false) end
print_parse_error(is_fatal, exception, file_path)
click to toggle source
# File lib/jekyll/tidy_json.rb, line 60 def print_parse_error(is_fatal, exception, file_path) logger = Jekyll.logger.public_method(is_fatal ? :error : :warn) logger.("Malformed JSON at path:", file_path) end