hotdocs 0.1.0 → 0.3.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 +4 -4
- data/README.md +3 -3
- data/app/assets/javascript/controllers/fetcher_controller.js +29 -0
- data/app/assets/javascript/controllers/search_controller.js +162 -0
- data/app/assets/stylesheets/hotdocs/application.css +173 -13
- data/app/helpers/hotdocs/application_helper.rb +12 -1
- data/app/views/layouts/hotdocs/application.html.erb +129 -73
- data/config/importmap.rb +1 -1
- data/lib/hotdocs/engine.rb +1 -2
- data/lib/hotdocs/kramdown_alerts.rb +92 -0
- data/lib/hotdocs/markdown.rb +21 -25
- data/lib/hotdocs/version.rb +1 -1
- data/lib/install/install.rb +189 -173
- data/lib/tasks/hotdocs_tasks.rake +88 -4
- metadata +48 -4
- data/lib/hotdocs/markdown.mjs +0 -177
data/lib/install/install.rb
CHANGED
@@ -7,7 +7,7 @@ def gem?(name)
|
|
7
7
|
|
8
8
|
regex = /gem ["']#{name}["']/
|
9
9
|
if File.readlines(gemfile_path).grep(regex).any?
|
10
|
-
say "#{name} already
|
10
|
+
say "#{name} already bundled"
|
11
11
|
false
|
12
12
|
else
|
13
13
|
run("bundle add #{name}") || abort("Failed to add #{name} to the bundle")
|
@@ -15,8 +15,16 @@ def gem?(name)
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
|
19
|
-
|
18
|
+
def pin(name)
|
19
|
+
importmap_path = Pathname(destination_root).join("config/importmap.rb")
|
20
|
+
|
21
|
+
regex = /pin ["']#{name}["']/
|
22
|
+
if File.readlines(importmap_path).grep(regex).any?
|
23
|
+
say "#{name} already pinned"
|
24
|
+
else
|
25
|
+
run("bin/importmap pin #{name}") || abort("Failed to pin #{name} to the importmap")
|
26
|
+
gsub_file importmap_path, /(pin ["']#{name}["'])(.*)/, '\1, preload: "hotdocs"\2'
|
27
|
+
end
|
20
28
|
end
|
21
29
|
|
22
30
|
if File.exist?("app/assets/config/manifest.js")
|
@@ -27,26 +35,40 @@ gem?("importmap-rails") && run("bin/rails importmap:install")
|
|
27
35
|
gem?("turbo-rails") && run("bin/rails turbo:install")
|
28
36
|
gem?("stimulus-rails") && run("bin/rails stimulus:install")
|
29
37
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
38
|
+
create_file(Pathname(destination_root).join("app/javascript/hotdocs.js"), <<~FILE)
|
39
|
+
import "@hotwired/turbo-rails";
|
40
|
+
import "controllers";
|
41
|
+
|
42
|
+
import { application } from "controllers/application"
|
43
|
+
import { eagerLoadControllersFrom } from "@hotwired/stimulus-loading"
|
44
|
+
eagerLoadControllersFrom("hotdocs/controllers", application)
|
45
|
+
FILE
|
35
46
|
|
36
|
-
|
47
|
+
importmap_path = Pathname(destination_root).join("config/importmap.rb")
|
48
|
+
append_to_file(importmap_path, %(pin "hotdocs", preload: "hotdocs"\n))
|
49
|
+
pin("lunr")
|
37
50
|
|
38
|
-
create_file(Pathname(destination_root).join("app/
|
51
|
+
create_file(Pathname(destination_root).join("app/controllers/hotdocs_controller.rb"), <<~FILE)
|
52
|
+
class HotdocsController < ApplicationController
|
53
|
+
helper Hotdocs::Engine.helpers
|
54
|
+
layout "hotdocs"
|
55
|
+
end
|
56
|
+
FILE
|
57
|
+
|
58
|
+
create_file(Pathname(destination_root).join("app/views/layouts/hotdocs.html.erb"), <<~FILE)
|
39
59
|
<% content_for :head do %>
|
40
60
|
<%= content_for(:title, "HotDocs") unless content_for?(:title) %>
|
41
61
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
42
|
-
<%= stylesheet_link_tag
|
43
|
-
<%=
|
62
|
+
<%= stylesheet_link_tag "hotdocs/application" %>
|
63
|
+
<%= stylesheet_link_tag "website" %>
|
64
|
+
<%= stylesheet_link_tag "rouge" %>
|
65
|
+
<%= javascript_importmap_tags "hotdocs" %>
|
44
66
|
<% end %>
|
45
67
|
|
46
68
|
<%= render template: "layouts/hotdocs/application" %>
|
47
|
-
|
69
|
+
FILE
|
48
70
|
|
49
|
-
create_file(Pathname(destination_root).join("app/views/hotdocs/index.html.mderb"), <<~
|
71
|
+
create_file(Pathname(destination_root).join("app/views/hotdocs/index.html.mderb"), <<~FILE)
|
50
72
|
<%= content_for(:title, "Welcome") %>
|
51
73
|
|
52
74
|
# Welcome to HotDocs
|
@@ -55,23 +77,24 @@ create_file(Pathname(destination_root).join("app/views/hotdocs/index.html.mderb"
|
|
55
77
|
|
56
78
|
## Todos
|
57
79
|
|
58
|
-
<input type="checkbox" id="first">
|
59
|
-
<label for="
|
60
|
-
<input type="checkbox" id="
|
61
|
-
|
62
|
-
<input type="checkbox" id="third">
|
63
|
-
<label for="third"> Maybe read the docs: <a href="https://hotdocsrails.com/" target="_blank">hotdocsrails.com</a></label>
|
64
|
-
VIEW
|
80
|
+
<input type="checkbox" id="first"><label for="first"> Update <code>app/views/layouts/hotdocs.html.erb</code></label>
|
81
|
+
<input type="checkbox" id="second"><label for="second"> Update <code>app/helpers/hotdocs_helper.rb</code></label>
|
82
|
+
<input type="checkbox" id="third"><label for="third"> Maybe read the docs: <a href="https://hotdocsrails.com/" target="_blank">hotdocsrails.com</a></label>
|
83
|
+
FILE
|
65
84
|
|
66
85
|
copy_file("app/assets/images/hotdocs/icon.svg", Pathname(destination_root).join("app/assets/images/hotdocs.svg"))
|
67
86
|
|
68
|
-
|
69
|
-
create_file(Pathname(destination_root).join("app/helpers/hotdocs_helper.rb"), <<~HELPER)
|
87
|
+
create_file(Pathname(destination_root).join("app/helpers/hotdocs_helper.rb"), <<~FILE)
|
70
88
|
module HotdocsHelper
|
89
|
+
# @return [Logo, nil]
|
71
90
|
def logo
|
72
91
|
Struct.new(:src, :alt).new(asset_path("hotdocs.svg"), "A humanized and happy hot dog")
|
73
92
|
end
|
74
93
|
|
94
|
+
def title
|
95
|
+
"HotDocs"
|
96
|
+
end
|
97
|
+
|
75
98
|
def nav_left_items(classes)
|
76
99
|
[
|
77
100
|
active_link_to("Docs", root_path, class: Array(classes))
|
@@ -123,165 +146,158 @@ create_file(Pathname(destination_root).join("app/helpers/hotdocs_helper.rb"), <<
|
|
123
146
|
}
|
124
147
|
]
|
125
148
|
end
|
126
|
-
end
|
127
|
-
HELPER
|
128
|
-
|
129
|
-
create_file(Pathname(destination_root).join("app/assets/stylesheets/prism.css"), <<~CSS)
|
130
|
-
code[class*="language-"],
|
131
|
-
pre[class*="language-"] {
|
132
|
-
color: #a9b7c6;
|
133
|
-
font-family: Consolas, Monaco, 'Andale Mono', monospace;
|
134
|
-
direction: ltr;
|
135
|
-
text-align: left;
|
136
|
-
white-space: pre;
|
137
|
-
word-spacing: normal;
|
138
|
-
word-break: normal;
|
139
|
-
line-height: 1.5;
|
140
|
-
|
141
|
-
-moz-tab-size: 4;
|
142
|
-
-o-tab-size: 4;
|
143
|
-
tab-size: 4;
|
144
|
-
|
145
|
-
-webkit-hyphens: none;
|
146
|
-
-moz-hyphens: none;
|
147
|
-
-ms-hyphens: none;
|
148
|
-
hyphens: none;
|
149
|
-
}
|
150
|
-
|
151
|
-
pre[class*="language-"]::-moz-selection, pre[class*="language-"] ::-moz-selection,
|
152
|
-
code[class*="language-"]::-moz-selection, code[class*="language-"] ::-moz-selection {
|
153
|
-
color: inherit;
|
154
|
-
background: rgba(33, 66, 131, .85);
|
155
|
-
}
|
156
|
-
|
157
|
-
pre[class*="language-"]::selection, pre[class*="language-"] ::selection,
|
158
|
-
code[class*="language-"]::selection, code[class*="language-"] ::selection {
|
159
|
-
color: inherit;
|
160
|
-
background: rgba(33, 66, 131, .85);
|
161
|
-
}
|
162
|
-
|
163
|
-
/* Code blocks */
|
164
|
-
pre[class*="language-"] {
|
165
|
-
padding: 1em;
|
166
|
-
margin: .5em 0;
|
167
|
-
overflow: auto;
|
168
|
-
}
|
169
|
-
|
170
|
-
:not(pre) > code[class*="language-"],
|
171
|
-
pre[class*="language-"] {
|
172
|
-
background: #2b2b2b;
|
173
|
-
}
|
174
|
-
|
175
|
-
/* Inline code */
|
176
|
-
:not(pre) > code[class*="language-"] {
|
177
|
-
padding: .1em;
|
178
|
-
border-radius: .3em;
|
179
|
-
}
|
180
|
-
|
181
|
-
.token.comment,
|
182
|
-
.token.prolog,
|
183
|
-
.token.cdata {
|
184
|
-
color: #808080;
|
185
|
-
}
|
186
|
-
|
187
|
-
.token.delimiter,
|
188
|
-
.token.boolean,
|
189
|
-
.token.keyword,
|
190
|
-
.token.selector,
|
191
|
-
.token.important,
|
192
|
-
.token.atrule {
|
193
|
-
color: #cc7832;
|
194
|
-
}
|
195
|
-
|
196
|
-
.token.operator,
|
197
|
-
.token.punctuation,
|
198
|
-
.token.attr-name {
|
199
|
-
color: #a9b7c6;
|
200
|
-
}
|
201
|
-
|
202
|
-
.token.tag,
|
203
|
-
.token.tag .punctuation,
|
204
|
-
.token.doctype,
|
205
|
-
.token.builtin {
|
206
|
-
color: #e8bf6a;
|
207
|
-
}
|
208
|
-
|
209
|
-
.token.entity,
|
210
|
-
.token.number,
|
211
|
-
.token.symbol {
|
212
|
-
color: #6897bb;
|
213
|
-
}
|
214
|
-
|
215
|
-
.token.property,
|
216
|
-
.token.constant,
|
217
|
-
.token.variable {
|
218
|
-
color: #9876aa;
|
219
|
-
}
|
220
|
-
|
221
|
-
.token.string,
|
222
|
-
.token.char {
|
223
|
-
color: #6a8759;
|
224
|
-
}
|
225
149
|
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
.token.attr-value .punctuation:first-child {
|
232
|
-
color: #a9b7c6;
|
233
|
-
}
|
234
|
-
|
235
|
-
.token.url {
|
236
|
-
color: #287bde;
|
237
|
-
text-decoration: underline;
|
238
|
-
}
|
239
|
-
|
240
|
-
.token.function {
|
241
|
-
color: #ffc66d;
|
242
|
-
}
|
243
|
-
|
244
|
-
.token.regex {
|
245
|
-
background: #364135;
|
246
|
-
}
|
247
|
-
|
248
|
-
.token.bold {
|
249
|
-
font-weight: bold;
|
250
|
-
}
|
251
|
-
|
252
|
-
.token.italic {
|
253
|
-
font-style: italic;
|
254
|
-
}
|
150
|
+
def fetcher_host
|
151
|
+
"http://127.0.0.1:3000"
|
152
|
+
end
|
153
|
+
end
|
154
|
+
FILE
|
255
155
|
|
256
|
-
|
257
|
-
|
156
|
+
create_file(Pathname(destination_root).join("app/assets/stylesheets/website.css"), <<~FILE)
|
157
|
+
:root {
|
158
|
+
--docs-code-background-color: #eee;
|
159
|
+
--docs-code-border-color: #00000022;
|
160
|
+
--docs-text-color: #1c1e21;
|
258
161
|
}
|
259
162
|
|
260
|
-
|
261
|
-
background: #
|
163
|
+
[data-theme=dark]:root {
|
164
|
+
--docs-code-background-color: #2b2b2b;
|
165
|
+
--docs-code-border-color: #ffffff22;
|
166
|
+
--docs-text-color: #e3e1de;
|
262
167
|
}
|
263
168
|
|
264
|
-
|
265
|
-
|
266
|
-
|
169
|
+
.article {
|
170
|
+
color: var(--docs-text-color);
|
171
|
+
|
172
|
+
a {
|
173
|
+
color: var(--docs-text-color);
|
174
|
+
|
175
|
+
&:has(code) {
|
176
|
+
text-underline-position: under;
|
177
|
+
text-decoration-thickness: 1px;
|
178
|
+
}
|
179
|
+
}
|
180
|
+
|
181
|
+
pre {
|
182
|
+
-webkit-overflow-scrolling: touch;
|
183
|
+
border-radius: .375rem;
|
184
|
+
box-sizing: border-box;
|
185
|
+
overflow-x: auto;
|
186
|
+
width: 100%;
|
187
|
+
}
|
188
|
+
|
189
|
+
code:not(pre code) {
|
190
|
+
background: var(--docs-code-background-color);
|
191
|
+
border-radius: 0.375rem;
|
192
|
+
border: .1rem solid var(--docs-code-border-color);
|
193
|
+
display: inline;
|
194
|
+
overflow-x: auto;
|
195
|
+
overflow: auto;
|
196
|
+
padding: 0.1rem 0.2rem;
|
197
|
+
word-break: break-word;
|
198
|
+
}
|
267
199
|
}
|
268
|
-
|
269
|
-
|
270
|
-
|
200
|
+
FILE
|
201
|
+
|
202
|
+
create_file(Pathname(destination_root).join("app/assets/stylesheets/rouge.css"), <<~FILE)
|
203
|
+
.article {
|
204
|
+
.highlight .hll { background-color: #6e7681 }
|
205
|
+
.highlight { background: #0d1117; color: #e6edf3 }
|
206
|
+
.highlight .c { color: #8b949e; font-style: italic } /* Comment */
|
207
|
+
.highlight .err { color: #f85149 } /* Error */
|
208
|
+
.highlight .esc { color: #e6edf3 } /* Escape */
|
209
|
+
.highlight .g { color: #e6edf3 } /* Generic */
|
210
|
+
.highlight .k { color: #ff7b72 } /* Keyword */
|
211
|
+
.highlight .l { color: #a5d6ff } /* Literal */
|
212
|
+
.highlight .n { color: #e6edf3 } /* Name */
|
213
|
+
.highlight .o { color: #ff7b72; font-weight: bold } /* Operator */
|
214
|
+
.highlight .x { color: #e6edf3 } /* Other */
|
215
|
+
.highlight .p { color: #e6edf3 } /* Punctuation */
|
216
|
+
.highlight .ch { color: #8b949e; font-style: italic } /* Comment.Hashbang */
|
217
|
+
.highlight .cm { color: #8b949e; font-style: italic } /* Comment.Multiline */
|
218
|
+
.highlight .cp { color: #8b949e; font-weight: bold; font-style: italic } /* Comment.Preproc */
|
219
|
+
.highlight .cpf { color: #8b949e; font-style: italic } /* Comment.PreprocFile */
|
220
|
+
.highlight .c1 { color: #8b949e; font-style: italic } /* Comment.Single */
|
221
|
+
.highlight .cs { color: #8b949e; font-weight: bold; font-style: italic } /* Comment.Special */
|
222
|
+
.highlight .gd { color: #ffa198; background-color: #490202 } /* Generic.Deleted */
|
223
|
+
.highlight .ge { color: #e6edf3; font-style: italic } /* Generic.Emph */
|
224
|
+
.highlight .ges { color: #e6edf3; font-weight: bold; font-style: italic } /* Generic.EmphStrong */
|
225
|
+
.highlight .gr { color: #ffa198 } /* Generic.Error */
|
226
|
+
.highlight .gh { color: #79c0ff; font-weight: bold } /* Generic.Heading */
|
227
|
+
.highlight .gi { color: #56d364; background-color: #0f5323 } /* Generic.Inserted */
|
228
|
+
.highlight .go { color: #8b949e } /* Generic.Output */
|
229
|
+
.highlight .gp { color: #8b949e } /* Generic.Prompt */
|
230
|
+
.highlight .gs { color: #e6edf3; font-weight: bold } /* Generic.Strong */
|
231
|
+
.highlight .gu { color: #79c0ff } /* Generic.Subheading */
|
232
|
+
.highlight .gt { color: #ff7b72 } /* Generic.Traceback */
|
233
|
+
.highlight .g-Underline { color: #e6edf3; text-decoration: underline } /* Generic.Underline */
|
234
|
+
.highlight .kc { color: #79c0ff } /* Keyword.Constant */
|
235
|
+
.highlight .kd { color: #ff7b72 } /* Keyword.Declaration */
|
236
|
+
.highlight .kn { color: #ff7b72 } /* Keyword.Namespace */
|
237
|
+
.highlight .kp { color: #79c0ff } /* Keyword.Pseudo */
|
238
|
+
.highlight .kr { color: #ff7b72 } /* Keyword.Reserved */
|
239
|
+
.highlight .kt { color: #ff7b72 } /* Keyword.Type */
|
240
|
+
.highlight .ld { color: #79c0ff } /* Literal.Date */
|
241
|
+
.highlight .m { color: #a5d6ff } /* Literal.Number */
|
242
|
+
.highlight .s { color: #a5d6ff } /* Literal.String */
|
243
|
+
.highlight .na { color: #e6edf3 } /* Name.Attribute */
|
244
|
+
.highlight .nb { color: #e6edf3 } /* Name.Builtin */
|
245
|
+
.highlight .nc { color: #f0883e; font-weight: bold } /* Name.Class */
|
246
|
+
.highlight .no { color: #79c0ff; font-weight: bold } /* Name.Constant */
|
247
|
+
.highlight .nd { color: #d2a8ff; font-weight: bold } /* Name.Decorator */
|
248
|
+
.highlight .ni { color: #ffa657 } /* Name.Entity */
|
249
|
+
.highlight .ne { color: #f0883e; font-weight: bold } /* Name.Exception */
|
250
|
+
.highlight .nf { color: #d2a8ff; font-weight: bold } /* Name.Function */
|
251
|
+
.highlight .nl { color: #79c0ff; font-weight: bold } /* Name.Label */
|
252
|
+
.highlight .nn { color: #ff7b72 } /* Name.Namespace */
|
253
|
+
.highlight .nx { color: #e6edf3 } /* Name.Other */
|
254
|
+
.highlight .py { color: #79c0ff } /* Name.Property */
|
255
|
+
.highlight .nt { color: #7ee787 } /* Name.Tag */
|
256
|
+
.highlight .nv { color: #79c0ff } /* Name.Variable */
|
257
|
+
.highlight .ow { color: #ff7b72; font-weight: bold } /* Operator.Word */
|
258
|
+
.highlight .pm { color: #e6edf3 } /* Punctuation.Marker */
|
259
|
+
.highlight .w { color: #6e7681 } /* Text.Whitespace */
|
260
|
+
.highlight .mb { color: #a5d6ff } /* Literal.Number.Bin */
|
261
|
+
.highlight .mf { color: #a5d6ff } /* Literal.Number.Float */
|
262
|
+
.highlight .mh { color: #a5d6ff } /* Literal.Number.Hex */
|
263
|
+
.highlight .mi { color: #a5d6ff } /* Literal.Number.Integer */
|
264
|
+
.highlight .mo { color: #a5d6ff } /* Literal.Number.Oct */
|
265
|
+
.highlight .sa { color: #79c0ff } /* Literal.String.Affix */
|
266
|
+
.highlight .sb { color: #a5d6ff } /* Literal.String.Backtick */
|
267
|
+
.highlight .sc { color: #a5d6ff } /* Literal.String.Char */
|
268
|
+
.highlight .dl { color: #79c0ff } /* Literal.String.Delimiter */
|
269
|
+
.highlight .sd { color: #a5d6ff } /* Literal.String.Doc */
|
270
|
+
.highlight .s2 { color: #a5d6ff } /* Literal.String.Double */
|
271
|
+
.highlight .se { color: #79c0ff } /* Literal.String.Escape */
|
272
|
+
.highlight .sh { color: #79c0ff } /* Literal.String.Heredoc */
|
273
|
+
.highlight .si { color: #a5d6ff } /* Literal.String.Interpol */
|
274
|
+
.highlight .sx { color: #a5d6ff } /* Literal.String.Other */
|
275
|
+
.highlight .sr { color: #79c0ff } /* Literal.String.Regex */
|
276
|
+
.highlight .s1 { color: #a5d6ff } /* Literal.String.Single */
|
277
|
+
.highlight .ss { color: #a5d6ff } /* Literal.String.Symbol */
|
278
|
+
.highlight .bp { color: #e6edf3 } /* Name.Builtin.Pseudo */
|
279
|
+
.highlight .fm { color: #d2a8ff; font-weight: bold } /* Name.Function.Magic */
|
280
|
+
.highlight .vc { color: #79c0ff } /* Name.Variable.Class */
|
281
|
+
.highlight .vg { color: #79c0ff } /* Name.Variable.Global */
|
282
|
+
.highlight .vi { color: #79c0ff } /* Name.Variable.Instance */
|
283
|
+
.highlight .vm { color: #79c0ff } /* Name.Variable.Magic */
|
284
|
+
.highlight .il { color: #a5d6ff } /* Literal.Number.Integer.Long */
|
271
285
|
}
|
286
|
+
FILE
|
272
287
|
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
CSS
|
288
|
+
empty_directory "app/assets/builds"
|
289
|
+
keep_file "app/assets/builds"
|
290
|
+
if Pathname(destination_root).join(".gitignore").exist?
|
291
|
+
append_to_file(".gitignore", %(\n/app/assets/builds/*\n!/app/assets/builds/.keep\n))
|
292
|
+
append_to_file(".gitignore", %(\n/node_modules/\n))
|
293
|
+
end
|
280
294
|
|
281
295
|
routes_path = Pathname(destination_root).join("config/routes.rb")
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
296
|
+
routes = File.readlines(routes_path)
|
297
|
+
unless routes.grep(/hotdocs#index/).any?
|
298
|
+
if routes.grep(/^\s*(?!#)root/).any?
|
299
|
+
route "get '/hotdocs', to: 'hotdocs#index'"
|
300
|
+
else
|
301
|
+
route "root to: 'hotdocs#index'"
|
302
|
+
end
|
287
303
|
end
|
@@ -1,9 +1,93 @@
|
|
1
1
|
namespace :hotdocs do
|
2
2
|
desc "Install HotDocs into the app"
|
3
3
|
task :install do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
location = File.expand_path("../install/install.rb", __dir__)
|
5
|
+
system("#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{location}")
|
6
|
+
# Needed for hotdocs:index to find the generated ::HotdocsController
|
7
|
+
Rails.application.reloader.reload!
|
8
|
+
Rake::Task["hotdocs:index"].invoke
|
8
9
|
end
|
10
|
+
|
11
|
+
desc "Build search data"
|
12
|
+
task index: :environment do
|
13
|
+
path = Rails.root.join("app/assets/builds/search_data.json")
|
14
|
+
# Propshaft caches the `@load_path`s. Rendering data goes through Propshaft
|
15
|
+
# because of the assets, so the file must exist before rendering.
|
16
|
+
File.write(path, "")
|
17
|
+
data = render_search_data.call.to_json
|
18
|
+
File.write(path, data)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
if Rake::Task.task_defined?("assets:precompile")
|
23
|
+
Rake::Task["assets:precompile"].enhance([ "hotdocs:index" ])
|
24
|
+
end
|
25
|
+
|
26
|
+
if Rake::Task.task_defined?("test:prepare")
|
27
|
+
Rake::Task["test:prepare"].enhance([ "hotdocs:index" ])
|
28
|
+
elsif Rake::Task.task_defined?("spec:prepare")
|
29
|
+
Rake::Task["spec:prepare"].enhance([ "hotdocs:index" ])
|
30
|
+
elsif Rake::Task.task_defined?("db:test:prepare")
|
31
|
+
Rake::Task["db:test:prepare"].enhance([ "hotdocs:index" ])
|
32
|
+
end
|
33
|
+
|
34
|
+
def render_search_data
|
35
|
+
renderer = Class.new(::HotdocsController) do
|
36
|
+
include Hotdocs::ApplicationHelper
|
37
|
+
|
38
|
+
def call
|
39
|
+
with_no_view_annotations { render_search_data }
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def with_no_view_annotations(&)
|
45
|
+
annotate = Rails.application.config.action_view.annotate_rendered_view_with_filenames
|
46
|
+
Rails.application.config.action_view.annotate_rendered_view_with_filenames = false
|
47
|
+
yield
|
48
|
+
ensure
|
49
|
+
Rails.application.config.action_view.annotate_rendered_view_with_filename = annotate
|
50
|
+
end
|
51
|
+
|
52
|
+
def render_search_data
|
53
|
+
pages = pages_from(menu_items)
|
54
|
+
$stderr.puts "Indexing #{pages.size} pages:"
|
55
|
+
render_pages(pages).tap { $stderr.puts }
|
56
|
+
end
|
57
|
+
|
58
|
+
def render_pages(pages)
|
59
|
+
pages.filter_map do |page|
|
60
|
+
$stderr.putc "."
|
61
|
+
html = render_path(page.fetch(:url))
|
62
|
+
next unless html
|
63
|
+
{ **page, html: html }
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def pages_from(menu_items, parent = "Docs")
|
68
|
+
menu_items
|
69
|
+
.filter { _1.fetch(:url).start_with?("/") }
|
70
|
+
.flat_map do |item|
|
71
|
+
current = { title: item.fetch(:label), parent: parent, url: item.fetch(:url) }
|
72
|
+
children = pages_from(item.fetch(:children, []), item.fetch(:label))
|
73
|
+
[ current ] + children
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def render_path(path)
|
78
|
+
base = ENV.fetch("RAILS_RELATIVE_URL_ROOT", "")
|
79
|
+
baseless_path = path.sub(/\A#{base}/, "")
|
80
|
+
controller, action = Rails.application.routes.recognize_path(baseless_path).values_at(:controller, :action)
|
81
|
+
render_to_string("#{controller}/#{action}", layout: false)
|
82
|
+
rescue ActionController::RoutingError => error
|
83
|
+
logger.info("Skipped building #{path}: #{error}")
|
84
|
+
nil
|
85
|
+
end
|
86
|
+
|
87
|
+
def request
|
88
|
+
ActionDispatch::TestRequest.create
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
renderer.new
|
9
93
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hotdocs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- 3v0k4
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: rails
|
@@ -23,6 +23,48 @@ dependencies:
|
|
23
23
|
- - ">="
|
24
24
|
- !ruby/object:Gem::Version
|
25
25
|
version: 7.1.0
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: kramdown
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - "~>"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '2.5'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '2.5'
|
40
|
+
- !ruby/object:Gem::Dependency
|
41
|
+
name: kramdown-parser-gfm
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
type: :runtime
|
48
|
+
prerelease: false
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
- !ruby/object:Gem::Dependency
|
55
|
+
name: rouge
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '4.5'
|
61
|
+
type: :runtime
|
62
|
+
prerelease: false
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '4.5'
|
26
68
|
description: HotDocs is a set of optimized Rails components & tools for writing docs.
|
27
69
|
email:
|
28
70
|
- riccardo.odone@gmail.com
|
@@ -36,6 +78,8 @@ files:
|
|
36
78
|
- Rakefile
|
37
79
|
- app/assets/images/hotdocs/icon.svg
|
38
80
|
- app/assets/javascript/controllers/accordion_controller.js
|
81
|
+
- app/assets/javascript/controllers/fetcher_controller.js
|
82
|
+
- app/assets/javascript/controllers/search_controller.js
|
39
83
|
- app/assets/javascript/controllers/sidenav_controller.js
|
40
84
|
- app/assets/javascript/controllers/toc_controller.js
|
41
85
|
- app/assets/stylesheets/hotdocs/application.css
|
@@ -46,7 +90,7 @@ files:
|
|
46
90
|
- config/importmap.rb
|
47
91
|
- lib/hotdocs.rb
|
48
92
|
- lib/hotdocs/engine.rb
|
49
|
-
- lib/hotdocs/
|
93
|
+
- lib/hotdocs/kramdown_alerts.rb
|
50
94
|
- lib/hotdocs/markdown.rb
|
51
95
|
- lib/hotdocs/version.rb
|
52
96
|
- lib/install/install.rb
|
@@ -74,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
118
|
- !ruby/object:Gem::Version
|
75
119
|
version: '0'
|
76
120
|
requirements: []
|
77
|
-
rubygems_version: 3.6.
|
121
|
+
rubygems_version: 3.6.9
|
78
122
|
specification_version: 4
|
79
123
|
summary: Write your docs with Ruby on Rails
|
80
124
|
test_files: []
|