lookbook 0.4.0.beta.1 ā 0.4.3
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 +4 -4
- data/README.md +16 -16
- data/app/controllers/lookbook/app_controller.rb +4 -9
- data/app/helpers/lookbook/application_helper.rb +6 -1
- data/app/views/lookbook/nav/_preview.html.erb +1 -1
- data/app/views/lookbook/{preview_group.html.erb ā preview/group.html.erb} +0 -0
- data/app/views/lookbook/workbench/_inspector.html.erb +2 -1
- data/lib/lookbook/engine.rb +1 -1
- data/lib/lookbook/preview.rb +6 -2
- data/lib/lookbook/preview_controller.rb +3 -3
- data/lib/lookbook/preview_example.rb +4 -0
- data/lib/lookbook/preview_group.rb +4 -0
- data/lib/lookbook/taggable.rb +3 -3
- data/lib/lookbook/version.rb +1 -1
- data/lib/tasks/lookbook_tasks.rake +5 -0
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f5cf46a07c480d8c8c3fe5f0a521ce01a316985f458becf36fb4c73c871f7cf
|
4
|
+
data.tar.gz: 2474c4105e357d9762c5228cee1190194a3b3069c6a9a9dc2afe0cf287339efe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 439aad3227d8e1e3c8d0202c4edf6b93983a2182c7a8d32c120c47f7fcd1c1dcdff675084029172c200d25fe052916b5cdcb812acd378b37af5e793ce5bea613
|
7
|
+
data.tar.gz: ab031ca977f442a1203fb059df65fe763db9e4877eeb594e44b09c63b2f0bd58bc7e6ab409ef2a11d7f33fe5b5a90f8b30a0eadd5114566c619dcc9b62be8a1e
|
data/README.md
CHANGED
@@ -76,7 +76,7 @@ Lookbook parses [Yard-style comment tags](https://rubydoc.info/gems/yard/file/do
|
|
76
76
|
|
77
77
|
```ruby
|
78
78
|
# @label Basic Button
|
79
|
-
# @display bg_color
|
79
|
+
# @display bg_color "#fff"
|
80
80
|
class ButtonComponentPreview < ViewComponent::Preview
|
81
81
|
|
82
82
|
# Primary button
|
@@ -94,7 +94,7 @@ class ButtonComponentPreview < ViewComponent::Preview
|
|
94
94
|
# ---------------
|
95
95
|
# For light-on-dark screens
|
96
96
|
#
|
97
|
-
# @display bg_color
|
97
|
+
# @display bg_color "#000"
|
98
98
|
def secondary
|
99
99
|
render ButtonComponent.new(style: :inverted) do
|
100
100
|
"Click me"
|
@@ -143,7 +143,7 @@ The following Lookbook-specific tags are available for use:
|
|
143
143
|
|
144
144
|
* `@label <label>` -[Customise navigation labels](#-label-text)
|
145
145
|
* `@hidden` - [Prevent items displaying in the navigation](#-hidden)
|
146
|
-
* `@display <key
|
146
|
+
* `@display <key> <value>` - [Specify params to pass into the preview template](#-display-key-value)
|
147
147
|
* `@!group <name> ... @!endgroup` - [Render examples in a group on the same page](#-group-name--endgroup)
|
148
148
|
|
149
149
|
### š `@label <text>`
|
@@ -180,16 +180,16 @@ class FooComponentPreview < ViewComponent::Preview
|
|
180
180
|
end
|
181
181
|
```
|
182
182
|
|
183
|
-
### š `@display <key
|
183
|
+
### š `@display <key> <value>`
|
184
184
|
|
185
185
|
The `@display` tag lets you pass custom parameters to your preview layout so that the component preview can be customised on a per-example basis.
|
186
186
|
|
187
187
|
```ruby
|
188
|
-
# @display bg_color
|
188
|
+
# @display bg_color "#eee"
|
189
189
|
class FooComponentPreview < ViewComponent::Preview
|
190
190
|
|
191
|
-
# @display max_width
|
192
|
-
# @display wrapper
|
191
|
+
# @display max_width "500px"
|
192
|
+
# @display wrapper true
|
193
193
|
def default
|
194
194
|
end
|
195
195
|
end
|
@@ -198,7 +198,7 @@ end
|
|
198
198
|
The `@display` tag can be applied at the preview (class) or at the example (method) level, and takes the following format:
|
199
199
|
|
200
200
|
```ruby
|
201
|
-
# @display <key
|
201
|
+
# @display <key> <value>
|
202
202
|
```
|
203
203
|
|
204
204
|
- `<key>` must be a valid Ruby hash key name, without quotes or spaces
|
@@ -249,19 +249,19 @@ Globally defined display params will be available to all previews. Any preview o
|
|
249
249
|
Valid:
|
250
250
|
|
251
251
|
```ruby
|
252
|
-
# @display body_classes
|
253
|
-
# @display wrap_in_container
|
254
|
-
# @display emojis_to_show
|
255
|
-
# @display page_title
|
252
|
+
# @display body_classes "bg-red border border-4 border-green"
|
253
|
+
# @display wrap_in_container true
|
254
|
+
# @display emojis_to_show 4
|
255
|
+
# @display page_title "Special example title"
|
256
256
|
```
|
257
257
|
|
258
258
|
Invalid:
|
259
259
|
|
260
260
|
```ruby
|
261
|
-
# @display body_classes
|
262
|
-
# @display wrap_in_container
|
263
|
-
# @display page title
|
264
|
-
# @display bg_color
|
261
|
+
# @display body_classes 'bg-red border border-4 border-green' [ā single quotes]
|
262
|
+
# @display wrap_in_container should_wrap [ā unquoted string, perhaps trying to call a method]
|
263
|
+
# @display page title "Special example title" [ā space in key]
|
264
|
+
# @display bg_color #fff [ā colors need quotes around them, it's not CSS!]
|
265
265
|
```
|
266
266
|
|
267
267
|
### š `@!group <name> ... @!endgroup`
|
@@ -50,7 +50,7 @@ module Lookbook
|
|
50
50
|
def find_preview
|
51
51
|
candidates = []
|
52
52
|
params[:path].to_s.scan(%r{/|$}) { candidates << $` }
|
53
|
-
match = candidates.detect { |candidate| Lookbook::Preview.exists?(candidate) }
|
53
|
+
match = candidates.reverse.detect { |candidate| Lookbook::Preview.exists?(candidate) }
|
54
54
|
@preview = match ? Lookbook::Preview.find(match) : nil
|
55
55
|
end
|
56
56
|
|
@@ -96,8 +96,7 @@ module Lookbook
|
|
96
96
|
}
|
97
97
|
end
|
98
98
|
set_params
|
99
|
-
|
100
|
-
preview_controller.render_in_layout_to_string(joined, @preview.lookbook_layout || current_layout)
|
99
|
+
preview_controller.render_in_layout_to_string("lookbook/preview/group", {examples: examples}, @preview.lookbook_layout)
|
101
100
|
else
|
102
101
|
set_params(@example)
|
103
102
|
preview_controller.params[:path] = "#{@preview.preview_name}/#{@example.name}".chomp("/")
|
@@ -106,18 +105,14 @@ module Lookbook
|
|
106
105
|
end
|
107
106
|
|
108
107
|
def set_params(example = nil)
|
109
|
-
example_params =
|
108
|
+
example_params = example.nil? ? @preview.display_params : example.display_params
|
110
109
|
preview_controller.params.merge!({
|
111
110
|
lookbook: {
|
112
|
-
display:
|
111
|
+
display: example_params
|
113
112
|
}
|
114
113
|
})
|
115
114
|
end
|
116
115
|
|
117
|
-
def current_layout
|
118
|
-
preview_controller.send :_layout, preview_controller.lookup_context, [:html]
|
119
|
-
end
|
120
|
-
|
121
116
|
def assign_inspector
|
122
117
|
@inspector = {
|
123
118
|
panes: {
|
@@ -8,7 +8,12 @@ module Lookbook
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def markdown(text)
|
11
|
-
Markdown.new(
|
11
|
+
markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, {
|
12
|
+
tables: true,
|
13
|
+
fenced_code_blocks: true,
|
14
|
+
disable_indented_code_blocks: true,
|
15
|
+
})
|
16
|
+
markdown.render(text).html_safe
|
12
17
|
end
|
13
18
|
|
14
19
|
def highlight(source, language)
|
File without changes
|
@@ -3,6 +3,7 @@
|
|
3
3
|
<nav class="-mb-px flex space-x-8 cursor-auto">
|
4
4
|
<% panes.each do |key, props| %>
|
5
5
|
<a
|
6
|
+
id="inspector-tab-<%= key %>"
|
6
7
|
href="#<%= key %>"
|
7
8
|
class="whitespace-nowrap py-2 px-1 border-b-2 cursor-pointer <%= "!text-gray-300" if props[:disabled] %>"
|
8
9
|
:class="{
|
@@ -23,7 +24,7 @@
|
|
23
24
|
<% if props[:clipboard].present? %>
|
24
25
|
<%= render "shared/clipboard" do %><%= h props[:clipboard].strip %><% end %>
|
25
26
|
<% end %>
|
26
|
-
<div class="flex flex-col h-full overflow-auto">
|
27
|
+
<div id="inspector-content-<%= key %>" class="flex flex-col h-full overflow-auto">
|
27
28
|
<%= render "workbench/inspector/#{props[:template]}", key: key, **props %>
|
28
29
|
</div>
|
29
30
|
</div>
|
data/lib/lookbook/engine.rb
CHANGED
@@ -30,7 +30,7 @@ module Lookbook
|
|
30
30
|
|
31
31
|
options.preview_controller = vc_options.preview_controller if options.preview_controller.nil?
|
32
32
|
options.preview_srcdoc = true if options.preview_srcdoc.nil?
|
33
|
-
options.preview_display_params ||= {}
|
33
|
+
options.preview_display_params ||= {}.with_indifferent_access
|
34
34
|
|
35
35
|
options.listen_paths = options.listen_paths.map(&:to_s)
|
36
36
|
options.listen_paths += options.preview_paths
|
data/lib/lookbook/preview.rb
CHANGED
@@ -23,8 +23,8 @@ module Lookbook
|
|
23
23
|
return @lookbook_examples if @lookbook_examples.present?
|
24
24
|
public_methods = public_instance_methods(false)
|
25
25
|
public_method_objects = code_object.meths.filter { |m| public_methods.include?(m.name) }
|
26
|
-
|
27
|
-
sorted = Lookbook.config.sort_examples ?
|
26
|
+
examples = public_method_objects.map { |m| PreviewExample.new(m.name.to_s, self) }
|
27
|
+
sorted = Lookbook.config.sort_examples ? examples.sort_by(&:label) : examples
|
28
28
|
@lookbook_examples = []
|
29
29
|
if code_object.groups.any?
|
30
30
|
sorted.group_by { |m| m.group }.each do |name, examples|
|
@@ -78,6 +78,10 @@ module Lookbook
|
|
78
78
|
defined?(@layout) ? @layout : nil
|
79
79
|
end
|
80
80
|
|
81
|
+
def display_params
|
82
|
+
Lookbook.config.preview_display_params.deep_merge(lookbook_display_params)
|
83
|
+
end
|
84
|
+
|
81
85
|
class << self
|
82
86
|
def all
|
83
87
|
ViewComponent::Preview.all.sort_by(&:label)
|
@@ -14,9 +14,9 @@ module Lookbook
|
|
14
14
|
render_to_string template, opts
|
15
15
|
end
|
16
16
|
|
17
|
-
def render_in_layout_to_string(
|
18
|
-
|
19
|
-
render_to_string
|
17
|
+
def render_in_layout_to_string(template, locals, layout = nil)
|
18
|
+
append_view_path Lookbook::Engine.root.join("app/views")
|
19
|
+
render_to_string template, locals: locals, **determine_layout(@preview.lookbook_layout)
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
data/lib/lookbook/taggable.rb
CHANGED
@@ -21,15 +21,15 @@ module Lookbook
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def lookbook_display_params
|
24
|
-
display_params = {}
|
24
|
+
display_params = {}.with_indifferent_access
|
25
25
|
if code_object&.tags(:display).present?
|
26
26
|
code_object.tags(:display).each do |tag|
|
27
|
-
parts = tag.text.match(
|
27
|
+
parts = tag.text.strip.match(/^([^\s]*)\s?(.*)$/)
|
28
28
|
if parts.present?
|
29
29
|
begin
|
30
30
|
display_params[parts[1]] = JSON.parse parts[2]
|
31
31
|
rescue JSON::ParserError => err
|
32
|
-
Rails.logger.error("\nš [Lookbook] Invalid JSON in @display tag.\nš [Lookbook] (#{err
|
32
|
+
Rails.logger.error("\nš [Lookbook] Invalid JSON in @display tag.\nš [Lookbook] (#{err})\n")
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
data/lib/lookbook/version.rb
CHANGED
@@ -11,5 +11,10 @@ namespace :lookbook do
|
|
11
11
|
contents = file.read
|
12
12
|
File.write(filename, contents.gsub(current_version, new_version))
|
13
13
|
end
|
14
|
+
|
15
|
+
desc "Build Gem and push to RubyGems"
|
16
|
+
task :build_and_push do
|
17
|
+
sh("rake build && gem push pkg/lookbook-#{Lookbook::VERSION}.gem")
|
18
|
+
end
|
14
19
|
end
|
15
20
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lookbook
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Perkins
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-10-
|
11
|
+
date: 2021-10-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -216,7 +216,7 @@ files:
|
|
216
216
|
- app/views/lookbook/nav/_leaf.html.erb
|
217
217
|
- app/views/lookbook/nav/_node.html.erb
|
218
218
|
- app/views/lookbook/nav/_preview.html.erb
|
219
|
-
- app/views/lookbook/
|
219
|
+
- app/views/lookbook/preview/group.html.erb
|
220
220
|
- app/views/lookbook/shared/_clipboard.html.erb
|
221
221
|
- app/views/lookbook/shared/_header.html.erb
|
222
222
|
- app/views/lookbook/shared/_sidebar.html.erb
|
@@ -259,9 +259,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
259
259
|
version: '0'
|
260
260
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
261
261
|
requirements:
|
262
|
-
- - "
|
262
|
+
- - ">="
|
263
263
|
- !ruby/object:Gem::Version
|
264
|
-
version:
|
264
|
+
version: '0'
|
265
265
|
requirements: []
|
266
266
|
rubygems_version: 3.1.2
|
267
267
|
signing_key:
|