module Plate # The Dsl class provides the methods available in plugin files in order to extend # the functionality a generated site. class Dsl class << self # Evaluate the given file path into the {Plate::Dsl dsl} instance. def evaluate_plugin(file_path) instance_eval_plugin(read_plugin_file(file_path)) end # Performs evaluation of the file's content def instance_eval_plugin(content) new.instance_eval(content) end # Read the given plugin file path into a string # # @return [String] The plugin file's contents def read_plugin_file(file_path) File.read(file_path) rescue raise PluginNotReadable end end # Register a new callback for the given object and event. # # @example Run block after rendering a site # callback :site, :after_render do # puts 'done!' # end # # @example Run block before rendering a page # callback :page, :before_render do |page| # puts "Rendering page #{page.path}" # end # # @example Run a method on the site after write # class Site # def finished! # log('All done.') # end # end # # callback :site, :after_write, :finished! # def callback(object, event, method_name = nil, &block) if Symbol === object object = "Plate::#{object.to_s.classify}".constantize end object.register_callback(event, method_name, &block) end alias :register_callback :callback # Set up a new engine designed for rendering dynamic assets. # Engines should be compatible with the Tilt::Template syntax. def register_asset_engine(extension, klass) Plate.register_asset_engine(extension, klass) end # Set up a new engine designed for rendering dynamic assets. # Engines should be compatible with the Tilt::Template syntax. def register_template_engine(extension, klass) Plate.register_template_engine(extension, klass) end end end