mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00

That is, the buffered branch is being removed and replaced with the edge branch. This marks the beginning of the edge branch. git-svn-id: svn://hamptoncatlin.com/haml/branches/edge@80 7063305b-7217-0410-af8c-cdc13e5119b9
45 lines
1.3 KiB
Ruby
45 lines
1.3 KiB
Ruby
require File.dirname(__FILE__) + '/../lib/haml/template'
|
|
require 'rubygems'
|
|
require 'active_support'
|
|
require 'action_view'
|
|
require 'profiler'
|
|
require 'stringio'
|
|
|
|
module Haml
|
|
# A profiler for HAML, mostly for development use. This simply implements
|
|
# the Ruby profiler for profiling HAML code.
|
|
class Profiler
|
|
|
|
# Creates a new profiler that looks for templates in the base
|
|
# directory.
|
|
def initialize(base = File.join(File.dirname(__FILE__), 'templates'))
|
|
ActionView::Base.register_template_handler("haml", Haml::Template)
|
|
unless base.class == ActionView::Base
|
|
@base = ActionView::Base.new(base)
|
|
else
|
|
@base = base
|
|
end
|
|
end
|
|
|
|
# Profiles HAML on the given template with the given number of runs.
|
|
# The template name shouldn't have a file extension; this will
|
|
# automatically look for a HAML template.
|
|
#
|
|
# Returns the results of the profiling as a string.
|
|
def profile(runs = 100, template_name = 'standard')
|
|
# Runs the profiler, collects information
|
|
Profiler__::start_profile
|
|
runs.times { @base.render template_name }
|
|
Profiler__::stop_profile
|
|
|
|
# Outputs information to a StringIO, returns result
|
|
io = StringIO.new
|
|
Profiler__::print_profile(io)
|
|
io.pos = 0
|
|
result = io.read
|
|
io.close
|
|
return result
|
|
end
|
|
|
|
end
|
|
end
|