lib/lookbook/config.rb in lookbook-1.0.0.beta.0 vs lib/lookbook/config.rb in lookbook-1.0.0.beta.1
- old
+ new
@@ -1,39 +1,28 @@
require "lookbook/markdown"
+require "lookbook/theme"
+require "lookbook/store"
module Lookbook
- class ConfigOptions < ActiveSupport::OrderedOptions
- def initialize(**data)
- super()
- data.keys.each { |key| self[key.to_sym] = data[key] }
- end
-
- def [](key)
- super(key.to_sym)
- end
-
- def []=(key, value)
- super(key.to_sym, value)
- end
- end
-
class Config
def initialize
- @store = ConfigOptions.new(**{
+ @options = Store.new
+ foobar = "bax"
+ @options.set({
project_name: "Lookbook",
log_level: 2,
auto_refresh: true,
page_controller: "Lookbook::PageController",
page_route: "pages",
page_paths: ["test/components/docs"],
- page_options: ConfigOptions.new,
- markdown_options: ConfigOptions.new(**Markdown::DEFAULT_OPTIONS),
+ page_options: {},
+ markdown_options: Markdown::DEFAULT_OPTIONS,
preview_paths: [],
- preview_display_params: ConfigOptions.new,
- preview_options: ConfigOptions.new,
+ preview_display_params: {},
+ preview_options: {},
preview_srcdoc: false,
sort_examples: true,
listen: Rails.env.development?,
listen_paths: [],
@@ -44,28 +33,89 @@
runtime_parsing: !Rails.env.production?,
parser_registry_path: "tmp/storage/.yardoc",
ui_theme: "indigo",
- ui_theme_overrides: ConfigOptions.new,
+ ui_theme_overrides: {},
+
+ inspector_panels: {
+ preview: {
+ pane: :main,
+ position: 1,
+ partial: "lookbook/previews/panels/preview",
+ hotkey: "v",
+ panel_classes: "overflow-hidden"
+ },
+ output: {
+ pane: :main,
+ position: 2,
+ partial: "lookbook/previews/panels/output",
+ label: "HTML",
+ hotkey: "h",
+ },
+ source: {
+ pane: :drawer,
+ position: 1,
+ partial: "lookbook/previews/panels/source",
+ label: "Source",
+ hotkey: "s",
+ copy: ->(data) { data.examples.map { |e| e[:source] }.join("\n") }
+ },
+ notes: {
+ pane: :drawer,
+ position: 2,
+ partial: "lookbook/previews/panels/notes",
+ label: "Notes",
+ hotkey: "n",
+ disabled: ->(data) { data.examples.filter { |e| e.notes.present? }.none? }
+ },
+ params: {
+ pane: :drawer,
+ position: 3,
+ partial: "lookbook/previews/panels/params",
+ label: "Params",
+ hotkey: "p",
+ disabled: ->(data) { data.preview.params.none? }
+ }
+ },
+
+ inspector_panel_defaults: {
+ id: ->(data) { "inspector-panel-#{data.name}" },
+ partial: "lookbook/previews/panels/content",
+ content: nil,
+ label: ->(data) { data.name.titleize },
+ pane: :drawer,
+ position: ->(data) { data.index_position },
+ hotkey: nil,
+ disabled: false,
+ show: true,
+ copy: nil,
+ panel_classes: nil,
+ locals: {}
+ },
+
experimental_features: false,
})
end
+ def inspector_panels(&block)
+ if block_given?
+ yield get(:inspector_panels)
+ else
+ get(:inspector_panels)
+ end
+ end
+
def ui_theme=(name)
name = name.to_s
- if ["indigo", "zinc", "blue"].include?(name)
- @store[:ui_theme] = name
+ if Theme.valid_theme?(name)
+ @options[:ui_theme] = name
else
- Lookbook.logger.warn "'#{name}' is not a valid Lookbook theme. Falling back to default."
+ Lookbook.logger.warn "'#{name}' is not a valid Lookbook theme. Theme setting not changed."
end
end
- def ui_theme_overrides=(theme)
- @store[:ui_theme_overrides] = ConfigOptions.new(theme)
- end
-
def ui_theme_overrides(&block)
if block_given?
yield get(:ui_theme_overrides)
else
get(:ui_theme_overrides)
@@ -75,23 +125,28 @@
def [](key)
get(key.to_sym)
end
def []=(key, value)
- @store[key.to_sym] = value
+ @options[key.to_sym] = value
end
def to_h
- @store.to_h
+ @options.to_h
end
def to_json(*a)
to_h.to_json(*a)
end
protected
+ def get_inspector_panels(panels)
+ panels.filter! { |key, panel| panel }
+ panels
+ end
+
def get_project_name(name)
name == false ? nil : name
end
def normalize_paths(paths)
@@ -109,14 +164,14 @@
alias_method :get_listen_paths, :normalize_paths
alias_method :get_parser_registry_path, :absolute_path
def get(name)
getter_name = "get_#{name}".to_sym
- respond_to?(getter_name, true) ? send(getter_name, @store[name]) : @store[name]
+ respond_to?(getter_name, true) ? send(getter_name, @options[name]) : @options[name]
end
def set(name, *args)
- @store.send(name, *args)
+ @options.send(name, *args)
end
def method_missing(name, *args)
args.any? ? set(name, *args) : get(name)
end
\ No newline at end of file