Skip to content

Commit d0004bf

Browse files
committed
Added helpers to jbuilder
1 parent a21d7b9 commit d0004bf

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

lib/gon/jbuilder.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ def handler(args, global = false)
88
raise 'You should provide :template when use rabl with global variables'
99
end
1010

11+
include_helpers
12+
1113
data = parse_jbuilder \
1214
Gon::Base.get_template_path(options,'jbuilder'),
1315
Gon::Base.get_controller(options)
@@ -17,6 +19,12 @@ def handler(args, global = false)
1719

1820
private
1921

22+
def include_helpers
23+
unless self.class.include? ::ActionView::Helpers
24+
self.class.send(:include, ::ActionView::Helpers)
25+
end
26+
end
27+
2028
def parse_options_from(args)
2129
if old_api? args
2230
text = "[DEPRECATION] view_path argument is now optional. "

spec/gon/jbuilder_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626
Gon.objects.length.should == 2
2727
end
2828

29+
it 'render json from jbuilder template with helpers' do
30+
Gon.jbuilder 'spec/test_data/sample_with_helpers.json.jbuilder', :controller => controller
31+
Gon.date.should == 'about 6 hours'
32+
end
33+
2934
it 'render json from jbuilder template with a partial' do
3035
controller.view_paths << 'spec/test_data'
3136
Gon.jbuilder 'spec/test_data/sample_with_partial.json.jbuilder', :controller => controller
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
json.date distance_of_time_in_words(20000)

0 commit comments

Comments
 (0)