lib/mustache_render/mustache.rb in mustache_render-0.0.9 vs lib/mustache_render/mustache.rb in mustache_render-0.0.10
- old
+ new
@@ -99,11 +99,12 @@
end
end
def impl_read_file_template name
# TODO: 对路径的语法需要加强
- full_path = "#{config.file_template_root_path}/#{self.class.generate_template_name(name, config.file_template_extension)}"
+ full_path = "#{config.file_template_root_path}/#{name}"
+
begin
File.read full_path
rescue
if config.raise_on_file_template_miss?
raise ::MustacheRender::Mustache::TemplateMiss.new("read file template error: #{full_path}")
@@ -112,10 +113,11 @@
end
end
end
def read_template_from_media name, media
+ ::MustacheRender.logger.debug "MustacheRender render -> read template from #{media}: #{name}"
# puts "read_template_from_media: #{name} #{media}"
case media
when :db
if ::MustacheRender.config.db_template_cache?
self.class.fetch_partial_cache name, media, :expires_in => ::MustacheRender.config.db_template_cache_expires_in do
@@ -133,23 +135,15 @@
impl_read_file_template name
end
end
end
- def self.fix_path_name name
- # 需要以 / 开头,此处fix一下这里
- if name.to_s.start_with?('/')
- name.to_s
- else
- "/#{name}"
- end
- end
-
# Override this in your subclass if you want to do fun things like
# reading templates from a database. It will be rendered by the
# context, so all you need to do is return a string.
def partial(name)
- name = self.class.fix_path_name name
+ name = self.class.generate_template_name name, config.file_template_extension
+
# return self.read_template_from_media name, media
@_cached_partials ||= {}
(@_cached_partials[media] ||= {})[name] ||= self.read_template_from_media name, media
end