lib/murdoc.rb in murdoc-0.1.13 vs lib/murdoc.rb in murdoc-0.2.0
- old
+ new
@@ -8,48 +8,68 @@
# [ro]: "http://rtomayko.github.com/rocco"
#
module Murdoc
+ AnnotatedFile = Struct.new(:filename, :source, :source_type, :paragraphs, :formatted_paragraphs)
+
+ def self.annotate(filename, highlight = true, do_not_count_comment_lines = false)
+ filename = File.expand_path(filename)
+ annotator = Annotator.from_file(filename, nil, do_not_count_comment_lines)
+ AnnotatedFile.new(filename,
+ annotator.source,
+ annotator.source_type,
+ annotator.paragraphs,
+ annotator.paragraphs.map {|p| FormattedParagraph.new(p, highlight) })
+ end
+
def self.generate_from_file(input, output, options = {})
options = default_options.merge(options)
- annotator = Annotator.from_file(input, nil, options)
+ annotator = Annotator.from_file(input, nil)
File.open(output, "w+") do |f|
- f.puts Formatter.new(options[:template]).render(:paragraphs => annotator.paragraphs,
- :stylesheet => File.read(options[:stylesheet]))
+ annotated_file = annotate(input, options[:highlight], options[:do_not_count_comment_lines])
+ f.puts Renderer.new(options[:template]).render(:annotated_file => annotated_file,
+ :stylesheet => File.read(options[:stylesheet]))
end
end
def self.generate_from_multiple_files(input_files, output, options = {})
options = default_options_for_multiple_files.merge(options)
- annotators = input_files.map {|fn| Annotator.from_file(fn, nil, options) }
+ annotated_files = input_files.map {|fn| annotate(fn, options[:highlight], options[:do_not_count_comment_lines]) }
File.open(output, "w+") do |f|
- f.puts Formatter.new(options[:template]).render(:annotators => annotators,
- :filenames => input_files,
- :stylesheet => File.read(options[:stylesheet]))
+ f.puts Renderer.new(options[:template]).render(:annotated_files => annotated_files,
+ :stylesheet => File.read(options[:stylesheet]))
end
end
def self.default_options
- @@options ||= {
- :template => "#{markup_dir}/template.haml",
- :stylesheet => "#{markup_dir}/stylesheet.css"
+ @options ||= {
+ template: "#{markup_dir}/template.haml",
+ stylesheet: "#{markup_dir}/stylesheet.css",
+ highlight: true
}
end
def self.default_options_for_multiple_files
- @@options ||= {
- :template => "#{markup_dir}/template_multifile.haml",
- :stylesheet => "#{markup_dir}/stylesheet.css"
+ @options ||= {
+ template: "#{markup_dir}/template_multifile.haml",
+ stylesheet: "#{markup_dir}/stylesheet.css",
+ highlight: true
}
end
def self.markup_dir
File.expand_path("../..", __FILE__)+ "/markup"
end
end
require "murdoc/annotator"
+require "murdoc/scanner"
require "murdoc/paragraph"
-require "murdoc/formatter"
-
-Dir["#{File.dirname(File.expand_path(__FILE__))}/murdoc/languages/*.rb"].each {|lang| require lang }
+require "murdoc/formatted_paragraph"
+require "murdoc/renderer"
+require "murdoc/languages/base"
+require "murdoc/languages/html"
+require "murdoc/languages/coffeescript"
+require "murdoc/languages/javascript"
+require "murdoc/languages/ruby"
+require "murdoc/languages/markdown"