Skip to content

Commit e3f1fe8

Browse files
committed
Replaced yajl with json, added logic for parsing rabl data
1 parent 5533aac commit e3f1fe8

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

gon.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ Gem::Specification.new do |s|
2020
s.require_paths = ["lib"]
2121
s.add_dependency "actionpack", '>= 2.3.0'
2222
s.add_dependency "rabl"
23-
s.add_dependency "yajl-ruby"
23+
s.add_dependency "json"
2424
s.add_development_dependency "rspec"
2525
end

lib/gon.rb

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,16 @@ def set_variable(name, value)
4444
end
4545

4646
def rabl(view_path, options = {})
47-
# if rabl_name = options[:as] || options[:to]
48-
49-
# end
50-
set_variable('rabl', Gon::Rabl.parse_rabl(view_path, @request_env['action_controller.instance']))
47+
rabl_data = Gon::Rabl.parse_rabl(view_path, @request_env['action_controller.instance'])
48+
if options[:as]
49+
set_variable(options[:as].to_s, rabl_data)
50+
elsif rabl_data.is_a? Hash
51+
rabl_data.each do |key, value|
52+
set_variable(key, value)
53+
end
54+
else
55+
set_variable('rabl', rabl_data)
56+
end
5157
end
5258
end
5359
end

lib/gon/rabl.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ def parse_rabl(rabl_path, controller)
66
source = File.read(rabl_path)
77
rabl_engine = Rabl::Engine.new(source, :format => 'json')
88
output = rabl_engine.render(controller, {})
9-
9+
JSON.parse(output)
1010
end
1111
end
1212
end

0 commit comments

Comments
 (0)