Class: NoteRenderer

Inherits:
Object
  • Object
show all
Includes:
ManipulateNode
Defined in:
public/app/models/note_renderer.rb

Overview

Base class for all renderers

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ManipulateNode

#inheritance, #process_mixed_content, #strip_mixed_content

Class Method Details

.for(type) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'public/app/models/note_renderer.rb', line 12

def self.for(type)
  result = @renderers.find {|renderer| renderer.handles_type?(type)}
  unless result
    $stderr.puts "No note renderer for '#{type}'"
    result = UnhandledNoteRenderer
  end

  result.new
end

.inherited(subclass) ⇒ Object



5
6
7
8
9
10
# File 'public/app/models/note_renderer.rb', line 5

def self.inherited(subclass)
  @renderers ||= []
  @renderers << subclass

  subclass.extend(ClassMethods)
end

Instance Method Details

#build_label(type, note) ⇒ Object



41
42
43
# File 'public/app/models/note_renderer.rb', line 41

def build_label(type, note)
  note.has_key?('label') ? note['label'] : I18n.t("enumerations._note_types.#{type}", :default => '')
end

#render(type, note, result) ⇒ Object



32
33
34
35
# File 'public/app/models/note_renderer.rb', line 32

def render(type, note, result)
  # Must fill out note_text and label
  raise "Implement this"
end

#render_partial(template, opts = {}) ⇒ Object



37
38
39
# File 'public/app/models/note_renderer.rb', line 37

def render_partial(template, opts = {})
  ApplicationController.new.render_to_string(opts.merge(:partial => 'shared/' + template))
end