Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support HJSON #140

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/locomotive/steam.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
begin
require 'hjson'
rescue LoadError

end

require 'locomotive/common'

require_relative 'steam/configuration'
Expand Down
17 changes: 13 additions & 4 deletions lib/locomotive/steam/adapters/filesystem/sanitizers/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 12 additions & 4 deletions lib/locomotive/steam/adapters/filesystem/sanitizers/section.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 12 additions & 4 deletions lib/locomotive/steam/adapters/filesystem/yaml_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down