lookbook 0.7.4 → 0.8.0.beta.0

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: 96f31c2b265d871a152627dfb10b0c0e1f6db8ae42e811abfeb138c7bf45d806
4
- data.tar.gz: 9ae695f9a3fc7c28bd5a7fbf77fc0959d92d46661525e7593961555cd41d76fb
3
+ metadata.gz: aa9a6048a7c6da30fcf5fe7c42a0a41365c3964da88d1d639a640c1acdd97a95
4
+ data.tar.gz: dbbf4e04289ccadde4f37453123aabc70d982104b6933b3e139b0c65ea2a68f4
5
5
  SHA512:
6
- metadata.gz: 8b658dc2f0e2b7213761be9197f916594381319927f02097c3901af13d9c35194e45d568d70a21c3da05407ea79e589ffa1c3530905c73dc5cbfa1100cc2ac3f
7
- data.tar.gz: 55bc108c5a1ee957970709efe01c75956ee7b925043bab7b5c6aba1bafa1f998191d7872a7e08ddbd85daad2d7713437ec9340c8f2273568ecffa17bbb78a738
6
+ metadata.gz: a9eea08255c6263b84d6212d88d4a08ac425377eb1b0f42e4c5e626e04e1281e711c3ba41df98b550e3777b4e292824884ecd5e05b733db97126ccb6ba4cd100
7
+ data.tar.gz: 8b48c299198427e2e957eb6c3dcccf6ae1544a921ef5ae4ba37fad558dd0274a1f864e9b8a37fb5b76a49c275f74f5a73e3363a8c6c4d4092a380639b99798e8
data/README.md CHANGED
@@ -13,7 +13,7 @@
13
13
  ---
14
14
 
15
15
  <div align="center">
16
- <a href="#installing">Installing</a> • <a href="#previews">Previews</a> • <a href="#pages">Pages</a> • <a href="#config">Configuration</a>
16
+ <a href="#installing">Installing</a> • <a href="#previews">Previews</a> • <a href="#pages">Pages</a> • <a href="#deployment">Deployment</a> • <a href="#config">Config</a>
17
17
  </div>
18
18
 
19
19
  ---
@@ -72,13 +72,6 @@ The `at` property determines the root URL that the Lookbook UI will be served at
72
72
 
73
73
  Then you can start your app as normal and navigate to `http://localhost:3000/lookbook` (or whatever mount path you specified) to view your component previews in the Lookbook UI.
74
74
 
75
- #### Mounting in Production
76
-
77
- If you would like to expose the Lookbook UI in production as well as in development
78
-
79
- 1. Remove the `if Rails.env.development?` condition from around the mount statement in `routes.rb`
80
- 2. Add `config.view_component.show_previews = true` to `config/environments/production.rb`
81
-
82
75
 
83
76
  <h2 id="previews">Previews</h2>
84
77
 
@@ -687,6 +680,73 @@ Default: `pages`
687
680
  config.lookbook.page_route = `docs`
688
681
  ```
689
682
 
683
+ <h2 id="deployment">Deploying in Production</h2>
684
+
685
+ Lookbook is intended to be a tool for aiding the ViewComponent development process, and so is usually restricted to running only when the app is in `development` mode.
686
+
687
+ However, it is possible to run Lookbook in a production environment if you wish.
688
+
689
+ ### Differences between development and production
690
+
691
+ By default, Lookbook will behave a little differently in production than it does in development:
692
+
693
+ 1. Watching files for changes is disabled
694
+ 2. Parsing preview files for annotations does **not** happen at runtime. Instead the preview files must be pre-parsed via a Rake task before starting the app (much like asset precompilation).
695
+
696
+ ### Pre-parsing preview files
697
+
698
+ Run the following command to pre-parse the preview files annotations:
699
+
700
+ ```
701
+ rake lookbook:previews:preparse
702
+ ```
703
+
704
+ If you wish to run this as part of your existing assets precompilation step, you can add the following into your app's `Rakefile`:
705
+
706
+ ```ruby
707
+ Rake::Task['assets:precompile'].enhance do
708
+ Rake::Task["lookbook:previews:preparse"].invoke
709
+ end
710
+ ```
711
+
712
+ The pre-parsing of preview files will then take place every time `rake assets:precompile` is called and so will not need to be run separately.
713
+
714
+ ### Configuration changes for production
715
+
716
+ You will also need to make sure that the following configuration changes have been made when deploying to production:
717
+
718
+ 1. Make sure ViewComponent is [configured to show previews in production](https://viewcomponent.org/api.html#show_previews) (by default it is disabled when not in development):
719
+
720
+ ```ruby
721
+ # config/environments/production.rb
722
+ config.view_component.show_previews = true
723
+ ```
724
+
725
+ 2. Remove any environment checking from around the Lookbook mounting declaration (if added as per install instructions):
726
+
727
+ ```ruby
728
+ # config/routes.rb
729
+ Rails.application.routes.draw do
730
+ # if Rails.env.development? <- remove
731
+ mount Lookbook::Engine, at: "/lookbook"
732
+ # end
733
+ end
734
+ ```
735
+
736
+ ### Overriding production default behaviours
737
+
738
+ If for some reason you wish to enable file watching or runtime preview annotation parsing in production, you can always override the default behaviour using thie following config options:
739
+
740
+ ```ruby
741
+ # config/environments/production.rb
742
+
743
+ # enable file-change listening
744
+ config.lookbook.listen = true
745
+
746
+ # enable runtime preview parsing
747
+ config.lookbook.runtime_parsing = true
748
+ ```
749
+
690
750
  <h2 id="config">General Configuration</h2>
691
751
 
692
752
  Lookbook will use the ViewComponent [configuration](https://viewcomponent.org/api.html#configuration) for your project to find and render your previews so you generally you won't need to configure much else separately.
@@ -145,7 +145,6 @@ module Lookbook
145
145
  def preview_controller
146
146
  return @preview_controller if @preview_controller.present?
147
147
  controller_class = Lookbook.config.preview_controller.constantize
148
- controller_class.class_eval { include Lookbook::PreviewController }
149
148
  controller = controller_class.new
150
149
  controller.request = request
151
150
  controller.response = response
@@ -49,6 +49,7 @@ module Lookbook
49
49
  options.preview_srcdoc = false if options.preview_srcdoc.nil?
50
50
  options.preview_display_params ||= {}.with_indifferent_access
51
51
 
52
+ options.listen = Rails.env.development? if options.listen.nil?
52
53
  options.listen_paths = options.listen_paths.map(&:to_s)
53
54
  options.listen_paths += options.preview_paths
54
55
  options.listen_paths << (vc_options.view_component_path || Rails.root.join("app/components"))
@@ -57,6 +58,9 @@ module Lookbook
57
58
  options.cable_mount_path ||= "/lookbook-cable"
58
59
  options.cable_logger ||= Rails.logger
59
60
 
61
+ options.runtime_parsing = !Rails.env.production? if options.runtime_parsing.nil?
62
+ options.parser_registry_path ||= Rails.root.join("tmp/storage/.yardoc")
63
+
60
64
  options.experimental_features = false unless options.experimental_features.present?
61
65
  end
62
66
 
@@ -72,32 +76,47 @@ module Lookbook
72
76
  end
73
77
 
74
78
  config.after_initialize do
75
- @preview_listener = Listen.to(*config.lookbook.listen_paths, only: /\.(rb|html.*)$/) do |modified, added, removed|
76
- begin
77
- parser.parse
78
- rescue
79
- end
80
- Lookbook::Preview.clear_cache
81
- Lookbook::Engine.websocket&.broadcast("reload", {
82
- modified: modified,
83
- removed: removed,
84
- added: added
85
- })
86
- end
87
- @preview_listener.start
88
-
89
- if Lookbook::Features.enabled?(:pages)
90
- @page_listener = Listen.to(*config.lookbook.page_paths.filter { |dir| Dir.exist? dir }, only: /\.(html.*|md.*)$/) do |modified, added, removed|
79
+ preview_controller = Lookbook.config.preview_controller.constantize
80
+ preview_controller.class_eval { include Lookbook::PreviewController }
81
+
82
+ if config.lookbook.listen
83
+ @preview_listener = Listen.to(*config.lookbook.listen_paths, only: /\.(rb|html.*)$/) do |modified, added, removed|
84
+ begin
85
+ parser.parse
86
+ rescue
87
+ end
88
+ Lookbook::Preview.clear_cache
91
89
  Lookbook::Engine.websocket&.broadcast("reload", {
92
90
  modified: modified,
93
91
  removed: removed,
94
92
  added: added
95
93
  })
96
94
  end
97
- @page_listener.start
98
- end
95
+ @preview_listener.start
96
+
97
+ if Lookbook::Features.enabled?(:pages)
98
+ @page_listener = Listen.to(*config.lookbook.page_paths.filter { |dir| Dir.exist? dir }, only: /\.(html.*|md.*)$/) do |modified, added, removed|
99
+ Lookbook::Engine.websocket&.broadcast("reload", {
100
+ modified: modified,
101
+ removed: removed,
102
+ added: added
103
+ })
104
+ end
105
+ @page_listener.start
106
+ end
99
107
 
100
- parser.parse
108
+ if config.lookbook.runtime_parsing
109
+ parser.parse
110
+ else
111
+ unless File.exist?(config.lookbook.parser_registry_path)
112
+ Lookbook.logger.warn "
113
+ Runtime parsing is disabled but no registry file has been found.
114
+ Did you run `rake lookbook:preparse` before starting the app?
115
+ Expected to find registry file at #{config.lookbook.parser_registry_path}
116
+ "
117
+ end
118
+ end
119
+ end
101
120
  end
102
121
 
103
122
  at_exit do
@@ -133,7 +152,7 @@ module Lookbook
133
152
  end
134
153
 
135
154
  def parser
136
- @parser ||= Lookbook::Parser.new(config.lookbook.preview_paths)
155
+ @parser ||= Lookbook::Parser.new(config.lookbook.preview_paths, config.lookbook.parser_registry_path)
137
156
  end
138
157
  end
139
158
  end
@@ -2,27 +2,31 @@ require "yard"
2
2
 
3
3
  module Lookbook
4
4
  class Parser
5
- YARDOC_FILE_PATH = Rails.root.join("tmp/storage/.yardoc").to_s
6
-
7
- def initialize(paths)
5
+ attr_reader :registry_path
6
+ def initialize(paths, registry_path)
8
7
  @paths = paths.map { |p| "#{p}/**/*preview.rb" }
9
- YARD::Registry.yardoc_file = YARDOC_FILE_PATH
8
+ @registry_path = registry_path.to_s
9
+ YARD::Registry.yardoc_file = registry_path
10
10
  end
11
11
 
12
12
  def parse
13
13
  YARD::Registry.clear
14
14
  YARD::Registry.lock_for_writing do
15
15
  YARD.parse(@paths)
16
- YARD::Registry.save(false, YARDOC_FILE_PATH)
16
+ YARD::Registry.save(false, registry_path)
17
17
  end
18
18
  end
19
19
 
20
20
  def get_code_object(path)
21
21
  registry = YARD::RegistryStore.new
22
- registry.load!(YARDOC_FILE_PATH)
22
+ registry.load!(registry_path)
23
23
  registry.get(path)
24
24
  end
25
25
 
26
+ # def yardoc_file_path
27
+ # Rails&.root ? Rails.root.join(YARDOC_FILE_PATH) : YARDOC_FILE_PATH
28
+ # end
29
+
26
30
  class << self
27
31
  def define_tags
28
32
  YARD::Tags::Library.define_tag("Hidden status", :hidden)
@@ -1,3 +1,3 @@
1
1
  module Lookbook
2
- VERSION = "0.7.4"
2
+ VERSION = "0.8.0.beta.0"
3
3
  end
@@ -1,6 +1,15 @@
1
1
  require_relative "../lookbook"
2
2
 
3
3
  namespace :lookbook do
4
+
5
+ namespace :previews do
6
+ desc "Preparse the previews"
7
+ task :preparse do
8
+ Lookbook::Engine.parser.parse
9
+ puts "Lookbook preview parsing complete"
10
+ end
11
+ end
12
+
4
13
  namespace :release do
5
14
  desc "Bump the Lookbook engine version number"
6
15
  task :bump_version, [:version] do |t, args|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lookbook
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.4
4
+ version: 0.8.0.beta.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Perkins
@@ -324,9 +324,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
324
324
  version: '0'
325
325
  required_rubygems_version: !ruby/object:Gem::Requirement
326
326
  requirements:
327
- - - ">="
327
+ - - ">"
328
328
  - !ruby/object:Gem::Version
329
- version: '0'
329
+ version: 1.3.1
330
330
  requirements: []
331
331
  rubygems_version: 3.2.22
332
332
  signing_key: