module Babl

Constants

VERSION

Public Class Methods

compile(*args, &block) click to toggle source
# File lib/babl.rb, line 62
def compile(*args, &block)
    raise ArgumentError, 'Wrong number of arguments' if args.size > 1
    raise ArgumentError, 'Template or block expected' unless args.empty? ^ block.nil?

    (args.empty? ? source(&block) : template.call(args.first)).compile(
        pretty: config.pretty,
        preloader: config.preloader,
        lookup_context: config.lookup_context
    )
end
config() click to toggle source
# File lib/babl.rb, line 95
def config
    @config ||= Config.new
end
configure() { |config| ... } click to toggle source
# File lib/babl.rb, line 91
def configure
    yield(config)
end
source(*args, &block) click to toggle source
# File lib/babl.rb, line 73
def source(*args, &block)
    template.source(*args, &block)
end
template() click to toggle source
# File lib/babl.rb, line 77
def template
    cached = @cached_template
    return cached.last if cached && [config.using].flatten == cached.first

    # Calling 'using' is a very inefficient operation, because
    # it creates a new class. We can avoid that cost most of the
    # time, assuming 'config.using' does not change often (typically
    # it should only change once at startup)
    modules = [config.using].flatten.dup
    template = Template.new.using(*modules)
    @cached_template = [modules, template]
    template
end