showcase-rails 0.2.5 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +52 -13
- data/app/assets/builds/showcase.css +42 -12
- data/app/views/layouts/showcase.html.erb +1 -0
- data/app/views/showcase/engine/_head.html.erb +2 -0
- data/app/views/showcase/engine/_javascripts.html.erb +1 -1
- data/app/views/showcase/engine/_options.html.erb +1 -1
- data/app/views/showcase/engine/_root.html.erb +1 -1
- data/app/views/showcase/engine/_sample.html.erb +5 -5
- data/app/views/showcase/engine/_stylesheets.html.erb +1 -1
- data/app/views/showcase/engine/index.html.erb +3 -0
- data/app/views/showcase/engine/path/_path.html.erb +2 -2
- data/app/views/showcase/engine/path/_tree.html.erb +1 -1
- data/lib/showcase/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 616178a6d44d9d2a3da1d3e501d65fcd15375b89d87c1ec25dff13f58dba3f4a
|
4
|
+
data.tar.gz: 9f2c3e39bda86712762003630c92796967f5b30f6d87102c72cb69fbd905580d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c47ba2bdb23a3173b3c4460387423338b02096b2b3fdd9cba9114f2bc429d39bae6c4a7c010991c7659294e6ab9508c663112701cca3450a4005e84a3282ee1
|
7
|
+
data.tar.gz: 575cb0f98daab6bfe9353d2faf3e5356756f7a67e8158ac16fd59bf5479ad50d2b4260a106b72c0bf27136531f01058200c9bbdf62114b7e84fe8b1e9ae20c51
|
data/README.md
CHANGED
@@ -1,21 +1,20 @@
|
|
1
1
|
# Showcase
|
2
2
|
|
3
|
-
Showcase lets you build previews for your partials, components, view helpers, Stimulus controllers and more
|
3
|
+
Showcase lets you build previews for your partials, components, view helpers, Stimulus controllers and more — Rails engines included!
|
4
4
|
|
5
|
-
Add a
|
5
|
+
Add a partial to `app/views/showcase/previews` and it'll show up in Showcase's menu. Here's how to showcase a standard button component:
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
```erb
|
10
|
-
<%# app/views/showcase/previews/_button.html.erb %>
|
7
|
+
```html
|
8
|
+
<%# app/views/showcase/previews/components/_button.html.erb %>
|
11
9
|
<% showcase.title "Button" %> <%# `title` is optional and inferred from the filename, by default. %>
|
10
|
+
<% showcase.badge :partial, :component %> <%# Optional badges you can add to further clarify the type of the showcase. %>
|
12
11
|
<% showcase.description "This button component handles what we click on" %>
|
13
12
|
|
14
13
|
<% showcase.sample "Basic" do %>
|
15
14
|
<%= render "component/button", content: "Button content", mode: :small %>
|
16
15
|
<% end %>
|
17
16
|
|
18
|
-
<% showcase.sample "Large" do %>
|
17
|
+
<% showcase.sample "Large", description: "This is our larger button" do %>
|
19
18
|
<%= render "component/button", content: "Button content", mode: :large %>
|
20
19
|
<% end %>
|
21
20
|
|
@@ -27,7 +26,35 @@ Here's how to showcase a standard button component:
|
|
27
26
|
|
28
27
|
Which will then render the following:
|
29
28
|
|
30
|
-
|
29
|
+
| Light Mode | Dark Mode |
|
30
|
+
| --- | --- |
|
31
|
+
| ![](/readme/example-light.png?raw=true "Showcase showing a button component") | ![](/readme/example-dark.png?raw=true "Showcase showing a button component") |
|
32
|
+
|
33
|
+
Each sample shows the render time in milliseconds and the allocation count so it's easier to spot if there's something different happening between your samples.
|
34
|
+
|
35
|
+
## Syntax Highlighting
|
36
|
+
|
37
|
+
To have out of the box syntax highlighting, add `gem "rouge"` to your Gemfile and Showcase will set it up. Any denoted syntaxes in your samples are then highlighted, e.g.
|
38
|
+
|
39
|
+
```erb
|
40
|
+
# app/views/showcase/previews/_plain_ruby.ruby
|
41
|
+
<% showcase.sample "Basic", syntax: :ruby do %>
|
42
|
+
concat "hello".upcase
|
43
|
+
<% end %>
|
44
|
+
```
|
45
|
+
|
46
|
+
To change the default theme, look at [Loading your own syntax highlighting theme](#loading-your-own-syntax-highlighting-theme).
|
47
|
+
|
48
|
+
To use a different syntax highlighter, you can assign your own Proc to `sample_renderer` like this:
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
# config/initializers/showcase.rb
|
52
|
+
if defined?(Showcase)
|
53
|
+
Showcase.sample_renderer = ->(source, syntax) do
|
54
|
+
# Return a String of lexed and formatted code.
|
55
|
+
end
|
56
|
+
end
|
57
|
+
```
|
31
58
|
|
32
59
|
## Using options contexts
|
33
60
|
|
@@ -36,7 +63,7 @@ Showcase also supports custom options contexts. They're useful for cases where t
|
|
36
63
|
By default, Showcase ships Nice Partials and Stimulus contexts out of the box. Here's a sample of the Stimulus one:
|
37
64
|
|
38
65
|
```erb
|
39
|
-
<% showcase.options.stimulus controller: :welcome do |o| %>
|
66
|
+
<% showcase.options.context :stimulus, controller: :welcome do |o| %>
|
40
67
|
<% o.optional.targets :greeter, "If the id of the target element must be printed" %>
|
41
68
|
<% end %>
|
42
69
|
```
|
@@ -83,6 +110,14 @@ class ShowcaseTest < Showcase::PreviewsTest
|
|
83
110
|
end
|
84
111
|
```
|
85
112
|
|
113
|
+
## Full Rails engine support
|
114
|
+
|
115
|
+
Any Rails engines in your app that ships previews in their `app/views/showcase/previews` directory will automatically be surfaced in your app. Here's an example from the [bullet_train-themes-light Rails engine](https://github.com/bullet-train-co/bullet_train-core/tree/main/bullet_train-themes-light/app/views/showcase/previews).
|
116
|
+
|
117
|
+
Showcase respects the Rails views rendering order, allowing you to override a specific preview. So if an engine ships an `app/views/showcase/previews/partials/_alert.html.erb` preview, you can copy that to the same path in your app and tailor it to suit your app's documentation needs. Showcase will then show your override instead of the engine's original.
|
118
|
+
|
119
|
+
_📖 How does this work? 📖_ Internally, Showcase leverages Rails controllers' ordered set of `view_paths` — which each engine automatically prepends their app/views directory to by calling something like [`ActionController::Base.prepend_view_path`](https://github.com/rails/rails/blob/e78ed07e008676752b2ed2cff97e74b31ffacaf5/railties/lib/rails/engine.rb#L606) when initializing.
|
120
|
+
|
86
121
|
## View examples
|
87
122
|
|
88
123
|
Clone the repository, run `bundle install`, then run `bin/rails server`, visit localhost:3000 in your browser.
|
@@ -122,23 +157,27 @@ Showcase bundles its own `showcase.js`, `showcase.css` and `showcase.highlights.
|
|
122
157
|
Action View's [javascript_include_tag][] and [stylesheet_link_tag][].
|
123
158
|
|
124
159
|
If your assets require more sophisticated loading techniques, declare your own
|
125
|
-
|
160
|
+
version of the [showcase/engine/_head.html.erb][] partial.
|
161
|
+
|
162
|
+
If you need to tweak showcase's assets, declare your own versions of
|
163
|
+
the [showcase/engine/_javascripts.html.erb][] and
|
126
164
|
[showcase/engine/_stylesheets.html.erb][] partials. When customizing those
|
127
165
|
partials, make sure to include `"showcase"` in your list of assets.
|
128
166
|
|
129
167
|
[javascript_include_tag]: https://edgeapi.rubyonrails.org/classes/ActionView/Helpers/AssetTagHelper.html#method-i-javascript_include_tag
|
130
168
|
[stylesheet_link_tag]: https://edgeapi.rubyonrails.org/classes/ActionView/Helpers/AssetTagHelper.html#method-i-stylesheet_link_tag
|
169
|
+
[showcase/engine/_head.html.erb]: ./showcase/engine/_head.html.erb
|
131
170
|
[showcase/engine/_javascripts.html.erb]: ./showcase/engine/_javascripts.html.erb
|
132
171
|
[showcase/engine/_stylesheets.html.erb]: ./showcase/engine/_stylesheets.html.erb
|
133
172
|
|
134
|
-
|
173
|
+
### Loading your own syntax highlighting theme
|
135
174
|
|
136
175
|
By default, Showcase's syntax highlighting runs on Rouge's "github" theme.
|
137
176
|
|
138
177
|
To use a different theme, override [showcase/engine/_stylesheets.html.erb][] with the following, replacing `:magritte` with a [valid theme](rouge-themes):
|
139
178
|
|
140
179
|
```erb
|
141
|
-
<%= stylesheet_link_tag "
|
180
|
+
<%= stylesheet_link_tag "showcase" %> # We've removed the default showcase.highlights file here.
|
142
181
|
<%= tag.style Rouge::Theme.find(:magritte).render(scope: ".sc-highlight") %>
|
143
182
|
```
|
144
183
|
|
@@ -146,7 +185,7 @@ To use a different theme, override [showcase/engine/_stylesheets.html.erb][] wit
|
|
146
185
|
|
147
186
|
## Installation
|
148
187
|
|
149
|
-
Add this line to your application's Gemfile. To get the
|
188
|
+
Add this line to your application's Gemfile. To get the previews testing make sure the `showcase-rails` gem is available to your test environment:
|
150
189
|
|
151
190
|
```ruby
|
152
191
|
group :development, :test do
|
@@ -727,10 +727,6 @@ select {
|
|
727
727
|
height: 100%;
|
728
728
|
}
|
729
729
|
|
730
|
-
.sc-max-h-20 {
|
731
|
-
max-height: 5rem;
|
732
|
-
}
|
733
|
-
|
734
730
|
.sc-min-h-screen {
|
735
731
|
min-height: 100vh;
|
736
732
|
}
|
@@ -826,6 +822,16 @@ select {
|
|
826
822
|
border-radius: 0.375rem;
|
827
823
|
}
|
828
824
|
|
825
|
+
.sc-rounded-b-md {
|
826
|
+
border-bottom-right-radius: 0.375rem;
|
827
|
+
border-bottom-left-radius: 0.375rem;
|
828
|
+
}
|
829
|
+
|
830
|
+
.sc-rounded-t-md {
|
831
|
+
border-top-left-radius: 0.375rem;
|
832
|
+
border-top-right-radius: 0.375rem;
|
833
|
+
}
|
834
|
+
|
829
835
|
.sc-border {
|
830
836
|
border-width: 1px;
|
831
837
|
}
|
@@ -964,9 +970,8 @@ select {
|
|
964
970
|
line-height: 1.375;
|
965
971
|
}
|
966
972
|
|
967
|
-
.sc-text-
|
968
|
-
|
969
|
-
color: rgb(0 0 0 / var(--tw-text-opacity));
|
973
|
+
.sc-text-inherit {
|
974
|
+
color: inherit;
|
970
975
|
}
|
971
976
|
|
972
977
|
.sc-text-slate-500 {
|
@@ -974,6 +979,10 @@ select {
|
|
974
979
|
color: rgb(100 116 139 / var(--tw-text-opacity));
|
975
980
|
}
|
976
981
|
|
982
|
+
.sc-no-underline {
|
983
|
+
text-decoration-line: none;
|
984
|
+
}
|
985
|
+
|
977
986
|
.hover\:sc-select-all:hover {
|
978
987
|
-webkit-user-select: all;
|
979
988
|
-moz-user-select: all;
|
@@ -985,12 +994,33 @@ select {
|
|
985
994
|
background-color: rgb(238 242 255 / var(--tw-bg-opacity));
|
986
995
|
}
|
987
996
|
|
988
|
-
|
989
|
-
|
990
|
-
|
997
|
+
@media (prefers-color-scheme: dark) {
|
998
|
+
.dark\:sc-bg-neutral-700\/50 {
|
999
|
+
background-color: rgb(64 64 64 / 0.5);
|
1000
|
+
}
|
991
1001
|
|
992
|
-
.
|
993
|
-
|
1002
|
+
.dark\:sc-bg-neutral-800 {
|
1003
|
+
--tw-bg-opacity: 1;
|
1004
|
+
background-color: rgb(38 38 38 / var(--tw-bg-opacity));
|
1005
|
+
}
|
1006
|
+
|
1007
|
+
.dark\:sc-bg-neutral-900 {
|
1008
|
+
--tw-bg-opacity: 1;
|
1009
|
+
background-color: rgb(23 23 23 / var(--tw-bg-opacity));
|
1010
|
+
}
|
1011
|
+
|
1012
|
+
.dark\:sc-text-inherit {
|
1013
|
+
color: inherit;
|
1014
|
+
}
|
1015
|
+
|
1016
|
+
.dark\:sc-text-white {
|
1017
|
+
--tw-text-opacity: 1;
|
1018
|
+
color: rgb(255 255 255 / var(--tw-text-opacity));
|
1019
|
+
}
|
1020
|
+
|
1021
|
+
.dark\:hover\:sc-bg-neutral-700\/50:hover {
|
1022
|
+
background-color: rgb(64 64 64 / 0.5);
|
1023
|
+
}
|
994
1024
|
}
|
995
1025
|
|
996
1026
|
@media (min-width: 768px) {
|
@@ -1 +1 @@
|
|
1
|
-
<%= javascript_include_tag "
|
1
|
+
<%= javascript_include_tag "showcase" %>
|
@@ -3,7 +3,7 @@
|
|
3
3
|
|
4
4
|
<table class="sc-table sc-border-collapse sc-border sc-border-gray-200">
|
5
5
|
<thead>
|
6
|
-
<tr class="sc-bg-slate-50">
|
6
|
+
<tr class="sc-bg-slate-50 dark:sc-bg-neutral-800">
|
7
7
|
<% options.headers.each do |header| %>
|
8
8
|
<th class="sc-px-4 sc-py-2"><%= header.to_s.humanize %></th>
|
9
9
|
<% end %>
|
@@ -1,4 +1,4 @@
|
|
1
|
-
<main class="sc-flex sc-flex-wrap" aria-labelledby="showcase_main_title">
|
1
|
+
<main class="sc-flex sc-flex-wrap dark:sc-bg-neutral-900 dark:sc-text-white" aria-labelledby="showcase_main_title">
|
2
2
|
<section class="sc-grid sc-grid-cols-12 sc-w-full">
|
3
3
|
<nav class="sc-col-span-3 xl:sc-col-span-2 sc-py-5 sc-h-full sc-border-r">
|
4
4
|
<h1 id="showcase_main_title" class="sc-font-black sc-text-2xl sc-py-2 sc-pl-4 sc-cursor-pointer"><%= link_to "Showcase", root_url %></h1>
|
@@ -1,11 +1,11 @@
|
|
1
1
|
<section class="sc-mb-4 sc-border sc-border-gray-200 sc-rounded-md" aria-labelledby="showcase_<%= sample.id %>_title">
|
2
2
|
<showcase-sample id="<%= sample.id %>" events="<%= sample.events %>">
|
3
|
-
<header class="sc-bg-slate-100/50">
|
3
|
+
<header class="sc-bg-slate-100/50 dark:sc-bg-neutral-700/50 sc-rounded-t-md">
|
4
4
|
<div class="sc-flex sc-justify-between">
|
5
5
|
<h3 id="showcase_<%= sample.id %>_title" class="sc-px-4 sc-py-2 sc-font-medium sc-text-base md:sc-text-lg sc-leading-snug sc-truncate"><%= link_to sample.name, "##{sample.id}" %></h3>
|
6
6
|
|
7
7
|
<% if event = sample.instrumented %>
|
8
|
-
<div class="sc-text-xs sc-grid sc-gap-x-2 sc-m-2 sc-italic sc-text-slate-500">
|
8
|
+
<div class="sc-text-xs sc-grid sc-gap-x-2 sc-m-2 sc-italic sc-text-slate-500 dark:sc-text-inherit">
|
9
9
|
<span><%= event.duration.round(1) %>ms</span>
|
10
10
|
<span><%= event.allocations %> allocs</span>
|
11
11
|
</div>
|
@@ -25,7 +25,7 @@
|
|
25
25
|
|
26
26
|
<% if sample.source %>
|
27
27
|
<details>
|
28
|
-
<summary class="sc-px-4 sc-py-2 hover:sc-bg-indigo-50 sc-cursor-pointer sc-select-none">View Source</summary>
|
28
|
+
<summary class="sc-px-4 sc-py-2 hover:sc-bg-indigo-50 dark:hover:sc-bg-neutral-700/50 sc-cursor-pointer sc-select-none">View Source</summary>
|
29
29
|
|
30
30
|
<section class="sc-highlight sc-px-4 sc-py-2 sc-relative sc-overflow-y-auto hover:sc-select-all">
|
31
31
|
<pre><%= sample.source %></pre>
|
@@ -34,10 +34,10 @@
|
|
34
34
|
<% end %>
|
35
35
|
|
36
36
|
<% if sample.events.any? %>
|
37
|
-
<section class="sc-px-4 sc-py-2 sc-font-small sc-bg-slate-50" aria-labelledby="showcase_<%= sample.id %>_javascript_events_title">
|
37
|
+
<section class="sc-px-4 sc-py-2 sc-font-small sc-bg-slate-50 dark:sc-bg-neutral-800 sc-rounded-b-md" aria-labelledby="showcase_<%= sample.id %>_javascript_events_title">
|
38
38
|
<h4 id="showcase_<%= sample.id %>_javascript_events_title" class="sc-mb-2 sc-font-medium sc-text-base">JavaScript Events</h4>
|
39
39
|
|
40
|
-
<div class="sc-overflow-scroll sc-max-h-
|
40
|
+
<div class="sc-overflow-scroll sc-max-h-50">
|
41
41
|
<pre data-showcase-sample-target="relay"></pre>
|
42
42
|
</div>
|
43
43
|
</section>
|
@@ -1 +1 @@
|
|
1
|
-
<%= stylesheet_link_tag "
|
1
|
+
<%= stylesheet_link_tag "showcase", "showcase.highlights" %>
|
@@ -25,6 +25,9 @@
|
|
25
25
|
<section class="sc-space-y-4">
|
26
26
|
<h2 class="sc-font-semibold sc-text-2xl">Additional resources</h2>
|
27
27
|
<ul class="sc-list-none">
|
28
|
+
<li>
|
29
|
+
<%= link_to "Showcase documentation", "https://github.com/bullet-train-co/showcase", target: "_blank" %>
|
30
|
+
</li>
|
28
31
|
<li>
|
29
32
|
<%= link_to "Bullet Train field partials documentation", "https://bullettrain.co/docs/field-partials", target: "_blank" %>
|
30
33
|
</li>
|
@@ -1,3 +1,3 @@
|
|
1
|
-
<article class="hover:sc-bg-indigo-50 <%= "sc-bg-indigo-50" if path.id == params[:id] %>">
|
2
|
-
<%= link_to path.basename.titleize, preview_path(path.id), class: "sc-inline-block sc-py-2 sc-px-8 sc-w-full
|
1
|
+
<article class="hover:sc-bg-indigo-50 dark:hover:sc-bg-neutral-700/50 <%= "sc-bg-indigo-50 dark:sc-bg-neutral-700/50" if path.id == params[:id] %>">
|
2
|
+
<%= link_to path.basename.titleize, preview_path(path.id), class: "sc-inline-block sc-py-2 sc-px-8 sc-w-full sc-text-inherit sc-no-underline" %>
|
3
3
|
</article>
|
@@ -1,4 +1,4 @@
|
|
1
1
|
<details open class="sc-flex sc-flex-col <%= "sc-pl-4" unless tree.root? %>">
|
2
|
-
<%= tag.summary tree.name.titleize, class: "hover:sc-bg-indigo-50 sc-
|
2
|
+
<%= tag.summary tree.name.titleize, class: "hover:sc-bg-indigo-50 dark:hover:sc-bg-neutral-700/50 sc-font-medium sc-text-base sc-py-2 sc-pl-4 sc-cursor-pointer" %>
|
3
3
|
<%= render tree.ordered_children %>
|
4
4
|
</details>
|
data/lib/showcase/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: showcase-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Pence
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2023-03-
|
12
|
+
date: 2023-03-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -59,6 +59,7 @@ files:
|
|
59
59
|
- app/models/showcase/preview.rb
|
60
60
|
- app/models/showcase/sample.rb
|
61
61
|
- app/views/layouts/showcase.html.erb
|
62
|
+
- app/views/showcase/engine/_head.html.erb
|
62
63
|
- app/views/showcase/engine/_javascripts.html.erb
|
63
64
|
- app/views/showcase/engine/_options.html.erb
|
64
65
|
- app/views/showcase/engine/_preview.html.erb
|
@@ -101,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
102
|
- !ruby/object:Gem::Version
|
102
103
|
version: '0'
|
103
104
|
requirements: []
|
104
|
-
rubygems_version: 3.4.
|
105
|
+
rubygems_version: 3.4.8
|
105
106
|
signing_key:
|
106
107
|
specification_version: 4
|
107
108
|
summary: Showcase helps you show off and document your partials, components, view
|