class Risu::Base::PostProcessManager
Attributes
registered_postprocesses[RW]
Public Class Methods
new(path)
click to toggle source
Creates new instance of TemplateManager
@param path Path relative to the base_dir of risu
@return New instance of the template manager with templates loaded.
# File lib/risu/base/post_process_manager.rb, line 33 def initialize path @registered_postprocesses = Array.new @postprocesses = Array.new base_dir = __FILE__.gsub("risu/base/post_process_manager.rb", "") load_postprocesses(base_dir + path) load_postprocesses(Dir.pwd, false) load_postprocesses(File.expand_path(USER_TEMPLATES_DIR)) if File.exist?(File.expand_path(USER_TEMPLATES_DIR)) && File.directory?(File.expand_path(USER_TEMPLATES_DIR)) sort end
Public Instance Methods
display_postprocesses()
click to toggle source
Displays a list of all the templates to STDOUT
# File lib/risu/base/post_process_manager.rb, line 103 def display_postprocesses puts "Available Post Processing" @registered_postprocesses.each do |p| if p.info[:plugin_id] != nil puts "\t#{p.info[:description]} (#{p.info[:plugin_id]})\n" else puts "\t#{p.info[:description]}" end end end
load_postprocesses(path, recursive=true)
click to toggle source
Loads templates from a specific path
@param path Path to templates to load
# File lib/risu/base/post_process_manager.rb, line 60 def load_postprocesses(path, recursive=true) begin search_path = "#{path}/**/*.rb" if recursive == true search_path = "#{path}/*.rb" if recursive == false Dir[search_path].each do |x| begin require x rescue => e #puts e.inspect #puts e.backtrace next end end PostProcessBase.possible_postprocesses.each do |p| if validate(p) == true @postprocesses << p if @postprocesses.include?(p) == false end end rescue => e puts "[!] Invalid post processing path" puts e.inspect puts e.backtrace end end
sort()
click to toggle source
# File lib/risu/base/post_process_manager.rb, line 46 def sort @postprocesses.each do |klass| k = klass.new @registered_postprocesses << k end @registered_postprocesses.sort! do |a,b| a <=> b end end
validate(template)
click to toggle source
Validates that a template is a valid template
@TODO look at refactoring this to valid?(template)
@param template The template to validate
@return [Boolean] If the template is valid
# File lib/risu/base/post_process_manager.rb, line 95 def validate template t = template.new return false if t == nil return t.instance_variable_defined?("@info") end