lib/mustache_render/mustache.rb in mustache_render-0.0.13 vs lib/mustache_render/mustache.rb in mustache_render-0.0.14
- old
+ new
@@ -3,10 +3,13 @@
require 'mustache_render/mustache/context'
require 'mustache_render/mustache/data'
module MustacheRender
class Mustache
+ # 可用的渲染的方法
+ # AVAILABLE_RENDER_METHODS = [:render, :file_render, :db_render].freeze
+
def self.render(*args)
new.render(*args)
end
attr_reader :media ## 模板的媒介
@@ -19,11 +22,11 @@
@media ||= config.default_render_media
end
def render(data = template, ctx = {})
impl_logger :level => :debug, :operation => 'MustacheRender::Mustache.render' do
- impl_render data, ctx
+ impl_template_render data, ctx
end
end
# TODO: 语法检查,片段树
def partials_tree
@@ -49,10 +52,19 @@
# and want access to the hash currently being iterated over.
def context
@context ||= Context.new(self)
end
+ # 使用default_media 进行渲染
+ def self.impl_render(name, context={})
+ self.new.send :impl_render, name, context
+ end
+
+ def impl_render name, context={}
+ send "#{::MustacheRender.config.default_render_media}_render".to_sym, name, context
+ end
+
# Given a file name and an optional context, attempts to load and
# render the file as a template.
def self.file_render(name, context = {})
self.new.file_render name, context
end
@@ -286,10 +298,10 @@
def impl_format_log_entry(operation, message = nil)
" \033[4;34;1m#{operation}\033[0m \033[0;1m#{message}\033[0m"
end
- def impl_render(data=template, ctx={})
+ def impl_template_render(data=template, ctx={})
self.template = data
return self.template.render(context) if ctx == {}
begin