Module: Murdoc

Defined in:
lib/murdoc/languages/html.rb,
lib/murdoc.rb,
lib/murdoc/scanner.rb,
lib/murdoc/version.rb,
lib/murdoc/renderer.rb,
lib/murdoc/annotator.rb,
lib/murdoc/paragraph.rb,
lib/murdoc/languages/base.rb,
lib/murdoc/languages/ruby.rb,
lib/murdoc/languages/markdown.rb,
lib/murdoc/formatted_paragraph.rb,
lib/murdoc/languages/javascript.rb,
lib/murdoc/languages/coffeescript.rb

Overview

Html language module

Defined Under Namespace

Modules: Languages Classes: AnnotatedFile, Annotator, FormattedParagraph, Paragraph, Renderer, Scanner

Constant Summary collapse

VERSION =
'0.2.0'

Class Method Summary collapse

Class Method Details

.annotate(filename, highlight = true, do_not_count_comment_lines = false) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/murdoc.rb', line 15

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

.default_optionsObject



44
45
46
47
48
49
50
# File 'lib/murdoc.rb', line 44

def self.default_options
  @options ||= {
    template:   "#{markup_dir}/template.haml",
    stylesheet: "#{markup_dir}/stylesheet.css",
    highlight: true
  }
end

.default_options_for_multiple_filesObject



52
53
54
55
56
57
58
# File 'lib/murdoc.rb', line 52

def self.default_options_for_multiple_files
  @options ||= {
    template:   "#{markup_dir}/template_multifile.haml",
    stylesheet: "#{markup_dir}/stylesheet.css",
    highlight: true
  }
end

.generate_from_file(input, output, options = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/murdoc.rb', line 25

def self.generate_from_file(input, output, options = {})
  options = default_options.merge(options)
  annotator = Annotator.from_file(input, nil)
  File.open(output, "w+") do |f|
    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

.generate_from_multiple_files(input_files, output, options = {}) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/murdoc.rb', line 35

def self.generate_from_multiple_files(input_files, output, options = {})
  options = default_options_for_multiple_files.merge(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 Renderer.new(options[:template]).render(:annotated_files => annotated_files,
                                                   :stylesheet => File.read(options[:stylesheet]))
  end
end

.markup_dirObject



60
61
62
# File 'lib/murdoc.rb', line 60

def self.markup_dir
  File.expand_path("../..", __FILE__)+ "/markup"
end