rdoc-generator-mdoc 0.0.1 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dc966f0f203abe863af4e82f195c61412bd84417
4
- data.tar.gz: 294a5f8c1f826fc2d8cc899ff6db5d99ae764319
3
+ metadata.gz: 65e13352de700980bfa375a2aa5984af7dd3e029
4
+ data.tar.gz: 129c79792e882b1fda01d38832cd6277f4a7735b
5
5
  SHA512:
6
- metadata.gz: 60ce89d4a4490ac922b11da2cf4575dd20a576e2f6c87a5c641247ed6bab0db41e1eae45c36797ab4ddc347994fcf4f4b9bfe4c35a45782cf4fb92cd5b38cb20
7
- data.tar.gz: 488e50382e04531abc0f4823d37a12b992de29d53015d90ad730279e1b9577ebfe30a09ea3a980e87756a6b7df5275c2df59d147cfce8f9828160f61b45c69b4
6
+ metadata.gz: 2f4b84fbbfd8ad2cc7e881172383d84c9932b69cf56bdda57d7b70a3c300313ddceda4bca81a25fab04d98d49580e63b8ee601f38011e52da4e2aff38f08d7bf
7
+ data.tar.gz: 0052a203799ac1574663875d7c7123c826918445538a06ddd5fefe699e51889691250f66aa29d58dd9c5e1bbfdd0d6fc949ccfc351e27e213c2d6a198662db33
@@ -1,6 +1,5 @@
1
1
  require "erb"
2
2
  require "rdoc"
3
- require "rdoc/generator/mdoc/version"
4
3
  require "rdoc/generator/mdoc/class"
5
4
  require "rdoc/generator/mdoc/module"
6
5
  require "rdoc/generator/mdoc/render_context"
@@ -27,8 +26,10 @@ class RDoc::Generator::Mdoc
27
26
  # Create an instance usign the provided RDoc::Store and RDoc::Options.
28
27
  def initialize(store, options)
29
28
  @store = store
30
- @mandb_section = options.mandb_section || "3-rdoc"
31
- @output_directory = File.expand_path(File.join(options.op_dir, "man", "man#{mandb_section.split('-').first}"))
29
+ @mandb_section = sanitize_mandb_section(
30
+ options.mandb_section || "3-rdoc",
31
+ )
32
+ @output_directory = File.expand_path(File.join(options.op_dir, "man#{mandb_section.split('-').first}"))
32
33
  FileUtils.mkdir_p output_directory
33
34
  end
34
35
 
@@ -36,7 +37,7 @@ class RDoc::Generator::Mdoc
36
37
  # Generate man pages.
37
38
  #
38
39
  # Every class, module and method gets their own man page in the
39
- # "man/manSECTION_PREFIX" subdirectory of the output directory.
40
+ # "manSECTION_PREFIX" subdirectory of the output directory.
40
41
  def generate
41
42
  generate_class_and_module_pages
42
43
  generate_method_pages
@@ -81,7 +82,18 @@ class RDoc::Generator::Mdoc
81
82
  end
82
83
 
83
84
  def file_name(object)
84
- File.join(output_directory, "#{object.full_name}.#{mandb_section}")
85
+ File.join(
86
+ output_directory,
87
+ "#{sanitize_file_name(object.full_name)}.#{mandb_section}",
88
+ )
89
+ end
90
+
91
+ def sanitize_file_name(string)
92
+ string.gsub("/", "\\")
93
+ end
94
+
95
+ def sanitize_mandb_section(string)
96
+ string.gsub(".", "-")
85
97
  end
86
98
 
87
99
  def render_template(template, assigns)
@@ -25,7 +25,7 @@ class RDoc::Generator::Mdoc
25
25
  private
26
26
 
27
27
  def comment
28
- @comment ||= Comment.new(rdoc_attribute.comment.text)
28
+ @comment ||= Comment.new(rdoc_attribute.comment)
29
29
  end
30
30
 
31
31
  attr_reader :rdoc_attribute
@@ -4,7 +4,9 @@ require "rdoc/generator/mdoc/module"
4
4
  class RDoc::Generator::Mdoc
5
5
  class Class < Module
6
6
  def superclass
7
- if rdoc_class.superclass.is_a? String
7
+ if rdoc_class.superclass.nil?
8
+ UnknownClass.new("Object")
9
+ elsif rdoc_class.superclass.is_a? String
8
10
  UnknownClass.new(rdoc_class.superclass)
9
11
  else
10
12
  self.class.new(rdoc_class.superclass, mandb_section)
@@ -3,8 +3,17 @@ require "rdoc/generator/mdoc/formatter"
3
3
 
4
4
  class RDoc::Generator::Mdoc
5
5
  class Comment
6
- def initialize(markup)
7
- @markup = markup
6
+ def initialize(comment)
7
+ case comment
8
+ when RDoc::Markup::Document
9
+ @rdoc_document = comment
10
+ when RDoc::Comment
11
+ @markup = comment.text
12
+ when String
13
+ @markup = comment
14
+ else
15
+ raise "Can't handle input of class: #{comment.class}"
16
+ end
8
17
  end
9
18
 
10
19
  def first_paragraph
@@ -27,7 +27,7 @@ class RDoc::Generator::Mdoc
27
27
  attr_reader :rdoc_constant
28
28
 
29
29
  def comment
30
- @comment ||= Comment.new(rdoc_constant.comment.text)
30
+ @comment ||= Comment.new(rdoc_constant.comment)
31
31
  end
32
32
  end
33
33
  end
@@ -21,13 +21,13 @@ class RDoc::Generator::Mdoc
21
21
  # > Typical syntax is shown in the first content macro displayed below,
22
22
  # > ‘.Ad’.
23
23
  def escape(string)
24
- string.gsub(%r|[+\-/*%<>=&`'"]|, '\\\&\0')
24
+ string.to_s.gsub(%r|[+\-/*%<>=&`'"]|, '\\\&\0')
25
25
  end
26
26
 
27
27
  ##
28
28
  # Returns a new string enclosed in double quotes.
29
29
  def quote(string)
30
- string.gsub(/^|$/, '"')
30
+ string.to_s.gsub(/^|$/, '"')
31
31
  end
32
32
  end
33
33
  end
@@ -24,7 +24,7 @@ class RDoc::Generator::Mdoc
24
24
  end
25
25
 
26
26
  def parameters
27
- rdoc_method.params.gsub(/[\(\)]/, '').split(", ")
27
+ rdoc_method.params.to_s.gsub(/[\(\)]/, '').split(", ")
28
28
  end
29
29
 
30
30
  def short_description
@@ -66,7 +66,7 @@ class RDoc::Generator::Mdoc
66
66
 
67
67
  def source
68
68
  @source ||= rdoc_method.token_stream &&
69
- strip_source_file_path(rdoc_method.tokens_to_s)
69
+ strip_source_file_path(extract_source(rdoc_method.token_stream))
70
70
  end
71
71
 
72
72
  def alias?
@@ -109,7 +109,7 @@ class RDoc::Generator::Mdoc
109
109
  end
110
110
 
111
111
  def comment
112
- @comment ||= Comment.new(rdoc_method.comment.text)
112
+ @comment ||= Comment.new(rdoc_method.comment)
113
113
  end
114
114
 
115
115
  def extract_invocation_examples(call_seq)
@@ -125,5 +125,9 @@ class RDoc::Generator::Mdoc
125
125
  def strip_source_file_path(source)
126
126
  source.lines[1..-1].join
127
127
  end
128
+
129
+ def extract_source(token_stream)
130
+ token_stream.compact.map { |t| t.text }.join('')
131
+ end
128
132
  end
129
133
  end
@@ -54,21 +54,27 @@ class RDoc::Generator::Mdoc
54
54
  rdoc_constants,
55
55
  rdoc_attributes,
56
56
  mandb_section,
57
+ self,
57
58
  )
58
59
  end
59
60
  end
60
61
 
62
+ def methods_by_type(section)
63
+ rdoc_module.methods_by_type(section)
64
+ end
65
+
61
66
  private
62
67
 
63
68
  def comment
64
- @comment ||= Comment.new(markup)
69
+ @comment ||= if rdoc_module.comment_location.is_a? RDoc::Markup::Document
70
+ Comment.new(rdoc_module.comment_location)
71
+ else
72
+ Comment.new(extract_markup(rdoc_module.comment_location))
73
+ end
65
74
  end
66
75
 
67
- def markup
68
- rdoc_module.
69
- comment_location.
70
- map { |rdoc_comment, _| rdoc_comment.text }.
71
- join("\n")
76
+ def extract_markup(comment_location)
77
+ comment_location.map { |rdoc_comment, _| rdoc_comment.text }.join("\n")
72
78
  end
73
79
 
74
80
  def decorate_rdoc_mixins(rdoc_mixins)
@@ -9,11 +9,18 @@ class RDoc::Generator::Mdoc
9
9
  [:class, :instance]
10
10
  end
11
11
 
12
- def initialize(rdoc_section, rdoc_constants, rdoc_attributes, mandb_section)
12
+ def initialize(
13
+ rdoc_section,
14
+ rdoc_constants,
15
+ rdoc_attributes,
16
+ mandb_section,
17
+ parent
18
+ )
13
19
  @rdoc_section = rdoc_section
14
20
  @rdoc_constants = rdoc_constants
15
21
  @rdoc_attributes = rdoc_attributes
16
22
  @mandb_section = mandb_section
23
+ @parent = parent
17
24
  end
18
25
 
19
26
  def titled?
@@ -51,12 +58,13 @@ class RDoc::Generator::Mdoc
51
58
  def methods_of_type(type)
52
59
  @methods_of_type ||= {}
53
60
  @methods_of_type[type] ||=
54
- rdoc_section.
55
61
  parent.
56
62
  methods_by_type(rdoc_section)[type.to_s].
57
63
  flat_map do |visibility, rdoc_methods|
58
- rdoc_methods.map do
59
- |rdoc_method| Method.new(rdoc_method, mandb_section, visibility)
64
+ rdoc_methods.select do |rdoc_method|
65
+ rdoc_method.is_a? RDoc::AnyMethod
66
+ end.map do |rdoc_method|
67
+ Method.new(rdoc_method, mandb_section, visibility)
60
68
  end
61
69
  end
62
70
  end
@@ -64,14 +72,14 @@ class RDoc::Generator::Mdoc
64
72
  private
65
73
 
66
74
  attr_reader :rdoc_section, :rdoc_constants, :rdoc_attributes,
67
- :mandb_section
68
-
69
- def markup
70
- rdoc_section.comments.map(&:normalize).map(&:text).join
71
- end
75
+ :mandb_section, :parent
72
76
 
73
77
  def comment
74
- @comment ||= Comment.new(markup)
78
+ @comment ||= if rdoc_section.comments.is_a? RDoc::Markup::Document
79
+ Comment.new(rdoc_section.comments)
80
+ else
81
+ Comment.new(rdoc_section.comments.map(&:normalize).map(&:text).join)
82
+ end
75
83
  end
76
84
  end
77
85
  end
@@ -1,10 +1,6 @@
1
- lib = File.expand_path("../lib", __FILE__)
2
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
- require "rdoc/generator/mdoc/version"
4
-
5
1
  Gem::Specification.new do |spec|
6
2
  spec.name = "rdoc-generator-mdoc"
7
- spec.version = RDoc::Generator::Mdoc::VERSION
3
+ spec.version = "0.0.3"
8
4
  spec.authors = ["Calle Erlandsson", "Mike Burns"]
9
5
  spec.email = ["calle@thoughtbot.com", "hello@thoughtbot.com"]
10
6
  spec.summary = "An mdoc(7) generator for RDoc"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdoc-generator-mdoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Calle Erlandsson
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-08-07 00:00:00.000000000 Z
12
+ date: 2014-08-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -94,7 +94,6 @@ files:
94
94
  - lib/rdoc/generator/mdoc/section.rb
95
95
  - lib/rdoc/generator/mdoc/unknown_class.rb
96
96
  - lib/rdoc/generator/mdoc/unknown_module.rb
97
- - lib/rdoc/generator/mdoc/version.rb
98
97
  - rdoc-generator-mdoc.gemspec
99
98
  - templates/method.mdoc.erb
100
99
  - templates/module.mdoc.erb
@@ -1,7 +0,0 @@
1
- module RDoc
2
- module Generator
3
- class Mdoc
4
- VERSION = "0.0.1"
5
- end
6
- end
7
- end