showcase-rails 0.2.8 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -3
- data/app/models/showcase/preview.rb +2 -2
- data/app/models/showcase/sample.rb +14 -11
- data/app/views/showcase/engine/_sample.html.erb +2 -2
- data/app/views/showcase/engine/path/_path.html.erb +1 -1
- data/lib/showcase/previews_test.rb +7 -8
- data/lib/showcase/version.rb +1 -1
- data/lib/showcase.rb +1 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3acbdb8f9aafaadded728f1f43bd2b834424a9ccd764605a093f3fa08019b9e7
|
4
|
+
data.tar.gz: 5fe6fde3e533bb60540ea1b47b69953de2d40234560f2b55cdb47bab43e9ed37
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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"
|
103
|
-
|
104
|
-
|
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
|
@@ -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.
|
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 "
|
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
|
17
|
+
def evaluate(&block)
|
18
18
|
if block.arity.zero?
|
19
|
-
|
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
|
27
|
-
|
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
|
-
@
|
34
|
+
@rendered = @view_context.capture(&block)
|
33
35
|
end
|
34
36
|
end
|
35
37
|
|
36
|
-
def
|
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,
|
44
|
-
|
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 =
|
49
|
+
indentation = starting_line.match(/^\s+/).to_s
|
47
50
|
matcher = /^#{indentation}\S/
|
48
51
|
|
49
52
|
index = lines.index { _1.match?(matcher) }
|
@@ -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,
|
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,
|
24
|
-
|
25
|
-
|
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}
|
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
|
-
|
32
|
+
instance_eval(&block)
|
34
33
|
end
|
35
34
|
end
|
36
35
|
end
|
data/lib/showcase/version.rb
CHANGED
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,
|
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.
|
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-
|
12
|
+
date: 2023-03-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|