lookbook 1.0.0.beta.6 → 1.0.0.beta.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 +1 -1
- data/app/components/lookbook/params_editor/field/component.rb +2 -1
- data/app/controllers/lookbook/application_controller.rb +1 -1
- data/app/helpers/lookbook/application_helper.rb +9 -0
- data/app/views/layouts/lookbook/skeleton.html.erb +15 -8
- data/lib/lookbook/config.rb +2 -0
- data/lib/lookbook/data.rb +11 -0
- data/lib/lookbook/engine.rb +61 -71
- data/lib/lookbook/hooks.rb +21 -0
- data/lib/lookbook/panels.rb +15 -0
- data/lib/lookbook/parser.rb +4 -1
- data/lib/lookbook/preview.rb +1 -1
- data/lib/lookbook/preview_example.rb +1 -1
- data/lib/lookbook/preview_group.rb +8 -0
- data/lib/lookbook/source_inspector.rb +9 -0
- data/lib/lookbook/tag.rb +108 -0
- data/lib/lookbook/tags.rb +22 -0
- data/lib/lookbook/theme.rb +36 -7
- data/lib/lookbook/version.rb +1 -1
- data/lib/lookbook.rb +1 -0
- data/public/lookbook-assets/js/lookbook.js +80 -80
- data/public/lookbook-assets/js/lookbook.js.map +1 -1
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52925967015a9d02a18dfcde3e185d7d1dcd1917ea03fdf63276743b3ce18e66
|
4
|
+
data.tar.gz: a8523484936828701e3775603996c8477bb14830ad2b18b5ca5ef1bc55d58117
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 104d5b01cc83a5bd4440e64e7da9a551e46b5f583e2a1209bc391bb75facf1c2633453a3b9d15f1a9e351269aa07b5d6e83783768301570346e111076c9511bf
|
7
|
+
data.tar.gz: 5b86248682b5105de0a56ba9e3832cfa243ed8307ac2215d1331ed7915386728db479ada8d8c9ab05a0fa0e00e98ed338416827ca7bfe613533e4c41795f2301
|
data/README.md
CHANGED
@@ -14,7 +14,7 @@ _For code and documentation for the current stable release see the [main branch]
|
|
14
14
|
|
15
15
|
The new (work-in-progress) **documentation site** for Lookbook v1.0 is available here:
|
16
16
|
|
17
|
-
👉 **https://
|
17
|
+
👉 **https://beta.lookbook.build/** 👈
|
18
18
|
|
19
19
|
> Documentation source files are located in the `/docs` directory within this repository. The docs are built using [Bridgetown](https://www.bridgetownrb.com/).
|
20
20
|
|
@@ -4,6 +4,15 @@ module Lookbook
|
|
4
4
|
Lookbook::Engine.config.lookbook
|
5
5
|
end
|
6
6
|
|
7
|
+
def theme
|
8
|
+
Lookbook.theme
|
9
|
+
end
|
10
|
+
|
11
|
+
def asset_path(file, version: true)
|
12
|
+
path = "/lookbook-assets/#{file}".gsub("//", "/")
|
13
|
+
version ? "#{path}?v=#{Lookbook::VERSION}" : path
|
14
|
+
end
|
15
|
+
|
7
16
|
def feature_enabled?(name)
|
8
17
|
Lookbook::Features.enabled?(name)
|
9
18
|
end
|
@@ -5,16 +5,24 @@
|
|
5
5
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
6
6
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
|
7
7
|
|
8
|
-
<link href="/
|
9
|
-
<link href="/
|
10
|
-
|
8
|
+
<link href="<%= asset_path("/css/lookbook.css") %>" rel="stylesheet">
|
9
|
+
<link href="<%= asset_path("/css/themes/#{config.ui_theme}.css") %>" rel="stylesheet">
|
10
|
+
|
11
|
+
<%- if @theme_overrides.present? %>
|
11
12
|
<style media="all">
|
12
13
|
<%== @theme_overrides %>
|
13
14
|
</style>
|
14
15
|
<% end %>
|
15
16
|
|
16
|
-
<% if config.ui_favicon
|
17
|
-
<link
|
17
|
+
<% if config.ui_favicon == true %>
|
18
|
+
<link
|
19
|
+
rel="icon"
|
20
|
+
href="data:image/svg+xml,%3Csvg width='96' height='84' viewBox='0 0 96 84' xmlns='http://www.w3.org/2000/svg'%3E%3Cdefs%3E%3CclipPath id='a'%3E%3Cpath d='M96 0v84H0V0h96Z'/%3E%3C/clipPath%3E%3CclipPath id='b'%3E%3Cpath d='M71.897 0a1.5 1.5 0 0 1 1.31.769l22.605 40.5a1.5 1.5 0 0 1 0 1.462l-22.605 40.5a1.5 1.5 0 0 1-1.31.769H49.481a1 1 0 0 1-.873-1.487L70.812 42.73a1.5 1.5 0 0 0 0-1.462L48.608 1.487A1 1 0 0 1 49.481 0ZM24.655.564l22.72 40.705a1.5 1.5 0 0 1 0 1.462l-22.72 40.705a1 1 0 0 1-1.746 0L.19 42.73a1.5 1.5 0 0 1 0-1.462L22.91.564a1 1 0 0 1 1.746 0Z'/%3E%3C/clipPath%3E%3C/defs%3E%3Cg clip-path='url(%23a)'%3E%3Cg clip-path='url(%23b)'%3E%3Cpath fill='<%= url_encode theme.favicon_dark_mode %>' d='M0 0h96v84H0V0z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E"
|
21
|
+
media="(prefers-color-scheme: dark)">
|
22
|
+
<link
|
23
|
+
rel="icon"
|
24
|
+
href="data:image/svg+xml,%3Csvg width='96' height='84' viewBox='0 0 96 84' xmlns='http://www.w3.org/2000/svg'%3E%3Cdefs%3E%3CclipPath id='a'%3E%3Cpath d='M96 0v84H0V0h96Z'/%3E%3C/clipPath%3E%3CclipPath id='b'%3E%3Cpath d='M71.897 0a1.5 1.5 0 0 1 1.31.769l22.605 40.5a1.5 1.5 0 0 1 0 1.462l-22.605 40.5a1.5 1.5 0 0 1-1.31.769H49.481a1 1 0 0 1-.873-1.487L70.812 42.73a1.5 1.5 0 0 0 0-1.462L48.608 1.487A1 1 0 0 1 49.481 0ZM24.655.564l22.72 40.705a1.5 1.5 0 0 1 0 1.462l-22.72 40.705a1 1 0 0 1-1.746 0L.19 42.73a1.5 1.5 0 0 1 0-1.462L22.91.564a1 1 0 0 1 1.746 0Z'/%3E%3C/clipPath%3E%3C/defs%3E%3Cg clip-path='url(%23a)'%3E%3Cg clip-path='url(%23b)'%3E%3Cpath fill='<%= url_encode theme.favicon_light_mode %>' d='M0 0h96v84H0V0z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E"
|
25
|
+
media="(prefers-color-scheme: light)">
|
18
26
|
<% end %>
|
19
27
|
|
20
28
|
<script>
|
@@ -25,15 +33,14 @@
|
|
25
33
|
<% end %>
|
26
34
|
</script>
|
27
35
|
|
28
|
-
<script src="/
|
36
|
+
<script src="<%= asset_path("/js/lookbook.js") %>" defer></script>
|
29
37
|
<% if params[:lookbook_embed] %>
|
30
|
-
<script src="/
|
38
|
+
<script src="<%= asset_path("/js/embed.js") %>" defer></script>
|
31
39
|
<% end %>
|
32
40
|
|
33
41
|
<title><%= [@title, config.project_name || "Lookbook"].compact.join(" :: ") %></title>
|
34
42
|
</head>
|
35
43
|
<body>
|
36
|
-
|
37
44
|
<%= yield :body %>
|
38
45
|
|
39
46
|
<% if Rails.env.development? %>
|
data/lib/lookbook/config.rb
CHANGED
@@ -23,6 +23,7 @@ module Lookbook
|
|
23
23
|
preview_paths: [],
|
24
24
|
preview_display_params: {},
|
25
25
|
preview_srcdoc: nil,
|
26
|
+
preview_tags: {},
|
26
27
|
sort_examples: false,
|
27
28
|
|
28
29
|
listen: Rails.env.development?,
|
@@ -38,6 +39,7 @@ module Lookbook
|
|
38
39
|
|
39
40
|
ui_theme: "indigo",
|
40
41
|
ui_theme_overrides: {},
|
42
|
+
ui_favicon: true,
|
41
43
|
|
42
44
|
hooks: {
|
43
45
|
after_initialize: [],
|
data/lib/lookbook/engine.rb
CHANGED
@@ -2,12 +2,22 @@ require "rails"
|
|
2
2
|
require "view_component"
|
3
3
|
require "action_cable/engine"
|
4
4
|
require "listen"
|
5
|
+
require "rake"
|
5
6
|
|
6
7
|
module Lookbook
|
7
8
|
|
8
9
|
autoload :Config, "lookbook/config"
|
9
|
-
|
10
|
+
autoload :Data, "lookbook/data"
|
11
|
+
autoload :Hooks, "lookbook/hooks"
|
12
|
+
autoload :Panels, "lookbook/panels"
|
13
|
+
autoload :Tags, "lookbook/tags"
|
14
|
+
|
10
15
|
class << self
|
16
|
+
include Lookbook::Data
|
17
|
+
include Lookbook::Hooks
|
18
|
+
include Lookbook::Panels
|
19
|
+
include Lookbook::Tags
|
20
|
+
|
11
21
|
def version
|
12
22
|
Lookbook::VERSION
|
13
23
|
end
|
@@ -48,46 +58,12 @@ module Lookbook
|
|
48
58
|
Page.any?
|
49
59
|
end
|
50
60
|
|
51
|
-
def data
|
52
|
-
@data ||= Store.new
|
53
|
-
end
|
54
|
-
|
55
|
-
def data=(props)
|
56
|
-
@data = Store.new(props)
|
57
|
-
end
|
58
|
-
|
59
|
-
def after_initialize(&block)
|
60
|
-
add_hook(:after_initialize, block)
|
61
|
-
end
|
62
|
-
|
63
|
-
def before_exit(&block)
|
64
|
-
add_hook(:before_exit, block)
|
65
|
-
end
|
66
|
-
|
67
|
-
def after_change(&block)
|
68
|
-
add_hook(:after_change, block)
|
69
|
-
end
|
70
|
-
|
71
|
-
def define_panel(name, opts = {})
|
72
|
-
config.define_inspector_panel(name, opts)
|
73
|
-
end
|
74
|
-
|
75
|
-
def amend_panel(name, opts = {})
|
76
|
-
config.amend_inspector_panel(name, opts)
|
77
|
-
end
|
78
|
-
|
79
|
-
def remove_panel(name)
|
80
|
-
config.remove_inspector_panel(name)
|
81
|
-
end
|
82
|
-
|
83
61
|
def broadcast(event_name, data = {})
|
84
62
|
Engine.websocket&.broadcast(event_name.to_s, data)
|
85
63
|
end
|
86
64
|
|
87
|
-
|
88
|
-
|
89
|
-
def add_hook(event_name, block)
|
90
|
-
config.hooks[event_name] << block
|
65
|
+
def theme
|
66
|
+
@theme ||= Lookbook::Theme.new(config.ui_theme, config.ui_theme_overrides)
|
91
67
|
end
|
92
68
|
end
|
93
69
|
|
@@ -112,7 +88,7 @@ module Lookbook
|
|
112
88
|
end
|
113
89
|
|
114
90
|
initializer "lookbook.parser.tags" do
|
115
|
-
Lookbook::Parser.define_tags
|
91
|
+
Lookbook::Parser.define_tags(Lookbook.config.preview_tags)
|
116
92
|
end
|
117
93
|
|
118
94
|
initializer "lookbook.assets.serve" do
|
@@ -126,39 +102,20 @@ module Lookbook
|
|
126
102
|
@preview_controller = Lookbook.config.preview_controller.constantize
|
127
103
|
@preview_controller.include(Lookbook::PreviewController)
|
128
104
|
|
129
|
-
if
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
*config.lookbook.listen_paths,
|
134
|
-
only: /\.(#{config.lookbook.listen_extensions.join("|")})$/,
|
135
|
-
force_polling: config.lookbook.listen_use_polling
|
136
|
-
) do |modified, added, removed|
|
137
|
-
changes = { modified: modified, added: added, removed: removed }
|
138
|
-
begin
|
139
|
-
parser.parse
|
140
|
-
rescue
|
141
|
-
end
|
142
|
-
Lookbook::Preview.clear_cache
|
143
|
-
Lookbook::Engine.reload_ui(changes)
|
144
|
-
Lookbook::Engine.run_hooks(:after_change, changes)
|
105
|
+
if Gem::Version.new(Rails.version) >= Gem::Version.new("6.1.3.1")
|
106
|
+
# Rails.application.server is only available for newer Rails versions
|
107
|
+
Rails.application.server do
|
108
|
+
init_listeners
|
145
109
|
end
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
only: /\.(html.*|md.*)$/,
|
151
|
-
force_polling: config.lookbook.listen_use_polling
|
152
|
-
) do |modified, added, removed|
|
153
|
-
changes = { modified: modified, added: added, removed: removed }
|
154
|
-
Lookbook::Engine.reload_ui(changes)
|
155
|
-
Lookbook::Engine.run_hooks(:after_change, changes)
|
110
|
+
else
|
111
|
+
# Fallback for older Rails versions - don't start listeners if running in a rake task.
|
112
|
+
unless File.basename($0) == "rake" || Rake.application.top_level_tasks.any?
|
113
|
+
init_listeners
|
156
114
|
end
|
157
|
-
Lookbook::Engine.register_listener(page_listener)
|
158
115
|
end
|
159
116
|
|
160
117
|
if config.lookbook.runtime_parsing
|
161
|
-
parser.parse
|
118
|
+
Lookbook::Engine.parser.parse
|
162
119
|
else
|
163
120
|
unless File.exist?(config.lookbook.parser_registry_path)
|
164
121
|
Lookbook.logger.warn "
|
@@ -172,8 +129,41 @@ module Lookbook
|
|
172
129
|
Lookbook::Engine.run_hooks(:after_initialize)
|
173
130
|
end
|
174
131
|
|
132
|
+
def init_listeners
|
133
|
+
return unless config.lookbook.listen == true
|
134
|
+
Listen.logger = Lookbook.logger
|
135
|
+
Lookbook.logger.info "Initializing listeners"
|
136
|
+
|
137
|
+
preview_listener = Listen.to(
|
138
|
+
*config.lookbook.listen_paths,
|
139
|
+
only: /\.(#{config.lookbook.listen_extensions.join("|")})$/,
|
140
|
+
force_polling: config.lookbook.listen_use_polling
|
141
|
+
) do |modified, added, removed|
|
142
|
+
changes = { modified: modified, added: added, removed: removed }
|
143
|
+
begin
|
144
|
+
Lookbook::Engine.parser.parse
|
145
|
+
rescue
|
146
|
+
end
|
147
|
+
Lookbook::Preview.clear_cache
|
148
|
+
Lookbook::Engine.reload_ui(changes)
|
149
|
+
Lookbook::Engine.run_hooks(:after_change, changes)
|
150
|
+
end
|
151
|
+
Lookbook::Engine.register_listener(preview_listener)
|
152
|
+
|
153
|
+
page_listener = Listen.to(
|
154
|
+
*config.lookbook.page_paths,
|
155
|
+
only: /\.(html.*|md.*)$/,
|
156
|
+
force_polling: config.lookbook.listen_use_polling
|
157
|
+
) do |modified, added, removed|
|
158
|
+
changes = { modified: modified, added: added, removed: removed }
|
159
|
+
Lookbook::Engine.reload_ui(changes)
|
160
|
+
Lookbook::Engine.run_hooks(:after_change, changes)
|
161
|
+
end
|
162
|
+
Lookbook::Engine.register_listener(page_listener)
|
163
|
+
end
|
164
|
+
|
175
165
|
at_exit do
|
176
|
-
if
|
166
|
+
if Lookbook::Engine.listeners.any?
|
177
167
|
Lookbook.logger.debug "Stopping listeners"
|
178
168
|
Lookbook::Engine.listeners.each { |listener| listener.stop }
|
179
169
|
end
|
@@ -194,9 +184,9 @@ module Lookbook
|
|
194
184
|
@websocket ||= if Rails.version.to_f >= 6.0
|
195
185
|
ActionCable::Server::Base.new(config: cable)
|
196
186
|
else
|
197
|
-
|
198
|
-
|
199
|
-
|
187
|
+
ws = ActionCable::Server::Base.new
|
188
|
+
ws.config = cable
|
189
|
+
ws
|
200
190
|
end
|
201
191
|
end
|
202
192
|
end
|
@@ -231,7 +221,7 @@ module Lookbook
|
|
231
221
|
end
|
232
222
|
|
233
223
|
def run_hooks(event_name, *args)
|
234
|
-
|
224
|
+
config.lookbook.hooks[event_name].each do |hook|
|
235
225
|
hook.call(Lookbook, *args)
|
236
226
|
end
|
237
227
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Lookbook
|
2
|
+
module Hooks
|
3
|
+
def after_initialize(&block)
|
4
|
+
add_hook(:after_initialize, block)
|
5
|
+
end
|
6
|
+
|
7
|
+
def before_exit(&block)
|
8
|
+
add_hook(:before_exit, block)
|
9
|
+
end
|
10
|
+
|
11
|
+
def after_change(&block)
|
12
|
+
add_hook(:after_change, block)
|
13
|
+
end
|
14
|
+
|
15
|
+
protected
|
16
|
+
|
17
|
+
def add_hook(event_name, block)
|
18
|
+
Lookbook.config.hooks[event_name] << block
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Lookbook
|
2
|
+
module Panels
|
3
|
+
def define_panel(name, opts = {})
|
4
|
+
Lookbook.config.define_inspector_panel(name, opts)
|
5
|
+
end
|
6
|
+
|
7
|
+
def amend_panel(name, opts = {})
|
8
|
+
Lookbook.amend_inspector_panel(name, opts)
|
9
|
+
end
|
10
|
+
|
11
|
+
def remove_panel(name)
|
12
|
+
Lookbook.remove_inspector_panel(name)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/lookbook/parser.rb
CHANGED
@@ -24,13 +24,16 @@ module Lookbook
|
|
24
24
|
end
|
25
25
|
|
26
26
|
class << self
|
27
|
-
def define_tags
|
27
|
+
def define_tags(custom = {})
|
28
28
|
YARD::Tags::Library.define_tag("Hidden status", :hidden)
|
29
29
|
YARD::Tags::Library.define_tag("Label", :label)
|
30
30
|
YARD::Tags::Library.define_tag("Display", :display)
|
31
31
|
YARD::Tags::Library.define_tag("Position", :position)
|
32
32
|
YARD::Tags::Library.define_tag("ID", :id)
|
33
33
|
YARD::Tags::Library.define_tag("Component", :component)
|
34
|
+
custom.each do |name, opts|
|
35
|
+
YARD::Tags::Library.define_tag(name.to_s.titleize, name)
|
36
|
+
end
|
34
37
|
end
|
35
38
|
end
|
36
39
|
end
|
data/lib/lookbook/preview.rb
CHANGED
@@ -3,7 +3,7 @@ module Lookbook
|
|
3
3
|
include Utils
|
4
4
|
|
5
5
|
delegate :name, :render_args, to: :@preview
|
6
|
-
delegate :position, :group, :notes, :hidden?, to: :@preview_inspector
|
6
|
+
delegate :position, :group, :notes, :hidden?, :tags, :tag, to: :@preview_inspector
|
7
7
|
|
8
8
|
def initialize(preview)
|
9
9
|
@preview = preview
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Lookbook
|
2
2
|
class PreviewExample < Entity
|
3
3
|
attr_reader :name, :preview
|
4
|
-
delegate :params, :position, :group, :notes, :hidden?, :source, to: :@example_inspector
|
4
|
+
delegate :params, :position, :group, :notes, :hidden?, :source, :tags, :tag, to: :@example_inspector
|
5
5
|
|
6
6
|
def initialize(name, preview)
|
7
7
|
@name = name
|
@@ -49,6 +49,14 @@ module Lookbook
|
|
49
49
|
@preview.hierarchy_depth + 1
|
50
50
|
end
|
51
51
|
|
52
|
+
def tags(name = nil)
|
53
|
+
examples.map { |example| example.tags(name) }.flatten
|
54
|
+
end
|
55
|
+
|
56
|
+
def tag(name = nil)
|
57
|
+
tags(name).first
|
58
|
+
end
|
59
|
+
|
52
60
|
alias_method :lookup_path, :path
|
53
61
|
end
|
54
62
|
end
|
@@ -79,5 +79,14 @@ module Lookbook
|
|
79
79
|
def methods
|
80
80
|
code_object&.meths
|
81
81
|
end
|
82
|
+
|
83
|
+
def tags(name = nil)
|
84
|
+
tag_objects = code_object&.tags(name).presence || []
|
85
|
+
Lookbook::Tags.process_tags(tag_objects)
|
86
|
+
end
|
87
|
+
|
88
|
+
def tag(name = nil)
|
89
|
+
tags(name).first
|
90
|
+
end
|
82
91
|
end
|
83
92
|
end
|
data/lib/lookbook/tag.rb
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
require "shellwords"
|
2
|
+
|
3
|
+
module Lookbook
|
4
|
+
class Tag
|
5
|
+
attr_reader :data, :arg_names
|
6
|
+
attr_accessor :args, :opts
|
7
|
+
|
8
|
+
def initialize(tag_object, arg_names = nil, parser: nil, **options)
|
9
|
+
@tag_object = tag_object
|
10
|
+
@arg_names = arg_names
|
11
|
+
@args = {}
|
12
|
+
@opts = {}
|
13
|
+
@options = options
|
14
|
+
@parser = parser
|
15
|
+
@data = Store.new
|
16
|
+
run_parser
|
17
|
+
end
|
18
|
+
|
19
|
+
def tag_name
|
20
|
+
@name ||= @tag_object.tag_name.to_sym
|
21
|
+
end
|
22
|
+
|
23
|
+
def tag_body
|
24
|
+
@tag_object.text
|
25
|
+
end
|
26
|
+
|
27
|
+
def get_opt(key, fallback = nil)
|
28
|
+
opts[key] || fallback
|
29
|
+
end
|
30
|
+
|
31
|
+
def opts_str
|
32
|
+
@opts_str ||= text_tokens.size > args_count ? text_tokens.slice(args_count, text_tokens.size).join(" ") : ""
|
33
|
+
end
|
34
|
+
|
35
|
+
protected
|
36
|
+
|
37
|
+
def parse_args
|
38
|
+
unless arg_names.nil?
|
39
|
+
values = text_tokens.slice(0, args_count)
|
40
|
+
@args = build_args(values)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def parse_opts
|
45
|
+
return @opts if @options[:parse_options] == false
|
46
|
+
parsed_opts = parse_yaml(opts_str)
|
47
|
+
@opts = parsed_opts.is_a?(Hash) ? parsed_opts.with_indifferent_access : {}
|
48
|
+
end
|
49
|
+
|
50
|
+
def run_parser
|
51
|
+
parse_args
|
52
|
+
parse_opts
|
53
|
+
@parser.call(self) if @parser.respond_to?(:call)
|
54
|
+
end
|
55
|
+
|
56
|
+
def arg_options
|
57
|
+
return [] if arg_names.nil?
|
58
|
+
@arg_options ||= arg_names.map do |arg|
|
59
|
+
unless arg.is_a? Hash
|
60
|
+
name = arg
|
61
|
+
arg = {
|
62
|
+
name: name.to_sym,
|
63
|
+
}
|
64
|
+
end
|
65
|
+
arg[:parse] = false unless arg.key? :parse
|
66
|
+
arg
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def validate_arg_names
|
71
|
+
if arg_names.present?
|
72
|
+
arg_names.each do |name|
|
73
|
+
if methods.include? name.to_sym
|
74
|
+
raise ArgumentError, "'#{name}' is a reserved word and cannot be used as an argument name."
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def args_count
|
81
|
+
arg_options.size
|
82
|
+
end
|
83
|
+
|
84
|
+
def parse_yaml(str, fallback = "~")
|
85
|
+
YAML.safe_load(str || fallback)
|
86
|
+
end
|
87
|
+
|
88
|
+
def text_tokens
|
89
|
+
@tokens ||= Shellwords.split(@tag_object.text)
|
90
|
+
end
|
91
|
+
|
92
|
+
def build_args(values)
|
93
|
+
arg_options.map.with_index do |arg, i|
|
94
|
+
value = values[i]
|
95
|
+
value = parse_arg(value) if arg[:parse] == true && value.present?
|
96
|
+
[arg[:name].to_sym, value]
|
97
|
+
end.to_h
|
98
|
+
end
|
99
|
+
|
100
|
+
def method_missing(name, *method_args)
|
101
|
+
if name.end_with? "="
|
102
|
+
data[name.to_s.chomp("=").to_sym] = method_args.first
|
103
|
+
else
|
104
|
+
data[name] || args[name]
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Lookbook
|
2
|
+
module Tags
|
3
|
+
def define_tag(name, args = nil, opts = {}, &block)
|
4
|
+
name = name.to_s.downcase.underscore.to_sym
|
5
|
+
if args.is_a? Hash
|
6
|
+
opts = args
|
7
|
+
args = nil
|
8
|
+
end
|
9
|
+
opts[:args] = args
|
10
|
+
opts[:parser] = block if block_given?
|
11
|
+
Lookbook.config.preview_tags[name] = opts
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.process_tags(tag_objects)
|
15
|
+
return [] if tag_objects.none?
|
16
|
+
tag_objects.map do |tag_object|
|
17
|
+
opts = Lookbook.config.preview_tags[tag_object.tag_name] || {}
|
18
|
+
Lookbook::Tag.new(tag_object, opts[:args], opts.except(:args))
|
19
|
+
end.compact
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/lookbook/theme.rb
CHANGED
@@ -1,18 +1,47 @@
|
|
1
1
|
module Lookbook
|
2
2
|
class Theme
|
3
|
+
BASE_THEMES = {
|
4
|
+
indigo: {
|
5
|
+
favicon_light_mode: "#4F46E5",
|
6
|
+
favicon_dark_mode: "#818CF8"
|
7
|
+
},
|
8
|
+
zinc: {
|
9
|
+
favicon_light_mode: "#52525b",
|
10
|
+
favicon_dark_mode: "#E4E4E7"
|
11
|
+
},
|
12
|
+
blue: {
|
13
|
+
favicon_light_mode: "#2563EB",
|
14
|
+
favicon_dark_mode: "#60A5FA"
|
15
|
+
}
|
16
|
+
}
|
3
17
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
@config = config
|
18
|
+
def initialize(base_theme, overrides = {})
|
19
|
+
@base_theme = base_theme
|
20
|
+
@overrides = overrides
|
8
21
|
@css = nil
|
9
22
|
end
|
10
23
|
|
24
|
+
def favicon_light_mode
|
25
|
+
(
|
26
|
+
@overrides[:favicon_light_mode].presence ||
|
27
|
+
@overrides[:favicon].presence ||
|
28
|
+
BASE_THEMES[@base_theme.to_sym][:favicon_light_mode]
|
29
|
+
)
|
30
|
+
end
|
31
|
+
|
32
|
+
def favicon_dark_mode
|
33
|
+
(
|
34
|
+
@overrides[:favicon_dark_mode].presence ||
|
35
|
+
@overrides[:favicon].presence ||
|
36
|
+
BASE_THEMES[@base_theme.to_sym][:favicon_dark_mode]
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
11
40
|
def to_css
|
12
41
|
return @css unless @css.nil?
|
13
|
-
@css ||= if @
|
42
|
+
@css ||= if @overrides.present?
|
14
43
|
styles = [":root {"]
|
15
|
-
styles << @
|
44
|
+
styles << @overrides.select { |key| !key.start_with?("favicon") }.map do |key, value|
|
16
45
|
" --lookbook-#{key.to_s.underscore.gsub("_","-")}: #{value};"
|
17
46
|
end
|
18
47
|
styles.push "}"
|
@@ -23,7 +52,7 @@ module Lookbook
|
|
23
52
|
end
|
24
53
|
|
25
54
|
def self.valid_theme?(name)
|
26
|
-
BASE_THEMES.
|
55
|
+
BASE_THEMES.key? name.to_sym
|
27
56
|
end
|
28
57
|
end
|
29
58
|
end
|
data/lib/lookbook/version.rb
CHANGED
data/lib/lookbook.rb
CHANGED
@@ -11,6 +11,7 @@ module Lookbook
|
|
11
11
|
autoload :Lang, "lookbook/lang"
|
12
12
|
autoload :Params, "lookbook/params"
|
13
13
|
autoload :Page, "lookbook/page"
|
14
|
+
autoload :Tag, "lookbook/tag"
|
14
15
|
autoload :PageSection, "lookbook/page_section"
|
15
16
|
autoload :PageCollection, "lookbook/page_collection"
|
16
17
|
autoload :Features, "lookbook/features"
|