lookbook 1.0.0.beta.7 → 1.0.0.beta.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +32 -30
  3. data/app/assets/lookbook/css/themes/blue.css +1 -1
  4. data/app/assets/lookbook/css/themes/indigo.css +1 -1
  5. data/app/assets/lookbook/css/themes/zinc.css +1 -1
  6. data/app/components/lookbook/base_component.rb +0 -1
  7. data/app/components/lookbook/inspector_panel/component.css +5 -0
  8. data/app/components/lookbook/inspector_panel/component.html.erb +6 -4
  9. data/app/components/lookbook/inspector_panel/component.rb +3 -3
  10. data/app/components/lookbook/nav/component.rb +1 -2
  11. data/app/components/lookbook/tab_panels/component.rb +1 -1
  12. data/app/components/lookbook/tab_panels/panel/component.rb +2 -2
  13. data/app/components/lookbook/tag_component.rb +1 -1
  14. data/app/controllers/lookbook/previews_controller.rb +6 -6
  15. data/app/views/lookbook/previews/panels/_notes.html.erb +1 -1
  16. data/app/views/lookbook/previews/show.html.erb +2 -2
  17. data/lib/lookbook/code_formatter.rb +1 -1
  18. data/lib/lookbook/collection.rb +1 -1
  19. data/lib/lookbook/component.rb +2 -3
  20. data/lib/lookbook/config.rb +13 -10
  21. data/lib/lookbook/data.rb +1 -1
  22. data/lib/lookbook/engine.rb +7 -9
  23. data/lib/lookbook/entity.rb +1 -1
  24. data/lib/lookbook/hooks.rb +1 -1
  25. data/lib/lookbook/markdown.rb +1 -1
  26. data/lib/lookbook/page.rb +4 -5
  27. data/lib/lookbook/page_section.rb +2 -4
  28. data/lib/lookbook/panels.rb +1 -1
  29. data/lib/lookbook/preview.rb +8 -10
  30. data/lib/lookbook/store.rb +7 -3
  31. data/lib/lookbook/tag.rb +5 -1
  32. data/lib/lookbook/tags.rb +2 -2
  33. data/lib/lookbook/theme.rb +2 -2
  34. data/lib/lookbook/version.rb +1 -1
  35. data/lib/tasks/lookbook_tasks.rake +1 -2
  36. data/public/lookbook-assets/css/lookbook.css +5 -0
  37. data/public/lookbook-assets/css/lookbook.css.map +1 -1
  38. data/public/lookbook-assets/css/themes/blue.css.map +1 -1
  39. data/public/lookbook-assets/css/themes/indigo.css.map +1 -1
  40. data/public/lookbook-assets/css/themes/zinc.css.map +1 -1
  41. data/public/lookbook-assets/js/lookbook.js +41 -41
  42. data/public/lookbook-assets/js/lookbook.js.map +1 -1
  43. metadata +3 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 52925967015a9d02a18dfcde3e185d7d1dcd1917ea03fdf63276743b3ce18e66
4
- data.tar.gz: a8523484936828701e3775603996c8477bb14830ad2b18b5ca5ef1bc55d58117
3
+ metadata.gz: d6db7e9d13ee8598e93dd86dfb32db3e0794ae33934075286203e74428df3a92
4
+ data.tar.gz: ceb9b3c0050b40c8370a04d30a26b79afecdfc3b9b434346537d695de4731a77
5
5
  SHA512:
6
- metadata.gz: 104d5b01cc83a5bd4440e64e7da9a551e46b5f583e2a1209bc391bb75facf1c2633453a3b9d15f1a9e351269aa07b5d6e83783768301570346e111076c9511bf
7
- data.tar.gz: 5b86248682b5105de0a56ba9e3832cfa243ed8307ac2215d1331ed7915386728db479ada8d8c9ab05a0fa0e00e98ed338416827ca7bfe613533e4c41795f2301
6
+ metadata.gz: 5e424de07347103593d71cc389daa097cfa159949f6c6352d1e3b76e7a3f32709551dd25a4fd51ad7499c79bd3228a689affecfe06c0d4bcf74d2f070f62041d
7
+ data.tar.gz: 7a3680ad7c88cd5d5b15f761311ccb28e3f5f2a57e36a4a67b3b015aecea0ea6ee182babbf9b8bc7daa27c0350e201f0096731b59b656138e13fd694c388414d
data/README.md CHANGED
@@ -1,53 +1,55 @@
1
- # Lookbook v1.0 [beta]
1
+ # Lookbook v1.0
2
2
 
3
- **This is the development branch for Lookbook v1.0.**
3
+ > **This is the Lookbook v1.0 BETA development branch.**<br>
4
+ >_For code and documentation for the current stable release see the [main branch](https://github.com/allmarkedup/lookbook/tree/main)._
4
5
 
5
- _For code and documentation for the current stable release see the [main branch](https://github.com/allmarkedup/lookbook/tree/main)._
6
6
 
7
- ---
7
+ ## Get started
8
8
 
9
- 📣 **This v1.0 beta is still under active development.** However no breaking changes are envisaged to the current implementation and it should now be stable enough to be used for day-to-day development. Give it a try! 🎉
9
+ If you are already using Lookbook in your project, just update the Lookbook gem to the latest beta release and then head over to the [beta documentation site](https://beta.lookbook.build/) to read more about the new features.
10
10
 
11
- ---
12
-
13
- ## 📚 Documentation
11
+ ```ruby
12
+ gem "lookbook", ">= 1.0.0.beta.7"
13
+ ```
14
14
 
15
- The new (work-in-progress) **documentation site** for Lookbook v1.0 is available here:
15
+ If you are **new to Lookbook** then check out the <a href="https://beta.lookbook.build/guide/quick-start/">v1.0 quick start guide</a> for more detailed instructions on installing Lookbook in your project
16
16
 
17
- 👉 **https://beta.lookbook.build/** 👈
18
17
 
19
- > Documentation source files are located in the `/docs` directory within this repository. The docs are built using [Bridgetown](https://www.bridgetownrb.com/).
18
+ <h4>Useful Resources</h4>
20
19
 
21
- ## 🚀 Demo app
20
+ * 👉 <a href="https://beta.lookbook.build/">v1.0 docs</a>
21
+ * 👉 <a href="https://lookbook-demo-app-v1-0-beta.herokuapp.com/lookbook">v1.0 demo app</a> <em>(The repo for the demo <a href="https://github.com/allmarkedup/lookbook-demo/tree/v1.0-beta">is here</a> if you want to dig in further)</em>
22
22
 
23
- There is a demo of the latest v1.0 beta here:
24
23
 
25
- 👉 **https://lookbook-demo-app-v1-0-beta.herokuapp.com/lookbook/** 👈
26
24
 
27
- [![Lookbook UI](.github/assets/lookbook_screenshot_v1.0_beta.png)](https://lookbook-demo-app-v1-0-beta.herokuapp.com/lookbook/)
25
+ ## Changes and new features in v1.0
28
26
 
27
+ Lookbook v1.0 includes a completely re-written UI, many under-the hood improvements and a some exciting new customisation options.
29
28
 
30
- ## 🔎 Release focus
29
+ ### Frontend changes:
31
30
 
32
- The main goals of the v1.0 release are:
31
+ * Completely re-written UI - now built with ViewComponents
32
+ * New [UI themes and customisation options](https://beta.lookbook.build/guide/themes/)
33
+ * Improved small-screen/mobile view
34
+ * Debug menu
35
+ * ...and many other small visual and usability improvements
33
36
 
34
- - [x] Rebuild app UI using ViewComponent components
35
- - [x] Improve usability of the small screen/mobile layout
36
- - [x] Add support for basic UI color theme customisation
37
- - [x] Allow users to extend Lookbook with custom panels and by hooking into lifecycle events
38
- - [x] Remove the `experimental` flag from the [Pages](https://github.com/allmarkedup/lookbook#pages)
39
- - [x] Improve the development/debugging setup
40
- - [ ] Improve the test setup and test coverage, switch to RSpec **[in progress]**
37
+ ### New options for extending Lookbook:
41
38
 
42
- **No breaking changes** are planned for user-facing features, although the app UI will include some minor visual updates and usability improvements.
39
+ * Define [custom tags](https://beta.lookbook.build/guide/extend/tags/) for preview file annotations
40
+ * Create [your own tab panels](https://beta.lookbook.build/guide/extend/panels/) - with complete control over content/layout and access to all Lookbook data
41
+ * Use [lifecycle hooks](https://beta.lookbook.build/guide/extend/hooks/) to run your own code when Lookbook starts up, when files change or at shutdown
43
42
 
44
- ## 👋 Testing and feedback - help wanted!
43
+ ### Other changes
45
44
 
46
- The bulk of the v1.0 'new feature' development work is now mostly complete, although testing and bug fixing is ongoing.
45
+ * 'Workbench' app for developing Lookbook's UI components in Lookbook
46
+ * New Rspec-based test suite and dummy app
47
+ * All new documentation site built using [Bridgetown](https://www.bridgetownrb.com/)
47
48
 
48
- **If you are an existing Lookbook user** I'd greatly appreciate if you can kick the tyres on the v1.0 beta and open an issue with any bug reports, suggestions or feedback you might have, either about Lookbook itself or the [new docs site](https://lookbook-docs-v1-beta.netlify.app/).
49
49
 
50
- ## 🛠 Workbench
50
+ [![Lookbook UI](.github/assets/lookbook_screenshot_v1.0_beta.png)](https://lookbook-demo-app-v1-0-beta.herokuapp.com/lookbook/)
51
+
52
+ ## Workbench
51
53
 
52
54
  As of this release, Lookbook's UI is itself built using ViewComponent components. To help with development it is possible to preview these components (in a Lookbook instance!) by running the included 'Workbench" app, as follows:
53
55
 
@@ -59,7 +61,7 @@ As of this release, Lookbook's UI is itself built using ViewComponent components
59
61
  This will start the Workbench app in development mode and any changes to Lookbooks views or assets will immediately be visible in the UI.
60
62
 
61
63
 
62
- ## 🚦 Running tests
64
+ ## Running tests
63
65
 
64
66
  The test suite is in the process of being completely overhauled.
65
67
 
@@ -60,4 +60,4 @@
60
60
  --lookbook-header-border: var(--lookbook-accent-700);
61
61
  --lookbook-branding-text: var(--lookbook-header-text);
62
62
  --lookbook-draggable-hint: rgb(224 231 255 / 0.2);
63
- }
63
+ }
@@ -60,4 +60,4 @@
60
60
  --lookbook-header-border: var(--lookbook-accent-700);
61
61
  --lookbook-branding-text: var(--lookbook-header-text);
62
62
  --lookbook-draggable-hint: rgb(224 231 255 / 0.2);
63
- }
63
+ }
@@ -60,4 +60,4 @@
60
60
  --lookbook-header-border: var(--lookbook-accent-700);
61
61
  --lookbook-branding-text: var(--lookbook-header-text);
62
62
  --lookbook-draggable-hint: rgb(224 231 255 / 0.2);
63
- }
63
+ }
@@ -12,7 +12,6 @@ module Lookbook
12
12
  merged_classes = class_names(attrs[:class], @html_attrs[:class])
13
13
  merged_attrs = @html_attrs.except(:class).deep_merge(attrs.except(:class))
14
14
 
15
-
16
15
  render Lookbook::TagComponent.new(tag: tag,
17
16
  name: component_name,
18
17
  **merged_attrs,
@@ -0,0 +1,5 @@
1
+ @layer components {
2
+ .lookbook-panel {
3
+ @apply p-4 min-h-full;
4
+ }
5
+ }
@@ -1,4 +1,6 @@
1
- <% if panel_styles %>
2
- <% content_for :panel_css do %><%= panel_styles %><% end %>
3
- <% end %>
4
- <%= panel_html %>
1
+ <%= render_component_tag :div, class: "h-full" do %>
2
+ <% if panel_styles %>
3
+ <% content_for :panel_css do %><%= panel_styles %><% end %>
4
+ <% end %>
5
+ <%= panel_html %>
6
+ <% end %>
@@ -15,8 +15,8 @@ module Lookbook
15
15
 
16
16
  def before_render
17
17
  if @system == false
18
- panel_dom = ::Nokogiri::HTML::fragment(content)
19
- style_tags = panel_dom.css('style')
18
+ panel_dom = ::Nokogiri::HTML.fragment(content)
19
+ style_tags = panel_dom.css("style")
20
20
  if style_tags.any?
21
21
  css_parser = ::CssParser::Parser.new
22
22
  @panel_styles = ""
@@ -27,7 +27,7 @@ module Lookbook
27
27
  end
28
28
  style_tag.unlink
29
29
  end
30
- @panel_html = panel_dom.to_html.html_safe
30
+ @panel_html = panel_dom.to_html.html_safe
31
31
  end
32
32
  end
33
33
  @panel_html ||= content
@@ -4,8 +4,7 @@ module Lookbook
4
4
  renders_one :toolbar, Lookbook::Toolbar::Component
5
5
 
6
6
  def initialize(
7
- id: nil,
8
- collection:,
7
+ collection:, id: nil,
9
8
  collapse_singles: false,
10
9
  **attrs
11
10
  )
@@ -3,7 +3,7 @@ module Lookbook
3
3
  renders_many :panels, ->(**attrs) do
4
4
  @panel_counter += 1
5
5
  attrs[:name] ||= "tab-#{@panel_counter}"
6
- Lookbook::TabPanels::Panel::Component.new **attrs
6
+ Lookbook::TabPanels::Panel::Component.new(**attrs)
7
7
  end
8
8
 
9
9
  def initialize(**html_attrs)
@@ -1,8 +1,8 @@
1
1
  module Lookbook
2
2
  class TabPanels::Panel::Component < Lookbook::BaseComponent
3
3
  def initialize(name:, id: nil, **html_attrs)
4
- @name = name
5
- @id = "#{id || "panel-#{name}"}"
4
+ @name = name
5
+ @id = (id || "panel-#{name}").to_s
6
6
  super(**html_attrs)
7
7
  end
8
8
  end
@@ -18,7 +18,7 @@ module Lookbook
18
18
  end
19
19
 
20
20
  def self.escape_attribute_key
21
- @escape_attribute_key ||= Gem::Version.new(Rails.version) < Gem::Version.new('6.1.5.1') ? :escape_attributes : :escape
21
+ @escape_attribute_key ||= Gem::Version.new(Rails.version) < Gem::Version.new("6.1.5.1") ? :escape_attributes : :escape
22
22
  end
23
23
  end
24
24
  end
@@ -130,7 +130,7 @@ module Lookbook
130
130
 
131
131
  context_data = {
132
132
  preview_params: preview_params,
133
- path: params[:path],
133
+ path: params[:path]
134
134
  }
135
135
 
136
136
  example = @example
@@ -145,7 +145,7 @@ module Lookbook
145
145
  output = preview_controller.process(:render_example_to_string, @preview, example.name)
146
146
  source = has_template ? example.template_source(render_args[:template]) : example.method_source
147
147
  source_lang = has_template ? example.template_lang(render_args[:template]) : example.lang
148
-
148
+
149
149
  example.define_singleton_method(:output, proc { output })
150
150
  example.define_singleton_method(:source, proc { source })
151
151
  example.define_singleton_method(:source_lang, proc { source_lang })
@@ -170,21 +170,21 @@ module Lookbook
170
170
 
171
171
  callable_data = {
172
172
  name: name.to_s,
173
- index_position: (@panels.select { |p| p.pane == config.pane }.size + 1),
173
+ index_position: (@panels.count { |p| p.pane == config.pane } + 1),
174
174
  **inspector_data
175
175
  }
176
176
 
177
177
  resolved_config = config_with_defaults.transform_values do |value|
178
- value.class == Proc ? value.call(Lookbook::Store.new(callable_data)) : value
178
+ value.instance_of?(Proc) ? value.call(Lookbook::Store.new(callable_data)) : value
179
179
  end
180
180
  resolved_config[:name] = name.to_s
181
-
181
+
182
182
  @panels << Lookbook::Store.new(resolved_config, deep: false)
183
183
  end
184
184
 
185
185
  @panels = @panels.select(&:show).sort_by { |p| [p.position, p.label] }
186
186
  end
187
-
187
+
188
188
  def main_panels
189
189
  panels.select { |panel| panel.pane == :main }
190
190
  end
@@ -11,7 +11,7 @@
11
11
  <% end %>
12
12
  </div>
13
13
  <% else %>
14
- <div class="p-4 bg-lookbook-prose-bg w-full h-full">
14
+ <div class="px-4 py-6 bg-lookbook-prose-bg w-full h-full">
15
15
  <%= render_component :prose do %>
16
16
  <%== items.any? ? items.first.notes : "<em class='opacity-50'>No notes provided.</em>" %>
17
17
  <% end %>
@@ -55,7 +55,7 @@
55
55
  <div class="h-full relative overflow-auto">
56
56
  <%= render_component :tab_panels, alpine_data: "$store.inspector.main" do |tabs| %>
57
57
  <% @main_panels.each do |panel| %>
58
- <% tabs.panel id: panel.id, name: panel.name, class: [panel.panel_classes, { "p-4": panel.padded, "prose": panel.prose }] do %>
58
+ <% tabs.panel id: panel.id, name: panel.name, class: panel.panel_classes do %>
59
59
  <%= render panel.partial, **@inspector_data, panel: panel, **panel.locals %>
60
60
  <% end %>
61
61
  <% end %>
@@ -123,7 +123,7 @@
123
123
  <div class="h-full overflow-auto">
124
124
  <%= render_component :tab_panels, alpine_data: "$store.inspector.drawer" do |tabs| %>
125
125
  <% @drawer_panels.each do |panel| %>
126
- <% tabs.panel id: panel.id, name: panel.name, class: [panel.panel_classes, { "p-4": panel.padded, "prose": panel.prose }] do %>
126
+ <% tabs.panel id: panel.id, name: panel.name, class: panel.panel_classes do %>
127
127
  <%= render_component :inspector_panel, **panel.slice(:id, :name, :system) do %>
128
128
  <%= render panel.partial, **@inspector_data, panel: panel, **panel.locals %>
129
129
  <% end %>
@@ -1,6 +1,6 @@
1
1
  require "rouge"
2
2
  require "htmlbeautifier"
3
- require 'htmlentities'
3
+ require "htmlentities"
4
4
 
5
5
  module Lookbook
6
6
  module CodeFormatter
@@ -10,7 +10,7 @@ module Lookbook
10
10
  items = path
11
11
  path = ""
12
12
  end
13
-
13
+
14
14
  @path = path.delete_prefix("/").delete_suffix("/")
15
15
  super(@path)
16
16
 
@@ -1,13 +1,12 @@
1
1
  module Lookbook
2
2
  class Component < Entity
3
-
4
3
  attr_accessor :name
5
4
 
6
5
  def initialize(name)
7
6
  @name = name
8
7
  super(path)
9
8
  end
10
-
9
+
11
10
  def path
12
11
  name.underscore
13
12
  end
@@ -28,4 +27,4 @@ module Lookbook
28
27
  template_path.present?
29
28
  end
30
29
  end
31
- end
30
+ end
@@ -6,14 +6,14 @@ module Lookbook
6
6
  class Config
7
7
  def initialize
8
8
  @options = Store.new
9
-
9
+
10
10
  @options.set({
11
11
  project_name: "Lookbook",
12
12
  log_level: 2,
13
13
  auto_refresh: true,
14
14
 
15
15
  components_path: "app/components",
16
-
16
+
17
17
  page_controller: "Lookbook::PageController",
18
18
  page_route: "pages",
19
19
  page_paths: ["test/components/docs"],
@@ -44,7 +44,7 @@ module Lookbook
44
44
  hooks: {
45
45
  after_initialize: [],
46
46
  before_exit: [],
47
- after_change: [],
47
+ after_change: []
48
48
  },
49
49
 
50
50
  debug_menu: Rails.env.development?,
@@ -100,7 +100,7 @@ module Lookbook
100
100
  padded: false,
101
101
  system: true
102
102
  }
103
- },
103
+ }
104
104
  })
105
105
  end
106
106
 
@@ -147,7 +147,7 @@ module Lookbook
147
147
 
148
148
  def inspector_panels(&block)
149
149
  panels = Store.new(@options.inspector_panels.select { |key, panel| panel != false })
150
- if block_given?
150
+ if block
151
151
  yield panels
152
152
  else
153
153
  panels
@@ -158,7 +158,7 @@ module Lookbook
158
158
  pane = opts[:pane].presence || :drawer
159
159
  siblings = inspector_panels.select { |key, panel| panel.pane == pane }
160
160
  opts[:position] ||= siblings.size + 1
161
- @options.inspector_panels[name] = opts
161
+ @options.inspector_panels[name] = opts
162
162
  siblings.each do |key, panel|
163
163
  if panel.position >= opts[:position]
164
164
  panel.position += 1
@@ -192,7 +192,6 @@ module Lookbook
192
192
  copy: nil,
193
193
  panel_classes: nil,
194
194
  locals: {},
195
- padded: true,
196
195
  system: false
197
196
  }
198
197
  end
@@ -207,7 +206,7 @@ module Lookbook
207
206
  end
208
207
 
209
208
  def ui_theme_overrides(&block)
210
- if block_given?
209
+ if block
211
210
  yield @options.ui_theme_overrides
212
211
  else
213
212
  @options.ui_theme_overrides
@@ -238,7 +237,7 @@ module Lookbook
238
237
  def to_json(*a)
239
238
  to_h.to_json(*a)
240
239
  end
241
-
240
+
242
241
  protected
243
242
 
244
243
  def normalize_paths(paths)
@@ -256,5 +255,9 @@ module Lookbook
256
255
  def method_missing(name, *args)
257
256
  @options.send(name, *args)
258
257
  end
258
+
259
+ def respond_to_missing?(name, *)
260
+ to_h.key? name
261
+ end
259
262
  end
260
- end
263
+ end
data/lib/lookbook/data.rb CHANGED
@@ -8,4 +8,4 @@ module Lookbook
8
8
  @data = Store.new(props)
9
9
  end
10
10
  end
11
- end
11
+ end
@@ -5,7 +5,6 @@ require "listen"
5
5
  require "rake"
6
6
 
7
7
  module Lookbook
8
-
9
8
  autoload :Config, "lookbook/config"
10
9
  autoload :Data, "lookbook/data"
11
10
  autoload :Hooks, "lookbook/hooks"
@@ -73,14 +72,14 @@ module Lookbook
73
72
  config.lookbook = Lookbook.config
74
73
  config.autoload_paths << File.expand_path(Lookbook::Engine.root.join("app/components"))
75
74
 
76
- initializer "lookbook.viewcomponent.config" do
75
+ initializer "lookbook.viewcomponent.config" do
77
76
  config.lookbook.preview_paths += config.view_component.preview_paths
78
77
  config.lookbook.preview_controller ||= config.view_component.preview_controller
79
78
 
80
79
  config.lookbook.components_path = config.view_component.view_component_path if config.view_component.view_component_path.present?
81
80
 
82
81
  config.lookbook.listen_paths += config.lookbook.preview_paths
83
- config.lookbook.listen_paths << config.lookbook.components_path
82
+ config.lookbook.listen_paths << config.lookbook.components_path
84
83
  end
85
84
 
86
85
  initializer "lookbook.logging.development" do
@@ -110,7 +109,7 @@ module Lookbook
110
109
  else
111
110
  # Fallback for older Rails versions - don't start listeners if running in a rake task.
112
111
  unless File.basename($0) == "rake" || Rake.application.top_level_tasks.any?
113
- init_listeners
112
+ init_listeners
114
113
  end
115
114
  end
116
115
 
@@ -133,13 +132,13 @@ module Lookbook
133
132
  return unless config.lookbook.listen == true
134
133
  Listen.logger = Lookbook.logger
135
134
  Lookbook.logger.info "Initializing listeners"
136
-
135
+
137
136
  preview_listener = Listen.to(
138
137
  *config.lookbook.listen_paths,
139
138
  only: /\.(#{config.lookbook.listen_extensions.join("|")})$/,
140
139
  force_polling: config.lookbook.listen_use_polling
141
140
  ) do |modified, added, removed|
142
- changes = { modified: modified, added: added, removed: removed }
141
+ changes = {modified: modified, added: added, removed: removed}
143
142
  begin
144
143
  Lookbook::Engine.parser.parse
145
144
  rescue
@@ -155,7 +154,7 @@ module Lookbook
155
154
  only: /\.(html.*|md.*)$/,
156
155
  force_polling: config.lookbook.listen_use_polling
157
156
  ) do |modified, added, removed|
158
- changes = { modified: modified, added: added, removed: removed }
157
+ changes = {modified: modified, added: added, removed: removed}
159
158
  Lookbook::Engine.reload_ui(changes)
160
159
  Lookbook::Engine.run_hooks(:after_change, changes)
161
160
  end
@@ -165,13 +164,12 @@ module Lookbook
165
164
  at_exit do
166
165
  if Lookbook::Engine.listeners.any?
167
166
  Lookbook.logger.debug "Stopping listeners"
168
- Lookbook::Engine.listeners.each { |listener| listener.stop }
167
+ Lookbook::Engine.listeners.each { |listener| listener.stop }
169
168
  end
170
169
  Lookbook::Engine.run_hooks(:before_exit)
171
170
  end
172
171
 
173
172
  class << self
174
-
175
173
  def websocket
176
174
  return @websocket unless @websocket.nil?
177
175
  if config.lookbook.auto_refresh
@@ -44,4 +44,4 @@ module Lookbook
44
44
 
45
45
  alias_method :url_path, :lookup_path
46
46
  end
47
- end
47
+ end
@@ -18,4 +18,4 @@ module Lookbook
18
18
  Lookbook.config.hooks[event_name] << block
19
19
  end
20
20
  end
21
- end
21
+ end
@@ -13,7 +13,7 @@ module Lookbook
13
13
  }
14
14
 
15
15
  def self.render(text)
16
- text&.gsub!(/\<\!\-\- (BEGIN|END) (.*) \-\-\>/, "")
16
+ text&.gsub!(/<!-- (BEGIN|END) (.*) -->/, "")
17
17
  markdown = Redcarpet::Markdown.new(Renderer, Lookbook.config.markdown_options)
18
18
  markdown.render(text).html_safe
19
19
  end
data/lib/lookbook/page.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  module Lookbook
2
2
  class Page < Entity
3
-
4
3
  FRONTMATTER_FIELDS = [
5
4
  :id,
6
5
  :label,
@@ -76,7 +75,7 @@ module Lookbook
76
75
  def type
77
76
  :page
78
77
  end
79
-
78
+
80
79
  def id
81
80
  options[:id]
82
81
  end
@@ -125,7 +124,7 @@ module Lookbook
125
124
  }))
126
125
  end
127
126
  @options = Lookbook.config.page_options.deep_merge(frontmatter).with_indifferent_access
128
- @options[:id] = @options[:id] ? generate_id(@options[:id]) : generate_id(lookup_path)
127
+ @options[:id] = generate_id(@options[:id] || lookup_path)
129
128
  @options[:label] ||= name.titleize
130
129
  @options[:title] ||= @options[:label]
131
130
  @options[:hidden] ||= false
@@ -159,7 +158,7 @@ module Lookbook
159
158
  end
160
159
 
161
160
  def all
162
- pages, sections =
161
+ pages, sections =
163
162
  Array(page_paths).flat_map do |dir|
164
163
  Dir["#{dir}/**/*.html.*", "#{dir}/**/*.md.*"].sort.map do |path|
165
164
  create(path, dir)
@@ -172,7 +171,7 @@ module Lookbook
172
171
 
173
172
  page_dict = sorted_pages.index_by(&:path)
174
173
  sorted_sections = sections.sort_by { |section| [section.position, section.label] }
175
-
174
+
176
175
  sorted_sections.each do |section|
177
176
  page_dict[section.path].sections << section
178
177
  end
@@ -1,6 +1,5 @@
1
1
  module Lookbook
2
2
  class PageSection < Page
3
-
4
3
  def name
5
4
  return @name if @name.present?
6
5
  matches = full_path.to_s.match(%r{\[(?<name>\w+)\]})
@@ -24,8 +23,7 @@ module Lookbook
24
23
  end
25
24
 
26
25
  def lookup_path
27
- "#{super}/#{name}"
26
+ "#{super}/#{name}"
28
27
  end
29
-
30
28
  end
31
- end
29
+ end
@@ -12,4 +12,4 @@ module Lookbook
12
12
  Lookbook.remove_inspector_panel(name)
13
13
  end
14
14
  end
15
- end
15
+ end
@@ -97,7 +97,7 @@ module Lookbook
97
97
  end
98
98
 
99
99
  def components
100
- component_classes = @preview_inspector&.components.any? ? @preview_inspector&.components : [guess_component]
100
+ component_classes = @preview_inspector&.components&.any? ? @preview_inspector&.components : [guess_component]
101
101
  component_classes.map do |class_name|
102
102
  Component.new(class_name.to_s)
103
103
  end
@@ -106,11 +106,9 @@ module Lookbook
106
106
  protected
107
107
 
108
108
  def guess_component
109
- begin
110
- name.chomp("Preview").constantize
111
- rescue
112
- nil
113
- end
109
+ name.chomp("Preview").constantize
110
+ rescue
111
+ nil
114
112
  end
115
113
 
116
114
  class << self
@@ -156,7 +154,7 @@ module Lookbook
156
154
 
157
155
  def clear_cache
158
156
  cache_dir = File.dirname(cache_marker_path)
159
- FileUtils.mkdir_p(cache_dir) unless File.exists?(cache_dir)
157
+ FileUtils.mkdir_p(cache_dir) unless File.exist?(cache_dir)
160
158
  File.write(cache_marker_path, Time.now.to_i)
161
159
  end
162
160
 
@@ -167,7 +165,7 @@ module Lookbook
167
165
  end
168
166
 
169
167
  def cache_stale?
170
- return false if !File.exists?(cache_marker_path)
168
+ return false if !File.exist?(cache_marker_path)
171
169
  cache_timestamp = File.read(cache_marker_path).to_i
172
170
  if @last_cache_timestamp.nil? || cache_timestamp > @last_cache_timestamp
173
171
  @last_cache_timestamp = cache_timestamp
@@ -179,7 +177,7 @@ module Lookbook
179
177
 
180
178
  def mark_as_cached
181
179
  cache_dir = File.dirname(cache_marker_path)
182
- FileUtils.mkdir_p(cache_dir) unless File.exists?(cache_dir)
180
+ FileUtils.mkdir_p(cache_dir) unless File.exist?(cache_dir)
183
181
  File.write(cache_marker_path, Time.now)
184
182
  end
185
183
 
@@ -196,7 +194,7 @@ module Lookbook
196
194
  )
197
195
  end
198
196
  end
199
-
197
+
200
198
  def preview_files
201
199
  files = Array(Lookbook.config.preview_paths).map do |preview_path|
202
200
  Dir["#{preview_path}/**/*preview.rb"].map do |path|