showcase-rails 0.2.0 → 0.2.2

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: 38aa85b8e5c0a98ee2dbb45f0a184981de8a86371efbb2237e2a06f0d2f56eef
4
- data.tar.gz: b4e44e25c0b76afcd33a2dc155cae5bdebe1a5a9ca3cd670d4cc2bae94d7f38b
3
+ metadata.gz: 24a9dbd46ccbe35d34075383efeb99bedb2825c56976b7b5ce2bb5fba294ffcc
4
+ data.tar.gz: 28dc05bf705b386845aa630a188d87295ba6069445583af781478e10052d5ae8
5
5
  SHA512:
6
- metadata.gz: 995f0b2b6f765c93936adb968c501218fccc592befe12df06e0aa19b9b092a0ea385cab086763f0b855e3e86eb784edf8365143b49e69dbda934bd8ce608016d
7
- data.tar.gz: 123c59c68801489dec09d40c144c64fbc09dc6c65925833cbeade7a4c8f479595b6d59274d3ab7e74cdd18495dd8276ef60fa714b3f87662c786d6c190d55c39
6
+ metadata.gz: e62b4977a6c7f8cb53fe74373e17de88870cf245ddcb449be791afb5cab22197a03aabe263aa543bde5d86bbd683e8914002ba133178825542abfe455bdbbda9
7
+ data.tar.gz: 77213dbf5e976b366ec64947b0e0a0efcf50eb8b0360a7d6698e72ea452512c5d8a37f91e838c9546a98c5b6f3d6b54cca4215bb8f301ad80e31029103de068c
data/README.md CHANGED
@@ -29,11 +29,11 @@ Which will then render the following:
29
29
 
30
30
  ![](/readme/example.png?raw=true "Showcase showing a button component")
31
31
 
32
- ## Automatic smokescreen testing
32
+ ## Automatic integration testing
33
33
 
34
- Run `bin/rails showcase:install:integration_test` to automatic testing installed in `test/integration/showcase_test.rb`.
34
+ Showcase automatically runs integration tests for all your Showcases by rendering them and asserting they respond with `200 OK`. As long as `gem "showcase-rails"` is in the `:test` group you're set.
35
35
 
36
- This will render every Showcase you've defined and assert they respond with `200 OK`. You can add custom assertions by overriding `assert_showcase_preview`.
36
+ If you want to tweak this, run `bin/rails showcase:install:integration_test` and open `test/integration/showcase_test.rb`. You can then add your own `setup` and `teardown` hooks, as well as override the provided `assert_showcase_preview` to add custom assertions.
37
37
 
38
38
  ## View examples
39
39
 
@@ -86,16 +86,9 @@ partials, make sure to include `"showcase"` in your list of assets.
86
86
 
87
87
  ## Installation
88
88
 
89
- Add this line to your application's Gemfile. If you're utilizing the
90
- [Showcase::IntegrationTest](lib/showcase/integration_test.rb) class, make sure
91
- that the `showcase-rails` gems is available to your test environment:
92
-
89
+ Add this line to your application's Gemfile. To get the automatic integration testing make sure the `showcase-rails` gem is available to your test environment:
93
90
 
94
91
  ```ruby
95
- # nested in the default group
96
- gem "showcase-rails"
97
-
98
- # or nested in the :development and :test groups
99
92
  group :development, :test do
100
93
  gem "showcase-rails"
101
94
  end
@@ -108,7 +101,7 @@ $ bundle
108
101
 
109
102
  Or install it yourself as:
110
103
  ```bash
111
- $ gem install showcase
104
+ $ gem install showcase-rails
112
105
  ```
113
106
 
114
107
  ## Contributing
@@ -1,5 +1,5 @@
1
1
  /*
2
- ! tailwindcss v3.2.4 | MIT License | https://tailwindcss.com
2
+ ! tailwindcss v3.2.6 | MIT License | https://tailwindcss.com
3
3
  */
4
4
 
5
5
  /*
@@ -691,6 +691,10 @@ select {
691
691
  grid-column: span 9 / span 9;
692
692
  }
693
693
 
694
+ .sc-m-2 {
695
+ margin: 0.5rem;
696
+ }
697
+
694
698
  .sc-mb-2 {
695
699
  margin-bottom: 0.5rem;
696
700
  }
@@ -699,6 +703,10 @@ select {
699
703
  margin-bottom: 1rem;
700
704
  }
701
705
 
706
+ .sc-mt-1 {
707
+ margin-top: 0.25rem;
708
+ }
709
+
702
710
  .sc-inline-block {
703
711
  display: inline-block;
704
712
  }
@@ -765,10 +773,13 @@ select {
765
773
  align-items: center;
766
774
  }
767
775
 
768
- .sc-space-y-8 > :not([hidden]) ~ :not([hidden]) {
769
- --tw-space-y-reverse: 0;
770
- margin-top: calc(2rem * calc(1 - var(--tw-space-y-reverse)));
771
- margin-bottom: calc(2rem * var(--tw-space-y-reverse));
776
+ .sc-justify-between {
777
+ justify-content: space-between;
778
+ }
779
+
780
+ .sc-gap-x-2 {
781
+ -moz-column-gap: 0.5rem;
782
+ column-gap: 0.5rem;
772
783
  }
773
784
 
774
785
  .sc-space-x-2 > :not([hidden]) ~ :not([hidden]) {
@@ -783,6 +794,12 @@ select {
783
794
  margin-bottom: calc(1rem * var(--tw-space-y-reverse));
784
795
  }
785
796
 
797
+ .sc-space-y-8 > :not([hidden]) ~ :not([hidden]) {
798
+ --tw-space-y-reverse: 0;
799
+ margin-top: calc(2rem * calc(1 - var(--tw-space-y-reverse)));
800
+ margin-bottom: calc(2rem * var(--tw-space-y-reverse));
801
+ }
802
+
786
803
  .sc-overflow-scroll {
787
804
  overflow: scroll;
788
805
  }
@@ -801,6 +818,10 @@ select {
801
818
  white-space: nowrap;
802
819
  }
803
820
 
821
+ .sc-rounded-full {
822
+ border-radius: 9999px;
823
+ }
824
+
804
825
  .sc-rounded-md {
805
826
  border-radius: 0.375rem;
806
827
  }
@@ -813,16 +834,20 @@ select {
813
834
  border-width: 0px;
814
835
  }
815
836
 
816
- .sc-border-t {
817
- border-top-width: 1px;
837
+ .sc-border-2 {
838
+ border-width: 2px;
839
+ }
840
+
841
+ .sc-border-b {
842
+ border-bottom-width: 1px;
818
843
  }
819
844
 
820
845
  .sc-border-r {
821
846
  border-right-width: 1px;
822
847
  }
823
848
 
824
- .sc-border-b {
825
- border-bottom-width: 1px;
849
+ .sc-border-t {
850
+ border-top-width: 1px;
826
851
  }
827
852
 
828
853
  .sc-border-gray-200 {
@@ -830,26 +855,36 @@ select {
830
855
  border-color: rgb(229 231 235 / var(--tw-border-opacity));
831
856
  }
832
857
 
833
- .sc-bg-slate-50 {
858
+ .sc-border-indigo-300 {
859
+ --tw-border-opacity: 1;
860
+ border-color: rgb(165 180 252 / var(--tw-border-opacity));
861
+ }
862
+
863
+ .sc-bg-indigo-50 {
834
864
  --tw-bg-opacity: 1;
835
- background-color: rgb(248 250 252 / var(--tw-bg-opacity));
865
+ background-color: rgb(238 242 255 / var(--tw-bg-opacity));
836
866
  }
837
867
 
838
868
  .sc-bg-slate-100\/50 {
839
869
  background-color: rgb(241 245 249 / 0.5);
840
870
  }
841
871
 
842
- .sc-bg-indigo-50 {
872
+ .sc-bg-slate-50 {
843
873
  --tw-bg-opacity: 1;
844
- background-color: rgb(238 242 255 / var(--tw-bg-opacity));
874
+ background-color: rgb(248 250 252 / var(--tw-bg-opacity));
875
+ }
876
+
877
+ .sc-p-12 {
878
+ padding: 3rem;
845
879
  }
846
880
 
847
881
  .sc-p-4 {
848
882
  padding: 1rem;
849
883
  }
850
884
 
851
- .sc-p-12 {
852
- padding: 3rem;
885
+ .sc-px-2 {
886
+ padding-left: 0.5rem;
887
+ padding-right: 0.5rem;
853
888
  }
854
889
 
855
890
  .sc-px-4 {
@@ -857,6 +892,11 @@ select {
857
892
  padding-right: 1rem;
858
893
  }
859
894
 
895
+ .sc-px-8 {
896
+ padding-left: 2rem;
897
+ padding-right: 2rem;
898
+ }
899
+
860
900
  .sc-py-2 {
861
901
  padding-top: 0.5rem;
862
902
  padding-bottom: 0.5rem;
@@ -867,11 +907,6 @@ select {
867
907
  padding-bottom: 1.25rem;
868
908
  }
869
909
 
870
- .sc-px-8 {
871
- padding-left: 2rem;
872
- padding-right: 2rem;
873
- }
874
-
875
910
  .sc-pl-4 {
876
911
  padding-left: 1rem;
877
912
  }
@@ -880,9 +915,9 @@ select {
880
915
  padding-top: 1.75rem;
881
916
  }
882
917
 
883
- .sc-text-xl {
884
- font-size: 1.25rem;
885
- line-height: 1.75rem;
918
+ .sc-text-2xl {
919
+ font-size: 1.5rem;
920
+ line-height: 2rem;
886
921
  }
887
922
 
888
923
  .sc-text-3xl {
@@ -895,17 +930,14 @@ select {
895
930
  line-height: 1.5rem;
896
931
  }
897
932
 
898
- .sc-text-2xl {
899
- font-size: 1.5rem;
900
- line-height: 2rem;
901
- }
902
-
903
- .sc-font-semibold {
904
- font-weight: 600;
933
+ .sc-text-xl {
934
+ font-size: 1.25rem;
935
+ line-height: 1.75rem;
905
936
  }
906
937
 
907
- .sc-font-normal {
908
- font-weight: 400;
938
+ .sc-text-xs {
939
+ font-size: 0.75rem;
940
+ line-height: 1rem;
909
941
  }
910
942
 
911
943
  .sc-font-black {
@@ -916,6 +948,14 @@ select {
916
948
  font-weight: 500;
917
949
  }
918
950
 
951
+ .sc-font-normal {
952
+ font-weight: 400;
953
+ }
954
+
955
+ .sc-font-semibold {
956
+ font-weight: 600;
957
+ }
958
+
919
959
  .sc-italic {
920
960
  font-style: italic;
921
961
  }
@@ -929,6 +969,11 @@ select {
929
969
  color: rgb(0 0 0 / var(--tw-text-opacity));
930
970
  }
931
971
 
972
+ .sc-text-slate-500 {
973
+ --tw-text-opacity: 1;
974
+ color: rgb(100 116 139 / var(--tw-text-opacity));
975
+ }
976
+
932
977
  .hover\:sc-select-all:hover {
933
978
  -webkit-user-select: all;
934
979
  -moz-user-select: all;
@@ -948,11 +993,11 @@ select {
948
993
  }
949
994
 
950
995
  @media (min-width: 1280px) {
951
- .xl\:sc-col-span-2 {
952
- grid-column: span 2 / span 2;
953
- }
954
-
955
996
  .xl\:sc-col-span-10 {
956
997
  grid-column: span 10 / span 10;
957
998
  }
999
+
1000
+ .xl\:sc-col-span-2 {
1001
+ grid-column: span 2 / span 2;
1002
+ }
958
1003
  }
@@ -41,8 +41,13 @@ class Showcase::Path
41
41
 
42
42
  private
43
43
 
44
- def find(id) = children.find { _1.id == id }
45
- def insert(id) = self.class.new(id).tap { self << _1 }
44
+ def find(id)
45
+ children.find { _1.id == id }
46
+ end
47
+
48
+ def insert(id)
49
+ self.class.new(id).tap { self << _1 }
50
+ end
46
51
  end
47
52
 
48
53
  def self.tree
@@ -1,6 +1,6 @@
1
1
  class Showcase::Sample
2
2
  attr_reader :name, :id, :events, :details
3
- attr_reader :source
3
+ attr_reader :source, :instrumented
4
4
 
5
5
  def initialize(view_context, name, description: nil, id: name.parameterize, events: nil, **details)
6
6
  @view_context = view_context
@@ -24,7 +24,13 @@ class Showcase::Sample
24
24
  end
25
25
 
26
26
  def preview(&block)
27
- block_given? ? @preview = @view_context.capture(&block) : @preview
27
+ return @preview unless block_given?
28
+
29
+ # TODO: Remove `is_a?` check when Rails 6.1 support is dropped.
30
+ assigns = proc { @instrumented = _1 if _1.is_a?(ActiveSupport::Notifications::Event) }
31
+ ActiveSupport::Notifications.subscribed(assigns, "render_partial.action_view") do
32
+ @preview = @view_context.capture(&block)
33
+ end
28
34
  end
29
35
 
30
36
  def extract(&block)
@@ -4,7 +4,9 @@
4
4
  <div class="sc-flex sc-items-center sc-space-x-2 sc-mb-2">
5
5
  <h2 class="sc-font-semibold sc-text-3xl"><%= preview.title %></h2>
6
6
 
7
- <%# TODO: Insert default badge support here. %>
7
+ <% preview.badges.each do |badge| %>
8
+ <span class="sc-border-2 sc-border-indigo-300 sc-rounded-full sc-px-2 sc-mt-1"><%= badge.to_s.titleize %></span>
9
+ <% end %>
8
10
  </div>
9
11
  <% end %>
10
12
 
@@ -1,7 +1,16 @@
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
3
  <header class="sc-bg-slate-100/50">
4
- <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>
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>
6
+
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">
9
+ <span><%= event.duration.round(1) %>ms</span>
10
+ <span><%= event.allocations %> allocs</span>
11
+ </div>
12
+ <% end %>
13
+ </div>
5
14
 
6
15
  <% if sample.description %>
7
16
  <p class="sc-px-4 sc-py-2 sc-text-base"><%= sample.description %></p>
@@ -2,8 +2,12 @@ module Showcase
2
2
  class Engine < ::Rails::Engine
3
3
  isolate_namespace Showcase
4
4
 
5
- initializer "showcase.assets" do |app|
6
- app.config.assets.precompile += %w[showcase_manifest]
5
+ initializer "showcase.assets" do
6
+ config.assets.precompile += %w[showcase_manifest]
7
+ end
8
+
9
+ initializer "showcase.integration_test.autorun" do
10
+ Showcase::IntegrationTest.autorun if Rails.env.test?
7
11
  end
8
12
  end
9
13
  end
@@ -1,10 +1,17 @@
1
1
  class Showcase::IntegrationTest < ActionDispatch::IntegrationTest
2
2
  def self.inherited(test_class)
3
3
  super
4
+ test_class.prepare
5
+ end
6
+
7
+ def self.autorun
8
+ at_exit { prepare unless subclasses.any? }
9
+ end
4
10
 
11
+ def self.prepare
5
12
  tree = Showcase::Path.tree
6
13
  tree.flat_map(&:ordered_paths).each do |path|
7
- test_class.test "Showcase: GET showcase/previews/#{path.id} renders successfully" do
14
+ test "Showcase: GET showcase/previews/#{path.id} renders successfully" do
8
15
  get showcase.preview_path(path.id)
9
16
 
10
17
  assert_response :ok
@@ -12,7 +19,7 @@ class Showcase::IntegrationTest < ActionDispatch::IntegrationTest
12
19
  end
13
20
  end
14
21
 
15
- test_class.test "Showcase: isn't empty" do
22
+ test "Showcase: isn't empty" do
16
23
  assert_not_empty tree, "Showcase couldn't find any samples to generate tests for"
17
24
  end
18
25
  end
@@ -1,3 +1,3 @@
1
1
  module Showcase
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.2"
3
3
  end
data/lib/showcase.rb CHANGED
@@ -1,9 +1,9 @@
1
- require "zeitwerk"
2
- loader = Zeitwerk::Loader.for_gem
3
- loader.ignore("#{__dir__}/showcase-rails.rb")
4
- loader.setup
1
+ require_relative "showcase/version"
5
2
 
6
3
  module Showcase
4
+ autoload :IntegrationTest, "showcase/integration_test"
5
+ autoload :RouteHelper, "showcase/route_helper"
6
+
7
7
  singleton_class.attr_accessor :sample_renderer
8
8
  @sample_renderer = ->(lines) { tag.pre lines.join.strip_heredoc }
9
9
 
@@ -2,9 +2,9 @@ namespace :showcase do
2
2
  namespace :install do
3
3
  INTEGRATION_TEST_PATH = "test/integration/showcase_test.rb"
4
4
 
5
- desc "Install Showcase smokescreen testing in #{INTEGRATION_TEST_PATH}"
6
- task :smokescreen_test do
7
- mkdir_p INTEGRATION_TEST_PATH
5
+ desc "Install Showcase integration testing in #{INTEGRATION_TEST_PATH}"
6
+ task :integration_test do
7
+ mkdir_p File.dirname(INTEGRATION_TEST_PATH)
8
8
  File.write INTEGRATION_TEST_PATH, <<~RUBY
9
9
  require "test_helper"
10
10
 
@@ -16,15 +16,4 @@ namespace :showcase do
16
16
  RUBY
17
17
  end
18
18
  end
19
-
20
- # desc "Pass a directory relative to app/views to copy over"
21
- # task :copy do |t, directory|
22
- # prefix = "app/views/#{directory}"
23
- #
24
- # Dir.glob(File.join(Dir.pwd, prefix, "**/*.*")).each do |filename|
25
- # new_filename = filename.sub(directory, Showcase.templates_path).sub(/\/_/, "/")
26
- # mkdir_p File.dirname(new_filename)
27
- # copy_file filename, new_filename
28
- # end
29
- # end
30
19
  end
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.0
4
+ version: 0.2.2
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-02-06 00:00:00.000000000 Z
12
+ date: 2023-02-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -53,7 +53,6 @@ files:
53
53
  - app/assets/config/showcase_manifest.js
54
54
  - app/assets/javascripts/showcase.js
55
55
  - app/controllers/showcase/engine_controller.rb
56
- - app/controllers/showcase/pages_controller.rb
57
56
  - app/controllers/showcase/previews_controller.rb
58
57
  - app/models/showcase/options.rb
59
58
  - app/models/showcase/path.rb
@@ -1,5 +0,0 @@
1
- class Showcase::PagesController < Showcase::EngineController
2
- def show
3
- @page = Showcase::Path.new(params[:id]).page_for view_context
4
- end
5
- end