hotdocs 0.1.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.
@@ -0,0 +1,393 @@
1
+ /*
2
+ // The code below is taken from
3
+ // https://unpkg.com/tailwindcss@3.4.17/src/css/preflight.css
4
+ // Copyright (c) Tailwind Labs, Inc. (MIT License)
5
+ */
6
+
7
+ /*
8
+ 1. Prevent padding and border from affecting element width. (https://github.com/mozdevs/cssremedy/issues/4)
9
+ 2. Allow adding a border to an element by just adding a border-width. (https://github.com/tailwindcss/tailwindcss/pull/116)
10
+ */
11
+
12
+ *,
13
+ ::before,
14
+ ::after {
15
+ box-sizing: border-box; /* 1 */
16
+ border-width: 0; /* 2 */
17
+ border-style: solid; /* 2 */
18
+ border-color: currentColor; /* 2 */
19
+ }
20
+
21
+ ::before,
22
+ ::after {
23
+ --tw-content: '';
24
+ }
25
+
26
+ /*
27
+ 1. Use a consistent sensible line-height in all browsers.
28
+ 2. Prevent adjustments of font size after orientation changes in iOS.
29
+ 3. Use a more readable tab size.
30
+ 4. Use the user's configured `sans` font-family by default.
31
+ 5. Use the user's configured `sans` font-feature-settings by default.
32
+ 6. Use the user's configured `sans` font-variation-settings by default.
33
+ 7. Disable tap highlights on iOS
34
+ */
35
+
36
+ html,
37
+ :host {
38
+ line-height: 1.5; /* 1 */
39
+ -webkit-text-size-adjust: 100%; /* 2 */
40
+ -moz-tab-size: 4; /* 3 */
41
+ tab-size: 4; /* 3 */
42
+ font-family: ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"; /* 4 */
43
+ font-feature-settings: normal; /* 5 */
44
+ font-variation-settings: normal; /* 6 */
45
+ -webkit-tap-highlight-color: transparent; /* 7 */
46
+ }
47
+
48
+ /*
49
+ 1. Remove the margin in all browsers.
50
+ 2. Inherit line-height from `html` so users can set them as a class directly on the `html` element.
51
+ */
52
+
53
+ body {
54
+ margin: 0; /* 1 */
55
+ line-height: inherit; /* 2 */
56
+ }
57
+
58
+ /*
59
+ 1. Add the correct height in Firefox.
60
+ 2. Correct the inheritance of border color in Firefox. (https://bugzilla.mozilla.org/show_bug.cgi?id=190655)
61
+ 3. Ensure horizontal rules are visible by default.
62
+ */
63
+
64
+ hr {
65
+ height: 0; /* 1 */
66
+ color: inherit; /* 2 */
67
+ border-top-width: 1px; /* 3 */
68
+ }
69
+
70
+ /*
71
+ Add the correct text decoration in Chrome, Edge, and Safari.
72
+ */
73
+
74
+ abbr:where([title]) {
75
+ text-decoration: underline dotted;
76
+ }
77
+
78
+ /*
79
+ Remove the default font size and weight for headings.
80
+ */
81
+
82
+ h1,
83
+ h2,
84
+ h3,
85
+ h4,
86
+ h5,
87
+ h6 {
88
+ font-size: inherit;
89
+ font-weight: inherit;
90
+ }
91
+
92
+ /*
93
+ Reset links to optimize for opt-in styling instead of opt-out.
94
+ */
95
+
96
+ a {
97
+ color: inherit;
98
+ text-decoration: inherit;
99
+ }
100
+
101
+ /*
102
+ Add the correct font weight in Edge and Safari.
103
+ */
104
+
105
+ b,
106
+ strong {
107
+ font-weight: bolder;
108
+ }
109
+
110
+ /*
111
+ 1. Use the user's configured `mono` font-family by default.
112
+ 2. Use the user's configured `mono` font-feature-settings by default.
113
+ 3. Use the user's configured `mono` font-variation-settings by default.
114
+ 4. Correct the odd `em` font sizing in all browsers.
115
+ */
116
+
117
+ code,
118
+ kbd,
119
+ samp,
120
+ pre {
121
+ font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; /* 1 */
122
+ font-feature-settings: normal; /* 2 */
123
+ font-variation-settings: normal; /* 3 */
124
+ font-size: 1em; /* 4 */
125
+ }
126
+
127
+ /*
128
+ Add the correct font size in all browsers.
129
+ */
130
+
131
+ small {
132
+ font-size: 80%;
133
+ }
134
+
135
+ /*
136
+ Prevent `sub` and `sup` elements from affecting the line height in all browsers.
137
+ */
138
+
139
+ sub,
140
+ sup {
141
+ font-size: 75%;
142
+ line-height: 0;
143
+ position: relative;
144
+ vertical-align: baseline;
145
+ }
146
+
147
+ sub {
148
+ bottom: -0.25em;
149
+ }
150
+
151
+ sup {
152
+ top: -0.5em;
153
+ }
154
+
155
+ /*
156
+ 1. Remove text indentation from table contents in Chrome and Safari. (https://bugs.chromium.org/p/chromium/issues/detail?id=999088, https://bugs.webkit.org/show_bug.cgi?id=201297)
157
+ 2. Correct table border color inheritance in all Chrome and Safari. (https://bugs.chromium.org/p/chromium/issues/detail?id=935729, https://bugs.webkit.org/show_bug.cgi?id=195016)
158
+ 3. Remove gaps between table borders by default.
159
+ */
160
+
161
+ table {
162
+ text-indent: 0; /* 1 */
163
+ border-color: inherit; /* 2 */
164
+ border-collapse: collapse; /* 3 */
165
+ }
166
+
167
+ /*
168
+ 1. Change the font styles in all browsers.
169
+ 2. Remove the margin in Firefox and Safari.
170
+ 3. Remove default padding in all browsers.
171
+ */
172
+
173
+ button,
174
+ input,
175
+ optgroup,
176
+ select,
177
+ textarea {
178
+ font-family: inherit; /* 1 */
179
+ font-feature-settings: inherit; /* 1 */
180
+ font-variation-settings: inherit; /* 1 */
181
+ font-size: 100%; /* 1 */
182
+ font-weight: inherit; /* 1 */
183
+ line-height: inherit; /* 1 */
184
+ letter-spacing: inherit; /* 1 */
185
+ color: inherit; /* 1 */
186
+ margin: 0; /* 2 */
187
+ padding: 0; /* 3 */
188
+ }
189
+
190
+ /*
191
+ Remove the inheritance of text transform in Edge and Firefox.
192
+ */
193
+
194
+ button,
195
+ select {
196
+ text-transform: none;
197
+ }
198
+
199
+ /*
200
+ 1. Correct the inability to style clickable types in iOS and Safari.
201
+ 2. Remove default button styles.
202
+ */
203
+
204
+ button,
205
+ input:where([type='button']),
206
+ input:where([type='reset']),
207
+ input:where([type='submit']) {
208
+ -webkit-appearance: button; /* 1 */
209
+ background-color: transparent; /* 2 */
210
+ background-image: none; /* 2 */
211
+ }
212
+
213
+ /*
214
+ Use the modern Firefox focus style for all focusable elements.
215
+ */
216
+
217
+ :-moz-focusring {
218
+ outline: auto;
219
+ }
220
+
221
+ /*
222
+ Remove the additional `:invalid` styles in Firefox. (https://github.com/mozilla/gecko-dev/blob/2f9eacd9d3d995c937b4251a5557d95d494c9be1/layout/style/res/forms.css#L728-L737)
223
+ */
224
+
225
+ :-moz-ui-invalid {
226
+ box-shadow: none;
227
+ }
228
+
229
+ /*
230
+ Add the correct vertical alignment in Chrome and Firefox.
231
+ */
232
+
233
+ progress {
234
+ vertical-align: baseline;
235
+ }
236
+
237
+ /*
238
+ Correct the cursor style of increment and decrement buttons in Safari.
239
+ */
240
+
241
+ ::-webkit-inner-spin-button,
242
+ ::-webkit-outer-spin-button {
243
+ height: auto;
244
+ }
245
+
246
+ /*
247
+ 1. Correct the odd appearance in Chrome and Safari.
248
+ 2. Correct the outline style in Safari.
249
+ */
250
+
251
+ [type='search'] {
252
+ -webkit-appearance: textfield; /* 1 */
253
+ outline-offset: -2px; /* 2 */
254
+ }
255
+
256
+ /*
257
+ Remove the inner padding in Chrome and Safari on macOS.
258
+ */
259
+
260
+ ::-webkit-search-decoration {
261
+ -webkit-appearance: none;
262
+ }
263
+
264
+ /*
265
+ 1. Correct the inability to style clickable types in iOS and Safari.
266
+ 2. Change font properties to `inherit` in Safari.
267
+ */
268
+
269
+ ::-webkit-file-upload-button {
270
+ -webkit-appearance: button; /* 1 */
271
+ font: inherit; /* 2 */
272
+ }
273
+
274
+ /*
275
+ Add the correct display in Chrome and Safari.
276
+ */
277
+
278
+ summary {
279
+ display: list-item;
280
+ }
281
+
282
+ /*
283
+ Removes the default spacing and border for appropriate elements.
284
+ */
285
+
286
+ blockquote,
287
+ dl,
288
+ dd,
289
+ h1,
290
+ h2,
291
+ h3,
292
+ h4,
293
+ h5,
294
+ h6,
295
+ hr,
296
+ figure,
297
+ p,
298
+ pre {
299
+ margin: 0;
300
+ }
301
+
302
+ fieldset {
303
+ margin: 0;
304
+ padding: 0;
305
+ }
306
+
307
+ legend {
308
+ padding: 0;
309
+ }
310
+
311
+ ol,
312
+ ul,
313
+ menu {
314
+ list-style: none;
315
+ margin: 0;
316
+ padding: 0;
317
+ }
318
+
319
+ /*
320
+ Reset default styling for dialogs.
321
+ */
322
+ dialog {
323
+ padding: 0;
324
+ }
325
+
326
+ /*
327
+ Prevent resizing textareas horizontally by default.
328
+ */
329
+
330
+ textarea {
331
+ resize: vertical;
332
+ }
333
+
334
+ /*
335
+ 1. Reset the default placeholder opacity in Firefox. (https://github.com/tailwindlabs/tailwindcss/issues/3300)
336
+ 2. Set the default placeholder color to the user's configured gray 400 color.
337
+ */
338
+
339
+ input::placeholder,
340
+ textarea::placeholder {
341
+ opacity: 1; /* 1 */
342
+ color: #9ca3af; /* 2 */
343
+ }
344
+
345
+ /*
346
+ Set the default cursor for buttons.
347
+ */
348
+
349
+ button,
350
+ [role="button"] {
351
+ cursor: pointer;
352
+ }
353
+
354
+ /*
355
+ Make sure disabled buttons don't get the pointer cursor.
356
+ */
357
+ :disabled {
358
+ cursor: default;
359
+ }
360
+
361
+ /*
362
+ 1. Make replaced elements `display: block` by default. (https://github.com/mozdevs/cssremedy/issues/14)
363
+ 2. Add `vertical-align: middle` to align replaced elements more sensibly by default. (https://github.com/jensimmons/cssremedy/issues/14#issuecomment-634934210)
364
+ This can trigger a poorly considered lint error in some tools but is included by design.
365
+ */
366
+
367
+ img,
368
+ svg,
369
+ video,
370
+ canvas,
371
+ audio,
372
+ iframe,
373
+ embed,
374
+ object {
375
+ display: block; /* 1 */
376
+ vertical-align: middle; /* 2 */
377
+ }
378
+
379
+ /*
380
+ Constrain images and videos to the parent width and preserve their intrinsic aspect ratio. (https://github.com/mozdevs/cssremedy/issues/14)
381
+ */
382
+
383
+ img,
384
+ video {
385
+ max-width: 100%;
386
+ height: auto;
387
+ }
388
+
389
+ /* Make elements with the HTML hidden attribute stay hidden by default */
390
+ [hidden]:where(:not([hidden="until-found"])) {
391
+ display: none;
392
+ }
393
+
@@ -0,0 +1,107 @@
1
+ module Hotdocs
2
+ module ApplicationHelper
3
+ include Rails.application.helpers # Include host helpers
4
+
5
+ def active_link_to(name = nil, options = nil, html_options = nil, &block)
6
+ if options.is_a?(String) && active_link?(options)
7
+ html_options = html_options.to_h.merge(class: "active") do |_, old, new|
8
+ [ *Array(old), new ].join(" ")
9
+ end
10
+ link_to(name, options, html_options, &block)
11
+ else
12
+ link_to(name, options, html_options, &block)
13
+ end
14
+ end
15
+
16
+ def external_link_to(name = nil, options = nil, html_options = nil)
17
+ default_html_options = {
18
+ class: "external-link",
19
+ target: "_blank",
20
+ rel: [ "noopener", "noreferrer" ]
21
+ }
22
+
23
+ html_options = html_options.to_h.merge(default_html_options) do |_, old, new|
24
+ [ *Array(old), *Array(new) ].join(" ")
25
+ end
26
+
27
+ link_to(options, html_options) do
28
+ concat(content_tag(:span, name))
29
+
30
+ concat(<<~SVG.html_safe)
31
+ <svg aria-hidden="true" viewBox="0 0 24 24" class="external-link__icon">
32
+ <path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path>
33
+ </svg>
34
+ SVG
35
+ end
36
+ end
37
+
38
+ def menu(items = menu_items)
39
+ menu_r(compute_menu(items))
40
+ end
41
+
42
+ def compute_menu(items)
43
+ compute_menu_r(items).first
44
+ end
45
+
46
+ def edit_link(base_url = repository_base_url)
47
+ return nil if base_url.nil?
48
+ return nil if base_url.empty?
49
+
50
+ template_path = lookup_context
51
+ .find_template("#{controller_path}/#{action_name}")
52
+ .identifier
53
+ .sub(Rails.root.to_s + "/", "")
54
+ href = "#{base_url}/#{template_path}"
55
+
56
+ html_options = {
57
+ class: "edit-link",
58
+ target: "_blank",
59
+ rel: [ "noopener", "noreferrer" ]
60
+ }
61
+
62
+ link_to(href, html_options) do
63
+ concat(<<~SVG.html_safe)
64
+ <svg aria-hidden="true" viewBox="0 0 40 40" class="edit-link__icon">
65
+ <path fill="currentColor" d="m34.5 11.7l-3 3.1-6.3-6.3 3.1-3q0.5-0.5 1.2-0.5t1.1 0.5l3.9 3.9q0.5 0.4 0.5 1.1t-0.5 1.2z m-29.5 17.1l18.4-18.5 6.3 6.3-18.4 18.4h-6.3v-6.2z"></path>
66
+ </svg>
67
+ SVG
68
+
69
+ concat(content_tag(:span, "Edit this page"))
70
+ end
71
+ end
72
+
73
+ private
74
+
75
+ def active_link?(url)
76
+ request.path == url
77
+ end
78
+
79
+ def compute_menu_r(items)
80
+ return [ [], false ] if items.nil?
81
+
82
+ new_items = items.map do |item|
83
+ children, expanded_below = compute_menu_r(item[:children])
84
+ active = active_link?(item.fetch(:url))
85
+ expanded = expanded_below || item[:expanded] || active
86
+ { **item, expanded: expanded, children: children }
87
+ end
88
+
89
+ [ new_items, new_items.any? { _1[:expanded] } ]
90
+ end
91
+
92
+ def menu_r(items)
93
+ return nil if items.size == 0
94
+
95
+ content_tag(:ul, class: "menu__section") do
96
+ items.each do |item|
97
+ concat(content_tag(:li) do
98
+ locals = { expanded: item.fetch(:expanded), label: item.fetch(:label), url: item.fetch(:url) }
99
+ concat(render partial: "hotdocs/menu_row", locals: locals)
100
+
101
+ concat(menu_r(item.fetch(:children)))
102
+ end)
103
+ end
104
+ end
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,11 @@
1
+ <%# locals: (label:, url:, expanded: false) -%>
2
+
3
+ <%= content_tag :div, class: "menu__row", data: { "controller": "accordion", "accordion-expanded-class-value": "menu__row--expanded", "accordion-expanded-value": expanded, "accordion-collapsed-aria-label-value": "Expand menu row '#{label}'", "accordion-expanded-aria-label-value": "Collapse menu row '#{label}'" } do %>
4
+ <%= active_link_to label, url, class: "menu__link" %>
5
+
6
+ <button type="button" class="menu__toggle" data-action="click->accordion#toggle" data-accordion-target="toggle">
7
+ <svg class="menu__toggle-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
8
+ <path fill="currentColor" d="M7.41 15.41L12 10.83l4.59 4.58L18 14l-6-6-6 6z"></path>
9
+ </svg>
10
+ </button>
11
+ <% end %>
@@ -0,0 +1,144 @@
1
+ <!DOCTYPE html>
2
+ <html data-theme="light">
3
+ <head>
4
+ <title><%= content_for(:title) %></title>
5
+
6
+ <%= yield :head %>
7
+
8
+ <%= stylesheet_link_tag "hotdocs/reset", media: "all", "data-turbo-track": "reload" %>
9
+ <%= stylesheet_link_tag "hotdocs/application", media: "all", "data-turbo-track": "reload" %>
10
+ </head>
11
+
12
+ <body>
13
+ <nav class="nav" data-controller="sidenav" data-sidenav-open-class-value="sidenav--open" data-sidenav-main-menu-class-value="sidenav__sections--main">
14
+ <div class="nav__section">
15
+ <button class="nav__toggle" type="button" aria-label="Toggle navigation" aria-expanded="false" data-action="click->sidenav#open">
16
+ <svg viewBox="0 0 30 30" aria-hidden="true">
17
+ <path stroke="currentColor" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" d="M4 7h22M4 15h22M4 23h22"></path>
18
+ </svg>
19
+ </button>
20
+
21
+ <%= link_to root_path, class: "nav__brand" do %>
22
+ <div class="nav__logo-wrapper">
23
+ <img class="nav__logo" src="<%= logo.src %>" alt="<%= logo.alt %>" height="32" width="32" />
24
+ </div>
25
+
26
+ <span class="nav__title">HotDocs</span>
27
+ <% end %>
28
+
29
+ <div class="nav__links">
30
+ <% nav_left_items("nav__link").each do |item| %>
31
+ <%= item %>
32
+ <% end %>
33
+ </div>
34
+ </div>
35
+
36
+ <div class="nav__section">
37
+ <div class="nav__links">
38
+ <% nav_right_items("nav__link").each do |item| %>
39
+ <%= item %>
40
+ <% end %>
41
+ </div>
42
+ </div>
43
+
44
+ <div class="sidenav-backdrop"></div>
45
+ <div class="sidenav">
46
+ <div class="sidenav__header">
47
+ <%= link_to root_path, class: "nav__brand" do %>
48
+ <div class="nav__logo-wrapper">
49
+ <img class="nav__logo" src="<%= logo.src %>" alt="<%= logo.alt %>" height="32" width="32" />
50
+ </div>
51
+
52
+ <span class="nav__title">HotDocs</span>
53
+ <% end %>
54
+
55
+ <button aria-label="Close navigation" class="sidenav__toggle" type="button" data-action="click->sidenav#close">
56
+ <svg viewBox="0 0 15 15">
57
+ <g stroke="currentColor" stroke-width="1.2">
58
+ <path d="M.75.75l13.5 13.5M14.25.75L.75 14.25"></path>
59
+ </g>
60
+ </svg>
61
+ </button>
62
+ </div>
63
+
64
+ <div class="sidenav__sections" data-sidenav-target="sections">
65
+ <div class="sidenav__section">
66
+ <ul class="menu__section">
67
+ <% (nav_left_items("menu__link") + nav_right_items("menu__link")).each do |item| %>
68
+ <li>
69
+ <div class="menu__row">
70
+ <%= item %>
71
+ </div>
72
+ </li>
73
+ <% end %>
74
+ </ul>
75
+ </div>
76
+
77
+ <div class="sidenav__section">
78
+ <div class="menu__section">
79
+ <button type="button" class="sidenav__back-button" data-action="click->sidenav#back">← Back to main menu</button>
80
+ </div>
81
+
82
+ <%= menu %>
83
+ </div>
84
+ </div>
85
+ </div>
86
+ </nav>
87
+
88
+ <div class="content">
89
+ <aside class="menu">
90
+ <div class="menu__sections">
91
+ <%= menu %>
92
+ </div>
93
+ </aside>
94
+
95
+ <main data-controller="toc" class="main">
96
+ <div class="central">
97
+ <details name="toc" class="toc">
98
+ <summary class="toc__label">Table of contents</summary>
99
+
100
+ <ul class="toc__entries" data-toc-target="toc">
101
+ <template data-toc-target="tocTemplate">
102
+ <li><a id class="toc__link" href></a></li>
103
+ </template>
104
+ </ul>
105
+ </details>
106
+
107
+ <article class="article" data-toc-target="article">
108
+ <%= yield %>
109
+ </article>
110
+
111
+ <%= edit_link %>
112
+ </div>
113
+
114
+ <div class="sidetoc">
115
+ <ul class="sidetoc__entries" data-toc-target="sidetoc">
116
+ <template data-toc-target="sidetocTemplate">
117
+ <li><a id class="sidetoc__link" href></a></li>
118
+ </template>
119
+ </ul>
120
+ </div>
121
+ </main>
122
+ </div>
123
+
124
+ <footer class="footer">
125
+ <div class="footer__sections">
126
+ <% footer_items.each do |footer_item| %>
127
+ <div class="footer__section">
128
+ <p class="footer__heading"><%= footer_item.fetch(:heading) %></p>
129
+
130
+ <ul>
131
+ <% footer_item.fetch(:items).each do |item| %>
132
+ <li><%= item %></li>
133
+ <% end %>
134
+ </ul>
135
+ </div>
136
+ <% end %>
137
+ </div>
138
+
139
+ <img class="footer__logo" src="<%= logo.src %>" alt="<%= logo.alt %>" height="150" width="150" />
140
+
141
+ <p class="credits">Built with Rails &amp; <a class="credits__link" href="https://hotdocsrails.com">HotDocs<img class="credits__logo" src="<%= asset_path "hotdocs/icon.svg" %>" alt="A humanized and happy hot dog" height="32" width="32" /></a></p>
142
+ </footer>
143
+ </body>
144
+ </html>
@@ -0,0 +1,3 @@
1
+ # Pin npm packages by running ./bin/importmap
2
+
3
+ pin_all_from Hotdocs::Engine.root.join("app/assets/javascript/controllers"), under: "controllers"
@@ -0,0 +1,20 @@
1
+ require_relative "markdown"
2
+
3
+ module Hotdocs
4
+ class Engine < ::Rails::Engine
5
+ isolate_namespace Hotdocs
6
+
7
+ initializer "hotdocs.importmap", before: "importmap" do |app|
8
+ # https://github.com/rails/importmap-rails#composing-import-maps
9
+ app.config.importmap.paths << Engine.root.join("config/importmap.rb")
10
+
11
+ # https://github.com/rails/importmap-rails#sweeping-the-cache-in-development-and-test
12
+ app.config.importmap.cache_sweepers << Engine.root.join("app/assets/javascript")
13
+ end
14
+
15
+ config.before_initialize do
16
+ MarkdownHandler.prepare(self)
17
+ ActionView::Template.register_template_handler :mderb, MarkdownHandler.new(self)
18
+ end
19
+ end
20
+ end