Faster Tagz
This commit is contained in:
+6
-7
@@ -8,13 +8,13 @@ require 'ostruct'
|
||||
|
||||
require 'erubis'
|
||||
require 'haml'
|
||||
require 'slim'
|
||||
require 'handlebars'
|
||||
require 'liquid'
|
||||
require 'mustache'
|
||||
require 'tenjin'
|
||||
require 'handlebars'
|
||||
# require 'parkaby'
|
||||
require 'slim'
|
||||
require 'tagz'
|
||||
|
||||
require 'tenjin'
|
||||
require 'tilt/erb'
|
||||
require 'tilt/erubis'
|
||||
require 'tilt/haml'
|
||||
@@ -22,9 +22,8 @@ require 'tilt/liquid'
|
||||
|
||||
require 'workbench/benchmark'
|
||||
require 'workbench/wrappers/base'
|
||||
require 'workbench/wrappers/handlebars'
|
||||
require 'workbench/wrappers/mustache'
|
||||
require 'workbench/wrappers/slim'
|
||||
require 'workbench/wrappers/tenjin'
|
||||
require 'workbench/wrappers/handlebars'
|
||||
require 'workbench/wrappers/parkaby'
|
||||
require 'workbench/wrappers/tagz'
|
||||
require 'workbench/wrappers/tenjin'
|
||||
|
||||
@@ -2,30 +2,32 @@ module Workbench
|
||||
module Wrappers
|
||||
class Tagz < Base
|
||||
def initialize path
|
||||
@tpl = File.read(path)
|
||||
@context = Context.new
|
||||
require path
|
||||
|
||||
if path.end_with?('small.rb')
|
||||
@tpl = TagzTemplates::Small.new
|
||||
else
|
||||
@tpl = TagzTemplates::Big.new
|
||||
end
|
||||
end
|
||||
|
||||
def render context, args = {}
|
||||
@context.with_args(args).instance_eval(tpl)
|
||||
end
|
||||
|
||||
class Context
|
||||
include ::Tagz
|
||||
|
||||
def with_args args
|
||||
@args = args
|
||||
self
|
||||
end
|
||||
|
||||
def method_missing method, *args
|
||||
if @args.key?(method)
|
||||
@args[method]
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
@tpl.with_args(args).render
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
module TagzTemplates
|
||||
class Base
|
||||
include Tagz
|
||||
|
||||
def with_args args
|
||||
args.each do |key, val|
|
||||
instance_variable_set(:"@#{key}", val)
|
||||
end
|
||||
|
||||
self
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user