middleman-mdocs 0.1.0.62562
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +224 -0
- data/README.md +3 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/middleman-mdocs/controller.rb +95 -0
- data/lib/middleman-mdocs/extension.rb +148 -0
- data/lib/middleman-mdocs/navigation.rb +134 -0
- data/lib/middleman-mdocs/resource.rb +75 -0
- data/lib/middleman-mdocs/sitemap.rb +4 -0
- data/lib/middleman-mdocs/tilt_template.rb +13 -0
- data/lib/middleman-mdocs/toc.rb +78 -0
- data/lib/middleman-mdocs/version.rb +5 -0
- data/lib/middleman-mdocs.rb +8 -0
- metadata +227 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8a178d824ca8aa52558c1d79e3caa57d591f7ca6061de94e7aa7bf8beb2deac5
|
4
|
+
data.tar.gz: 3ae7963d4b26818877c8263dd682d7da4e425cad6eea79d0910c0218b870a8d8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9e8662688f936f346461d76a3c02e531de5330ac1d99edcfe9cd44a61ce4fdbde488e1c918d00b00c51559f83532cf898af5ce8238761d66412fbc87e3bf8135
|
7
|
+
data.tar.gz: 151d8aa1ba4f99207382b1e976b1c28daecdf8618d578b6221952802f071b0fae09782a97ffed92d30bb986adef2c3d6488b56c2fc33f44b2b5a2eac451f7202
|
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in mdocs.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
gem 'rake', '~> 13.0'
|
9
|
+
gem 'simplecov', '~> 0.21'
|
10
|
+
gem 'rspec', '~> 3.10'
|
11
|
+
gem 'rspec_junit_formatter', '~> 0.4'
|
12
|
+
gem 'simplecov-console'
|
13
|
+
|
14
|
+
gem 'rubocop', require: false
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,224 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
middleman-mdocs (0.1.0.62562)
|
5
|
+
activesupport
|
6
|
+
awesome_print
|
7
|
+
kramdown
|
8
|
+
mdocs_kramdown
|
9
|
+
middleman (~> 4.3.11)
|
10
|
+
middleman-imageoptim
|
11
|
+
middleman-search
|
12
|
+
nokogiri
|
13
|
+
redcarpet
|
14
|
+
russian
|
15
|
+
slim
|
16
|
+
stringex
|
17
|
+
|
18
|
+
GEM
|
19
|
+
remote: https://rubygems.org/
|
20
|
+
specs:
|
21
|
+
activesupport (5.2.6)
|
22
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
23
|
+
i18n (>= 0.7, < 2)
|
24
|
+
minitest (~> 5.1)
|
25
|
+
tzinfo (~> 1.1)
|
26
|
+
addressable (2.8.0)
|
27
|
+
public_suffix (>= 2.0.2, < 5.0)
|
28
|
+
ansi (1.5.0)
|
29
|
+
asciidoctor (2.0.16)
|
30
|
+
asciidoctor-plantuml (0.0.12)
|
31
|
+
asciidoctor (>= 1.5.6, < 3.0.0)
|
32
|
+
ast (2.4.2)
|
33
|
+
awesome_print (1.9.2)
|
34
|
+
backports (3.21.0)
|
35
|
+
coffee-script (2.4.1)
|
36
|
+
coffee-script-source
|
37
|
+
execjs
|
38
|
+
coffee-script-source (1.12.2)
|
39
|
+
concurrent-ruby (1.1.9)
|
40
|
+
contracts (0.13.0)
|
41
|
+
diff-lcs (1.4.4)
|
42
|
+
docile (1.4.0)
|
43
|
+
dotenv (2.7.6)
|
44
|
+
erubis (2.7.0)
|
45
|
+
execjs (2.8.1)
|
46
|
+
exifr (1.3.9)
|
47
|
+
fast_blank (1.0.1)
|
48
|
+
fastimage (2.2.5)
|
49
|
+
ffi (1.15.4)
|
50
|
+
fspath (3.1.2)
|
51
|
+
gitlab_kramdown (0.10.0)
|
52
|
+
asciidoctor-plantuml (= 0.0.12)
|
53
|
+
kramdown (~> 2.3.0)
|
54
|
+
nokogiri (~> 1.10.10)
|
55
|
+
rouge (~> 3.2)
|
56
|
+
haml (5.2.2)
|
57
|
+
temple (>= 0.8.0)
|
58
|
+
tilt
|
59
|
+
hamster (3.0.0)
|
60
|
+
concurrent-ruby (~> 1.0)
|
61
|
+
hashie (3.6.0)
|
62
|
+
i18n (0.9.5)
|
63
|
+
concurrent-ruby (~> 1.0)
|
64
|
+
image_optim (0.25.0)
|
65
|
+
exifr (~> 1.2, >= 1.2.2)
|
66
|
+
fspath (~> 3.0)
|
67
|
+
image_size (~> 1.5)
|
68
|
+
in_threads (~> 1.3)
|
69
|
+
progress (~> 3.0, >= 3.0.1)
|
70
|
+
image_optim_pack (0.2.3)
|
71
|
+
fspath (>= 2.1, < 4)
|
72
|
+
image_optim (~> 0.19)
|
73
|
+
image_size (1.5.0)
|
74
|
+
in_threads (1.5.4)
|
75
|
+
kramdown (2.3.1)
|
76
|
+
rexml
|
77
|
+
libv8 (3.16.14.19-x86_64-linux)
|
78
|
+
listen (3.0.8)
|
79
|
+
rb-fsevent (~> 0.9, >= 0.9.4)
|
80
|
+
rb-inotify (~> 0.9, >= 0.9.7)
|
81
|
+
mdocs_kramdown (0.1.1.47381)
|
82
|
+
gitlab_kramdown (~> 0)
|
83
|
+
memoist (0.16.2)
|
84
|
+
middleman (4.3.11)
|
85
|
+
coffee-script (~> 2.2)
|
86
|
+
haml (>= 4.0.5)
|
87
|
+
kramdown (>= 2.3.0)
|
88
|
+
middleman-cli (= 4.3.11)
|
89
|
+
middleman-core (= 4.3.11)
|
90
|
+
middleman-cli (4.3.11)
|
91
|
+
thor (>= 0.17.0, < 2.0)
|
92
|
+
middleman-core (4.3.11)
|
93
|
+
activesupport (>= 4.2, < 6.0)
|
94
|
+
addressable (~> 2.3)
|
95
|
+
backports (~> 3.6)
|
96
|
+
bundler
|
97
|
+
contracts (~> 0.13.0)
|
98
|
+
dotenv
|
99
|
+
erubis
|
100
|
+
execjs (~> 2.0)
|
101
|
+
fast_blank
|
102
|
+
fastimage (~> 2.0)
|
103
|
+
hamster (~> 3.0)
|
104
|
+
hashie (~> 3.4)
|
105
|
+
i18n (~> 0.9.0)
|
106
|
+
listen (~> 3.0.0)
|
107
|
+
memoist (~> 0.14)
|
108
|
+
padrino-helpers (~> 0.13.0)
|
109
|
+
parallel
|
110
|
+
rack (>= 1.4.5, < 3)
|
111
|
+
sassc (~> 2.0)
|
112
|
+
servolux
|
113
|
+
tilt (~> 2.0.9)
|
114
|
+
uglifier (~> 3.0)
|
115
|
+
middleman-imageoptim (0.3.0)
|
116
|
+
image_optim (~> 0.25.0)
|
117
|
+
image_optim_pack (~> 0.2.1)
|
118
|
+
middleman-cli
|
119
|
+
middleman-core (>= 3.1)
|
120
|
+
middleman-search (0.10.0)
|
121
|
+
middleman-core (>= 3.2)
|
122
|
+
nokogiri (~> 1.6)
|
123
|
+
therubyracer (~> 0.12.2)
|
124
|
+
mini_portile2 (2.4.0)
|
125
|
+
minitest (5.14.4)
|
126
|
+
nokogiri (1.10.10)
|
127
|
+
mini_portile2 (~> 2.4.0)
|
128
|
+
padrino-helpers (0.13.3.4)
|
129
|
+
i18n (~> 0.6, >= 0.6.7)
|
130
|
+
padrino-support (= 0.13.3.4)
|
131
|
+
tilt (>= 1.4.1, < 3)
|
132
|
+
padrino-support (0.13.3.4)
|
133
|
+
activesupport (>= 3.1)
|
134
|
+
parallel (1.21.0)
|
135
|
+
parser (3.0.2.0)
|
136
|
+
ast (~> 2.4.1)
|
137
|
+
progress (3.6.0)
|
138
|
+
public_suffix (4.0.6)
|
139
|
+
rack (2.2.3)
|
140
|
+
rainbow (3.0.0)
|
141
|
+
rake (13.0.6)
|
142
|
+
rb-fsevent (0.11.0)
|
143
|
+
rb-inotify (0.10.1)
|
144
|
+
ffi (~> 1.0)
|
145
|
+
redcarpet (3.5.1)
|
146
|
+
ref (2.0.0)
|
147
|
+
regexp_parser (2.1.1)
|
148
|
+
rexml (3.2.5)
|
149
|
+
rouge (3.26.1)
|
150
|
+
rspec (3.10.0)
|
151
|
+
rspec-core (~> 3.10.0)
|
152
|
+
rspec-expectations (~> 3.10.0)
|
153
|
+
rspec-mocks (~> 3.10.0)
|
154
|
+
rspec-core (3.10.1)
|
155
|
+
rspec-support (~> 3.10.0)
|
156
|
+
rspec-expectations (3.10.1)
|
157
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
158
|
+
rspec-support (~> 3.10.0)
|
159
|
+
rspec-mocks (3.10.2)
|
160
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
161
|
+
rspec-support (~> 3.10.0)
|
162
|
+
rspec-support (3.10.2)
|
163
|
+
rspec_junit_formatter (0.4.1)
|
164
|
+
rspec-core (>= 2, < 4, != 2.12.0)
|
165
|
+
rubocop (1.21.0)
|
166
|
+
parallel (~> 1.10)
|
167
|
+
parser (>= 3.0.0.0)
|
168
|
+
rainbow (>= 2.2.2, < 4.0)
|
169
|
+
regexp_parser (>= 1.8, < 3.0)
|
170
|
+
rexml
|
171
|
+
rubocop-ast (>= 1.9.1, < 2.0)
|
172
|
+
ruby-progressbar (~> 1.7)
|
173
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
174
|
+
rubocop-ast (1.11.0)
|
175
|
+
parser (>= 3.0.1.1)
|
176
|
+
ruby-progressbar (1.11.0)
|
177
|
+
russian (0.6.0)
|
178
|
+
i18n (>= 0.5.0)
|
179
|
+
sassc (2.4.0)
|
180
|
+
ffi (~> 1.9)
|
181
|
+
servolux (0.13.0)
|
182
|
+
simplecov (0.21.2)
|
183
|
+
docile (~> 1.1)
|
184
|
+
simplecov-html (~> 0.11)
|
185
|
+
simplecov_json_formatter (~> 0.1)
|
186
|
+
simplecov-console (0.9.1)
|
187
|
+
ansi
|
188
|
+
simplecov
|
189
|
+
terminal-table
|
190
|
+
simplecov-html (0.12.3)
|
191
|
+
simplecov_json_formatter (0.1.3)
|
192
|
+
slim (4.1.0)
|
193
|
+
temple (>= 0.7.6, < 0.9)
|
194
|
+
tilt (>= 2.0.6, < 2.1)
|
195
|
+
stringex (2.8.5)
|
196
|
+
temple (0.8.2)
|
197
|
+
terminal-table (3.0.2)
|
198
|
+
unicode-display_width (>= 1.1.1, < 3)
|
199
|
+
therubyracer (0.12.3)
|
200
|
+
libv8 (~> 3.16.14.15)
|
201
|
+
ref
|
202
|
+
thor (1.1.0)
|
203
|
+
thread_safe (0.3.6)
|
204
|
+
tilt (2.0.10)
|
205
|
+
tzinfo (1.2.9)
|
206
|
+
thread_safe (~> 0.1)
|
207
|
+
uglifier (3.2.0)
|
208
|
+
execjs (>= 0.3.0, < 3)
|
209
|
+
unicode-display_width (2.1.0)
|
210
|
+
|
211
|
+
PLATFORMS
|
212
|
+
x86_64-linux
|
213
|
+
|
214
|
+
DEPENDENCIES
|
215
|
+
middleman-mdocs!
|
216
|
+
rake (~> 13.0)
|
217
|
+
rspec (~> 3.10)
|
218
|
+
rspec_junit_formatter (~> 0.4)
|
219
|
+
rubocop
|
220
|
+
simplecov (~> 0.21)
|
221
|
+
simplecov-console
|
222
|
+
|
223
|
+
BUNDLED WITH
|
224
|
+
2.2.26
|
data/README.md
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'mdocs'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
module MiddlemanMdocs
|
2
|
+
class Controller
|
3
|
+
attr_reader :nav, :sitemap, :app
|
4
|
+
|
5
|
+
def initialize(sitemap)
|
6
|
+
@sitemap = sitemap
|
7
|
+
@app = sitemap.app
|
8
|
+
@guards = {}
|
9
|
+
end
|
10
|
+
|
11
|
+
def load(mdocs)
|
12
|
+
@nav = ::MiddlemanMdocs::Navigation.parse(mdocs['nav'])
|
13
|
+
end
|
14
|
+
|
15
|
+
def tags
|
16
|
+
sitemap.resources.select { |r| r.is_a?(::MiddlemanMdocs::Resource) }.map do |r|
|
17
|
+
guard_recursive('tags', r.path, []) do |_key|
|
18
|
+
r.tags
|
19
|
+
end
|
20
|
+
end.flatten.compact.map(&:to_sym).uniq
|
21
|
+
end
|
22
|
+
|
23
|
+
def has_tag?(tag)
|
24
|
+
tags.include?(tag.to_sym)
|
25
|
+
end
|
26
|
+
|
27
|
+
def select_by_meta(meta)
|
28
|
+
with_ensure_resource do
|
29
|
+
if meta.is_a? Hash
|
30
|
+
sitemap.resources.select do |resource|
|
31
|
+
resource.is_a?(::MiddlemanMdocs::Resource) && resource.meta_match?(meta) && resource.template?
|
32
|
+
end
|
33
|
+
else
|
34
|
+
sitemap.resources.select do |resource|
|
35
|
+
resource.is_a?(::MiddlemanMdocs::Resource) && resource.has_meta?(*meta) && resource.template?
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def select_by_meta_force(meta)
|
42
|
+
with_ensure_resource do
|
43
|
+
if meta.is_a? Hash
|
44
|
+
sitemap.resources.select do |resource|
|
45
|
+
resource.is_a?(::MiddlemanMdocs::Resource) && resource.meta_match?(meta)
|
46
|
+
end
|
47
|
+
else
|
48
|
+
sitemap.resources.select do |resource|
|
49
|
+
resource.is_a?(::MiddlemanMdocs::Resource) && resource.has_meta?(*meta)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def select_by_tags(*tags)
|
56
|
+
with_ensure_resource do
|
57
|
+
sitemap.resources.select do |resource|
|
58
|
+
resource.is_a?(::MiddlemanMdocs::Resource) && resource.has_tags?(*tags) && resource.template?
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def select(tags, *meta)
|
64
|
+
select_by_meta(*meta).select do |resource|
|
65
|
+
resource.is_a?(::MiddlemanMdocs::Resource) && resource.has_tags?(*tags) && resource.template?
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def with_ensure_resource
|
70
|
+
guard_recursive('with_ensure_resource', 'none', nil) do
|
71
|
+
sitemap.instance_variable_get('@lock').synchronize do
|
72
|
+
sitemap.ensure_resource_list_updated!
|
73
|
+
yield
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def tr(tag, scope: :tags)
|
79
|
+
I18n.t(tag.to_s.upcase.presence, scope: [:mdocs, scope],
|
80
|
+
default: I18n.t(tag.to_s.downcase.presence, scope: [:mdocs, scope], default: tag.to_s).presence)
|
81
|
+
end
|
82
|
+
|
83
|
+
def guard_recursive(name, key, default = nil)
|
84
|
+
guard = @guards[name] ||= {}
|
85
|
+
return guard[key] if guard.has_key?(key)
|
86
|
+
|
87
|
+
begin
|
88
|
+
guard[key] = default
|
89
|
+
guard[key] = yield(key)
|
90
|
+
ensure
|
91
|
+
guard.delete(key)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,148 @@
|
|
1
|
+
module MiddlemanMdocs
|
2
|
+
class Extension < Middleman::Extension
|
3
|
+
attr_reader :mdocs, :mdocsnav, :mdocsmeta
|
4
|
+
|
5
|
+
expose_to_application :mdocs, :mdocsnav
|
6
|
+
expose_to_template :mdocs, :mdocsnav
|
7
|
+
expose_to_config :mdocs, :enrich_metadata
|
8
|
+
|
9
|
+
def initialize(*args, **_kwargs, &block)
|
10
|
+
super
|
11
|
+
|
12
|
+
# Only require dependency on activation
|
13
|
+
require 'kramdown/parser'
|
14
|
+
require 'kramdown/converter'
|
15
|
+
|
16
|
+
require 'mdocs_kramdown'
|
17
|
+
require 'kramdown/parser/mdocs_kramdown'
|
18
|
+
|
19
|
+
require_relative 'resource'
|
20
|
+
require_relative 'toc'
|
21
|
+
require_relative 'tilt_template'
|
22
|
+
require_relative 'navigation'
|
23
|
+
require_relative 'controller'
|
24
|
+
require_relative 'sitemap'
|
25
|
+
|
26
|
+
@mdocs = Controller.new(app.sitemap)
|
27
|
+
|
28
|
+
configure_application
|
29
|
+
|
30
|
+
register_helpers(::MiddlemanMdocs::TOC)
|
31
|
+
register_helpers(::MiddlemanMdocs::Navigation)
|
32
|
+
|
33
|
+
@mdocsmeta = {}
|
34
|
+
|
35
|
+
::ActiveSupport::Notifications.subscribe('sitemap.update.middleman') do
|
36
|
+
lookup = @mdocs.sitemap.instance_variable_get('@_lookup_by_destination_path')
|
37
|
+
@mdocs.sitemap.resources.each do |resource|
|
38
|
+
lookup[::Middleman::Util.normalize_path(resource.destination_path)] = resource
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def configure_application
|
44
|
+
::Middleman::Sitemap::Store.include(::MiddlemanMdocs::Sitemap)
|
45
|
+
|
46
|
+
app.config[:markdown_engine] = :kramdown
|
47
|
+
app.config[:markdown] = {
|
48
|
+
tables: true,
|
49
|
+
linkable_headers: true,
|
50
|
+
auto_ids: true,
|
51
|
+
auto_id_prefix: true,
|
52
|
+
auto_id_stripping: true,
|
53
|
+
transliterated_header_ids: true,
|
54
|
+
syntax_highlighter: :rouge,
|
55
|
+
syntax_highlighter_opts: {
|
56
|
+
default_lang: 'html'
|
57
|
+
},
|
58
|
+
parse_block_html: true,
|
59
|
+
input: 'MdocsKramdown'
|
60
|
+
}
|
61
|
+
end
|
62
|
+
|
63
|
+
def register_helpers(modul)
|
64
|
+
unless self.class.defined_helpers.include?(modul)
|
65
|
+
self.class.include modul
|
66
|
+
self.class.defined_helpers << modul
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def after_configuration
|
71
|
+
markdown_exts = %w[markdown mdown md mkd mkdn]
|
72
|
+
::Tilt.register ::MiddlemanMdocs::TiltTempalte, *markdown_exts
|
73
|
+
end
|
74
|
+
|
75
|
+
def enrich_metadata(rx, &block)
|
76
|
+
@enrichers ||= []
|
77
|
+
@enrichers.push([rx, block])
|
78
|
+
end
|
79
|
+
|
80
|
+
def ready
|
81
|
+
mdocs.load(app.data.mdocs)
|
82
|
+
end
|
83
|
+
|
84
|
+
helpers do
|
85
|
+
end
|
86
|
+
|
87
|
+
def manipulate_resource_list(resources)
|
88
|
+
resources.each do |resource|
|
89
|
+
# install MdDocs::Resource extension
|
90
|
+
resource.extend(::MiddlemanMdocs::Resource) unless resource.is_a?(::MiddlemanMdocs::Resource)
|
91
|
+
resource.mdocs_extention = self
|
92
|
+
|
93
|
+
next if resource.metadata[:ignore]
|
94
|
+
|
95
|
+
if resource.source_file.end_with?('.md')
|
96
|
+
resource.add_meta(markdown: true)
|
97
|
+
resource.add_options(layout: (resource.options[:layout] || app.config.layout))
|
98
|
+
resource.destination_path << '.html' unless resource.destination_path.end_with?('.html')
|
99
|
+
end
|
100
|
+
|
101
|
+
resource.add_tags(*resource.data.tags)
|
102
|
+
resource.add_keywords(*resource.data.keywords)
|
103
|
+
|
104
|
+
# enrich recursive metadata from metadata.yml in each folder
|
105
|
+
metadata = get_metadata(resource.source_file)
|
106
|
+
resource.add_meta(::Middleman::Util.recursively_enhance(metadata))
|
107
|
+
|
108
|
+
# run apropriate enrichers
|
109
|
+
@enrichers.each do |(rx, block)|
|
110
|
+
if (md = rx.match(resource.source_file))
|
111
|
+
block.call(resource, md)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
resources
|
117
|
+
end
|
118
|
+
|
119
|
+
def get_metadata(path)
|
120
|
+
return {} unless path[app.source_dir.to_s]
|
121
|
+
|
122
|
+
path = ::Pathname.new(path)
|
123
|
+
current_dir = path.dirname.relative_path_from(app.source_dir).to_s
|
124
|
+
|
125
|
+
@mdocsmeta[current_dir] || begin
|
126
|
+
tokens = current_dir.split('/')
|
127
|
+
|
128
|
+
([''] + tokens).reduce(::Pathname('')) do |parent, token|
|
129
|
+
return {} if ['.', ','].include?(token)
|
130
|
+
|
131
|
+
current = parent.join(token)
|
132
|
+
token_path = app.source_dir.join(current)
|
133
|
+
meta = load_metadata(token_path)
|
134
|
+
@mdocsmeta[current.to_s] ||= (@mdocsmeta[parent.to_s] || {}).merge(meta)
|
135
|
+
current
|
136
|
+
end
|
137
|
+
|
138
|
+
@mdocsmeta[current_dir] || {}
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
def load_metadata(path)
|
143
|
+
::YAML.load_file(path.join('metadata.yml'))
|
144
|
+
rescue StandardError
|
145
|
+
{}
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
@@ -0,0 +1,134 @@
|
|
1
|
+
module MiddlemanMdocs
|
2
|
+
module Navigation
|
3
|
+
class Item
|
4
|
+
attr_reader :label, :value, :group
|
5
|
+
|
6
|
+
def initialize(label, value = nil)
|
7
|
+
@label = label
|
8
|
+
@value = value
|
9
|
+
if @value.is_a?(Hash) && @value.group?
|
10
|
+
@group = @value.group
|
11
|
+
elsif @value.is_a?(Array)
|
12
|
+
@recursive = true
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def separator?
|
17
|
+
value.nil?
|
18
|
+
end
|
19
|
+
|
20
|
+
def link?
|
21
|
+
value.is_a?(String)
|
22
|
+
end
|
23
|
+
|
24
|
+
def group?
|
25
|
+
!!@group
|
26
|
+
end
|
27
|
+
|
28
|
+
def recursive?
|
29
|
+
!!@recursive
|
30
|
+
end
|
31
|
+
|
32
|
+
def groupped(sitemap)
|
33
|
+
sitemap.select_by_meta(@group.to_sym).group_by do |resource|
|
34
|
+
resource.metadata[@group.to_sym]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def tr(group)
|
39
|
+
I18n.t(group, scope: [:mdocs, self.group], default: group)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.parse(list)
|
44
|
+
list.map do |p|
|
45
|
+
if p.is_a?(Hash)
|
46
|
+
k, v = p.first
|
47
|
+
elsif p.is_a?(String)
|
48
|
+
k = p
|
49
|
+
v = nil
|
50
|
+
else
|
51
|
+
ap "Error: #{p.inspect}"
|
52
|
+
next
|
53
|
+
end
|
54
|
+
|
55
|
+
v = parse(v) if v.is_a?(Array)
|
56
|
+
Item.new(k, v)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# Try to catch relative path and find resource for it
|
61
|
+
def link_to(*args, &block)
|
62
|
+
url_arg_index = block_given? ? 0 : 1
|
63
|
+
options_index = block_given? ? 1 : 2
|
64
|
+
url = args[url_arg_index]
|
65
|
+
|
66
|
+
if url
|
67
|
+
url = translate_to_destination(url)
|
68
|
+
args[url_arg_index] = url
|
69
|
+
end
|
70
|
+
super(*args, &block)
|
71
|
+
end
|
72
|
+
|
73
|
+
def link_to_tag(tag, *args, &block)
|
74
|
+
raise "There no tag #{tag.inspect} defined in mdocs" if tag && !mdocs.has_tag?(tag)
|
75
|
+
|
76
|
+
if block_given?
|
77
|
+
link_to("/tags/#{tag}", *args, &block)
|
78
|
+
else
|
79
|
+
link_to(I18n.t(tag, scope: %i[mdocs tags], default: tag.to_s), "/tags/#{tag}.html", *args, &block)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def fuzzy_find_resource(url)
|
84
|
+
source_file = if url.try(:source_file)
|
85
|
+
url.try(:source_file)
|
86
|
+
elsif url.start_with?('/')
|
87
|
+
app.source_dir.join(url[1..-1]).to_s
|
88
|
+
else
|
89
|
+
::Pathname.new(current_page.source_file).dirname.join(url).to_s
|
90
|
+
end
|
91
|
+
app.sitemap.resources.find { |r| r.source_file == source_file }
|
92
|
+
end
|
93
|
+
|
94
|
+
def merge(url)
|
95
|
+
resource = fuzzy_find_resource(url)
|
96
|
+
raise "unable to find resource by #{url}" unless resource
|
97
|
+
|
98
|
+
current_page.add_tags(*resource.data.fetch(:tags, []))
|
99
|
+
current_page.data.reverse_merge!(resource.data)
|
100
|
+
end
|
101
|
+
|
102
|
+
def include(page_id_or_path, merge: true, render: true)
|
103
|
+
merge(page_id_or_path) if merge
|
104
|
+
resource = fuzzy_find_resource(page_id_or_path) || sitemap.find_resource_by_page_id(page_id_or_path)
|
105
|
+
if render
|
106
|
+
resource.render(layout: false)
|
107
|
+
else
|
108
|
+
::File.read(resource.try(:source_file) || page_id_or_path)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
# some custom magic to find result path to generated resource
|
113
|
+
# Ex: readme.md -> readme.html
|
114
|
+
# Absolute Ex: /docs/readme.md -> docs/readme.html
|
115
|
+
# Relative Ex: quick.md -> docs/quick.html from docs/page.md
|
116
|
+
def translate_to_destination(url)
|
117
|
+
if r = fuzzy_find_resource(url)
|
118
|
+
r.url
|
119
|
+
else
|
120
|
+
url
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
# is this is url for current page
|
125
|
+
def active_url?(url)
|
126
|
+
translated = translate_to_destination(url)
|
127
|
+
url == current_page.url || current_page.url == translated || begin
|
128
|
+
current_page.url == translated.force_encoding('ASCII-8BIT')
|
129
|
+
rescue StandardError
|
130
|
+
nil
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module MiddlemanMdocs
|
2
|
+
module Resource
|
3
|
+
attr_accessor :mdocs_extention
|
4
|
+
|
5
|
+
def markdown?
|
6
|
+
true
|
7
|
+
end
|
8
|
+
|
9
|
+
def add_options(opts)
|
10
|
+
options.deep_merge!(opts)
|
11
|
+
end
|
12
|
+
|
13
|
+
def add_meta(opts)
|
14
|
+
metadata.deep_merge!(opts)
|
15
|
+
end
|
16
|
+
|
17
|
+
def add_tags(*args)
|
18
|
+
tags = (options[:tags] ||= [])
|
19
|
+
tags.append(*args.map(&:to_sym))
|
20
|
+
tags = tags.map(&:to_s).map(&:upcase).uniq.map(&:to_sym)
|
21
|
+
options[:tags] = tags
|
22
|
+
|
23
|
+
add_keywords(*args)
|
24
|
+
add_keywords(*args.map { |tag| I18n.t(tag, scope: %i[mdocs tags], default: tag.to_s) })
|
25
|
+
end
|
26
|
+
|
27
|
+
def add_keywords(*args)
|
28
|
+
keywords = (options[:keywords] ||= [])
|
29
|
+
keywords.append(*args.map(&:to_s))
|
30
|
+
keywords.uniq!
|
31
|
+
end
|
32
|
+
|
33
|
+
def tags
|
34
|
+
unless @rendered
|
35
|
+
unless metadata[:ignore]
|
36
|
+
begin
|
37
|
+
render(layout: false)
|
38
|
+
rescue StandardError
|
39
|
+
nil
|
40
|
+
end
|
41
|
+
end
|
42
|
+
@rendered = true
|
43
|
+
end
|
44
|
+
(options[:tags] ||= [])
|
45
|
+
end
|
46
|
+
|
47
|
+
def title
|
48
|
+
return nil unless metadata[:markdown]
|
49
|
+
|
50
|
+
data[:title] ||= @mdocs_extention.table_of_contents(self).children.first&.raw_text
|
51
|
+
end
|
52
|
+
|
53
|
+
def keywords
|
54
|
+
(options[:keywords] ||= [])
|
55
|
+
end
|
56
|
+
|
57
|
+
def meta_match?(meta)
|
58
|
+
meta.all? do |k, v|
|
59
|
+
metadata.include?(k) && (metadata[k].is_a?(Array) ? metadata[k].include?(v) : metadata[k] == v)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def has_meta?(*keys)
|
64
|
+
keys.compact!
|
65
|
+
keys.uniq!
|
66
|
+
(metadata.keys.uniq.sort & keys).size == keys.size
|
67
|
+
end
|
68
|
+
|
69
|
+
def has_tags?(*keys)
|
70
|
+
keys.compact!
|
71
|
+
keys.uniq!
|
72
|
+
(tags & keys).size == keys.size
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'middleman-core/renderers/kramdown'
|
2
|
+
|
3
|
+
module MiddlemanMdocs
|
4
|
+
class TiltTempalte < ::Middleman::Renderers::KramdownTemplate
|
5
|
+
def render(*args)
|
6
|
+
erb = Middleman::Renderers::ERb::Template.new(file, line, options) { data }
|
7
|
+
@data = erb.render(*args)
|
8
|
+
|
9
|
+
prepare
|
10
|
+
super
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'kramdown'
|
2
|
+
|
3
|
+
module MiddlemanMdocs
|
4
|
+
module TOC
|
5
|
+
## TOC item representation
|
6
|
+
#
|
7
|
+
class Item
|
8
|
+
attr_accessor :attrs, :children
|
9
|
+
|
10
|
+
delegate :merge, :merge!, to: :attrs
|
11
|
+
|
12
|
+
def initialize(attrs = {})
|
13
|
+
@attrs = attrs.with_indifferent_access
|
14
|
+
@children = []
|
15
|
+
end
|
16
|
+
|
17
|
+
def flatten
|
18
|
+
children.each_with_object([attrs.empty? ? [] : self]) do |child, list|
|
19
|
+
list.append(child.flatten)
|
20
|
+
end.flatten
|
21
|
+
end
|
22
|
+
|
23
|
+
def method_missing(sym, *)
|
24
|
+
if attrs.include? sym
|
25
|
+
@attrs[sym]
|
26
|
+
else
|
27
|
+
super
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.create(item)
|
32
|
+
Item.new.tap do |composed|
|
33
|
+
[item, item.value || {}].each do |obj|
|
34
|
+
composed.merge!(obj.try(:attr) || {}).merge!(obj.try(:options) || {})
|
35
|
+
end
|
36
|
+
|
37
|
+
(item.value.try(:children) || []).each do |el|
|
38
|
+
composed.merge!(create(el).attrs)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.parse_kramdown_toc(toc)
|
44
|
+
root = create(toc)
|
45
|
+
root.children = toc.children.map { |item| parse_kramdown_toc(item) }
|
46
|
+
root
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
## Generate TOC object tree for current page or source file
|
51
|
+
#
|
52
|
+
def table_of_contents(page_or_source, input: 'markdown')
|
53
|
+
begin
|
54
|
+
return nil if page_or_source.metadata[:ignore]
|
55
|
+
|
56
|
+
content = page_or_source.render(layout: false)
|
57
|
+
toc = Kramdown::Document.new(content, app.config[:markdown].merge(input: 'html')).to_toc
|
58
|
+
|
59
|
+
return Item.parse_kramdown_toc(toc)
|
60
|
+
rescue StandardError => e
|
61
|
+
# puts "WARNING: #{e}"
|
62
|
+
# puts e.backtrace
|
63
|
+
end
|
64
|
+
|
65
|
+
content = ::File.read(page_or_source.try(:source_file) || page_or_source)
|
66
|
+
# remove YAML frontmatter
|
67
|
+
content = content.gsub(/^(---\s*\n.*?\n?)^(---\s*$\n?)/m, '')
|
68
|
+
|
69
|
+
toc = if input == 'markdown'
|
70
|
+
Kramdown::Document.new(content, app.config[:markdown]).to_toc
|
71
|
+
else
|
72
|
+
Kramdown::Document.new(content, input: input).to_toc
|
73
|
+
end
|
74
|
+
|
75
|
+
Item.parse_kramdown_toc(toc)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
metadata
ADDED
@@ -0,0 +1,227 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: middleman-mdocs
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0.62562
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Samoylenko Yuri
|
8
|
+
- Poliev Alexey
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2021-09-24 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activesupport
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: awesome_print
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: kramdown
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :runtime
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: mdocs_kramdown
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :runtime
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: middleman
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - "~>"
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 4.3.11
|
77
|
+
type: :runtime
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - "~>"
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: 4.3.11
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: middleman-imageoptim
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
type: :runtime
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: middleman-search
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
type: :runtime
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
- !ruby/object:Gem::Dependency
|
113
|
+
name: nokogiri
|
114
|
+
requirement: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
type: :runtime
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: redcarpet
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
type: :runtime
|
134
|
+
prerelease: false
|
135
|
+
version_requirements: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
- !ruby/object:Gem::Dependency
|
141
|
+
name: russian
|
142
|
+
requirement: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
type: :runtime
|
148
|
+
prerelease: false
|
149
|
+
version_requirements: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - ">="
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
154
|
+
- !ruby/object:Gem::Dependency
|
155
|
+
name: slim
|
156
|
+
requirement: !ruby/object:Gem::Requirement
|
157
|
+
requirements:
|
158
|
+
- - ">="
|
159
|
+
- !ruby/object:Gem::Version
|
160
|
+
version: '0'
|
161
|
+
type: :runtime
|
162
|
+
prerelease: false
|
163
|
+
version_requirements: !ruby/object:Gem::Requirement
|
164
|
+
requirements:
|
165
|
+
- - ">="
|
166
|
+
- !ruby/object:Gem::Version
|
167
|
+
version: '0'
|
168
|
+
- !ruby/object:Gem::Dependency
|
169
|
+
name: stringex
|
170
|
+
requirement: !ruby/object:Gem::Requirement
|
171
|
+
requirements:
|
172
|
+
- - ">="
|
173
|
+
- !ruby/object:Gem::Version
|
174
|
+
version: '0'
|
175
|
+
type: :runtime
|
176
|
+
prerelease: false
|
177
|
+
version_requirements: !ruby/object:Gem::Requirement
|
178
|
+
requirements:
|
179
|
+
- - ">="
|
180
|
+
- !ruby/object:Gem::Version
|
181
|
+
version: '0'
|
182
|
+
description: MDocs extension for middleman
|
183
|
+
email:
|
184
|
+
- kinnalru@gmail.com
|
185
|
+
- apoliev@rnds.pro
|
186
|
+
executables: []
|
187
|
+
extensions: []
|
188
|
+
extra_rdoc_files: []
|
189
|
+
files:
|
190
|
+
- Gemfile
|
191
|
+
- Gemfile.lock
|
192
|
+
- README.md
|
193
|
+
- bin/console
|
194
|
+
- bin/setup
|
195
|
+
- lib/middleman-mdocs.rb
|
196
|
+
- lib/middleman-mdocs/controller.rb
|
197
|
+
- lib/middleman-mdocs/extension.rb
|
198
|
+
- lib/middleman-mdocs/navigation.rb
|
199
|
+
- lib/middleman-mdocs/resource.rb
|
200
|
+
- lib/middleman-mdocs/sitemap.rb
|
201
|
+
- lib/middleman-mdocs/tilt_template.rb
|
202
|
+
- lib/middleman-mdocs/toc.rb
|
203
|
+
- lib/middleman-mdocs/version.rb
|
204
|
+
homepage: https://rnds.pro
|
205
|
+
licenses: []
|
206
|
+
metadata:
|
207
|
+
homepage_uri: https://rnds.pro
|
208
|
+
post_install_message:
|
209
|
+
rdoc_options: []
|
210
|
+
require_paths:
|
211
|
+
- lib
|
212
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
213
|
+
requirements:
|
214
|
+
- - ">="
|
215
|
+
- !ruby/object:Gem::Version
|
216
|
+
version: 2.4.0
|
217
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
218
|
+
requirements:
|
219
|
+
- - ">="
|
220
|
+
- !ruby/object:Gem::Version
|
221
|
+
version: '0'
|
222
|
+
requirements: []
|
223
|
+
rubygems_version: 3.0.3
|
224
|
+
signing_key:
|
225
|
+
specification_version: 4
|
226
|
+
summary: Extension for Middleman
|
227
|
+
test_files: []
|