markdown_ruby_documentation 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0195aa8a642b4e01747ef74e449c4a0e0195fcc5
4
- data.tar.gz: c752bf835f1c6fbf3bbf5ed968cc35a3810bb930
3
+ metadata.gz: a68bd5fe5f99c18c45c27e6181f8496cfeebb5d7
4
+ data.tar.gz: 09a1174ba49e82834e7aca0daffb530f7a685d12
5
5
  SHA512:
6
- metadata.gz: a736068cff89585b1efa8dbce9dc0854effea63f90a38819dbe75c406594240824162f0e297c6095054e65824caeae4abf47f19d76fecafc7b445caa9566ca92
7
- data.tar.gz: c2ce815983eb44535d554e0599a61588a9f1d7adff1892ad52330f3256fb6eb7a28575af2a198aa625de755f34e3483df4f920dc1aa1ad4e6f32c81673d2dd5b
6
+ metadata.gz: 8f8121c1c700e8a563a107cecb0186c74bce3e4f9437f5eb6466a5f3da223ee2ff8efd05767420065d169ef90f403a1110ee4c0bf6ca0f981720bb5c02711458
7
+ data.tar.gz: afccbc3dc8db8ce1fd535207b70500e9998e0a6ea4c61e0e8d77b8b4a72110a1480cedb717b4d8e3b468fc4dca1c67bf2898f1ac1731412d61318fc71a622ac5
@@ -0,0 +1,54 @@
1
+ module MarkdownRubyDocumentation
2
+ class ClassLevelComment
3
+ attr_reader :subject
4
+ include TemplateParser::Parsing
5
+ def initialize(subject)
6
+ @subject = subject
7
+ end
8
+
9
+ def call(interface)
10
+ _method = interface.reject do |_, meth|
11
+ meth[:method_object].is_a?(NullMethod)
12
+ end.first
13
+ if _method
14
+ filename, lineno = _method[1][:method_object].to_proc.source_location
15
+ comment = extract_dsl_comment(strip_comment_hash(comment(filename, lineno)+"\n"))
16
+ interface[:class_level_comment] = { text: comment }
17
+ end
18
+ interface
19
+ end
20
+
21
+ def comment(filename, lineno)
22
+ method_to_top_of_file = File.read(filename).split("\n")[0..(lineno-1)]
23
+ subject_start_line = find_start_of_subject(method_to_top_of_file, filename)
24
+ extract_last_comment(method_to_top_of_file[0..(subject_start_line-1)].reverse).reverse.join("\n")
25
+ end
26
+
27
+ def find_start_of_subject(method_to_top_of_file, filename)
28
+ method_to_top_of_file.each_with_index do |line, index|
29
+ if line =~ /#{subject.class.to_s.downcase} #{subject.name.split("::").last}/
30
+ return index
31
+ end
32
+ end
33
+ puts /#{subject.class} #{subject.name.split("::").last}/
34
+ puts method_to_top_of_file
35
+ raise "class #{subject.name} not found in #{filename}"
36
+ end
37
+
38
+ def extract_last_comment(lines)
39
+ buffer = []
40
+
41
+ lines.each do |line|
42
+ # Add any line that is a valid ruby comment,
43
+ # but clear as soon as we hit a non comment line.
44
+ if line =~ /^\s*#/
45
+ buffer << line.lstrip
46
+ else
47
+ return buffer
48
+ end
49
+ end
50
+
51
+ buffer
52
+ end
53
+ end
54
+ end
@@ -90,6 +90,7 @@ module MarkdownRubyDocumentation
90
90
  RejectBlankMethod,
91
91
  GitHubLink.new(subject: subject),
92
92
  ConstantsPresenter.new(subject),
93
+ ClassLevelComment.new(subject),
93
94
  MarkdownPresenter.new(summary: summary, title_key: section_key),
94
95
  ]
95
96
  end
@@ -14,7 +14,11 @@ module MarkdownRubyDocumentation
14
14
  def call(items=nil)
15
15
  @items ||= items
16
16
  return "" if nothing_to_display?
17
- md = ["# #{summary.title}", "#{summary.summary}\n".gsub(/\n\n\n/, "\n\n"), instances_methods, class_methods, "#{null_methods}\n".gsub(/\n\n\n/, "\n\n")].join("\n").gsub(/[\n]+\Z/, "\n\n")
17
+ md = ["# #{summary.title}", "#{summary.summary}\n".gsub(/\n\n\n/, "\n\n"), class_level_comment, instances_methods, class_methods, "#{null_methods}\n".gsub(/\n\n\n/, "\n\n")]
18
+ .reject(&:empty?)
19
+ .join("\n")
20
+ .gsub(/[\n]{3,}/, "\n\n")
21
+ .gsub(/[\n]+\Z/, "\n\n")
18
22
  other_types!
19
23
  md
20
24
  end
@@ -25,6 +29,16 @@ module MarkdownRubyDocumentation
25
29
  @item_types ||= items.group_by { |_, hash| hash[:method_object].class.name }
26
30
  end
27
31
 
32
+ def class_level_comment
33
+ @class_level_comment ||= (items.delete(:class_level_comment) || {})
34
+
35
+ if @class_level_comment[:text]
36
+ "#{@class_level_comment[:text]}\n"
37
+ else
38
+ ""
39
+ end
40
+ end
41
+
28
42
  def instances_methods
29
43
  @instance_methods ||= item_types.delete("MarkdownRubyDocumentation::InstanceMethod") || {}
30
44
  @instance_methods.map do |name, hash|
@@ -47,7 +61,7 @@ module MarkdownRubyDocumentation
47
61
  if md.blank?
48
62
  ""
49
63
  else
50
- "## Reference Values\n" << md
64
+ "\n## Reference Values\n" << md
51
65
  end
52
66
  end
53
67
 
@@ -56,7 +70,7 @@ module MarkdownRubyDocumentation
56
70
  end
57
71
 
58
72
  def nothing_to_display?
59
- [instances_methods, class_methods, null_methods].all?(&:empty?)
73
+ [class_level_comment, instances_methods, class_methods, null_methods].all?(&:empty?)
60
74
  end
61
75
  end
62
76
  end
@@ -1,32 +1,34 @@
1
- class Summary
2
- attr_reader :erb_methods_class, :subject
1
+ module MarkdownRubyDocumentation
2
+ class Summary
3
+ attr_reader :erb_methods_class, :subject
3
4
 
4
- def initialize(subject:, erb_methods_class:)
5
- @subject = subject
6
- @erb_methods_class = erb_methods_class
7
- end
5
+ def initialize(subject:, erb_methods_class:)
6
+ @subject = subject
7
+ @erb_methods_class = erb_methods_class
8
+ end
8
9
 
9
- def title
10
- ancestors = subject.ancestors.select do |klass|
11
- klass.is_a?(Class) && ![BasicObject, Object, subject].include?(klass)
12
- end.sort_by { |klass| klass.name }
13
- [format_class(subject), *ancestors.map { |a| create_link(a) }].join(" < ")
14
- end
10
+ def title
11
+ ancestors = subject.ancestors.select do |klass|
12
+ klass.is_a?(Class) && ![BasicObject, Object, subject].include?(klass)
13
+ end.sort_by { |klass| klass.name }
14
+ [format_class(subject), *ancestors.map { |a| create_link(a) }].join(" < ")
15
+ end
15
16
 
16
- def summary
17
- descendants = ObjectSpace.each_object(Class).select { |klass| klass < subject && !klass.name.include?("InstanceToClassMethods") }.sort_by { |klass| klass.name }
17
+ def summary
18
+ descendants = ObjectSpace.each_object(Class).select { |klass| klass < subject && !klass.name.include?("InstanceToClassMethods") }.sort_by { |klass| klass.name }
18
19
 
19
- descendants_links = descendants.map { |d| create_link(d) }.join(", ")
20
- "Descendants: #{descendants_links}" if descendants.count >= 1
21
- end
20
+ descendants_links = descendants.map { |d| create_link(d) }.join(", ")
21
+ "Descendants: #{descendants_links}" if descendants.count >= 1
22
+ end
22
23
 
23
- private
24
+ private
24
25
 
25
- def create_link(klass)
26
- erb_methods_class.link_to_markdown(klass.to_s, title: format_class(klass))
27
- end
26
+ def create_link(klass)
27
+ erb_methods_class.link_to_markdown(klass.to_s, title: format_class(klass))
28
+ end
28
29
 
29
- def format_class(klass)
30
- klass.name.titleize.split("/").last
30
+ def format_class(klass)
31
+ klass.name.titleize.split("/").last
32
+ end
31
33
  end
32
34
  end
@@ -1,3 +1,3 @@
1
1
  module MarkdownRubyDocumentation
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -18,6 +18,7 @@ require "markdown_ruby_documentation/method/null_method"
18
18
  require "markdown_ruby_documentation/write_markdown_to_disk"
19
19
  require "markdown_ruby_documentation/default_erb_methods"
20
20
  require "markdown_ruby_documentation/constants_presenter"
21
+ require "markdown_ruby_documentation/class_level_comment"
21
22
  require "ruby-progressbar"
22
23
  require "active_support/core_ext/string"
23
24
  require "method_source"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: markdown_ruby_documentation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dustin Zeisler
@@ -115,6 +115,7 @@ files:
115
115
  - bin/setup
116
116
  - lib/github-markdown.css
117
117
  - lib/markdown_ruby_documentation.rb
118
+ - lib/markdown_ruby_documentation/class_level_comment.rb
118
119
  - lib/markdown_ruby_documentation/constants_presenter.rb
119
120
  - lib/markdown_ruby_documentation/default_erb_methods.rb
120
121
  - lib/markdown_ruby_documentation/generate.rb