Sha256: 51f440a58c51d92333fb1ebb55bf361d1c53cfd41fcd7fafca3c407e058b9e38
Contents?: true
Size: 1.1 KB
Versions: 3
Compression:
Stored size: 1.1 KB
Contents
module Locomotive::Steam module Adapters module Filesystem module Sanitizers class Section include Adapters::Filesystem::Sanitizer def apply_to_entity(entity) super parse_json(entity) end private def parse_json(entity) content = File.read(entity.template_path) match = content.match(JSON_FRONTMATTER_REGEXP) raise_parsing_error(entity, content) if match.nil? json, template = match[:json], match[:template] begin entity.definition = MultiJson.load(json) rescue MultiJson::ParseError => e raise Locomotive::Steam::JsonParsingError.new(e, entity.template_path, json) end entity.template = template end def raise_parsing_error(entity, content) message = 'Your section requires a valid JSON header' raise Locomotive::Steam::ParsingRenderingError.new(message, entity.template_path, content, 0, nil) end end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems