lib/dnote/format.rb in dnote-1.1.4 vs lib/dnote/format.rb in dnote-1.2.0
- old
+ new
@@ -23,10 +23,13 @@
#
attr_accessor :format
#
+ attr_accessor :subtype
+
+ #
attr_accessor :output
#
attr_accessor :template
@@ -36,94 +39,48 @@
#
attr_accessor :dryrun
#
def initialize(notes, options={})
- @notes = notes
- @format = :gnu
- @title = "Developer's Notes"
- options.each do |k,v|
- __send__("#{k}=", v) if v
- end
+ @notes = notes
+ @format = 'text'
+ @subtype = 'label'
+ @title = "Developer's Notes"
+ options.each{ |k,v| __send__("#{k}=", v) if v }
+ yield(self) if block_given?
end
#
def render
if notes.empty?
$stderr << "No #{notes.labels.join(', ')} notes.\n"
else
- raise ArgumentError unless respond_to?("render_#{format}")
- __send__("render_#{format}")
+ case format
+ when 'custom'
+ render_custom
+ else
+ render_template
+ end
end
end
- # S E R I A L I Z A T I O N
+ # C U S T O M
- def render_yaml
- result = notes.to_yaml
- publish(result)
- end
-
- def render_json
- result = notes.to_json
- publish(result)
- end
-
- # M L M A R K U P
-
- def render_soap
- result = notes.to_soap
- publish(result)
- end
-
- def render_xoxo
- result = notes.to_xoxo
- publish(result)
- end
-
- def render_xml
- template = File.join(File.dirname(__FILE__), 'templates/xml.erb')
+ #
+ def render_custom
+ #raise ArgumentError unless File.exist?(template)
result = erb(template)
- publish(result)
+ publish(result)
end
- def render_html
- template = File.join(File.dirname(__FILE__), 'templates/html.erb')
- result = erb(template)
- publish(result)
- end
+ # T E M P L A T E
- def render_index
- template = File.join(File.dirname(__FILE__), 'templates/html.erb')
+ #
+ 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, 'index.html')
- end
-
- # W I K I M A R K U P
-
- def render_gnu
- template = File.join(File.dirname(__FILE__), 'templates/gnu.erb')
- result = erb(template)
- publish(result)
- end
-
- def render_rdoc
- template = File.join(File.dirname(__FILE__), 'templates/rdoc.erb')
- result = erb(template)
- publish(result)
- end
-
- def render_markdown
- template = File.join(File.dirname(__FILE__), 'templates/markdown.erb')
- result = erb(template)
- publish(result)
- end
-
- # C U S T O M T E M P L A T E
-
- def render_custom
- result = erb(template)
- publish(result)
+ publish(result)
end
private
#