hotdocs 0.4.0 → 0.5.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.
@@ -81,6 +81,58 @@ module Hotdocs
81
81
  content_tag(:div, id: id, data: data, style: "visibility: hidden;", &)
82
82
  end
83
83
 
84
+ PATHS_BY_ALERT_TYPE = {
85
+ "danger" => [
86
+ "M15.362 5.214A8.252 8.252 0 0 1 12 21 8.25 8.25 0 0 1 6.038 7.047 8.287 8.287 0 0 0 9 9.601a8.983 8.983 0 0 1 3.361-6.867 8.21 8.21 0 0 0 3 2.48Z",
87
+ "M12 18a3.75 3.75 0 0 0 .495-7.468 5.99 5.99 0 0 0-1.925 3.547 5.975 5.975 0 0 1-2.133-1.001A3.75 3.75 0 0 0 12 18Z"
88
+ ],
89
+ "warning" => [
90
+ "M12 9v3.75m-9.303 3.376c-.866 1.5.217 3.374 1.948 3.374h14.71c1.73 0 2.813-1.874 1.948-3.374L13.949 3.378c-.866-1.5-3.032-1.5-3.898 0L2.697 16.126ZM12 15.75h.007v.008H12v-.008Z"
91
+ ],
92
+ "tip" => [
93
+ "M12 18v-5.25m0 0a6.01 6.01 0 0 0 1.5-.189m-1.5.189a6.01 6.01 0 0 1-1.5-.189m3.75 7.478a12.06 12.06 0 0 1-4.5 0m3.75 2.383a14.406 14.406 0 0 1-3 0M14.25 18v-.192c0-.983.658-1.823 1.508-2.316a7.5 7.5 0 1 0-7.517 0c.85.493 1.509 1.333 1.509 2.316V18"
94
+ ],
95
+ "info" => [
96
+ "m11.25 11.25.041-.02a.75.75 0 0 1 1.063.852l-.708 2.836a.75.75 0 0 0 1.063.853l.041-.021M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Zm-9-3.75h.008v.008H12V8.25Z"
97
+ ]
98
+ }
99
+
100
+ def alert(type, &block)
101
+ paths = PATHS_BY_ALERT_TYPE.fetch(type.to_s)
102
+
103
+ content_tag(:div, class: "alert alert--#{type}") do
104
+ content_tag(:div) do
105
+ concat(
106
+ content_tag(:div, class: "alert__header") do
107
+ concat(
108
+ content_tag(
109
+ :svg,
110
+ class: "alert__icon",
111
+ xmlns: "http://www.w3.org/2000/svg",
112
+ fill: "none",
113
+ viewBox: "0 0 24 24",
114
+ "stroke-width": "1.5",
115
+ stroke: "currentColor"
116
+ ) do
117
+ paths.each do |path|
118
+ concat(content_tag(:path, {}, "stroke-linecap": "round", "stroke-linejoin": "round", d: path))
119
+ end
120
+ end
121
+ )
122
+ concat(content_tag(:span, type.upcase, class: "alert__label"))
123
+ end
124
+ )
125
+ concat(content_tag(:div, class: "alert__content", &block))
126
+ end
127
+ end
128
+ end
129
+
130
+ def external_url?(url)
131
+ !URI.parse(url).host.nil?
132
+ rescue URI::InvalidURIError
133
+ false
134
+ end
135
+
84
136
  private
85
137
 
86
138
  def active_link?(url)
@@ -92,7 +144,7 @@ module Hotdocs
92
144
 
93
145
  new_items = items.map do |item|
94
146
  children, expanded_below = compute_menu_r(item[:children])
95
- active = active_link?(item.fetch(:url))
147
+ active = active_link?(item.fetch(:url, nil))
96
148
  expanded = expanded_below || item[:expanded] || active
97
149
  { **item, expanded: expanded, children: children }
98
150
  end
@@ -106,7 +158,7 @@ module Hotdocs
106
158
  content_tag(:ul, class: "menu__section") do
107
159
  items.each do |item|
108
160
  concat(content_tag(:li) do
109
- locals = { expanded: item.fetch(:expanded), label: item.fetch(:label), url: item.fetch(:url) }
161
+ locals = { expanded: item.fetch(:expanded), label: item.fetch(:label), url: item.fetch(:url, nil) }
110
162
  concat(render partial: "hotdocs/menu_row", locals: locals)
111
163
 
112
164
  concat(menu_r(item.fetch(:children)))
@@ -1,11 +1,14 @@
1
1
  <%# locals: (label:, url:, expanded: false) -%>
2
2
 
3
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" %>
4
+ <%= active_link_to label, url, class: "menu__link" if !url.nil? && !external_url?(url) %>
5
+ <%= external_link_to label, url, class: "menu__link" if !url.nil? && external_url?(url) %>
6
+
7
+ <%= content_tag :button, type: "button", class: class_names("menu__toggle", "menu__toggle--full": url.nil?), data: { action: "click->accordion#toggle", "accordion-target": "toggle" } do %>
8
+ <%= content_tag :span, label, class: "menu__link" if url.nil? %>
5
9
 
6
- <button type="button" class="menu__toggle" data-action="click->accordion#toggle" data-accordion-target="toggle">
7
10
  <svg class="menu__toggle-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
8
11
  <path fill="currentColor" d="M7.41 15.41L12 10.83l4.59 4.58L18 14l-6-6-6 6z"></path>
9
12
  </svg>
10
- </button>
13
+ <% end %>
11
14
  <% end %>
@@ -5,12 +5,11 @@
5
5
 
6
6
  <%= yield :head %>
7
7
 
8
- <%= stylesheet_link_tag "hotdocs/reset", media: "all", "data-turbo-track": "reload" %>
9
8
  <%= stylesheet_link_tag "hotdocs/application", media: "all", "data-turbo-track": "reload" %>
10
9
  </head>
11
10
 
12
11
  <body data-controller="search">
13
- <dialog data-search-target="search" class="search">
12
+ <dialog data-search-target="search" class="reset search">
14
13
  <div data-search-target="dialog" class="search__dialog">
15
14
  <div class="search__header">
16
15
  <input autofocus data-action="input->search#search" type="text" class="search__input"></input>
@@ -42,11 +41,15 @@
42
41
  </script>
43
42
  </dialog>
44
43
 
44
+ <% if content_for?(:announcement) %>
45
+ <%= content_for(:announcement) %>
46
+ <% end %>
47
+
45
48
  <% if content_for?(:hotdocs_nav) %>
46
49
  <%= content_for(:hotdocs_nav) %>
47
50
 
48
51
  <% else %>
49
- <nav class="nav" data-controller="sidenav" data-sidenav-open-class-value="sidenav--open" data-sidenav-main-menu-class-value="sidenav__sections--main">
52
+ <nav class="reset nav" data-controller="sidenav" data-sidenav-open-class-value="sidenav--open" data-sidenav-main-menu-class-value="sidenav__sections--main">
50
53
  <div class="nav__section">
51
54
  <button class="nav__toggle" type="button" aria-label="Toggle navigation" aria-expanded="false" data-action="click->sidenav#open">
52
55
  <svg viewBox="0 0 30 30" aria-hidden="true">
@@ -78,13 +81,15 @@
78
81
  <% end %>
79
82
  </div>
80
83
 
81
- <button type="button" data-action="click->search#open:stop" class="search-button" aria-label="Open search dialog">
82
- <svg class="search-button__icon" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
83
- <path stroke-linecap="round" stroke-linejoin="round" d="m21 21-5.197-5.197m0 0A7.5 7.5 0 1 0 5.196 5.196a7.5 7.5 0 0 0 10.607 10.607Z" />
84
- </svg>
84
+ <div class="search-box">
85
+ <button type="button" data-action="click->search#open:stop" class="search-box__button" aria-label="Open search dialog">
86
+ <svg class="search-box__icon" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
87
+ <path stroke-linecap="round" stroke-linejoin="round" d="m21 21-5.197-5.197m0 0A7.5 7.5 0 1 0 5.196 5.196a7.5 7.5 0 0 0 10.607 10.607Z" />
88
+ </svg>
85
89
 
86
- <span class="search-button__label">Type / to search</span>
87
- </button>
90
+ <span class="search-box__label">Type / to search</span>
91
+ </button>
92
+ </div>
88
93
  </div>
89
94
 
90
95
  <div class="sidenav-backdrop"></div>
@@ -135,7 +140,7 @@
135
140
  <% end %>
136
141
 
137
142
  <div class="content">
138
- <aside class="menu">
143
+ <aside class="reset menu">
139
144
  <div class="menu__sections">
140
145
  <%= menu %>
141
146
  </div>
@@ -143,7 +148,7 @@
143
148
 
144
149
  <main data-controller="toc" class="main">
145
150
  <div class="central">
146
- <details name="toc" class="toc">
151
+ <details name="toc" class="reset toc">
147
152
  <summary class="toc__label">Table of contents</summary>
148
153
 
149
154
  <ul class="toc__entries" data-toc-target="toc">
@@ -153,19 +158,23 @@
153
158
  </ul>
154
159
  </details>
155
160
 
156
- <article class="article" data-toc-target="article">
161
+ <div class="article" data-toc-target="article">
157
162
  <%= yield %>
158
- </article>
163
+ </div>
159
164
 
160
- <%= edit_link %>
165
+ <div class="reset">
166
+ <%= edit_link %>
167
+ </div>
161
168
  </div>
162
169
 
163
- <div class="sidetoc">
164
- <ul class="sidetoc__entries" data-toc-target="sidetoc">
165
- <template data-toc-target="sidetocTemplate">
166
- <li><a id class="sidetoc__link" href></a></li>
167
- </template>
168
- </ul>
170
+ <div class="reset sidetoc">
171
+ <div class="sidetoc__section">
172
+ <ul class="sidetoc__entries" data-toc-target="sidetoc">
173
+ <template data-toc-target="sidetocTemplate">
174
+ <li><a id class="sidetoc__link" href></a></li>
175
+ </template>
176
+ </ul>
177
+ </div>
169
178
  </div>
170
179
  </main>
171
180
  </div>
@@ -174,7 +183,7 @@
174
183
  <%= content_for(:hotdocs_footer) %>
175
184
 
176
185
  <% else %>
177
- <footer class="footer">
186
+ <footer class="reset footer">
178
187
  <div class="footer__sections">
179
188
  <% footer_items.each do |footer_item| %>
180
189
  <div class="footer__section">
@@ -195,6 +204,6 @@
195
204
  </footer>
196
205
  <% end %>
197
206
 
198
- <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>
207
+ <p class="reset 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>
199
208
  </body>
200
209
  </html>
@@ -2,8 +2,6 @@ require "kramdown"
2
2
  require "kramdown-parser-gfm"
3
3
  require "rouge"
4
4
 
5
- require_relative "kramdown_alerts"
6
-
7
5
  class MarkdownHandler
8
6
  def call(template, source)
9
7
  # If the template contains a `fetcher`, do not allow Rails to cache the page.
@@ -27,7 +25,7 @@ class MarkdownHandler
27
25
  .new
28
26
  .call(template, source)
29
27
  .split(";")
30
- .grep(/content_for.*\(.*:/)
28
+ .grep(/@output_buffer.append=\(\scontent_for.*\(.*:/)
31
29
 
32
30
  <<~STRING
33
31
  #{content_fors.join(";")}
@@ -1,3 +1,3 @@
1
1
  module Hotdocs
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -60,11 +60,15 @@ create_file(Pathname(destination_root).join("app/views/layouts/hotdocs.html.erb"
60
60
  <%= content_for(:title, "HotDocs") unless content_for?(:title) %>
61
61
  <meta name="viewport" content="width=device-width,initial-scale=1">
62
62
  <%= stylesheet_link_tag "hotdocs/application" %>
63
- <%= stylesheet_link_tag "hotdocs/base" %>
63
+ <%= stylesheet_link_tag "hotdocs/custom" %>
64
64
  <%= stylesheet_link_tag "hotdocs/rouge" %>
65
65
  <%= javascript_importmap_tags "hotdocs" %>
66
66
  <% end %>
67
67
 
68
+ <%= content_for(:announcement) do %>
69
+ <div class="announcement">This is an announcement at the top of the page</div>
70
+ <% end if false %>
71
+
68
72
  <%= render template: "layouts/hotdocs/application" %>
69
73
  FILE
70
74
 
@@ -110,7 +114,7 @@ create_file(Pathname(destination_root).join("app/helpers/hotdocs_helper.rb"), <<
110
114
  ]
111
115
  end
112
116
 
113
- # { label: "", url: *_path, children: [], expanded: false/true }
117
+ # { label: String, url?: [String, nil], children?: Array, expanded: Boolean }
114
118
  def menu_items
115
119
  [
116
120
  { label: "Welcome", url: hotdocs_path },
@@ -158,7 +162,7 @@ FILE
158
162
 
159
163
  empty_directory "app/assets/stylesheets/hotdocs"
160
164
 
161
- create_file(Pathname(destination_root).join("app/assets/stylesheets/hotdocs/base.css"), <<~FILE)
165
+ create_file(Pathname(destination_root).join("app/assets/stylesheets/hotdocs/custom.css"), <<~FILE)
162
166
  :root {
163
167
  --docs-code-background-color: #eee;
164
168
  --docs-code-border-color: #00000022;
@@ -294,5 +298,4 @@ empty_directory "app/assets/builds"
294
298
  keep_file "app/assets/builds"
295
299
  if Pathname(destination_root).join(".gitignore").exist?
296
300
  append_to_file(".gitignore", %(\n/app/assets/builds/*\n!/app/assets/builds/.keep\n))
297
- append_to_file(".gitignore", %(\n/node_modules/\n))
298
301
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hotdocs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - 3v0k4
@@ -90,7 +90,6 @@ files:
90
90
  - config/importmap.rb
91
91
  - lib/hotdocs.rb
92
92
  - lib/hotdocs/engine.rb
93
- - lib/hotdocs/kramdown_alerts.rb
94
93
  - lib/hotdocs/markdown.rb
95
94
  - lib/hotdocs/version.rb
96
95
  - lib/install/install.rb
@@ -1,92 +0,0 @@
1
- module Kramdown
2
- class Element
3
- def to_h
4
- {
5
- children: children.map(&:to_h),
6
- type:,
7
- value:
8
- }
9
- end
10
- end
11
- end
12
-
13
- module Alert
14
- PATHS_BY_ALERT_TYPE = {
15
- "danger" => [
16
- "M15.362 5.214A8.252 8.252 0 0 1 12 21 8.25 8.25 0 0 1 6.038 7.047 8.287 8.287 0 0 0 9 9.601a8.983 8.983 0 0 1 3.361-6.867 8.21 8.21 0 0 0 3 2.48Z",
17
- "M12 18a3.75 3.75 0 0 0 .495-7.468 5.99 5.99 0 0 0-1.925 3.547 5.975 5.975 0 0 1-2.133-1.001A3.75 3.75 0 0 0 12 18Z"
18
- ],
19
- "warning" => [
20
- "M12 9v3.75m-9.303 3.376c-.866 1.5.217 3.374 1.948 3.374h14.71c1.73 0 2.813-1.874 1.948-3.374L13.949 3.378c-.866-1.5-3.032-1.5-3.898 0L2.697 16.126ZM12 15.75h.007v.008H12v-.008Z"
21
- ],
22
- "tip" => [
23
- "M12 18v-5.25m0 0a6.01 6.01 0 0 0 1.5-.189m-1.5.189a6.01 6.01 0 0 1-1.5-.189m3.75 7.478a12.06 12.06 0 0 1-4.5 0m3.75 2.383a14.406 14.406 0 0 1-3 0M14.25 18v-.192c0-.983.658-1.823 1.508-2.316a7.5 7.5 0 1 0-7.517 0c.85.493 1.509 1.333 1.509 2.316V18"
24
- ],
25
- "info" => [
26
- "m11.25 11.25.041-.02a.75.75 0 0 1 1.063.852l-.708 2.836a.75.75 0 0 0 1.063.853l.041-.021M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Zm-9-3.75h.008v.008H12V8.25Z"
27
- ]
28
- }
29
-
30
- def convert_blockquote(el, indent)
31
- child = el.children[0]
32
-
33
- case child.to_h
34
- in {
35
- type: :p,
36
- children: [
37
- { type: :text, value: /\A\[!(INFO|TIP|WARNING|DANGER)\]\z/ },
38
- { type: :br },
39
- *
40
- ]
41
- }
42
- alert_type = $+.downcase
43
- child.children.slice!(0, 2) # remove :text & :br
44
-
45
- svg = Kramdown::Element.new(
46
- :html_element,
47
- :svg,
48
- {
49
- class: "alert__icon",
50
- xmlns: "http://www.w3.org/2000/svg",
51
- fill: "none",
52
- viewBox: "0 0 24 24",
53
- "stroke-width": "1.5",
54
- stroke: "currentColor"
55
- }
56
- )
57
-
58
- PATHS_BY_ALERT_TYPE[alert_type].each do |path|
59
- svg.children << Kramdown::Element.new(:html_element, :path, {
60
- "stroke-linecap": "round",
61
- "stroke-linejoin": "round",
62
- d: path
63
- })
64
- end
65
-
66
- label = Kramdown::Element.new(:html_element, :span, { class: "alert__label" })
67
- label.children << Kramdown::Element.new(:text, alert_type.upcase)
68
-
69
- header = Kramdown::Element.new(:html_element, :div, { class: "alert__header" })
70
- header.children << svg
71
- header.children << label
72
-
73
- content = Kramdown::Element.new(:html_element, :div, { class: "alert__content" })
74
- content.children.push(*el.children)
75
-
76
- alert = Kramdown::Element.new(:html_element, :div, {})
77
- alert.children << header
78
- alert.children << content
79
-
80
- format_as_block_html(
81
- "div",
82
- { class: "alert alert--#{alert_type}" },
83
- format_as_indented_block_html("div", {}, inner(alert, indent), indent),
84
- indent
85
- )
86
- else
87
- super
88
- end
89
- end
90
- end
91
-
92
- Kramdown::Converter::Html.prepend(Alert)