docyard 0.5.0 → 0.7.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.
Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -1
  3. data/CHANGELOG.md +34 -1
  4. data/lib/docyard/build/static_generator.rb +3 -44
  5. data/lib/docyard/builder.rb +14 -4
  6. data/lib/docyard/cli.rb +6 -3
  7. data/lib/docyard/components/aliases.rb +29 -0
  8. data/lib/docyard/components/base_processor.rb +6 -0
  9. data/lib/docyard/components/processors/callout_processor.rb +124 -0
  10. data/lib/docyard/components/processors/code_block_diff_preprocessor.rb +106 -0
  11. data/lib/docyard/components/processors/code_block_focus_preprocessor.rb +79 -0
  12. data/lib/docyard/components/processors/code_block_options_preprocessor.rb +78 -0
  13. data/lib/docyard/components/processors/code_block_processor.rb +175 -0
  14. data/lib/docyard/components/processors/code_snippet_import_preprocessor.rb +127 -0
  15. data/lib/docyard/components/processors/heading_anchor_processor.rb +39 -0
  16. data/lib/docyard/components/processors/icon_processor.rb +53 -0
  17. data/lib/docyard/components/processors/table_of_contents_processor.rb +68 -0
  18. data/lib/docyard/components/processors/table_wrapper_processor.rb +22 -0
  19. data/lib/docyard/components/processors/tabs_processor.rb +48 -0
  20. data/lib/docyard/components/registry.rb +4 -4
  21. data/lib/docyard/components/support/code_block/feature_extractor.rb +117 -0
  22. data/lib/docyard/components/support/code_block/icon_detector.rb +44 -0
  23. data/lib/docyard/components/support/code_block/line_parser.rb +84 -0
  24. data/lib/docyard/components/support/code_block/line_wrapper.rb +50 -0
  25. data/lib/docyard/components/support/code_block/patterns.rb +55 -0
  26. data/lib/docyard/components/support/code_detector.rb +61 -0
  27. data/lib/docyard/components/support/tabs/icon_detector.rb +62 -0
  28. data/lib/docyard/components/support/tabs/parser.rb +195 -0
  29. data/lib/docyard/components/support/tabs/range_finder.rb +46 -0
  30. data/lib/docyard/config/branding_resolver.rb +74 -0
  31. data/lib/docyard/{constants.rb → config/constants.rb} +1 -0
  32. data/lib/docyard/config/validator.rb +8 -0
  33. data/lib/docyard/config.rb +17 -1
  34. data/lib/docyard/{prev_next_builder.rb → navigation/prev_next_builder.rb} +2 -2
  35. data/lib/docyard/{sidebar → navigation/sidebar}/renderer.rb +3 -14
  36. data/lib/docyard/{sidebar → navigation/sidebar}/tree_builder.rb +9 -2
  37. data/lib/docyard/{sidebar_builder.rb → navigation/sidebar_builder.rb} +3 -15
  38. data/lib/docyard/{icons → rendering/icons}/file_types.rb +0 -13
  39. data/lib/docyard/{icons → rendering/icons}/phosphor.rb +4 -1
  40. data/lib/docyard/{markdown.rb → rendering/markdown.rb} +23 -14
  41. data/lib/docyard/{renderer.rb → rendering/renderer.rb} +24 -20
  42. data/lib/docyard/search/build_indexer.rb +74 -0
  43. data/lib/docyard/search/dev_indexer.rb +110 -0
  44. data/lib/docyard/search/pagefind_support.rb +31 -0
  45. data/lib/docyard/{asset_handler.rb → server/asset_handler.rb} +1 -1
  46. data/lib/docyard/{server.rb → server/dev_server.rb} +32 -9
  47. data/lib/docyard/{preview_server.rb → server/preview_server.rb} +1 -1
  48. data/lib/docyard/{rack_application.rb → server/rack_application.rb} +53 -50
  49. data/lib/docyard/server/resolution_result.rb +29 -0
  50. data/lib/docyard/{router.rb → server/router.rb} +4 -4
  51. data/lib/docyard/templates/assets/css/code.css +12 -4
  52. data/lib/docyard/templates/assets/css/components/code-block.css +427 -24
  53. data/lib/docyard/templates/assets/css/components/navigation.css +12 -9
  54. data/lib/docyard/templates/assets/css/components/search.css +549 -0
  55. data/lib/docyard/templates/assets/css/components/tabs.css +50 -44
  56. data/lib/docyard/templates/assets/css/layout.css +15 -1
  57. data/lib/docyard/templates/assets/css/variables.css +44 -0
  58. data/lib/docyard/templates/assets/js/components/search.js +685 -0
  59. data/lib/docyard/templates/layouts/default.html.erb +14 -2
  60. data/lib/docyard/templates/partials/_code_block.html.erb +50 -2
  61. data/lib/docyard/templates/partials/_heading_anchor.html.erb +1 -1
  62. data/lib/docyard/templates/partials/_prev_next.html.erb +1 -1
  63. data/lib/docyard/templates/partials/_search_modal.html.erb +45 -0
  64. data/lib/docyard/templates/partials/_search_trigger.html.erb +22 -0
  65. data/lib/docyard/utils/html_helpers.rb +14 -0
  66. data/lib/docyard/utils/path_resolver.rb +2 -1
  67. data/lib/docyard/utils/url_helpers.rb +20 -0
  68. data/lib/docyard/version.rb +1 -1
  69. data/lib/docyard.rb +22 -15
  70. metadata +57 -36
  71. data/lib/docyard/components/callout_processor.rb +0 -121
  72. data/lib/docyard/components/code_block_processor.rb +0 -55
  73. data/lib/docyard/components/code_detector.rb +0 -59
  74. data/lib/docyard/components/heading_anchor_processor.rb +0 -34
  75. data/lib/docyard/components/icon_detector.rb +0 -57
  76. data/lib/docyard/components/icon_processor.rb +0 -51
  77. data/lib/docyard/components/table_of_contents_processor.rb +0 -64
  78. data/lib/docyard/components/table_wrapper_processor.rb +0 -18
  79. data/lib/docyard/components/tabs_parser.rb +0 -60
  80. data/lib/docyard/components/tabs_processor.rb +0 -44
  81. data/lib/docyard/routing/resolution_result.rb +0 -31
  82. /data/lib/docyard/{sidebar → navigation/sidebar}/config_parser.rb +0 -0
  83. /data/lib/docyard/{sidebar → navigation/sidebar}/file_system_scanner.rb +0 -0
  84. /data/lib/docyard/{sidebar → navigation/sidebar}/item.rb +0 -0
  85. /data/lib/docyard/{sidebar → navigation/sidebar}/title_extractor.rb +0 -0
  86. /data/lib/docyard/{icons → rendering/icons}/LICENSE.phosphor +0 -0
  87. /data/lib/docyard/{icons.rb → rendering/icons.rb} +0 -0
  88. /data/lib/docyard/{language_mapping.rb → rendering/language_mapping.rb} +0 -0
  89. /data/lib/docyard/{file_watcher.rb → server/file_watcher.rb} +0 -0
  90. /data/lib/docyard/{errors.rb → utils/errors.rb} +0 -0
  91. /data/lib/docyard/{logging.rb → utils/logging.rb} +0 -0
@@ -43,7 +43,15 @@
43
43
  <% end %>
44
44
  </a>
45
45
 
46
- <%= render_partial('_theme_toggle') %>
46
+ <% if @search_enabled %>
47
+ <div class="header-center">
48
+ <%= render_partial('_search_trigger') %>
49
+ </div>
50
+ <% end %>
51
+
52
+ <div class="header-actions">
53
+ <%= render_partial('_theme_toggle') %>
54
+ </div>
47
55
  </div>
48
56
  </header>
49
57
 
@@ -68,7 +76,7 @@
68
76
 
69
77
  <!-- Main content area -->
70
78
  <div class="layout-main">
71
- <main id="main-content" class="content">
79
+ <main id="main-content" class="content" data-pagefind-body>
72
80
  <%= @content %>
73
81
 
74
82
  <!-- Previous/Next Navigation -->
@@ -80,6 +88,10 @@
80
88
  <%= render_partial('_table_of_contents') %>
81
89
  </div>
82
90
 
91
+ <% if @search_enabled %>
92
+ <%= render_partial('_search_modal') %>
93
+ <% end %>
94
+
83
95
  <script src="/assets/js/theme.js"></script>
84
96
  <script src="/assets/js/components.js"></script>
85
97
  <script src="/assets/js/reload.js"></script>
@@ -1,6 +1,54 @@
1
- <div class="docyard-code-block">
2
- <%= @code_block_html %>
1
+ <% has_diff = @diff_lines&.any? %><% has_focus = @focus_lines&.any? %><% has_error = @error_lines&.any? %><% has_warning = @warning_lines&.any? %><% has_title = !@title.nil? && !@title.empty? %><div class="docyard-code-block<%= ' docyard-code-block--line-numbers' if @show_line_numbers %><%= ' docyard-code-block--highlighted' if @highlights&.any? %><%= ' docyard-code-block--diff' if has_diff %><%= ' docyard-code-block--has-focus' if has_focus %><%= ' docyard-code-block--has-error' if has_error %><%= ' docyard-code-block--has-warning' if has_warning %><%= ' docyard-code-block--titled' if has_title %>" data-pagefind-ignore>
2
+ <% if has_title %>
3
+ <div class="docyard-code-block__header">
4
+ <% if @icon %>
5
+ <span class="docyard-code-block__icon"><% if @icon_source == "file-extension" %><%= Docyard::Icons.render_file_extension(@icon) %><% elsif @icon_source == "phosphor" %><%= Docyard::Icons.render(@icon) %><% end %></span>
6
+ <% end %>
7
+ <span class="docyard-code-block__title" title="<%= @title %>"><%= @title %></span>
8
+ <button class="docyard-code-block__copy" aria-label="Copy code to clipboard" data-code="<%= @code_text %>">
9
+ <%= @copy_icon %>
10
+ </button>
11
+ </div>
12
+ <% end %>
13
+ <div class="docyard-code-block__body">
14
+ <% if @show_line_numbers %>
15
+ <div class="docyard-code-block__lines" aria-hidden="true">
16
+ <% @line_numbers.each_with_index do |num, index| %>
17
+ <%
18
+ source_line = index + 1
19
+ diff_type = @diff_lines&.dig(source_line)
20
+ is_error = @error_lines&.dig(source_line)
21
+ is_warning = @warning_lines&.dig(source_line)
22
+ line_class = case diff_type
23
+ when :addition then "docyard-code-block__line--diff-add"
24
+ when :deletion then "docyard-code-block__line--diff-remove"
25
+ else
26
+ if is_error
27
+ "docyard-code-block__line--error"
28
+ elsif is_warning
29
+ "docyard-code-block__line--warning"
30
+ elsif @highlights&.include?(num)
31
+ "docyard-code-block__line--highlighted"
32
+ end
33
+ end
34
+ prefix = case diff_type
35
+ when :addition then "+"
36
+ when :deletion then "-"
37
+ else ""
38
+ end
39
+ %><% if line_class %><span class="<%= line_class %>"><%= prefix %><%= num %></span><% else %><span><%= num %></span><% end %>
40
+ <% end %>
41
+ </div>
42
+ <% elsif has_diff %>
43
+ <div class="docyard-code-block__diff-gutter" aria-hidden="true"><% line_count = @code_block_html.scan(/<span class="docyard-code-line/).count %><% line_count = 1 if line_count.zero? %><% (1..line_count).each do |num| %><% diff_type = @diff_lines&.dig(num) %><% gutter_class = diff_type == :addition ? "docyard-code-block__diff-indicator--add" : (diff_type == :deletion ? "docyard-code-block__diff-indicator--remove" : nil) %><% indicator = diff_type == :addition ? "+" : (diff_type == :deletion ? "-" : "") %><% if gutter_class %><span class="<%= gutter_class %>"><%= indicator %></span><% else %><span>&nbsp;</span><% end %><% end %></div>
44
+ <% end %>
45
+ <div class="docyard-code-block__content">
46
+ <%= @code_block_html %>
47
+ </div>
48
+ <% unless has_title %>
3
49
  <button class="docyard-code-block__copy" aria-label="Copy code to clipboard" data-code="<%= @code_text %>">
4
50
  <%= @copy_icon %>
5
51
  </button>
52
+ <% end %>
53
+ </div>
6
54
  </div>
@@ -1 +1 @@
1
- <a href="#<%= @id %>" class="heading-anchor" aria-label="Link to this section" data-heading-id="<%= @id %>">#</a>
1
+ <a href="#<%= @id %>" class="heading-anchor" aria-label="Link to this section" data-heading-id="<%= @id %>" data-pagefind-ignore>#</a>
@@ -1,5 +1,5 @@
1
1
  <% if @prev || @next %>
2
- <footer class="doc-footer">
2
+ <footer class="doc-footer" data-pagefind-ignore>
3
3
  <nav class="pager" aria-labelledby="doc-footer-aria-label">
4
4
  <span id="doc-footer-aria-label" class="visually-hidden">Pager</span>
5
5
 
@@ -0,0 +1,45 @@
1
+ <div class="search-modal" role="dialog" aria-modal="true" aria-label="Search documentation" data-search-modal data-pagefind-ignore hidden>
2
+ <div class="search-modal-backdrop" data-search-backdrop></div>
3
+ <div class="search-modal-container">
4
+ <div class="search-modal-header">
5
+ <svg class="search-modal-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256" fill="currentColor" aria-hidden="true">
6
+ <path d="M229.66,218.34l-50.07-50.06a88.11,88.11,0,1,0-11.31,11.31l50.06,50.07a8,8,0,0,0,11.32-11.32ZM40,112a72,72,0,1,1,72,72A72.08,72.08,0,0,1,40,112Z"></path>
7
+ </svg>
8
+ <input
9
+ type="text"
10
+ class="search-modal-input"
11
+ placeholder="<%= @search_placeholder || 'Search documentation...' %>"
12
+ autocomplete="off"
13
+ autocorrect="off"
14
+ autocapitalize="off"
15
+ spellcheck="false"
16
+ data-search-input
17
+ >
18
+ <button type="button" class="search-modal-close" data-search-close aria-label="Close search">
19
+ <span class="search-modal-close-text">esc</span>
20
+ </button>
21
+ </div>
22
+
23
+ <div class="search-modal-body" data-search-body hidden>
24
+ <div class="search-modal-loading" data-search-loading hidden>
25
+ <div class="search-modal-spinner"></div>
26
+ </div>
27
+
28
+ <div class="search-modal-empty" data-search-empty hidden>
29
+ <svg class="search-empty-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256" fill="currentColor">
30
+ <path d="M229.66,218.34l-50.07-50.06a88.11,88.11,0,1,0-11.31,11.31l50.06,50.07a8,8,0,0,0,11.32-11.32ZM40,112a72,72,0,1,1,72,72A72.08,72.08,0,0,1,40,112Z"></path>
31
+ </svg>
32
+ <span class="search-empty-title">No results found</span>
33
+ <span class="search-empty-hint">Try different keywords or check your spelling</span>
34
+ </div>
35
+
36
+ <ul class="search-modal-results" role="listbox" data-search-results hidden></ul>
37
+ </div>
38
+
39
+ <div class="search-modal-footer">
40
+ <span class="search-modal-hint"><kbd>Enter</kbd> select</span>
41
+ <span class="search-modal-hint"><kbd>&uarr;</kbd><kbd>&darr;</kbd> navigate</span>
42
+ <span class="search-modal-hint"><kbd>Esc</kbd> close</span>
43
+ </div>
44
+ </div>
45
+ </div>
@@ -0,0 +1,22 @@
1
+ <button
2
+ type="button"
3
+ class="search-trigger"
4
+ aria-label="Search documentation"
5
+ aria-haspopup="dialog"
6
+ data-search-trigger
7
+ >
8
+ <span class="search-trigger-icon" aria-hidden="true">
9
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256" fill="currentColor">
10
+ <path d="M229.66,218.34l-50.07-50.06a88.11,88.11,0,1,0-11.31,11.31l50.06,50.07a8,8,0,0,0,11.32-11.32ZM40,112a72,72,0,1,1,72,72A72.08,72.08,0,0,1,40,112Z"></path>
11
+ </svg>
12
+ </span>
13
+ <span class="search-trigger-text">Search...</span>
14
+ <kbd class="search-trigger-shortcut" data-search-shortcut>
15
+ <span class="search-trigger-shortcut-icon" aria-hidden="true">
16
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256" fill="currentColor">
17
+ <path d="M180,144H160V112h20a36,36,0,1,0-36-36V96H112V76a36,36,0,1,0-36,36H96v32H76a36,36,0,1,0,36,36V160h32v20a36,36,0,1,0,36-36ZM160,76a20,20,0,1,1,20,20H160ZM56,76a20,20,0,0,1,40,0V96H76A20,20,0,0,1,56,76ZM96,180a20,20,0,1,1-20-20H96Zm16-68h32v32H112Zm68,88a20,20,0,0,1-20-20V160h20a20,20,0,0,1,0,40Z"></path>
18
+ </svg>
19
+ </span>
20
+ <span class="search-trigger-shortcut-text">K</span>
21
+ </kbd>
22
+ </button>
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Docyard
4
+ module Utils
5
+ module HtmlHelpers
6
+ def escape_html_attribute(text)
7
+ text.gsub('"', "&quot;")
8
+ .gsub("'", "&#39;")
9
+ .gsub("<", "&lt;")
10
+ .gsub(">", "&gt;")
11
+ end
12
+ end
13
+ end
14
+ end
@@ -6,7 +6,8 @@ module Docyard
6
6
  def self.normalize(path)
7
7
  return "/" if path.nil? || path.empty?
8
8
 
9
- normalized = path.delete_suffix(".md")
9
+ normalized = path.delete_suffix("/")
10
+ .delete_suffix(".md")
10
11
  .delete_suffix("/index")
11
12
 
12
13
  normalized = "" if normalized == "index"
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Docyard
4
+ module Utils
5
+ module UrlHelpers
6
+ def normalize_base_url(url)
7
+ return "/" if url.nil? || url.empty?
8
+
9
+ url = "/#{url}" unless url.start_with?("/")
10
+ url.end_with?("/") ? url : "#{url}/"
11
+ end
12
+
13
+ def link_path(path)
14
+ return path if path.nil? || path.start_with?("http://", "https://")
15
+
16
+ "#{base_url.chomp('/')}#{path}"
17
+ end
18
+ end
19
+ end
20
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Docyard
4
- VERSION = "0.5.0"
4
+ VERSION = "0.7.0"
5
5
  end
data/lib/docyard.rb CHANGED
@@ -1,34 +1,41 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Core modules
4
3
  require_relative "docyard/version"
5
- require_relative "docyard/constants"
6
- require_relative "docyard/errors"
7
- require_relative "docyard/logging"
4
+ require_relative "docyard/config/constants"
5
+ require_relative "docyard/utils/errors"
6
+ require_relative "docyard/utils/logging"
8
7
 
9
- # Utilities
10
8
  require_relative "docyard/utils/text_formatter"
11
9
  require_relative "docyard/utils/path_resolver"
10
+ require_relative "docyard/utils/url_helpers"
11
+ require_relative "docyard/utils/html_helpers"
12
12
 
13
- # Routing
14
- require_relative "docyard/routing/resolution_result"
15
- require_relative "docyard/router"
13
+ require_relative "docyard/server/resolution_result"
14
+ require_relative "docyard/server/router"
15
+ require_relative "docyard/server/asset_handler"
16
+ require_relative "docyard/server/dev_server"
17
+ require_relative "docyard/server/preview_server"
18
+
19
+ require_relative "docyard/rendering/markdown"
20
+ require_relative "docyard/rendering/renderer"
21
+
22
+ require_relative "docyard/navigation/sidebar_builder"
23
+ require_relative "docyard/navigation/prev_next_builder"
24
+
25
+ require_relative "docyard/config/branding_resolver"
16
26
 
17
- # Application components
18
- require_relative "docyard/markdown"
19
- require_relative "docyard/renderer"
20
- require_relative "docyard/asset_handler"
21
27
  require_relative "docyard/initializer"
22
- require_relative "docyard/server"
23
28
  require_relative "docyard/cli"
24
29
 
25
- # Build components
30
+ require_relative "docyard/search/pagefind_support"
31
+ require_relative "docyard/search/dev_indexer"
32
+ require_relative "docyard/search/build_indexer"
33
+
26
34
  require_relative "docyard/builder"
27
35
  require_relative "docyard/build/static_generator"
28
36
  require_relative "docyard/build/asset_bundler"
29
37
  require_relative "docyard/build/file_copier"
30
38
  require_relative "docyard/build/sitemap_generator"
31
- require_relative "docyard/preview_server"
32
39
 
33
40
  module Docyard
34
41
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docyard
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sanif Himani
@@ -183,52 +183,65 @@ files:
183
183
  - README.md
184
184
  - Rakefile
185
185
  - lib/docyard.rb
186
- - lib/docyard/asset_handler.rb
187
186
  - lib/docyard/build/asset_bundler.rb
188
187
  - lib/docyard/build/file_copier.rb
189
188
  - lib/docyard/build/sitemap_generator.rb
190
189
  - lib/docyard/build/static_generator.rb
191
190
  - lib/docyard/builder.rb
192
191
  - lib/docyard/cli.rb
192
+ - lib/docyard/components/aliases.rb
193
193
  - lib/docyard/components/base_processor.rb
194
- - lib/docyard/components/callout_processor.rb
195
- - lib/docyard/components/code_block_processor.rb
196
- - lib/docyard/components/code_detector.rb
197
- - lib/docyard/components/heading_anchor_processor.rb
198
- - lib/docyard/components/icon_detector.rb
199
- - lib/docyard/components/icon_processor.rb
194
+ - lib/docyard/components/processors/callout_processor.rb
195
+ - lib/docyard/components/processors/code_block_diff_preprocessor.rb
196
+ - lib/docyard/components/processors/code_block_focus_preprocessor.rb
197
+ - lib/docyard/components/processors/code_block_options_preprocessor.rb
198
+ - lib/docyard/components/processors/code_block_processor.rb
199
+ - lib/docyard/components/processors/code_snippet_import_preprocessor.rb
200
+ - lib/docyard/components/processors/heading_anchor_processor.rb
201
+ - lib/docyard/components/processors/icon_processor.rb
202
+ - lib/docyard/components/processors/table_of_contents_processor.rb
203
+ - lib/docyard/components/processors/table_wrapper_processor.rb
204
+ - lib/docyard/components/processors/tabs_processor.rb
200
205
  - lib/docyard/components/registry.rb
201
- - lib/docyard/components/table_of_contents_processor.rb
202
- - lib/docyard/components/table_wrapper_processor.rb
203
- - lib/docyard/components/tabs_parser.rb
204
- - lib/docyard/components/tabs_processor.rb
206
+ - lib/docyard/components/support/code_block/feature_extractor.rb
207
+ - lib/docyard/components/support/code_block/icon_detector.rb
208
+ - lib/docyard/components/support/code_block/line_parser.rb
209
+ - lib/docyard/components/support/code_block/line_wrapper.rb
210
+ - lib/docyard/components/support/code_block/patterns.rb
211
+ - lib/docyard/components/support/code_detector.rb
212
+ - lib/docyard/components/support/tabs/icon_detector.rb
213
+ - lib/docyard/components/support/tabs/parser.rb
214
+ - lib/docyard/components/support/tabs/range_finder.rb
205
215
  - lib/docyard/config.rb
216
+ - lib/docyard/config/branding_resolver.rb
217
+ - lib/docyard/config/constants.rb
206
218
  - lib/docyard/config/validator.rb
207
- - lib/docyard/constants.rb
208
- - lib/docyard/errors.rb
209
- - lib/docyard/file_watcher.rb
210
- - lib/docyard/icons.rb
211
- - lib/docyard/icons/LICENSE.phosphor
212
- - lib/docyard/icons/file_types.rb
213
- - lib/docyard/icons/phosphor.rb
214
219
  - lib/docyard/initializer.rb
215
- - lib/docyard/language_mapping.rb
216
- - lib/docyard/logging.rb
217
- - lib/docyard/markdown.rb
218
- - lib/docyard/prev_next_builder.rb
219
- - lib/docyard/preview_server.rb
220
- - lib/docyard/rack_application.rb
221
- - lib/docyard/renderer.rb
222
- - lib/docyard/router.rb
223
- - lib/docyard/routing/resolution_result.rb
224
- - lib/docyard/server.rb
225
- - lib/docyard/sidebar/config_parser.rb
226
- - lib/docyard/sidebar/file_system_scanner.rb
227
- - lib/docyard/sidebar/item.rb
228
- - lib/docyard/sidebar/renderer.rb
229
- - lib/docyard/sidebar/title_extractor.rb
230
- - lib/docyard/sidebar/tree_builder.rb
231
- - lib/docyard/sidebar_builder.rb
220
+ - lib/docyard/navigation/prev_next_builder.rb
221
+ - lib/docyard/navigation/sidebar/config_parser.rb
222
+ - lib/docyard/navigation/sidebar/file_system_scanner.rb
223
+ - lib/docyard/navigation/sidebar/item.rb
224
+ - lib/docyard/navigation/sidebar/renderer.rb
225
+ - lib/docyard/navigation/sidebar/title_extractor.rb
226
+ - lib/docyard/navigation/sidebar/tree_builder.rb
227
+ - lib/docyard/navigation/sidebar_builder.rb
228
+ - lib/docyard/rendering/icons.rb
229
+ - lib/docyard/rendering/icons/LICENSE.phosphor
230
+ - lib/docyard/rendering/icons/file_types.rb
231
+ - lib/docyard/rendering/icons/phosphor.rb
232
+ - lib/docyard/rendering/language_mapping.rb
233
+ - lib/docyard/rendering/markdown.rb
234
+ - lib/docyard/rendering/renderer.rb
235
+ - lib/docyard/search/build_indexer.rb
236
+ - lib/docyard/search/dev_indexer.rb
237
+ - lib/docyard/search/pagefind_support.rb
238
+ - lib/docyard/server/asset_handler.rb
239
+ - lib/docyard/server/dev_server.rb
240
+ - lib/docyard/server/file_watcher.rb
241
+ - lib/docyard/server/preview_server.rb
242
+ - lib/docyard/server/rack_application.rb
243
+ - lib/docyard/server/resolution_result.rb
244
+ - lib/docyard/server/router.rb
232
245
  - lib/docyard/templates/assets/css/code.css
233
246
  - lib/docyard/templates/assets/css/components/callout.css
234
247
  - lib/docyard/templates/assets/css/components/code-block.css
@@ -237,6 +250,7 @@ files:
237
250
  - lib/docyard/templates/assets/css/components/logo.css
238
251
  - lib/docyard/templates/assets/css/components/navigation.css
239
252
  - lib/docyard/templates/assets/css/components/prev-next.css
253
+ - lib/docyard/templates/assets/css/components/search.css
240
254
  - lib/docyard/templates/assets/css/components/table-of-contents.css
241
255
  - lib/docyard/templates/assets/css/components/tabs.css
242
256
  - lib/docyard/templates/assets/css/components/theme-toggle.css
@@ -250,6 +264,7 @@ files:
250
264
  - lib/docyard/templates/assets/js/components/code-block.js
251
265
  - lib/docyard/templates/assets/js/components/heading-anchor.js
252
266
  - lib/docyard/templates/assets/js/components/navigation.js
267
+ - lib/docyard/templates/assets/js/components/search.js
253
268
  - lib/docyard/templates/assets/js/components/table-of-contents.js
254
269
  - lib/docyard/templates/assets/js/components/tabs.js
255
270
  - lib/docyard/templates/assets/js/reload.js
@@ -275,14 +290,20 @@ files:
275
290
  - lib/docyard/templates/partials/_nav_list.html.erb
276
291
  - lib/docyard/templates/partials/_nav_section.html.erb
277
292
  - lib/docyard/templates/partials/_prev_next.html.erb
293
+ - lib/docyard/templates/partials/_search_modal.html.erb
294
+ - lib/docyard/templates/partials/_search_trigger.html.erb
278
295
  - lib/docyard/templates/partials/_sidebar.html.erb
279
296
  - lib/docyard/templates/partials/_sidebar_footer.html.erb
280
297
  - lib/docyard/templates/partials/_table_of_contents.html.erb
281
298
  - lib/docyard/templates/partials/_table_of_contents_toggle.html.erb
282
299
  - lib/docyard/templates/partials/_tabs.html.erb
283
300
  - lib/docyard/templates/partials/_theme_toggle.html.erb
301
+ - lib/docyard/utils/errors.rb
302
+ - lib/docyard/utils/html_helpers.rb
303
+ - lib/docyard/utils/logging.rb
284
304
  - lib/docyard/utils/path_resolver.rb
285
305
  - lib/docyard/utils/text_formatter.rb
306
+ - lib/docyard/utils/url_helpers.rb
286
307
  - lib/docyard/version.rb
287
308
  - sig/docyard.rbs
288
309
  homepage: https://github.com/sanifhimani/docyard
@@ -1,121 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "../icons"
4
- require_relative "../renderer"
5
- require_relative "base_processor"
6
- require "kramdown"
7
- require "kramdown-parser-gfm"
8
-
9
- module Docyard
10
- module Components
11
- class CalloutProcessor < BaseProcessor
12
- self.priority = 10
13
-
14
- CALLOUT_TYPES = {
15
- "note" => { title: "Note", icon: "info", color: "note" },
16
- "tip" => { title: "Tip", icon: "lightbulb", color: "tip" },
17
- "important" => { title: "Important", icon: "warning-circle", color: "important" },
18
- "warning" => { title: "Warning", icon: "warning", color: "warning" },
19
- "danger" => { title: "Danger", icon: "siren", color: "danger" }
20
- }.freeze
21
-
22
- GITHUB_ALERT_TYPES = {
23
- "NOTE" => "note",
24
- "TIP" => "tip",
25
- "IMPORTANT" => "important",
26
- "WARNING" => "warning",
27
- "CAUTION" => "danger"
28
- }.freeze
29
-
30
- def preprocess(markdown)
31
- process_container_syntax(markdown)
32
- end
33
-
34
- def postprocess(html)
35
- process_github_alerts(html)
36
- end
37
-
38
- private
39
-
40
- def process_container_syntax(markdown)
41
- markdown.gsub(/^:::[ \t]*(\w+)(?:[ \t]+([^\n]+?))?[ \t]*\n(.*?)^:::[ \t]*$/m) do
42
- process_callout_match(Regexp.last_match(0), Regexp.last_match(1), Regexp.last_match(2), Regexp.last_match(3))
43
- end
44
- end
45
-
46
- def process_callout_match(original_match, type_raw, custom_title, content_markdown)
47
- type = type_raw.downcase
48
- return original_match unless CALLOUT_TYPES.key?(type)
49
-
50
- config = CALLOUT_TYPES[type]
51
- title = determine_title(custom_title, config[:title])
52
- content_html = render_markdown_content(content_markdown.strip)
53
-
54
- wrap_in_nomarkdown(render_callout_html(type, title, content_html, config[:icon]))
55
- end
56
-
57
- def determine_title(custom_title, default_title)
58
- title = custom_title&.strip
59
- title.nil? || title.empty? ? default_title : title
60
- end
61
-
62
- def render_markdown_content(content_markdown)
63
- return "" if content_markdown.empty?
64
-
65
- Kramdown::Document.new(
66
- content_markdown,
67
- input: "GFM",
68
- hard_wrap: false,
69
- syntax_highlighter: "rouge"
70
- ).to_html
71
- end
72
-
73
- def wrap_in_nomarkdown(html)
74
- "{::nomarkdown}\n#{html}\n{:/nomarkdown}"
75
- end
76
-
77
- def process_github_alerts(html)
78
- github_alert_regex = %r{
79
- <blockquote>\s*
80
- <p>\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]\s*
81
- (?:<br\s*/>)?\s*
82
- (.*?)</p>
83
- (.*?)
84
- </blockquote>
85
- }mx
86
-
87
- html.gsub(github_alert_regex) do
88
- process_github_alert_match(Regexp.last_match(1), Regexp.last_match(2), Regexp.last_match(3))
89
- end
90
- end
91
-
92
- def process_github_alert_match(alert_type, first_para, rest_content)
93
- type = GITHUB_ALERT_TYPES[alert_type]
94
- config = CALLOUT_TYPES[type]
95
- content_html = combine_alert_content(first_para.strip, rest_content.strip)
96
-
97
- render_callout_html(type, config[:title], content_html, config[:icon])
98
- end
99
-
100
- def combine_alert_content(first_para, rest_content)
101
- return "<p>#{first_para}</p>" if rest_content.empty?
102
-
103
- "<p>#{first_para}</p>#{rest_content}"
104
- end
105
-
106
- def render_callout_html(type, title, content_html, icon_name)
107
- icon_svg = Icons.render(icon_name, "duotone") || ""
108
- renderer = Renderer.new
109
-
110
- renderer.render_partial(
111
- "_callout", {
112
- type: type,
113
- title: title,
114
- content_html: content_html,
115
- icon_svg: icon_svg
116
- }
117
- )
118
- end
119
- end
120
- end
121
- end
@@ -1,55 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "../icons"
4
- require_relative "../renderer"
5
- require_relative "base_processor"
6
-
7
- module Docyard
8
- module Components
9
- class CodeBlockProcessor < BaseProcessor
10
- self.priority = 20
11
-
12
- def postprocess(html)
13
- return html unless html.include?('<div class="highlight">')
14
-
15
- html.gsub(%r{<div class="highlight">(.*?)</div>}m) do
16
- process_code_block(Regexp.last_match(0), Regexp.last_match(1))
17
- end
18
- end
19
-
20
- private
21
-
22
- def process_code_block(original_html, inner_html)
23
- code_text = extract_code_text(inner_html)
24
-
25
- render_code_block_with_copy(original_html, code_text)
26
- end
27
-
28
- def extract_code_text(html)
29
- text = html.gsub(/<[^>]+>/, "")
30
- text = CGI.unescapeHTML(text)
31
- text.strip
32
- end
33
-
34
- def render_code_block_with_copy(code_block_html, code_text)
35
- copy_icon = Icons.render("copy", "regular") || ""
36
- renderer = Renderer.new
37
-
38
- renderer.render_partial(
39
- "_code_block", {
40
- code_block_html: code_block_html,
41
- code_text: escape_html_attribute(code_text),
42
- copy_icon: copy_icon
43
- }
44
- )
45
- end
46
-
47
- def escape_html_attribute(text)
48
- text.gsub('"', "&quot;")
49
- .gsub("'", "&#39;")
50
- .gsub("<", "&lt;")
51
- .gsub(">", "&gt;")
52
- end
53
- end
54
- end
55
- end