markdown_ruby_documentation 0.8.0 → 0.9.0

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: da10c03a7f12fb025a7db239f90eb3f64048b539
4
- data.tar.gz: 78ee42c083c248f85c70acd89b45943fb501d103
3
+ metadata.gz: 89c92e0b3d12b3f80da67905864c6f5b7a31cd79
4
+ data.tar.gz: 15c908a0de16d99f4baf8b03d4f66f58416bb242
5
5
  SHA512:
6
- metadata.gz: 9f63f39ef70eec9ad9c8c26e0b5a39800fe8e44ea74dd0b13eb960b10d843767d5acdbe8338d4b5ad25ef48a942cf8fa44cdcd99990fb85284f3e6aab009060e
7
- data.tar.gz: 494a8f0a5d00dc2e27b3624e398afc09c9467d3a04ef7bf1fb08b8b4dc7e1c52332b9fa0c7536f8596cd680d8eda07c4932a8ca3087bab7037566f62e7af87ec
6
+ metadata.gz: 5bc675cf2689ed27296c5c22fa8224590a1ae71beee02ae189461985a57d6a353ee52b50b211bd72747cc5a88803633141bebf67c3bf7cc0f6f31b3901e36718
7
+ data.tar.gz: 8de69ad32561270e855092dbf111066c9c7de1deffad0f548b642d43ba59d494ad885b84b4e3238c8c2521d6697f42feb0bc5707fa84587bc007d956eb6e47c4
data/README.md CHANGED
@@ -77,6 +77,14 @@ Creates a url to the method location on GitHub based on the current sha or it de
77
77
  ##### `git_hub_file_url(file_path || Class)`
78
78
  Creates a url to the file on GitHub based on the current sha or it defaults to master.
79
79
 
80
+ ##### `link_to_markdown` or `link_to`(klass_or_path, title: String)
81
+ @param [Class, String, Pathname] klass_or_path
82
+ 1. String or Class representing a method reference
83
+ 2. Pathname representing the full path of the file location a method is defined
84
+ @param [String] title is the link display value
85
+ @return [String, Symbol] Creates link to a given generated markdown file or returns :non_project_location message.
86
+ 1. "[title](path/to/markdown/file.md#method-name)"
87
+ 2. :non_project_location
80
88
 
81
89
  ##### Example method reference inputs
82
90
 
@@ -11,6 +11,7 @@ require "markdown_ruby_documentation/git_hub_link"
11
11
  require "markdown_ruby_documentation/git_hub_project"
12
12
  require "markdown_ruby_documentation/reject_blank_methods"
13
13
  require "markdown_ruby_documentation/method_linker"
14
+ require "markdown_ruby_documentation/relative_link_converter"
14
15
  require "markdown_ruby_documentation/method"
15
16
  require "markdown_ruby_documentation/method/instance_method"
16
17
  require "markdown_ruby_documentation/method/class_method"
@@ -115,6 +115,7 @@ module MarkdownRubyDocumentation
115
115
  def string_pipeline
116
116
  [
117
117
  MethodLinker.new(section_key: section_key, root_path: "./"),
118
+ RelativeLinkConverter.new(subject: subject),
118
119
  ]
119
120
  end
120
121
 
@@ -4,7 +4,6 @@ module MarkdownRubyDocumentation
4
4
  attr_reader :text, :section_key, :root_path
5
5
 
6
6
  def initialize(section_key:, root_path:)
7
-
8
7
  @section_key = section_key
9
8
  @root_path = root_path
10
9
  end
@@ -0,0 +1,43 @@
1
+ module MarkdownRubyDocumentation
2
+ class RelativeLinkConverter
3
+ attr_reader :text, :root_path, :subject
4
+
5
+ def initialize(subject:)
6
+ @root_path = root_path
7
+ @subject = subject
8
+ end
9
+
10
+ def call(text=nil)
11
+ @text = text
12
+ generate
13
+ end
14
+
15
+ def generate
16
+ text.scan(/\[.*\]\((.*)\)/).each do |r|
17
+ link = r.first
18
+ if link.include?(path.to_s)
19
+ @text = text.gsub(link, create_relative_link(link))
20
+ end
21
+ end
22
+ text
23
+ end
24
+
25
+ def path
26
+ @path ||= begin
27
+ method = MarkdownRubyDocumentation::Method.create(subject.name, null_method: true, context: Kernel)
28
+ parts = method.context_name.to_s.split("::").reject(&:blank?)
29
+ path = parts.map { |p| p.underscore }.join("/")
30
+ path = "#{path}.md#{method.type_symbol}#{method.name}"
31
+ MarkdownRubyDocumentation::GitHubLink::FileUrl.new(file_path: File.join(MarkdownRubyDocumentation::Generate.output_object.relative_dir, path)).to_s
32
+ end
33
+ end
34
+
35
+ def create_relative_link(link)
36
+ if link.include?("#")
37
+ "#" + link.split("#").last
38
+ else
39
+ link
40
+ end
41
+ end
42
+ end
43
+ end
@@ -251,7 +251,7 @@ module MarkdownRubyDocumentation
251
251
  # @return [String, Symbol] Creates link to a given generated markdown file or returns :non_project_location message.
252
252
  # 1. "[title](path/to/markdown/file.md#method-name)"
253
253
  # 2. :non_project_location
254
- def link_to_markdown(klass_or_path, title:, _ruby_class: ruby_class)
254
+ def link_to_markdown(klass_or_path, _ruby_class: ruby_class, title: default_title(klass_or_path, _ruby_class))
255
255
  if klass_or_path.is_a?(String) || klass_or_path.is_a?(Class) || klass_or_path.is_a?(Module)
256
256
  link_to_markdown_method_reference(method_reference: klass_or_path, title: title, ruby_class: _ruby_class)
257
257
  elsif klass_or_path.is_a?(Pathname)
@@ -261,6 +261,17 @@ module MarkdownRubyDocumentation
261
261
  end
262
262
  end
263
263
 
264
+ alias_method :link_to, :link_to_markdown
265
+
266
+ def default_title(klass_or_path, _ruby_class)
267
+ method = MarkdownRubyDocumentation::Method.create(klass_or_path, null_method: true, context: _ruby_class)
268
+ if method.name
269
+ method.name
270
+ else
271
+ method.context_name.to_s.demodulize
272
+ end.to_s.titleize
273
+ end
274
+
264
275
  def link_to_markdown_method_reference(method_reference:, title:, ruby_class:)
265
276
  method = MarkdownRubyDocumentation::Method.create(method_reference, null_method: true, context: ruby_class)
266
277
  parts = method.context_name.to_s.split("::").reject(&:blank?)
@@ -1,3 +1,3 @@
1
1
  module MarkdownRubyDocumentation
2
- VERSION = "0.8.0"
2
+ VERSION = "0.9.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: markdown_ruby_documentation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dustin Zeisler
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-08-23 00:00:00.000000000 Z
11
+ date: 2016-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: method_source
@@ -128,6 +128,7 @@ files:
128
128
  - lib/markdown_ruby_documentation/method/null_method.rb
129
129
  - lib/markdown_ruby_documentation/method_linker.rb
130
130
  - lib/markdown_ruby_documentation/reject_blank_methods.rb
131
+ - lib/markdown_ruby_documentation/relative_link_converter.rb
131
132
  - lib/markdown_ruby_documentation/summary.rb
132
133
  - lib/markdown_ruby_documentation/template_parser.rb
133
134
  - lib/markdown_ruby_documentation/template_parser/any_args.rb