lib/lookbook/config.rb in lookbook-1.0.0.beta.2 vs lib/lookbook/config.rb in lookbook-1.0.0.beta.3

- old
+ new

@@ -9,10 +9,12 @@ foobar = "bax" @options.set({ project_name: "Lookbook", log_level: 2, auto_refresh: true, + + components_path: "app/components", page_controller: "Lookbook::PageController", page_route: "pages", page_paths: ["test/components/docs"], page_options: {}, @@ -35,48 +37,61 @@ parser_registry_path: "tmp/storage/.yardoc", ui_theme: "indigo", ui_theme_overrides: {}, + hooks: { + after_initialize: [], + before_exit: [], + after_change: [], + }, + + experimental_features: false, + inspector_panels: { preview: { pane: :main, position: 1, partial: "lookbook/previews/panels/preview", hotkey: "v", - panel_classes: "overflow-hidden" + panel_classes: "overflow-hidden", + padded: false }, output: { pane: :main, position: 2, partial: "lookbook/previews/panels/output", label: "HTML", hotkey: "h", + padded: false }, source: { pane: :drawer, position: 1, partial: "lookbook/previews/panels/source", label: "Source", hotkey: "s", - copy: ->(data) { data.examples.map { |e| e[:source] }.join("\n") } + copy: ->(data) { data.examples.map { |e| e.source }.join("\n") }, + padded: false }, notes: { pane: :drawer, position: 2, partial: "lookbook/previews/panels/notes", label: "Notes", hotkey: "n", - disabled: ->(data) { data.examples.filter { |e| e.notes.present? }.none? } + disabled: ->(data) { data.examples.select { |e| e.notes.present? }.none? }, + padded: false }, params: { pane: :drawer, position: 3, partial: "lookbook/previews/panels/params", label: "Params", hotkey: "p", - disabled: ->(data) { data.preview.params.none? } + disabled: ->(data) { data.preview.params.none? }, + padded: false } }, inspector_panel_defaults: { id: ->(data) { "inspector-panel-#{data.name}" }, @@ -88,14 +103,13 @@ hotkey: nil, disabled: false, show: true, copy: nil, panel_classes: nil, - locals: {} + locals: {}, + padded: true }, - - experimental_features: false, }) end def inspector_panels(&block) if block_given? @@ -103,10 +117,37 @@ else get(:inspector_panels) end end + def define_inspector_panel(name, opts = {}) + inspector_panels[name] = opts + if opts[:position].present? + pane = inspector_panels[name].pane.presence || :drawer + siblings = inspector_panels.select do |key, panel| + panel.pane == pane && key != name.to_sym + end + siblings.each do |key, panel| + if panel.position >= opts[:position] + panel.position += 1 + end + end + end + end + + def amend_inspector_panel(name, opts = {}) + if opts == false + inspector_panels[name] = false + else + inspector_panels[name].merge!(opts) + end + end + + def remove_inspector_panel(name) + amend_inspector_panel(name, false) + end + def ui_theme=(name) name = name.to_s if Theme.valid_theme?(name) @options[:ui_theme] = name else @@ -139,20 +180,24 @@ end protected def get_inspector_panels(panels) - panels.filter! { |key, panel| panel } + panels.select! { |key, panel| panel } panels end def get_project_name(name) name == false ? nil : name end + def get_components_path(path) + absolute_path(path) + end + def normalize_paths(paths) paths.map! { |path| absolute_path(path) } - paths.filter! { |path| Dir.exist?(path) } + paths.select! { |path| Dir.exist?(path) } paths end def absolute_path(path) File.absolute_path(path.to_s, Rails.root) \ No newline at end of file