mirror of
https://github.com/kemko/liquid.git
synced 2026-01-01 15:55:40 +03:00
Add a simple profiling system to liquid rendering. Each
liquid tag ({{ }} and {% %}) is processed through this profiling,
keeping track of the partial name (in the case of {% include %}), line
number, and the time it took to render the tag. In the case of {%
include %}, the profiler keeps track of the name of the partial and
properly links back tag rendering to the partial and line number for
easy lookup and dive down. With this, it's now possible to track down
exactly how long each tag takes to render.
These hooks get installed and uninstalled on an as-need basis so by
default there is no impact on the overall liquid execution speed.
77 lines
2.9 KiB
Ruby
77 lines
2.9 KiB
Ruby
# Copyright (c) 2005 Tobias Luetke
|
|
#
|
|
# Permission is hereby granted, free of charge, to any person obtaining
|
|
# a copy of this software and associated documentation files (the
|
|
# "Software"), to deal in the Software without restriction, including
|
|
# without limitation the rights to use, copy, modify, merge, publish,
|
|
# distribute, sublicense, and/or sell copies of the Software, and to
|
|
# permit persons to whom the Software is furnished to do so, subject to
|
|
# the following conditions:
|
|
#
|
|
# The above copyright notice and this permission notice shall be
|
|
# included in all copies or substantial portions of the Software.
|
|
#
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
module Liquid
|
|
FilterSeparator = /\|/
|
|
ArgumentSeparator = ','.freeze
|
|
FilterArgumentSeparator = ':'.freeze
|
|
VariableAttributeSeparator = '.'.freeze
|
|
TagStart = /\{\%/
|
|
TagEnd = /\%\}/
|
|
VariableSignature = /\(?[\w\-\.\[\]]\)?/
|
|
VariableSegment = /[\w\-]/
|
|
VariableStart = /\{\{/
|
|
VariableEnd = /\}\}/
|
|
VariableIncompleteEnd = /\}\}?/
|
|
QuotedString = /"[^"]*"|'[^']*'/
|
|
QuotedFragment = /#{QuotedString}|(?:[^\s,\|'"]|#{QuotedString})+/o
|
|
TagAttributes = /(\w+)\s*\:\s*(#{QuotedFragment})/o
|
|
AnyStartingTag = /\{\{|\{\%/
|
|
PartialTemplateParser = /#{TagStart}.*?#{TagEnd}|#{VariableStart}.*?#{VariableIncompleteEnd}/om
|
|
TemplateParser = /(#{PartialTemplateParser}|#{AnyStartingTag})/om
|
|
VariableParser = /\[[^\]]+\]|#{VariableSegment}+\??/o
|
|
|
|
singleton_class.send(:attr_accessor, :cache_classes)
|
|
self.cache_classes = true
|
|
end
|
|
|
|
require "liquid/version"
|
|
require 'liquid/lexer'
|
|
require 'liquid/parser'
|
|
require 'liquid/i18n'
|
|
require 'liquid/drop'
|
|
require 'liquid/extensions'
|
|
require 'liquid/errors'
|
|
require 'liquid/interrupts'
|
|
require 'liquid/strainer'
|
|
require 'liquid/expression'
|
|
require 'liquid/context'
|
|
require 'liquid/tag'
|
|
require 'liquid/block'
|
|
require 'liquid/document'
|
|
require 'liquid/variable'
|
|
require 'liquid/variable_lookup'
|
|
require 'liquid/range_lookup'
|
|
require 'liquid/file_system'
|
|
require 'liquid/template'
|
|
require 'liquid/standardfilters'
|
|
require 'liquid/condition'
|
|
require 'liquid/module_ex'
|
|
require 'liquid/utils'
|
|
|
|
# Load all the tags of the standard library
|
|
#
|
|
Dir[File.dirname(__FILE__) + '/liquid/tags/*.rb'].each { |f| require f }
|
|
|
|
require 'liquid/profiler'
|
|
require 'liquid/profiler/token'
|
|
require 'liquid/profiler/hooks'
|