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.1'
Class Method Summary collapse
-
.annotate(filename, highlight = true, do_not_count_comment_lines = false) ⇒ Object
‘Murdoc.annotate` arguments are gathered from CLI utility.
-
.default_options ⇒ Object
Rest is self-explanatory.
- .default_options_for_index ⇒ Object
- .default_options_for_multiple_files ⇒ Object
- .default_options_for_tree ⇒ Object
-
.generate_from_file(input, output, options = {}) ⇒ Object
Generate a single file story.
-
.generate_from_multiple_files(input_files, output, options = {}) ⇒ Object
…
- .generate_index(fn, options) ⇒ Object
-
.generate_tree(input_dir, output_dir, has_parent = false, base_dir = nil, options = {}) ⇒ Object
Generate a documentation tree.
- .markup_dir ⇒ Object
- .try_load_yaml(yaml) ⇒ Object
Class Method Details
.annotate(filename, highlight = true, do_not_count_comment_lines = false) ⇒ Object
‘Murdoc.annotate` arguments are gathered from CLI utility
‘highlight` regulates syntax highlighting and `do_not_count_comment_lines` flag toggles counting comment lines towards line numbering in the output.
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/murdoc.rb', line 22 def self.annotate(filename, highlight = true, do_not_count_comment_lines = false) filename = File.(filename) annotator = Annotator.from_file(filename, nil, do_not_count_comment_lines) AnnotatedFile.new(filename, annotator., annotator.source, annotator.source_type, annotator.paragraphs, annotator.paragraphs.map {|p| FormattedParagraph.new(p, highlight) }) end |
.default_options ⇒ Object
Rest is self-explanatory
117 118 119 120 121 122 123 |
# File 'lib/murdoc.rb', line 117 def self. @options ||= { template: "#{markup_dir}/template.haml", stylesheet: "#{markup_dir}/stylesheet.css", highlight: true } end |
.default_options_for_index ⇒ Object
144 145 146 147 148 149 |
# File 'lib/murdoc.rb', line 144 def self. @options_index ||= { template: "#{markup_dir}/template_index.haml", stylesheet: "#{markup_dir}/stylesheet.css" } end |
.default_options_for_multiple_files ⇒ Object
125 126 127 128 129 130 131 |
# File 'lib/murdoc.rb', line 125 def self. @options_multi ||= { template: "#{markup_dir}/template_multifile.haml", stylesheet: "#{markup_dir}/stylesheet.css", highlight: true } end |
.default_options_for_tree ⇒ Object
133 134 135 136 137 138 139 140 141 142 |
# File 'lib/murdoc.rb', line 133 def self. @options_tree ||= { index_template: [:template], index_stylesheet: [:stylesheet], template: [:template], stylesheet: [:stylesheet], highlight: [:highlight], do_not_count_comment_lines: false } end |
.generate_from_file(input, output, options = {}) ⇒ Object
Generate a single file story
34 35 36 37 38 39 40 41 42 |
# File 'lib/murdoc.rb', line 34 def self.generate_from_file(input, output, = {}) = .merge() annotator = Annotator.from_file(input, nil) File.open(output, "w+") do |f| annotated_file = annotate(input, [:highlight], [:do_not_count_comment_lines]) f.puts Renderer.new([:template]).render(:annotated_file => annotated_file, :stylesheet => File.read([:stylesheet])) end end |
.generate_from_multiple_files(input_files, output, options = {}) ⇒ Object
… or use multiple files
45 46 47 48 49 50 51 52 |
# File 'lib/murdoc.rb', line 45 def self.generate_from_multiple_files(input_files, output, = {}) = .merge() annotated_files = input_files.map {|fn| annotate(fn, [:highlight], [:do_not_count_comment_lines]) } File.open(output, "w+") do |f| f.puts Renderer.new([:template]).render(:annotated_files => annotated_files, :stylesheet => File.read([:stylesheet])) end end |
.generate_index(fn, options) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/murdoc.rb', line 101 def self.generate_index(fn, ) = .merge() File.open(fn, 'w+') do |f| f.puts Renderer.new([:template]).render({ stylesheet: File.read([:stylesheet]), base_dir: [:base_dir], has_parent: [:has_parent], current_directory: [:current_directory], files: [:files], directories: [:directories] }) end end |
.generate_tree(input_dir, output_dir, has_parent = false, base_dir = nil, options = {}) ⇒ Object
Generate a documentation tree
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/murdoc.rb', line 55 def self.generate_tree(input_dir, output_dir, has_parent = false, base_dir = nil, = {}) = .merge() input_dir = Pathname(input_dir). output_dir = Pathname(output_dir). base_dir ||= input_dir FileUtils.mkdir_p(output_dir) entries = input_dir.children directories = entries.select(&:directory?). reject {|dir| dir == output_dir }. reject {|dir| dir.basename.to_s.start_with?('.')} directories.each do |dir| next if dir == output_dir generate_tree(dir, output_dir + dir.relative_path_from(input_dir), true, base_dir, ) end files = entries.select(&:file?).select {|file| Languages.detect(file.to_s) } files.each do |file| relpath = file.relative_path_from(input_dir) generate_from_file(file, "#{output_dir}/#{relpath}.html", { highlight: [:highlight], template: [:template], stylesheet: [:stylesheet], do_not_count_comment_lines: [:do_not_count_comment_lines] }) end unless files.empty? && directories.empty? generate_index("#{output_dir}/index.html", { current_directory: input_dir, files: files, directories: directories, has_parent: has_parent, base_dir: base_dir, template: [:index_template], stylesheet: [:index_stylesheet] }) end end |
.markup_dir ⇒ Object
151 152 153 |
# File 'lib/murdoc.rb', line 151 def self.markup_dir File.("../..", __FILE__)+ "/markup" end |
.try_load_yaml(yaml) ⇒ Object
156 157 158 159 160 |
# File 'lib/murdoc.rb', line 156 def self.try_load_yaml(yaml) YAML.load(yaml) rescue => e nil end |