yard-aggredator 0.9.9

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2329a8840dfbf9198aa25a5df489948156b7dbdbb4b84ee162ad6587dc40fbb9
4
+ data.tar.gz: 29fc1c6f471c11aa96ba7b1bb511c0055d3cee540e759e2b84a7d5b5dfa18d04
5
+ SHA512:
6
+ metadata.gz: e23f535d3f9904679d4afdd5fe4ed712585b68cf099cb778e88aaad8f12e07c63e32e3eea5a0eb67c1c326276cb2507c05b250288bdd99d82d9137e03006f081
7
+ data.tar.gz: 6df5884a9b8351aefeec9ccd13df5533186d3510950977c9f30bb74ae078bc40e843cf128f95327d10648f085710a4713280afc5b3e545352c99e3b9d7d7d9e1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Ivan Godko
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
File without changes
@@ -0,0 +1,146 @@
1
+ require 'json'
2
+ require 'coderay'
3
+
4
+ YARD::Templates::Helpers::MarkupHelper::MARKUP_PROVIDERS[:plain] = []
5
+ YARD::Templates::Helpers::MarkupHelper::MARKUP_EXTENSIONS[:plain] = %w[json txt text mermaid]
6
+
7
+ module YARD
8
+ module Aggredator
9
+ module Helper
10
+ def htmlify(text, markup = options.markup)
11
+ detected_markup = plain_detect_markup(@current_linking_file || @file&.filename, markup)
12
+
13
+ return super if detected_markup == :markdown
14
+
15
+ if (detected_markup || %i[plain text
16
+ mermaid].include?(markup)) && text && respond_to?(:plain_pretty_include)
17
+ return plain_pretty_include(text, detected_markup, markup)
18
+ end
19
+
20
+ super
21
+ end
22
+
23
+ def plain_detect_markup(file, markup)
24
+ return nil unless file
25
+
26
+ case File.extname(file).downcase
27
+ when '.json'
28
+ :json
29
+ when '.txt', '.text', '.csv'
30
+ :text
31
+ when '.mermaid'
32
+ :mermaid
33
+ else
34
+ markup.to_sym
35
+ end
36
+ end
37
+
38
+ def html_syntax_highlight_mermaid(source)
39
+ # html="
40
+ # <script type=\"module\">
41
+ # import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.esm.min.mjs';
42
+ # mermaid.initialize({ startOnLoad: false });
43
+ # window.onload = function(){mermaid.init()};
44
+ # </script><pre class=\"mermaid\">#{source}</pre>
45
+ # "
46
+ "<pre class=\"mermaid\">#{source}</pre>"
47
+ end
48
+
49
+ def plain_pretty_include(text, detected_markup, markup)
50
+ markup = detected_markup || markup
51
+
52
+ pretty = case markup
53
+ when :json
54
+ begin
55
+ JSON.pretty_generate(JSON.parse(text))
56
+ rescue StandardError
57
+ text
58
+ end
59
+ else
60
+ text
61
+ end
62
+
63
+ # html = "<pre>#{pretty}</pre>"
64
+ html = "<pre>\t!!!#{markup}\n#{pretty}</pre>"
65
+ if @file
66
+ # we are inside server layout rendering
67
+ parse_codeblocks(html)
68
+ else
69
+ html
70
+ end
71
+ end
72
+
73
+ def parse_codeblocks(html)
74
+ html.gsub(%r{<pre((?:\s+\w+="(?:.+?)")*)\s*>(?:\s*<code((?:\s+\w+="(?:.+?)")*)\s*>)?(.+?)(?:</code>\s*)?</pre>}m) do
75
+ string = ::Regexp.last_match(3)
76
+
77
+ # handle !!!LANG prefix to send to html_syntax_highlight_LANG
78
+ language, = parse_lang_for_codeblock(string)
79
+ language ||= detect_lang_in_codeblock_attributes(::Regexp.last_match(1), ::Regexp.last_match(2))
80
+ language ||= object.source_type
81
+
82
+ string = html_syntax_highlight(CGI.unescapeHTML(string), language) if options.highlight
83
+
84
+ if language == 'mermaid'
85
+ string
86
+ else
87
+ classes = ['code', language].compact.join(' ')
88
+ %(<pre class="#{classes}"><code class="#{language}">#{string}</code></pre>)
89
+ end
90
+ end
91
+ end
92
+
93
+ def link_include_file(file)
94
+ @current_linking_file = file
95
+ super
96
+ ensure
97
+ @current_linking_file = nil
98
+ end
99
+
100
+ def linkify(*args)
101
+ if args.first.is_a?(String) && /^link:file:(\S+)/.match(args.first)
102
+ file = ::Regexp.last_match(1)
103
+ relpath = File.relative_path(Dir.pwd, File.expand_path(file))
104
+ if serializer.class == YARD::Serializers::FileSystemSerializer
105
+ link_url(url_for(relpath), args[1])
106
+ else
107
+ link_file(relpath, args[1])
108
+ end
109
+ else
110
+ super
111
+ end
112
+ end
113
+
114
+ # Это рабочий код, но он меняет стандартное поведение
115
+ # def link_file(filename, title = nil, anchor = nil)
116
+ # return super unless serializer.class == YARD::Serializers::FileSystemSerializer
117
+
118
+ # if YARD::CodeObjects::ExtraFileObject === filename
119
+ # file = filename
120
+ # else
121
+ # contents = File.file?(filename) ? nil : ''
122
+ # relpath = File.relative_path(Dir.pwd, File.expand_path(filename))
123
+ # file = YARD::CodeObjects::ExtraFileObject.new(filename, contents)
124
+ # file.send(:ensure_parsed)
125
+ # return link_url(url_for(relpath), title || file.title)
126
+ # end
127
+
128
+ # super
129
+ # end
130
+ end
131
+ end
132
+
133
+ module ExtraFileObjectPatch
134
+ def initialize(*args)
135
+ super
136
+ dirname = File.dirname(filename).strip.gsub('/', '_')
137
+ return unless !['', '.', '..'].include?(dirname) && !name[dirname]
138
+
139
+ self.name = "#{dirname}_#{name}"
140
+ end
141
+ end
142
+ end
143
+
144
+ ::YARD::Templates::Engine.register_template_path(File.dirname(__FILE__) + '/../../../templates')
145
+ ::YARD::Templates::Template.extra_includes << ::YARD::Aggredator::Helper
146
+ ::YARD::CodeObjects::ExtraFileObject.prepend(::YARD::ExtraFileObjectPatch)
@@ -0,0 +1,5 @@
1
+ module YARD
2
+ module Aggredator
3
+ VERSION = '0.9.9'
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ require 'yard'
2
+
3
+ require_relative 'yard/aggredator/version'
4
+ require_relative 'yard/aggredator/plugin'
@@ -0,0 +1 @@
1
+ require_relative 'yard-aggredator'