Class: DNote::Format

Inherits:
Object
  • Object
show all
Defined in:
lib/dnote/format.rb

Overview

Notes Formatter

TODO: Need good CSS file.

TODO: Need XSL?

++

Defined Under Namespace

Classes: ErbScope

Constant Summary collapse

EXTENSIONS =
{ 'text' => 'txt', 'soap' => 'xml', 'xoxo' => 'xml' }.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(notes, options = {}) {|_self| ... } ⇒ Format

Returns a new instance of Format.

Yields:

  • (_self)

Yield Parameters:

  • _self (DNote::Format)

    the object that the method was called on



33
34
35
36
37
38
39
40
41
# File 'lib/dnote/format.rb', line 33

def initialize(notes, options = {})
  @notes   = notes
  @format  = 'text'
  @subtype = 'label'
  @title   = "Developer's Notes"
  @dryrun  = false
  options.each { |k, v| __send__("#{k}=", v) if v }
  yield(self) if block_given?
end

Instance Attribute Details

#dryrunObject

Returns the value of attribute dryrun.



31
32
33
# File 'lib/dnote/format.rb', line 31

def dryrun
  @dryrun
end

#formatObject

Returns the value of attribute format.



21
22
23
# File 'lib/dnote/format.rb', line 21

def format
  @format
end

#notesObject (readonly)

Returns the value of attribute notes.



19
20
21
# File 'lib/dnote/format.rb', line 19

def notes
  @notes
end

#outputObject

Returns the value of attribute output.



25
26
27
# File 'lib/dnote/format.rb', line 25

def output
  @output
end

#subtypeObject

Returns the value of attribute subtype.



23
24
25
# File 'lib/dnote/format.rb', line 23

def subtype
  @subtype
end

#templateObject

Returns the value of attribute template.



27
28
29
# File 'lib/dnote/format.rb', line 27

def template
  @template
end

#titleObject

Returns the value of attribute title.



29
30
31
# File 'lib/dnote/format.rb', line 29

def title
  @title
end

Instance Method Details

#renderObject



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/dnote/format.rb', line 43

def render
  if notes.empty?
    $stderr << "No #{notes.labels.join(', ')} notes.\n"
  else
    case format
    when 'custom'
      render_custom
    else
      render_template
    end
  end
end

#render_customObject

C U S T O M



58
59
60
61
# File 'lib/dnote/format.rb', line 58

def render_custom
  result = erb(template)
  publish(result)
end

#render_templateObject

T E M P L A T E



65
66
67
68
69
70
71
# File 'lib/dnote/format.rb', line 65

def render_template
  template = File.join(File.dirname(__FILE__), 'templates', "#{format}.erb")
  raise "No such format - #{format}" unless File.exist?(template)

  result = erb(template)
  publish(result)
end