Class: Risu::Base::PostProcessManager

Inherits:
Object
  • Object
show all
Defined in:
lib/risu/base/post_process_manager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Object

Creates new instance of TemplateManager

Parameters:

  • path

    Path relative to the base_dir of risu



33
34
35
36
37
38
39
40
41
42
43
44
# 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

Instance Attribute Details

#registered_postprocessesObject

Returns the value of attribute registered_postprocesses.



26
27
28
# File 'lib/risu/base/post_process_manager.rb', line 26

def registered_postprocesses
  @registered_postprocesses
end

Instance Method Details

#display_postprocessesObject

Displays a list of all the templates to STDOUT



103
104
105
106
107
108
109
110
111
112
# 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) ⇒ Object

Loads templates from a specific path

Parameters:

  • path

    Path to templates to load



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# 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

#sortObject



46
47
48
49
50
51
52
53
54
55
# 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) ⇒ Boolean

Validates that a template is a valid template

Parameters:

  • template

    The template to validate

Returns:

  • (Boolean)

    If the template is valid



95
96
97
98
99
100
# 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