diff --git a/lib/locomotive/steam.rb b/lib/locomotive/steam.rb index 1883ac8b..62b6ec7a 100644 --- a/lib/locomotive/steam.rb +++ b/lib/locomotive/steam.rb @@ -1,3 +1,9 @@ +begin + require 'hjson' +rescue LoadError + +end + require 'locomotive/common' require_relative 'steam/configuration' diff --git a/lib/locomotive/steam/adapters/filesystem/sanitizers/page.rb b/lib/locomotive/steam/adapters/filesystem/sanitizers/page.rb index b44424c7..5c6200de 100644 --- a/lib/locomotive/steam/adapters/filesystem/sanitizers/page.rb +++ b/lib/locomotive/steam/adapters/filesystem/sanitizers/page.rb @@ -160,11 +160,20 @@ def transform_sections_content(page, locale) if content = page[name][locale] return unless content.is_a?(String) - begin - page[name][locale] = MultiJson.load(content) - rescue MultiJson::ParseError => e - raise Locomotive::Steam::JsonParsingError.new(e, page.template_path[locale], content) + if defined?(Hjson) + begin + page[name][locale] = Hjson.parse(content) + rescue Hjson::Error => e + raise Locomotive::Steam::JsonParsingError.new(e, page.template_path[locale], content) + end + else + begin + page[name][locale] = MultiJson.load(content) + rescue MultiJson::ParseError => e + raise Locomotive::Steam::JsonParsingError.new(e, page.template_path[locale], content) + end end + end end end diff --git a/lib/locomotive/steam/adapters/filesystem/sanitizers/section.rb b/lib/locomotive/steam/adapters/filesystem/sanitizers/section.rb index 8b5281b8..2eaa7107 100644 --- a/lib/locomotive/steam/adapters/filesystem/sanitizers/section.rb +++ b/lib/locomotive/steam/adapters/filesystem/sanitizers/section.rb @@ -21,10 +21,18 @@ def parse_json(entity) json, template = match[:json], match[:template] - begin - entity.definition = handle_aliases(MultiJson.load(json)) - rescue MultiJson::ParseError => e - raise Locomotive::Steam::JsonParsingError.new(e, entity.template_path, json) + if defined?(Hjson) + begin + entity.definition = handle_aliases(Hjson.parse(json)) + rescue Hjson::Error => e + raise Locomotive::Steam::JsonParsingError.new(e, entity.template_path, json) + end + else + begin + entity.definition = handle_aliases(MultiJson.load(json)) + rescue MultiJson::ParseError => e + raise Locomotive::Steam::JsonParsingError.new(e, entity.template_path, json) + end end entity.template = template diff --git a/lib/locomotive/steam/adapters/filesystem/yaml_loader.rb b/lib/locomotive/steam/adapters/filesystem/yaml_loader.rb index ad017d76..6d963f07 100644 --- a/lib/locomotive/steam/adapters/filesystem/yaml_loader.rb +++ b/lib/locomotive/steam/adapters/filesystem/yaml_loader.rb @@ -51,10 +51,18 @@ def safe_json_load(path) json = File.read(path) - begin - MultiJson.load(json) - rescue MultiJson::ParseError => e - raise Locomotive::Steam::JsonParsingError.new(e, path, json) + if defined?(Hjson) + begin + Hjson.parse(json) + rescue Hjson::Error => e + raise Locomotive::Steam::JsonParsingError.new(e, path, json) + end + else + begin + MultiJson.load(json) + rescue MultiJson::ParseError => e + raise Locomotive::Steam::JsonParsingError.new(e, path, json) + end end end