showcase-rails 0.2.7 → 0.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 616178a6d44d9d2a3da1d3e501d65fcd15375b89d87c1ec25dff13f58dba3f4a
4
- data.tar.gz: 9f2c3e39bda86712762003630c92796967f5b30f6d87102c72cb69fbd905580d
3
+ metadata.gz: 3acbdb8f9aafaadded728f1f43bd2b834424a9ccd764605a093f3fa08019b9e7
4
+ data.tar.gz: 5fe6fde3e533bb60540ea1b47b69953de2d40234560f2b55cdb47bab43e9ed37
5
5
  SHA512:
6
- metadata.gz: 0c47ba2bdb23a3173b3c4460387423338b02096b2b3fdd9cba9114f2bc429d39bae6c4a7c010991c7659294e6ab9508c663112701cca3450a4005e84a3282ee1
7
- data.tar.gz: 575cb0f98daab6bfe9353d2faf3e5356756f7a67e8158ac16fd59bf5479ad50d2b4260a106b72c0bf27136531f01058200c9bbdf62114b7e84fe8b1e9ae20c51
6
+ metadata.gz: fd7b71e810edb02e6f411f628ed80745944b36c920e7c86588b42544575fb8805a97e35bb30119b3d3a02ea9c127b8ced65d44a61808e5c30046e8ac90253719
7
+ data.tar.gz: a5ef78400af5a631f38c57a51bc2ea900007213d6fe018da459b7d104d8f36132d8c7a51f3c8a8d3a078b4d4f837110bf0ffaf777a5885b15ea8a18061965318
data/README.md CHANGED
@@ -99,9 +99,10 @@ class ShowcaseTest < Showcase::PreviewsTest
99
99
  assert_text "This is a combobox, for sure."
100
100
  end
101
101
 
102
- test showcase: "button", id: "basic" do
103
- # This test block runs within the #button container element's #basic sample.
104
- assert_button class: ["text-xs"]
102
+ test showcase: "button" do
103
+ assert_selector id: "basic" do
104
+ assert_button class: ["text-xs"]
105
+ end
105
106
  end
106
107
 
107
108
  test "some non-Showcase test" do
@@ -727,6 +727,10 @@ select {
727
727
  height: 100%;
728
728
  }
729
729
 
730
+ .sc-max-h-48 {
731
+ max-height: 12rem;
732
+ }
733
+
730
734
  .sc-min-h-screen {
731
735
  min-height: 100vh;
732
736
  }
@@ -796,6 +800,10 @@ select {
796
800
  margin-bottom: calc(2rem * var(--tw-space-y-reverse));
797
801
  }
798
802
 
803
+ .sc-overflow-clip {
804
+ overflow: clip;
805
+ }
806
+
799
807
  .sc-overflow-scroll {
800
808
  overflow: scroll;
801
809
  }
@@ -827,27 +835,14 @@ select {
827
835
  border-bottom-left-radius: 0.375rem;
828
836
  }
829
837
 
830
- .sc-rounded-t-md {
831
- border-top-left-radius: 0.375rem;
832
- border-top-right-radius: 0.375rem;
833
- }
834
-
835
838
  .sc-border {
836
839
  border-width: 1px;
837
840
  }
838
841
 
839
- .sc-border-0 {
840
- border-width: 0px;
841
- }
842
-
843
842
  .sc-border-2 {
844
843
  border-width: 2px;
845
844
  }
846
845
 
847
- .sc-border-b {
848
- border-bottom-width: 1px;
849
- }
850
-
851
846
  .sc-border-r {
852
847
  border-right-width: 1px;
853
848
  }
@@ -970,8 +965,8 @@ select {
970
965
  line-height: 1.375;
971
966
  }
972
967
 
973
- .sc-text-inherit {
974
- color: inherit;
968
+ .\!sc-text-inherit {
969
+ color: inherit !important;
975
970
  }
976
971
 
977
972
  .sc-text-slate-500 {
@@ -979,8 +974,8 @@ select {
979
974
  color: rgb(100 116 139 / var(--tw-text-opacity));
980
975
  }
981
976
 
982
- .sc-no-underline {
983
- text-decoration-line: none;
977
+ .\!sc-no-underline {
978
+ text-decoration-line: none !important;
984
979
  }
985
980
 
986
981
  .hover\:sc-select-all:hover {
@@ -994,6 +989,10 @@ select {
994
989
  background-color: rgb(238 242 255 / var(--tw-bg-opacity));
995
990
  }
996
991
 
992
+ .hover\:sc-underline:hover {
993
+ text-decoration-line: underline;
994
+ }
995
+
997
996
  @media (prefers-color-scheme: dark) {
998
997
  .dark\:sc-bg-neutral-700\/50 {
999
998
  background-color: rgb(64 64 64 / 0.5);
@@ -110,3 +110,118 @@
110
110
  color: #24292f;
111
111
  font-weight: bold;
112
112
  }
113
+
114
+ @media (prefers-color-scheme: dark) {
115
+ .sc-highlight table td { padding: 5px; }
116
+ .sc-highlight table pre { margin: 0; }
117
+ .sc-highlight, .sc-highlight .w {
118
+ color: #c9d1d9;
119
+ background-color: #161b22;
120
+ }
121
+ .sc-highlight .k, .sc-highlight .kd, .sc-highlight .kn, .sc-highlight .kp, .sc-highlight .kr, .sc-highlight .kt, .sc-highlight .kv {
122
+ color: #ff7b72;
123
+ }
124
+ .sc-highlight .gr {
125
+ color: #f0f6fc;
126
+ }
127
+ .sc-highlight .gd {
128
+ color: #ffdcd7;
129
+ background-color: #67060c;
130
+ }
131
+ .sc-highlight .nb {
132
+ color: #ffa657;
133
+ }
134
+ .sc-highlight .nc {
135
+ color: #ffa657;
136
+ }
137
+ .sc-highlight .no {
138
+ color: #ffa657;
139
+ }
140
+ .sc-highlight .nn {
141
+ color: #ffa657;
142
+ }
143
+ .sc-highlight .sr {
144
+ color: #7ee787;
145
+ }
146
+ .sc-highlight .na {
147
+ color: #7ee787;
148
+ }
149
+ .sc-highlight .nt {
150
+ color: #7ee787;
151
+ }
152
+ .sc-highlight .gi {
153
+ color: #aff5b4;
154
+ background-color: #033a16;
155
+ }
156
+ .sc-highlight .kc {
157
+ color: #79c0ff;
158
+ }
159
+ .sc-highlight .l, .sc-highlight .ld, .sc-highlight .m, .sc-highlight .mb, .sc-highlight .mf, .sc-highlight .mh, .sc-highlight .mi, .sc-highlight .il, .sc-highlight .mo, .sc-highlight .mx {
160
+ color: #79c0ff;
161
+ }
162
+ .sc-highlight .sb {
163
+ color: #79c0ff;
164
+ }
165
+ .sc-highlight .bp {
166
+ color: #79c0ff;
167
+ }
168
+ .sc-highlight .ne {
169
+ color: #79c0ff;
170
+ }
171
+ .sc-highlight .nl {
172
+ color: #79c0ff;
173
+ }
174
+ .sc-highlight .py {
175
+ color: #79c0ff;
176
+ }
177
+ .sc-highlight .nv, .sc-highlight .vc, .sc-highlight .vg, .sc-highlight .vi, .sc-highlight .vm {
178
+ color: #79c0ff;
179
+ }
180
+ .sc-highlight .o, .sc-highlight .ow {
181
+ color: #79c0ff;
182
+ }
183
+ .sc-highlight .gh {
184
+ color: #1f6feb;
185
+ font-weight: bold;
186
+ }
187
+ .sc-highlight .gu {
188
+ color: #1f6feb;
189
+ font-weight: bold;
190
+ }
191
+ .sc-highlight .s, .sc-highlight .sa, .sc-highlight .sc, .sc-highlight .dl, .sc-highlight .sd, .sc-highlight .s2, .sc-highlight .se, .sc-highlight .sh, .sc-highlight .sx, .sc-highlight .s1, .sc-highlight .ss {
192
+ color: #a5d6ff;
193
+ }
194
+ .sc-highlight .nd {
195
+ color: #d2a8ff;
196
+ }
197
+ .sc-highlight .nf, .sc-highlight .fm {
198
+ color: #d2a8ff;
199
+ }
200
+ .sc-highlight .err {
201
+ color: #f0f6fc;
202
+ background-color: #8e1519;
203
+ }
204
+ .sc-highlight .c, .sc-highlight .ch, .sc-highlight .cd, .sc-highlight .cm, .sc-highlight .cp, .sc-highlight .cpf, .sc-highlight .c1, .sc-highlight .cs {
205
+ color: #8b949e;
206
+ }
207
+ .sc-highlight .gl {
208
+ color: #8b949e;
209
+ }
210
+ .sc-highlight .gt {
211
+ color: #8b949e;
212
+ }
213
+ .sc-highlight .ni {
214
+ color: #c9d1d9;
215
+ }
216
+ .sc-highlight .si {
217
+ color: #c9d1d9;
218
+ }
219
+ .sc-highlight .ge {
220
+ color: #c9d1d9;
221
+ font-style: italic;
222
+ }
223
+ .sc-highlight .gs {
224
+ color: #c9d1d9;
225
+ font-weight: bold;
226
+ }
227
+ }
@@ -66,7 +66,7 @@ class Showcase::Preview
66
66
  # - the `sample.events` what JavaScript `events` to listen for on the element
67
67
  # - any other custom options are available in `sample.details`.
68
68
  def sample(name, **options, &block)
69
- @samples << Showcase::Sample.new(@view_context, name, **options).tap { _1.collect(&block) }
69
+ @samples << Showcase::Sample.new(@view_context, name, **options).tap { _1.evaluate(&block) }
70
70
  end
71
71
 
72
72
  # Yields an Options object to help define the configuration table for a Preview.
@@ -88,7 +88,7 @@ class Showcase::Preview
88
88
  end
89
89
 
90
90
  def render_associated_partial
91
- @view_context.render "#{Showcase.previews_path}/#{id}", showcase: self
91
+ @view_context.render "showcase/previews/#{id}", showcase: self
92
92
  nil
93
93
  end
94
94
  end
@@ -1,6 +1,6 @@
1
1
  class Showcase::Sample
2
2
  attr_reader :name, :id, :events, :details
3
- attr_reader :source, :instrumented
3
+ attr_reader :rendered, :source, :instrumented
4
4
 
5
5
  def initialize(view_context, name, description: nil, id: name.parameterize, syntax: :erb, events: nil, **details)
6
6
  @view_context = view_context
@@ -14,36 +14,39 @@ class Showcase::Sample
14
14
  @description
15
15
  end
16
16
 
17
- def collect(&block)
17
+ def evaluate(&block)
18
18
  if block.arity.zero?
19
- preview(&block)
20
- extract(&block)
19
+ consume(&block)
21
20
  else
22
21
  @view_context.capture(self, &block)
23
22
  end
24
23
  end
25
24
 
26
- def preview(&block)
27
- return @preview unless block_given?
25
+ def consume(&block)
26
+ render(&block)
27
+ extract_source(&block)
28
+ end
28
29
 
30
+ def render(&block)
29
31
  # TODO: Remove `is_a?` check when Rails 6.1 support is dropped.
30
32
  assigns = proc { @instrumented = _1 if _1.is_a?(ActiveSupport::Notifications::Event) }
31
33
  ActiveSupport::Notifications.subscribed(assigns, "render_partial.action_view") do
32
- @preview = @view_context.capture(&block)
34
+ @rendered = @view_context.capture(&block)
33
35
  end
34
36
  end
35
37
 
36
- def extract(&block)
38
+ def extract_source(&block)
37
39
  source = extract_source_block_via_matched_indentation_from(*block.source_location)
38
40
  @source = @view_context.instance_exec(source, @syntax, &Showcase.sample_renderer)
39
41
  end
40
42
 
41
43
  private
42
44
 
43
- def extract_source_block_via_matched_indentation_from(file, starting_index)
44
- first_line, *lines = File.readlines(file).from(starting_index - 1)
45
+ def extract_source_block_via_matched_indentation_from(file, source_location_index)
46
+ # `Array`s are zero-indexed, but `source_location` indexes are not, hence `pred`.
47
+ starting_line, *lines = File.readlines(file).slice(source_location_index.pred..)
45
48
 
46
- indentation = first_line.match(/^\s+(?=\b)/).to_s
49
+ indentation = starting_line.match(/^\s+/).to_s
47
50
  matcher = /^#{indentation}\S/
48
51
 
49
52
  index = lines.index { _1.match?(matcher) }
@@ -1,7 +1,9 @@
1
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
- <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>
4
+ <h1 id="showcase_main_title" class="sc-font-black sc-text-2xl sc-py-2 sc-pl-4 sc-cursor-pointer">
5
+ <%= link_to "Showcase", root_url, class: "!sc-text-inherit hover:sc-underline" %>
6
+ </h1>
5
7
 
6
8
  <%= render Showcase::Path.tree %>
7
9
  </nav>
@@ -1,8 +1,10 @@
1
- <section class="sc-mb-4 sc-border sc-border-gray-200 sc-rounded-md" aria-labelledby="showcase_<%= sample.id %>_title">
1
+ <section class="sc-mb-4 sc-border sc-border-gray-200 sc-rounded-md sc-overflow-clip" aria-labelledby="showcase_<%= sample.id %>_title">
2
2
  <showcase-sample id="<%= sample.id %>" events="<%= sample.events %>">
3
- <header class="sc-bg-slate-100/50 dark:sc-bg-neutral-700/50 sc-rounded-t-md">
3
+ <header class="sc-bg-slate-100/50 dark:sc-bg-neutral-700/50">
4
4
  <div class="sc-flex sc-justify-between">
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>
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">
6
+ <%= link_to sample.name, "##{sample.id}", class: "!sc-text-inherit" %>
7
+ </h3>
6
8
 
7
9
  <% if event = sample.instrumented %>
8
10
  <div class="sc-text-xs sc-grid sc-gap-x-2 sc-m-2 sc-italic sc-text-slate-500 dark:sc-text-inherit">
@@ -17,9 +19,9 @@
17
19
  <% end %>
18
20
  </header>
19
21
 
20
- <% if sample.preview %>
21
- <section class="sc-px-4 sc-py-2 sc-border sc-border-gray-200 sc-border-0 sc-border-b">
22
- <%= sample.preview %>
22
+ <% if sample.rendered %>
23
+ <section class="sc-px-4 sc-py-2">
24
+ <%= sample.rendered %>
23
25
  </section>
24
26
  <% end %>
25
27
 
@@ -37,7 +39,7 @@
37
39
  <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
40
  <h4 id="showcase_<%= sample.id %>_javascript_events_title" class="sc-mb-2 sc-font-medium sc-text-base">JavaScript Events</h4>
39
41
 
40
- <div class="sc-overflow-scroll sc-max-h-50">
42
+ <div class="sc-overflow-scroll sc-max-h-48">
41
43
  <pre data-showcase-sample-target="relay"></pre>
42
44
  </div>
43
45
  </section>
@@ -1,3 +1,3 @@
1
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" %>
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,12 +1,12 @@
1
1
  class Showcase::PreviewsTest < ActionView::TestCase
2
2
  def self.inherited(test_class)
3
3
  super
4
+
5
+ test_class.tests Showcase::EngineController._helpers
4
6
  test_class.prepare
5
7
  end
6
8
 
7
9
  def self.prepare
8
- tests Showcase::EngineController._helpers
9
-
10
10
  tree = Showcase::Path.tree
11
11
  tree.flat_map(&:ordered_paths).each do |path|
12
12
  test "Showcase: automatically renders showcase/previews/#{path.id}" do
@@ -20,17 +20,16 @@ class Showcase::PreviewsTest < ActionView::TestCase
20
20
  end
21
21
  end
22
22
 
23
- def self.test(name = nil, showcase: nil, id: nil, &block)
24
- case
25
- when name then super(name, &block)
26
- when id && showcase.nil? then raise ArgumentError, "can't test a sample without a showcase"
23
+ def self.test(name = nil, showcase: nil, &block)
24
+ if name
25
+ super(name, &block)
27
26
  else
28
- super "Showcase: showcase/previews/#{showcase} #{"sample #{id}" if id}".squish do
27
+ super "Showcase: showcase/previews/#{showcase}" do
29
28
  path = Showcase::Path.new(showcase)
30
29
  render "showcase/engine/preview", preview: path.preview_for(view)
31
30
 
32
31
  assert_showcase_preview(path.id)
33
- assert_element(id: id || path.id) { instance_eval(&block) }
32
+ instance_eval(&block)
34
33
  end
35
34
  end
36
35
  end
@@ -1,8 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Showcase::RouteHelper
2
4
  def method_missing(name, ...)
3
- case name
4
- when /_path\Z/, /_url\Z/ then main_app.public_send(name, ...)
5
- else super
5
+ if name.end_with?("_path", "_url")
6
+ main_app.public_send(name, ...)
7
+ else
8
+ super
6
9
  end
7
10
  end
8
11
  end
@@ -1,3 +1,3 @@
1
1
  module Showcase
2
- VERSION = "0.2.7"
2
+ VERSION = "0.3.0"
3
3
  end
data/lib/showcase.rb CHANGED
@@ -24,12 +24,9 @@ module Showcase
24
24
  end
25
25
  end
26
26
 
27
- singleton_class.attr_reader :previews_path
28
- @previews_path = "showcase/previews"
29
-
30
27
  def self.previews
31
28
  Showcase::EngineController.view_paths.map(&:path).flat_map do |root|
32
- Dir.glob("**/*.*", base: File.join(root, previews_path))
29
+ Dir.glob("**/*.*", base: File.join(root, "showcase/previews"))
33
30
  end.uniq
34
31
  end
35
32
 
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.7
4
+ version: 0.3.0
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-14 00:00:00.000000000 Z
12
+ date: 2023-03-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails