docyard 0.5.0 → 0.6.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 (33) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -1
  3. data/CHANGELOG.md +20 -1
  4. data/lib/docyard/build/static_generator.rb +1 -1
  5. data/lib/docyard/components/base_processor.rb +6 -0
  6. data/lib/docyard/components/code_block_diff_preprocessor.rb +104 -0
  7. data/lib/docyard/components/code_block_feature_extractor.rb +113 -0
  8. data/lib/docyard/components/code_block_focus_preprocessor.rb +77 -0
  9. data/lib/docyard/components/code_block_icon_detector.rb +40 -0
  10. data/lib/docyard/components/code_block_line_wrapper.rb +46 -0
  11. data/lib/docyard/components/code_block_options_preprocessor.rb +76 -0
  12. data/lib/docyard/components/code_block_patterns.rb +51 -0
  13. data/lib/docyard/components/code_block_processor.rb +135 -14
  14. data/lib/docyard/components/code_line_parser.rb +80 -0
  15. data/lib/docyard/components/code_snippet_import_preprocessor.rb +125 -0
  16. data/lib/docyard/components/registry.rb +4 -4
  17. data/lib/docyard/components/table_of_contents_processor.rb +1 -1
  18. data/lib/docyard/components/tabs_parser.rb +135 -4
  19. data/lib/docyard/components/tabs_range_finder.rb +42 -0
  20. data/lib/docyard/config/validator.rb +8 -0
  21. data/lib/docyard/config.rb +7 -0
  22. data/lib/docyard/icons/file_types.rb +0 -13
  23. data/lib/docyard/markdown.rb +13 -5
  24. data/lib/docyard/rack_application.rb +1 -1
  25. data/lib/docyard/renderer.rb +4 -3
  26. data/lib/docyard/templates/assets/css/code.css +12 -4
  27. data/lib/docyard/templates/assets/css/components/code-block.css +427 -24
  28. data/lib/docyard/templates/assets/css/components/navigation.css +12 -9
  29. data/lib/docyard/templates/assets/css/components/tabs.css +50 -44
  30. data/lib/docyard/templates/assets/css/variables.css +44 -0
  31. data/lib/docyard/templates/partials/_code_block.html.erb +50 -2
  32. data/lib/docyard/version.rb +1 -1
  33. metadata +11 -1
@@ -1,4 +1,4 @@
1
- /* Tabs Component - Modern Design */
1
+ /* Tabs Component */
2
2
 
3
3
  .docyard-tabs {
4
4
  margin: var(--space-6) 0;
@@ -13,12 +13,16 @@
13
13
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
14
14
  }
15
15
 
16
- /* Tab List Wrapper - Contains scroll indicators */
16
+ /* Tab List Wrapper */
17
17
  .docyard-tabs__list-wrapper {
18
18
  position: relative;
19
19
  background: var(--color-bg-secondary);
20
20
  }
21
21
 
22
+ .dark .docyard-tabs__list-wrapper {
23
+ background: rgba(255, 255, 255, 0.03);
24
+ }
25
+
22
26
  /* Tab List Container */
23
27
  .docyard-tabs__list {
24
28
  display: flex;
@@ -36,7 +40,7 @@
36
40
  display: none;
37
41
  }
38
42
 
39
- /* Bottom border line - sits behind tabs */
43
+ /* Bottom border line */
40
44
  .docyard-tabs__list::after {
41
45
  content: '';
42
46
  position: absolute;
@@ -81,7 +85,7 @@
81
85
 
82
86
  .docyard-tabs__tab[aria-selected="true"] {
83
87
  color: var(--color-primary);
84
- background: var(--color-bg);
88
+ background: var(--color-code-bg);
85
89
  }
86
90
 
87
91
  /* Cover the border-bottom for active tab */
@@ -92,11 +96,11 @@
92
96
  left: 0;
93
97
  right: 0;
94
98
  height: 2px;
95
- background: var(--color-bg);
99
+ background: var(--color-code-bg);
96
100
  z-index: 2;
97
101
  }
98
102
 
99
- /* Focus indicator for keyboard navigation */
103
+ /* Focus state */
100
104
  .docyard-tabs__tab:focus-visible {
101
105
  outline: 2px solid var(--color-primary);
102
106
  outline-offset: 2px;
@@ -121,7 +125,7 @@
121
125
  height: 100%;
122
126
  }
123
127
 
124
- /* Scroll Indicators - Gradient overlays showing more content */
128
+ /* Scroll Indicators */
125
129
  .docyard-tabs__scroll-indicator {
126
130
  position: absolute;
127
131
  top: 0;
@@ -151,7 +155,7 @@
151
155
  opacity: 1;
152
156
  }
153
157
 
154
- /* Slide indicator - vibrant accent line */
158
+ /* Slide Indicator */
155
159
  .docyard-tabs__indicator {
156
160
  position: absolute;
157
161
  top: 0;
@@ -173,11 +177,7 @@
173
177
  background: var(--color-bg);
174
178
  }
175
179
 
176
- /* If panel has mixed content (not just code block), add padding to panel */
177
- .docyard-tabs__panel:not(:has(> [class*="language-"]:only-child)) {
178
- padding: var(--space-6);
179
- }
180
-
180
+ /* Panel base styles */
181
181
  .docyard-tabs__panel p {
182
182
  margin-bottom: 0;
183
183
  }
@@ -186,7 +186,7 @@
186
186
  display: block;
187
187
  }
188
188
 
189
- /* Ensure proper spacing for content inside panels */
189
+ /* Panel content spacing */
190
190
  .docyard-tabs__panel>*:first-child {
191
191
  margin-top: 0;
192
192
  }
@@ -195,43 +195,49 @@
195
195
  margin-bottom: 0;
196
196
  }
197
197
 
198
- /* Code blocks inside tabs - seamless integration */
199
- .docyard-tabs__panel .highlight,
200
- .docyard-tabs__panel pre {
198
+ /* Code blocks inside tabs */
199
+ .docyard-tabs__panel .docyard-code-block {
201
200
  margin: 0;
202
- border-radius: 0;
203
- border: none;
204
- padding: 0 !important;
205
- background-color: var(--color-bg) !important;
206
- box-shadow: none !important;
207
201
  }
208
202
 
209
- /* If panel has ONLY code block, add padding to the highlight element */
210
- .docyard-tabs__panel:has(> [class*="language-"]:only-child) pre {
211
- padding: var(--space-6) !important;
203
+ /* Reset code block styling in tabs */
204
+ .docyard-tabs__panel .docyard-code-block .highlight {
205
+ border: none;
206
+ border-radius: 0;
207
+ box-shadow: none;
208
+ background: transparent;
212
209
  }
213
210
 
214
- /* Apply secondary background when highlighter-rouge has siblings */
215
- .docyard-tabs__panel .highlighter-rouge:not(:only-child) .highlight pre code {
216
- padding: var(--space-4) !important;
217
- background-color: var(--color-bg-secondary) !important;
218
- border-radius: var(--radius-lg) !important;
219
- border: 1px solid var(--color-border) !important;
220
- box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.03) !important;
211
+ /* Panel styles with :has() support */
212
+ @supports selector(:has(*)) {
213
+ .docyard-tabs__panel:not(:has(> [class*="language-"]:only-child)) {
214
+ padding: var(--space-6);
215
+ }
216
+
217
+ .docyard-tabs__panel:has(> [class*="language-"]:only-child) {
218
+ background: var(--color-code-bg);
219
+ }
220
+
221
+ .docyard-tabs__panel:has(> [class*="language-"]:only-child) .highlight pre {
222
+ padding: var(--space-6);
223
+ background: transparent;
224
+ }
221
225
  }
222
226
 
223
- .docyard-tabs__panel pre code {
224
- padding: 0 !important;
225
- display: block;
226
- overflow-x: auto;
227
- background-color: var(--color-bg) !important;
228
- border-radius: 0;
229
- border: none !important;
230
- box-shadow: none !important;
227
+ /* Fallback for browsers without :has() */
228
+ @supports not selector(:has(*)) {
229
+ .docyard-tabs__panel {
230
+ padding: var(--space-6);
231
+ }
231
232
  }
232
233
 
233
- .docyard-tabs__panel pre code .w {
234
- background-color: var(--color-bg) !important;
234
+ /* Code blocks with siblings */
235
+ .docyard-tabs__panel .docyard-code-block:not(:only-child) .highlight {
236
+ border: 1px solid var(--color-border);
237
+ border-radius: var(--radius-lg);
238
+ box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.03);
239
+ margin: var(--space-4) 0;
240
+ background: var(--color-code-bg);
235
241
  }
236
242
 
237
243
  /* Inline code inside tabs */
@@ -242,7 +248,7 @@
242
248
  font-size: 0.9em;
243
249
  }
244
250
 
245
- /* Mobile responsive - preserve design language */
251
+ /* Mobile responsive */
246
252
  @media (max-width: 640px) {
247
253
  .docyard-tabs {
248
254
  margin: var(--space-4) 0;
@@ -256,7 +262,7 @@
256
262
  .docyard-tabs__tab {
257
263
  padding: var(--space-3) var(--space-3);
258
264
  font-size: var(--font-size-sm);
259
- gap: var(--space-1-5);
265
+ gap: var(--space-2);
260
266
  }
261
267
 
262
268
  .docyard-tabs__icon .docyard-icon {
@@ -12,6 +12,7 @@
12
12
  --color-border: #e4e7eb;
13
13
  --color-border-secondary: #f3f4f6;
14
14
  --color-primary: #2563eb;
15
+ --color-primary-rgb: 37, 99, 235;
15
16
  --color-primary-hover: #1d4ed8;
16
17
  --color-primary-light: #eff6ff;
17
18
  --color-link: #0969da;
@@ -32,6 +33,27 @@
32
33
  --color-info: #0969da;
33
34
  --color-info-bg: #ddf4ff;
34
35
 
36
+ /* Diff colors - Light Theme */
37
+ --color-diff-add-bg: rgba(34, 197, 94, 0.15);
38
+ --color-diff-add-border: #22c55e;
39
+ --color-diff-add-gutter-bg: rgba(34, 197, 94, 0.2);
40
+ --color-diff-add-indicator: #166534;
41
+
42
+ --color-diff-remove-bg: rgba(239, 68, 68, 0.15);
43
+ --color-diff-remove-border: #ef4444;
44
+ --color-diff-remove-gutter-bg: rgba(239, 68, 68, 0.2);
45
+ --color-diff-remove-indicator: #991b1b;
46
+
47
+ /* Code error/warning colors - Light Theme */
48
+ --color-code-error-bg: rgba(239, 68, 68, 0.15);
49
+ --color-code-error-border: #ef4444;
50
+ --color-code-error-gutter-bg: rgba(239, 68, 68, 0.2);
51
+ --color-code-error-indicator: #991b1b;
52
+ --color-code-warning-bg: rgba(245, 158, 11, 0.15);
53
+ --color-code-warning-border: #f59e0b;
54
+ --color-code-warning-gutter-bg: rgba(245, 158, 11, 0.2);
55
+ --color-code-warning-indicator: #78350f;
56
+
35
57
  /* Callout colors - shadcn inspired */
36
58
  --callout-note: #0ea5e9;
37
59
  --callout-note-text: #0c4a6e;
@@ -143,6 +165,7 @@
143
165
  --color-border: #30363d;
144
166
  --color-border-secondary: #21262d;
145
167
  --color-primary: #3b82f6;
168
+ --color-primary-rgb: 59, 130, 246;
146
169
  --color-primary-hover: #60a5fa;
147
170
  --color-primary-light: #1e3a8a;
148
171
  --color-link: #58a6ff;
@@ -163,6 +186,27 @@
163
186
  --color-info: #58a6ff;
164
187
  --color-info-bg: #1e3a5f;
165
188
 
189
+ /* Diff colors - Dark Theme */
190
+ --color-diff-add-bg: rgba(34, 197, 94, 0.1);
191
+ --color-diff-add-border: #22c55e;
192
+ --color-diff-add-gutter-bg: rgba(34, 197, 94, 0.15);
193
+ --color-diff-add-indicator: #4ade80;
194
+
195
+ --color-diff-remove-bg: rgba(239, 68, 68, 0.1);
196
+ --color-diff-remove-border: #ef4444;
197
+ --color-diff-remove-gutter-bg: rgba(239, 68, 68, 0.15);
198
+ --color-diff-remove-indicator: #f87171;
199
+
200
+ /* Code error/warning colors - Dark Theme */
201
+ --color-code-error-bg: rgba(239, 68, 68, 0.1);
202
+ --color-code-error-border: #ef4444;
203
+ --color-code-error-gutter-bg: rgba(239, 68, 68, 0.15);
204
+ --color-code-error-indicator: #f87171;
205
+ --color-code-warning-bg: rgba(245, 158, 11, 0.1);
206
+ --color-code-warning-border: #f59e0b;
207
+ --color-code-warning-gutter-bg: rgba(245, 158, 11, 0.15);
208
+ --color-code-warning-indicator: #fbbf24;
209
+
166
210
  /* Callout colors - Dark mode shadcn inspired */
167
211
  --callout-note: #38bdf8;
168
212
  --callout-note-text: #7dd3fc;
@@ -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 %>">
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,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Docyard
4
- VERSION = "0.5.0"
4
+ VERSION = "0.6.0"
5
5
  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.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sanif Himani
@@ -192,8 +192,17 @@ files:
192
192
  - lib/docyard/cli.rb
193
193
  - lib/docyard/components/base_processor.rb
194
194
  - lib/docyard/components/callout_processor.rb
195
+ - lib/docyard/components/code_block_diff_preprocessor.rb
196
+ - lib/docyard/components/code_block_feature_extractor.rb
197
+ - lib/docyard/components/code_block_focus_preprocessor.rb
198
+ - lib/docyard/components/code_block_icon_detector.rb
199
+ - lib/docyard/components/code_block_line_wrapper.rb
200
+ - lib/docyard/components/code_block_options_preprocessor.rb
201
+ - lib/docyard/components/code_block_patterns.rb
195
202
  - lib/docyard/components/code_block_processor.rb
196
203
  - lib/docyard/components/code_detector.rb
204
+ - lib/docyard/components/code_line_parser.rb
205
+ - lib/docyard/components/code_snippet_import_preprocessor.rb
197
206
  - lib/docyard/components/heading_anchor_processor.rb
198
207
  - lib/docyard/components/icon_detector.rb
199
208
  - lib/docyard/components/icon_processor.rb
@@ -202,6 +211,7 @@ files:
202
211
  - lib/docyard/components/table_wrapper_processor.rb
203
212
  - lib/docyard/components/tabs_parser.rb
204
213
  - lib/docyard/components/tabs_processor.rb
214
+ - lib/docyard/components/tabs_range_finder.rb
205
215
  - lib/docyard/config.rb
206
216
  - lib/docyard/config/validator.rb
207
217
  - lib/docyard/constants.rb