@@ -31,11 +31,22 @@ def read_template_file(template_path, context)
31
31
# file_system.full_path("mypartial") # => "/some/path/_mypartial.liquid"
32
32
# file_system.full_path("dir/mypartial") # => "/some/path/dir/_mypartial.liquid"
33
33
#
34
+ # Optionally in the second argument you can specify a custom pattern for template filenames.
35
+ # The Kernel::sprintf format specification is used.
36
+ # Default pattern is "_%s.liquid".
37
+ #
38
+ # Example:
39
+ #
40
+ # file_system = Liquid::LocalFileSystem.new("/some/path", "%s.html")
41
+ #
42
+ # file_system.full_path("index") # => "/some/path/index.html"
43
+ #
34
44
class LocalFileSystem
35
45
attr_accessor :root
36
46
37
- def initialize ( root )
47
+ def initialize ( root , pattern = "_%s.liquid" )
38
48
@root = root
49
+ @pattern = pattern
39
50
end
40
51
41
52
def read_template_file ( template_path , context )
@@ -49,9 +60,9 @@ def full_path(template_path)
49
60
raise FileSystemError , "Illegal template name '#{ template_path } '" unless template_path =~ /^[^.\/ ][a-zA-Z0-9_\/ ]+$/
50
61
51
62
full_path = if template_path . include? ( '/' )
52
- File . join ( root , File . dirname ( template_path ) , "_ #{ File . basename ( template_path ) } .liquid" )
63
+ File . join ( root , File . dirname ( template_path ) , @pattern % File . basename ( template_path ) )
53
64
else
54
- File . join ( root , "_ #{ template_path } .liquid" )
65
+ File . join ( root , @pattern % template_path )
55
66
end
56
67
57
68
raise FileSystemError , "Illegal template path '#{ File . expand_path ( full_path ) } '" unless File . expand_path ( full_path ) =~ /^#{ File . expand_path ( root ) } /
0 commit comments