diff --git a/CHANGELOG.md b/CHANGELOG.md index 6afb49a5..a6a457f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,7 @@ Main (3.0.0.alpha) * [#322](https://github.com/rails/sdoc/pull/322) Use `type="search"` for search input [@jonathanhefner](https://github.com/jonathanhefner) * [#323](https://github.com/rails/sdoc/pull/323) Update favicon [@jonathanhefner](https://github.com/jonathanhefner) * [#345](https://github.com/rails/sdoc/pull/345) Version explicit links to `api.rubyonrails.org` [@jonathanhefner](https://github.com/jonathanhefner) +* [#356](https://github.com/rails/sdoc/pull/356) Redesign "Constants" section [@jonathanhefner](https://github.com/jonathanhefner) 2.6.1 ===== diff --git a/lib/rdoc/generator/template/rails/_context.rhtml b/lib/rdoc/generator/template/rails/_context.rhtml index c1dd1378..b0412dd2 100644 --- a/lib/rdoc/generator/template/rails/_context.rhtml +++ b/lib/rdoc/generator/template/rails/_context.rhtml @@ -54,27 +54,22 @@ <%= description_for section %> + <% unless constants.empty? %> -

Constants

- - <% constants.each do |const| %> - - - - - - <% if const.comment && !const.comment.empty? %> - - - - - <% end %> - <% end %> -
<%= short_name_for const %>=<%= h const.value %>
 <%= const.description.strip %>
+ <% constants.each do |constant| %> +
+
+

<%= short_name_for constant %>

+
+ <%= description_for constant %> +
+
<%= h constant.value %>
+
+
+ <% end %> <% end %> - <% unless attributes.empty? %>

Attributes

@@ -135,7 +130,7 @@ <% end %> -
<%= source_code %>
+
<%= source_code %>
<% elsif source_url %>

<%= link_to_external "GitHub", source_url %>

diff --git a/lib/rdoc/generator/template/rails/resources/css/main.css b/lib/rdoc/generator/template/rails/resources/css/main.css index 9ba0e878..c463eb7a 100644 --- a/lib/rdoc/generator/template/rails/resources/css/main.css +++ b/lib/rdoc/generator/template/rails/resources/css/main.css @@ -289,21 +289,25 @@ th font-style: italic; } -.description pre, .method__source pre { +.description pre, pre.source-code { padding: 0.5ch 1ch; border-radius: 6px; overflow-x: auto; - - background: var(--code-bg); } - :is(.description p, p.description) code { - background: var(--code-bg); padding: 0 0.15em; border-radius: 3px; } +.description pre, :is(.description p, p.description) code { + background: var(--code-bg); +} + +pre.source-code { + background: var(--source-code-bg); +} + @media (hover: hover) { .description a:hover code { box-shadow: 0 0 0 1px; @@ -737,11 +741,35 @@ html { border-bottom: 1px solid; } -.content__section-title + .content__divider { +.content__section-title + .content__divider, +.content__divider + :is(*, div /* increase selector specificity */) { margin-top: var(--space); } +/* + * Constant + */ + +.constant { + margin-top: var(--space-lg); +} + +.constant__name { + padding-bottom: var(--space-xs); + border-bottom: 2px solid var(--code-bg); +} + +.constant__name code { + font-size: 1rem; + font-weight: bold; +} + +.constant__name + *, .constant__source { + margin-top: var(--space-sm); +} + + /* * Method */ @@ -750,10 +778,6 @@ html { margin-top: var(--space-xl); } -.content__divider + .method { - margin-top: var(--space); -} - .method__signature { padding-bottom: var(--space-xs); @@ -847,7 +871,6 @@ html { .method__source pre { margin-top: var(--space-xs); - background: var(--source-code-bg); } diff --git a/lib/sdoc/postprocessor.rb b/lib/sdoc/postprocessor.rb index 8ba39094..6679a4de 100644 --- a/lib/sdoc/postprocessor.rb +++ b/lib/sdoc/postprocessor.rb @@ -92,7 +92,7 @@ def unify_h1_headings!(document) end def highlight_code_blocks!(document) - document.css(".description pre > code, .method__source pre > code").each do |element| + document.css(".description pre > code, pre.source-code > code").each do |element| code = element.inner_text language = element.classes.include?("ruby") ? "ruby" : guess_code_language(code) element.inner_html = highlight_code(code, language) diff --git a/spec/postprocessor_spec.rb b/spec/postprocessor_spec.rb index 1be2b9bc..be3af987 100644 --- a/spec/postprocessor_spec.rb +++ b/spec/postprocessor_spec.rb @@ -151,7 +151,7 @@ _(SDoc::Postprocessor.process(rendered)).must_include rendered end - it "highlights code blocks" do + it "highlights description code blocks" do rendered = <<~HTML

Ruby:

@@ -173,25 +173,15 @@ _(SDoc::Postprocessor.process(rendered)).must_include expected end - it "highlights method source code" do + it "highlights source code blocks" do rendered = <<~HTML -
-
# highlighted by RDoc
-
- -
-
DELETE FROM 'tricky_ruby'
-
+
# highlighted by RDoc
+
DELETE FROM 'tricky_ruby'
HTML expected = <<~HTML -
-
#{SDoc::Postprocessor.highlight_code("# highlighted by RDoc", "ruby")}
-
- -
-
#{SDoc::Postprocessor.highlight_code("DELETE FROM 'tricky_ruby'", "ruby")}
-
+
#{SDoc::Postprocessor.highlight_code("# highlighted by RDoc", "ruby")}
+
#{SDoc::Postprocessor.highlight_code("DELETE FROM 'tricky_ruby'", "ruby")}
HTML _(SDoc::Postprocessor.process(rendered)).must_include expected