Skip to content

Commit 5d7bdad

Browse files
committed
Use controller_path instead of controller_name for template path resolving. Makes partials in namespaces work.
1 parent c794276 commit 5d7bdad

File tree

6 files changed

+22
-6
lines changed

6 files changed

+22
-6
lines changed

lib/liquid-rails/file_system.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ module Liquid
44
module Rails
55
class FileSystem < ::Liquid::LocalFileSystem
66
def read_template_file(template_path, context)
7-
controller_name = context.registers[:controller].controller_name
8-
template_path = "#{controller_name}/#{template_path}" unless template_path.include?('/')
9-
7+
controller_path = context.registers[:controller].controller_path
8+
template_path = "#{controller_path}/#{template_path}" unless template_path.include?('/')
109
super
1110
end
1211
end
1312
end
14-
end
13+
end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class Foospace::BarController < ApplicationController
2+
def index_partial
3+
render layout: false
4+
end
5+
end
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Bar Partial
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Foospace::BarController
2+
3+
{% include 'partial' %}

spec/dummy/config/routes.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@
77

88
get '/index_partial', to: 'home#index_partial'
99
get '/index_partial_with_full_path', to: 'home#index_partial_with_full_path'
10-
end
10+
11+
get '/foospace/bar/index_partial', to: 'foospace/bar#index_partial'
12+
end

spec/lib/liquid-rails/template_handler_spec.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@
3535

3636
expect(page.body).to eq "Application Layout\nLiquid on Rails\n\nHome Partial\nShared Partial"
3737
end
38+
39+
it 'respects namespace of original template for partials path' do
40+
visit '/foospace/bar/index_partial'
41+
expect(page.body.strip).to eq("Foospace::BarController\n\nBar Partial")
42+
end
43+
3844
end
3945

4046
context 'render with filter' do
@@ -50,4 +56,4 @@
5056
expect(page.body).to eq("Application Layout\nLiquid on Rails\nThis is a long section of text")
5157
end
5258
end
53-
end
59+
end

0 commit comments

Comments
 (0)