lib/lookbook.rb in lookbook-1.1.0 vs lib/lookbook.rb in lookbook-1.1.1
- old
+ new
@@ -1,34 +1,79 @@
-require "active_support/dependencies/autoload"
-require "lookbook/engine"
+require "zeitwerk"
+require "ostruct"
require "lookbook/version"
-require "view_component/engine"
+loader = Zeitwerk::Loader.for_gem
+loader.ignore("#{__dir__}/lookbook.rb")
+loader.push_dir("#{__dir__}/lookbook", namespace: Lookbook)
+loader.setup
+
module Lookbook
- extend ActiveSupport::Autoload
+ class << self
+ include Lookbook::Hooks
+ include Lookbook::Panels
+ include Lookbook::Tags
- autoload :Error, "lookbook/error"
- autoload :Utils, "lookbook/utils"
- autoload :Lang, "lookbook/lang"
- autoload :Params, "lookbook/params"
- autoload :TagOptions, "lookbook/tag_options"
- autoload :Page, "lookbook/page"
- autoload :Tag, "lookbook/tag"
- autoload :PageSection, "lookbook/page_section"
- autoload :PageCollection, "lookbook/page_collection"
- autoload :Features, "lookbook/features"
- autoload :Collection, "lookbook/collection"
- autoload :Entity, "lookbook/entity"
- autoload :Parser, "lookbook/parser"
- autoload :Preview, "lookbook/preview"
- autoload :PreviewCollection, "lookbook/preview_collection"
- autoload :PreviewController, "lookbook/preview_controller"
- autoload :PreviewExample, "lookbook/preview_example"
- autoload :PreviewGroup, "lookbook/preview_group"
- autoload :SourceInspector, "lookbook/source_inspector"
- autoload :TemplateParser, "lookbook/template_parser"
- autoload :CodeFormatter, "lookbook/code_formatter"
- autoload :Markdown, "lookbook/markdown"
- autoload :Theme, "lookbook/theme"
- autoload :Store, "lookbook/store"
- autoload :Component, "lookbook/component"
+ def version
+ Lookbook::VERSION
+ end
+
+ def config
+ @config ||= Config.new
+ end
+
+ def configure
+ yield(config)
+ end
+
+ def data
+ @data ||= Store.new
+ end
+
+ def data=(new_data)
+ @data = Store.new(new_data)
+ end
+
+ def logger
+ @logger ||= if Rails.logger.present? && config.log_use_rails_logger
+ Rails.logger
+ else
+ logger = Logger.new($stdout)
+ logger.level = config.log_level
+ logger
+ end
+ end
+
+ def debug_data
+ {
+ version: version,
+ env: Rails.env.to_s,
+ config: config.to_h
+ }
+ end
+
+ def previews
+ Preview.all
+ end
+
+ def pages
+ Page.all
+ end
+
+ def broadcast(event_name, data = {})
+ Engine.websocket&.broadcast(event_name.to_s, data)
+ end
+
+ def theme
+ @theme ||= Lookbook::Theme.new(config.ui_theme, config.ui_theme_overrides)
+ end
+
+ def define_param_input(input, partial, input_options = nil)
+ config.preview_param_inputs[input.to_sym] = {
+ partial: partial,
+ input_options: input_options || {}
+ }
+ end
+ end
end
+
+require "lookbook/engine"