lib/lookbook/config.rb in lookbook-1.0.0.beta.5 vs lib/lookbook/config.rb in lookbook-1.0.0.beta.6
- old
+ new
@@ -20,13 +20,12 @@
page_options: {},
markdown_options: Markdown::DEFAULT_OPTIONS,
preview_paths: [],
preview_display_params: {},
- preview_options: {},
- preview_srcdoc: false,
- sort_examples: true,
+ preview_srcdoc: nil,
+ sort_examples: false,
listen: Rails.env.development?,
listen_paths: [],
listen_extensions: ["rb", "html.*"],
listen_use_polling: false,
@@ -55,64 +54,53 @@
pane: :main,
position: 1,
partial: "lookbook/previews/panels/preview",
hotkey: "v",
panel_classes: "overflow-hidden",
- padded: false
+ padded: false,
+ system: true
},
output: {
pane: :main,
position: 2,
partial: "lookbook/previews/panels/output",
label: "HTML",
hotkey: "h",
- padded: false
+ padded: false,
+ system: true
},
source: {
pane: :drawer,
position: 1,
partial: "lookbook/previews/panels/source",
label: "Source",
hotkey: "s",
copy: ->(data) { data.examples.map { |e| e.source }.join("\n") },
- padded: false
+ padded: false,
+ system: true
},
notes: {
pane: :drawer,
position: 2,
partial: "lookbook/previews/panels/notes",
label: "Notes",
hotkey: "n",
disabled: ->(data) { data.examples.select { |e| e.notes.present? }.none? },
- padded: false
+ padded: false,
+ system: true
},
params: {
pane: :drawer,
position: 3,
partial: "lookbook/previews/panels/params",
label: "Params",
hotkey: "p",
disabled: ->(data) { data.preview.params.none? },
- padded: false
+ padded: false,
+ system: true
}
},
-
- 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: {},
- padded: true
- },
})
end
def project_name
@options.project_name == false ? nil : @options.project_name
@@ -120,26 +108,37 @@
def components_path
absolute_path(@options.components_path)
end
+ def page_paths=(paths = [])
+ @options.page_paths += paths if paths.is_a? Array
+ end
+
def page_paths
normalize_paths(@options.page_paths)
end
+ def preview_paths=(paths = [])
+ @options.preview_paths += paths if paths.is_a? Array
+ end
+
def preview_paths
normalize_paths(@options.preview_paths)
end
+ def preview_srcdoc=(enable)
+ Lookbook.logger.warn "The `preview_srcdoc` config option is deprecated and will be removed in v2.0"
+ end
+
def listen_paths
normalize_paths(@options.listen_paths)
end
- def listen_extensions
- @options.listen_extensions += ["rb", "html.*"]
+ def listen_extensions=(extensions = [])
+ @options.listen_extensions += extensions if extensions.is_a? Array
@options.listen_extensions.uniq!
- @options.listen_extensions
end
def parser_registry_path
absolute_path(@options.parser_registry_path)
end
@@ -152,21 +151,18 @@
panels
end
end
def define_inspector_panel(name, opts = {})
- @options.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
+ pane = opts[:pane].presence || :drawer
+ siblings = inspector_panels.select { |key, panel| panel.pane == pane }
+ opts[:position] ||= siblings.size + 1
+ @options.inspector_panels[name] = opts
+ siblings.each do |key, panel|
+ if panel.position >= opts[:position]
+ panel.position += 1
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
@@ -178,10 +174,29 @@
def remove_inspector_panel(name)
amend_inspector_panel(name, false)
end
+ def 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: {},
+ padded: true,
+ system: false
+ }
+ end
+
def ui_theme=(name)
name = name.to_s
if Theme.valid_theme?(name)
@options.ui_theme = name
else
@@ -223,11 +238,13 @@
end
protected
def normalize_paths(paths)
- paths.map! { |path| absolute_path(path) }
- paths.select! { |path| Dir.exist?(path) }
+ paths.map! do |path|
+ full_path = absolute_path(path)
+ full_path if Dir.exist?(full_path)
+ end.compact!
paths
end
def absolute_path(path)
File.absolute_path(path.to_s, Rails.root)
\ No newline at end of file