Skip to content

Commit

Permalink
use hjson only if included in Gemfile
Browse files Browse the repository at this point in the history
  • Loading branch information
westonganger committed Jun 28, 2019
1 parent a42abaa commit e55a90f
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 19 deletions.
8 changes: 3 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ PATH
compass (~> 1.0.3)
dragonfly (~> 1.2.0)
duktape (~> 2.0.1.1)
hjson (~> 0.1.2)
httparty (~> 0.16.0)
kramdown (~> 1.16.2)
locomotivecms-solid (~> 4.0.1)
Expand All @@ -30,6 +29,7 @@ PATH
mimetype-fu (~> 0.1.2)
moneta (~> 1.0.0)
morphine (~> 0.1.1)
multi_json (~> 1.13.1)
nokogiri (~> 1.8.2)
pony (~> 1.12)
rack-cache (~> 1.7.0)
Expand Down Expand Up @@ -93,13 +93,11 @@ GEM
rack (>= 1.3)
duktape (2.0.1.1)
execjs (2.7.0)
ffi (1.11.1)
ffi (1.10.0)
flamegraph (0.9.5)
haml (5.0.4)
temple (>= 0.8.0)
tilt
hjson (0.1.2)
json (>= 1.7.5)
httparty (0.16.4)
mime-types (~> 3.0)
multi_xml (>= 0.5.2)
Expand Down Expand Up @@ -140,7 +138,7 @@ GEM
origin (2.3.1)
pony (1.13.1)
mail (>= 2.0)
public_suffix (3.1.0)
public_suffix (3.0.3)
puma (3.12.0)
rack (2.0.6)
rack-cache (1.7.2)
Expand Down
6 changes: 5 additions & 1 deletion lib/locomotive/steam.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
require 'hjson'
begin
require 'hjson'
rescue LoadError

end

require 'locomotive/common'

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] = Hjson.parse(content)
rescue Exception => 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(Hjson.parse(json))
rescue Exception => 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
Hjson.parse(json)
rescue Exception => 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
2 changes: 1 addition & 1 deletion locomotivecms_steam.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
spec.add_dependency 'httparty', '~> 0.16.0'
spec.add_dependency 'chronic', '~> 0.10.2'
spec.add_dependency 'bcrypt', '~> 3.1.11'
spec.add_dependency 'hjson', '~> 0.1.2'
spec.add_dependency 'multi_json', '~> 1.13.1'

spec.add_dependency 'rack-rewrite', '~> 1.5.1'
spec.add_dependency 'rack-cache', '~> 1.7.0'
Expand Down

0 comments on commit e55a90f

Please sign in to comment.