lookbook 0.7.2 → 0.8.0.beta.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6df32e43d6fbb0a7b88e0db9bbb4bd9562f3528f3a7160463d078daf262954f3
4
- data.tar.gz: cfbd08c5a4d06a56ef8bd9016139e3d04a4195e2590d5be741e1c238ce390744
3
+ metadata.gz: aa9a6048a7c6da30fcf5fe7c42a0a41365c3964da88d1d639a640c1acdd97a95
4
+ data.tar.gz: dbbf4e04289ccadde4f37453123aabc70d982104b6933b3e139b0c65ea2a68f4
5
5
  SHA512:
6
- metadata.gz: bd42877713e33dc0ad3d1bf4fddc1ab561171d01417f6b415ceda15abeeba45996c9e0478afb02117363a1686b063daf1e283ff0f84c6d0b591c59c50e0ba744
7
- data.tar.gz: e12acc1799810736e3f5bad6e3d096f7c1f68ddb0de5b0d1aa0324f1b7b0bd707d733750c5ed8a56cb3ab87d921036cd7b340927971186f98bbf5a402d41acf0
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
@@ -1,4 +1,4 @@
1
- <div class="bg-gray-50 h-full">
1
+ <div class="bg-gray-50 h-full overflow-auto">
2
2
  <% if @example.type == :group %>
3
3
  <div class="p-4 prose prose-sm">
4
4
  <em class='opacity-50'>Params are not yet supported for grouped examples.</em>
data/config/routes.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  Lookbook::Engine.routes.draw do
2
2
  if Lookbook.config.auto_refresh
3
- mount Lookbook::Engine.websocket => Lookbook.config.cable.mount_path
3
+ mount Lookbook::Engine.websocket => Lookbook.config.cable_mount_path
4
4
  end
5
5
 
6
6
  root to: "application#index", as: :home
@@ -10,7 +10,7 @@ module Lookbook
10
10
  end
11
11
 
12
12
  def logger
13
- @logger ||= config.debug == true ? Rails.logger : Lookbook::NullLogger.new
13
+ @logger ||= Rails.logger
14
14
  end
15
15
 
16
16
  def version
@@ -49,15 +49,17 @@ 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"))
55
56
  options.listen_paths.filter! { |path| Dir.exist? path }
56
57
 
57
- options.cable = ActionCable::Server::Configuration.new
58
- options.cable.cable = {adapter: "async"}.with_indifferent_access
59
- options.cable.mount_path ||= "/lookbook-cable"
60
- options.cable.connection_class = -> { Lookbook::Connection }
58
+ options.cable_mount_path ||= "/lookbook-cable"
59
+ options.cable_logger ||= Rails.logger
60
+
61
+ options.runtime_parsing = !Rails.env.production? if options.runtime_parsing.nil?
62
+ options.parser_registry_path ||= Rails.root.join("tmp/storage/.yardoc")
61
63
 
62
64
  options.experimental_features = false unless options.experimental_features.present?
63
65
  end
@@ -73,41 +75,48 @@ module Lookbook
73
75
  )
74
76
  end
75
77
 
76
- initializer "lookbook.logging" do
77
- if config.lookbook.debug == true
78
- config.lookbook.cable.logger ||= Rails.logger
79
- else
80
- config.lookbook.cable.logger = Lookbook::NullLogger.new
81
- end
82
- end
83
-
84
78
  config.after_initialize do
85
- @preview_listener = Listen.to(*config.lookbook.listen_paths, only: /\.(rb|html.*)$/) do |modified, added, removed|
86
- begin
87
- parser.parse
88
- rescue
89
- end
90
- Lookbook::Preview.clear_cache
91
- Lookbook::Engine.websocket&.broadcast("reload", {
92
- modified: modified,
93
- removed: removed,
94
- added: added
95
- })
96
- end
97
- @preview_listener.start
98
-
99
- if Lookbook::Features.enabled?(:pages)
100
- @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
101
89
  Lookbook::Engine.websocket&.broadcast("reload", {
102
90
  modified: modified,
103
91
  removed: removed,
104
92
  added: added
105
93
  })
106
94
  end
107
- @page_listener.start
108
- 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
109
107
 
110
- 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
111
120
  end
112
121
 
113
122
  at_exit do
@@ -118,18 +127,24 @@ module Lookbook
118
127
  class << self
119
128
  def websocket
120
129
  if config.lookbook.auto_refresh
130
+ cable = ActionCable::Server::Configuration.new
131
+ cable.cable = {adapter: "async"}.with_indifferent_access
132
+ cable.mount_path = config.lookbook.cable_mount_path
133
+ cable.connection_class = -> { Lookbook::Connection }
134
+ cable.logger = config.lookbook.cable_logger
135
+
121
136
  @websocket ||= if Rails.version.to_f >= 6.0
122
- ActionCable::Server::Base.new(config: config.lookbook.cable)
137
+ ActionCable::Server::Base.new(config: cable)
123
138
  else
124
139
  websocket ||= ActionCable::Server::Base.new
125
- websocket.config = config.lookbook.cable
140
+ websocket.config = cable
126
141
  websocket
127
142
  end
128
143
  end
129
144
  end
130
145
 
131
146
  def websocket_mount_path
132
- "#{mounted_path}#{config.lookbook.cable.mount_path}" if websocket
147
+ "#{mounted_path}#{config.lookbook.cable_mount_path}" if websocket
133
148
  end
134
149
 
135
150
  def mounted_path
@@ -137,7 +152,7 @@ module Lookbook
137
152
  end
138
153
 
139
154
  def parser
140
- @parser ||= Lookbook::Parser.new(config.lookbook.preview_paths)
155
+ @parser ||= Lookbook::Parser.new(config.lookbook.preview_paths, config.lookbook.parser_registry_path)
141
156
  end
142
157
  end
143
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.2"
2
+ VERSION = "0.8.0.beta.0"
3
3
  end
data/lib/lookbook.rb CHANGED
@@ -20,7 +20,6 @@ module Lookbook
20
20
  autoload :PreviewExample, "lookbook/preview_example"
21
21
  autoload :PreviewGroup, "lookbook/preview_group"
22
22
  autoload :CodeInspector, "lookbook/code_inspector"
23
- autoload :NullLogger, "lookbook/null_logger"
24
23
  autoload :CodeFormatter, "lookbook/code_formatter"
25
24
  autoload :Markdown, "lookbook/markdown"
26
25
 
@@ -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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lookbook
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
4
+ version: 0.8.0.beta.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Perkins
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-05 00:00:00.000000000 Z
11
+ date: 2022-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actioncable
@@ -290,7 +290,6 @@ files:
290
290
  - lib/lookbook/features.rb
291
291
  - lib/lookbook/lang.rb
292
292
  - lib/lookbook/markdown.rb
293
- - lib/lookbook/null_logger.rb
294
293
  - lib/lookbook/page.rb
295
294
  - lib/lookbook/page_collection.rb
296
295
  - lib/lookbook/params.rb
@@ -325,9 +324,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
325
324
  version: '0'
326
325
  required_rubygems_version: !ruby/object:Gem::Requirement
327
326
  requirements:
328
- - - ">="
327
+ - - ">"
329
328
  - !ruby/object:Gem::Version
330
- version: '0'
329
+ version: 1.3.1
331
330
  requirements: []
332
331
  rubygems_version: 3.2.22
333
332
  signing_key:
@@ -1,47 +0,0 @@
1
- module Lookbook
2
- class NullLogger
3
- def unknown(*)
4
- nil
5
- end
6
-
7
- def fatal(*)
8
- nil
9
- end
10
-
11
- def fatal?
12
- false
13
- end
14
-
15
- def error(*)
16
- nil
17
- end
18
-
19
- def error?
20
- false
21
- end
22
-
23
- def warn(*)
24
- nil
25
- end
26
-
27
- def warn?
28
- false
29
- end
30
-
31
- def info(*)
32
- nil
33
- end
34
-
35
- def info?
36
- false
37
- end
38
-
39
- def debug(*)
40
- nil
41
- end
42
-
43
- def debug?
44
- false
45
- end
46
- end
47
- end