lookbook 1.3.4 → 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +11 -11
  3. data/app/assets/lookbook/css/themes/blue.css +1 -1
  4. data/app/assets/lookbook/css/themes/green.css +1 -1
  5. data/app/assets/lookbook/css/themes/indigo.css +1 -1
  6. data/app/assets/lookbook/css/themes/rose.css +1 -1
  7. data/app/assets/lookbook/css/themes/zinc.css +1 -1
  8. data/app/components/lookbook/code/component.rb +2 -4
  9. data/app/components/lookbook/header/component.html.erb +1 -1
  10. data/app/components/lookbook/inspector_panel/component.rb +1 -1
  11. data/app/components/lookbook/nav/component.rb +8 -15
  12. data/app/components/lookbook/nav/directory/component.html.erb +28 -0
  13. data/app/components/lookbook/nav/directory/component.rb +4 -0
  14. data/app/components/lookbook/nav/{item → entity}/component.html.erb +7 -7
  15. data/app/components/lookbook/nav/entity/component.rb +49 -0
  16. data/app/components/lookbook/nav/item/component.css +15 -0
  17. data/app/components/lookbook/nav/item/component.js +4 -0
  18. data/app/components/lookbook/nav/item/component.rb +13 -56
  19. data/app/controllers/concerns/lookbook/targetable_concern.rb +13 -38
  20. data/app/controllers/lookbook/application_controller.rb +9 -7
  21. data/app/controllers/lookbook/page_controller.rb +2 -2
  22. data/app/controllers/lookbook/pages_controller.rb +9 -15
  23. data/app/helpers/lookbook/application_helper.rb +1 -1
  24. data/app/helpers/lookbook/page_helper.rb +7 -4
  25. data/app/views/layouts/lookbook/application.html.erb +3 -4
  26. data/app/views/layouts/lookbook/page.html.erb +2 -2
  27. data/app/views/layouts/lookbook/shell.html.erb +2 -2
  28. data/app/views/layouts/lookbook/skeleton.html.erb +7 -7
  29. data/app/views/lookbook/index.html.erb +3 -3
  30. data/app/views/lookbook/inspector/panels/_params.html.erb +2 -2
  31. data/config/languages.yml +41 -0
  32. data/config/panels.yml +1 -1
  33. data/config/tags.yml +4 -0
  34. data/lib/lookbook/engine.rb +65 -43
  35. data/lib/lookbook/entities/collections/component_collection.rb +4 -0
  36. data/lib/lookbook/entities/collections/concerns/hierarchical_collection.rb +23 -0
  37. data/lib/lookbook/entities/collections/entity_collection.rb +61 -0
  38. data/lib/lookbook/entities/collections/page_collection.rb +30 -0
  39. data/lib/lookbook/entities/collections/preview_collection.rb +35 -0
  40. data/lib/lookbook/entities/collections/preview_example_collection.rb +4 -0
  41. data/lib/lookbook/entities/component.rb +31 -0
  42. data/lib/lookbook/entities/concerns/annotatable.rb +58 -0
  43. data/lib/lookbook/entities/concerns/inspectable.rb +44 -0
  44. data/lib/lookbook/entities/concerns/locatable.rb +73 -0
  45. data/lib/lookbook/entities/concerns/navigable.rb +43 -0
  46. data/lib/lookbook/entities/entity.rb +53 -0
  47. data/lib/lookbook/entities/page.rb +80 -0
  48. data/lib/lookbook/entities/page_section.rb +43 -0
  49. data/lib/lookbook/entities/preview.rb +87 -0
  50. data/lib/lookbook/entities/preview_example.rb +100 -0
  51. data/lib/lookbook/entities/preview_group.rb +48 -0
  52. data/lib/lookbook/file_watcher.rb +1 -1
  53. data/lib/lookbook/lang.rb +12 -35
  54. data/lib/lookbook/param.rb +2 -2
  55. data/lib/lookbook/preview_parser.rb +1 -1
  56. data/lib/lookbook/rendered_example.rb +37 -0
  57. data/lib/lookbook/services/code/code_indenter.rb +14 -0
  58. data/lib/lookbook/services/data/resolvers/data_resolver.rb +2 -2
  59. data/lib/lookbook/services/data/resolvers/file_resolver.rb +1 -1
  60. data/lib/lookbook/services/data/resolvers/method_resolver.rb +1 -1
  61. data/lib/lookbook/services/entities/entity_tree_builder.rb +45 -0
  62. data/lib/lookbook/services/position_prefix_parser.rb +16 -0
  63. data/lib/lookbook/support/store.rb +0 -33
  64. data/lib/lookbook/support/tree_node.rb +87 -0
  65. data/lib/lookbook/support/utils/path_utils.rb +26 -2
  66. data/lib/lookbook/support/utils/utils.rb +24 -0
  67. data/lib/lookbook/tags/component_tag.rb +6 -0
  68. data/lib/lookbook/tags/custom_tag.rb +2 -0
  69. data/lib/lookbook/tags/id_tag.rb +1 -1
  70. data/lib/lookbook/tags/logical_path_tag.rb +3 -0
  71. data/lib/lookbook/tags/param_tag.rb +2 -0
  72. data/lib/lookbook/tags/source_tag.rb +7 -0
  73. data/lib/lookbook/tags/yard_tag.rb +35 -7
  74. data/lib/lookbook/version.rb +1 -1
  75. data/lib/lookbook.rb +11 -7
  76. data/public/lookbook-assets/css/lookbook.css +33 -21
  77. data/public/lookbook-assets/css/lookbook.css.map +1 -1
  78. data/public/lookbook-assets/js/lookbook.js +56 -55
  79. data/public/lookbook-assets/js/lookbook.js.map +1 -1
  80. metadata +35 -18
  81. data/lib/lookbook/collection.rb +0 -161
  82. data/lib/lookbook/component.rb +0 -34
  83. data/lib/lookbook/entity.rb +0 -47
  84. data/lib/lookbook/page.rb +0 -194
  85. data/lib/lookbook/page_collection.rb +0 -19
  86. data/lib/lookbook/page_section.rb +0 -29
  87. data/lib/lookbook/preview.rb +0 -181
  88. data/lib/lookbook/preview_collection.rb +0 -23
  89. data/lib/lookbook/preview_example.rb +0 -93
  90. data/lib/lookbook/preview_group.rb +0 -58
  91. data/lib/lookbook/source_inspector.rb +0 -76
  92. data/lib/lookbook/support/utils/attribute_utils.rb +0 -14
  93. data/lib/lookbook/utils.rb +0 -65
@@ -0,0 +1,73 @@
1
+ module Lookbook
2
+ module Locatable
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ attr_reader :file_path, :base_directories
7
+
8
+ def file_name(strip_ext = false)
9
+ basename = file_pathname.basename
10
+ (strip_ext ? basename.to_s.split(".").first : basename).to_s
11
+ end
12
+
13
+ def file_name_base
14
+ @_file_name_slug ||= file_name(true).gsub(/(_component_preview|component_preview|preview)$/, "")
15
+ end
16
+
17
+ def file_extension
18
+ @_file_extension ||= file_pathname.extname
19
+ end
20
+
21
+ def directory_path
22
+ @_directory_path ||= Pathname(file_pathname.dirname)
23
+ end
24
+
25
+ def relative_file_path
26
+ @_relative_file_path ||= file_pathname.relative_path_from(base_directory)
27
+ end
28
+
29
+ def relative_directory_path
30
+ @_relative_directory_path ||= directory_path.relative_path_from(base_directory)
31
+ end
32
+
33
+ def last_modified
34
+ @_last_modified ||= File.mtime(file_path)
35
+ end
36
+
37
+ def logical_path
38
+ return @_logical_path if @_logical_path
39
+
40
+ directory = fetch_config(:logical_path) { relative_directory_path.to_s }
41
+ @_logical_path ||= PathUtils.to_path(directory, file_name_base)
42
+ end
43
+
44
+ def full_path
45
+ Lookbook.logger.warn "The `full_path` method has been deprecated - use `file_path` instead. `full_path` will be removed in v2.0"
46
+ file_path
47
+ end
48
+
49
+ def rel_path
50
+ Lookbook.logger.warn "The `rel_path` method has been deprecated - use `relative_file_path` instead. `rel_path` will be removed in v2.0"
51
+ relative_file_path
52
+ end
53
+
54
+ def dir_path
55
+ Lookbook.logger.warn "The `dir_path` method has been deprecated - use `directory_path` instead. `dir_path` will be removed in v2.0"
56
+ directory_path
57
+ end
58
+
59
+ protected
60
+
61
+ def file_pathname
62
+ Pathname(file_path)
63
+ end
64
+
65
+ def base_directory
66
+ return @_base_directory if @_base_directory
67
+
68
+ directories = [Rails.root, *Array(base_directories)].map(&:to_s).sort_by(&:length).reverse
69
+ @_base_directory ||= directories.first { |dir| file_path.start_with?(dir) }
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,43 @@
1
+ module Lookbook
2
+ module Navigable
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ def hidden?
7
+ fetch_config(:hidden, false)
8
+ end
9
+
10
+ def visible?
11
+ !hidden?
12
+ end
13
+
14
+ def position
15
+ return @_position if @_position
16
+
17
+ pos = if @position_prefixes && respond_to?(:file_name)
18
+ PositionPrefixParser.call(file_name).first || default_position
19
+ else
20
+ fetch_config(:position, default_position)
21
+ end
22
+
23
+ @_position ||= pos.to_i
24
+ end
25
+
26
+ def depth
27
+ path.split("/").size
28
+ end
29
+
30
+ def default_position
31
+ @default_position || 10000
32
+ end
33
+
34
+ def <=>(other)
35
+ if respond_to?(:sort_handler, true)
36
+ sort_handler(other)
37
+ else
38
+ [position, label] <=> [other.position, other.label]
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,53 @@
1
+ module Lookbook
2
+ class Entity
3
+ include Comparable
4
+ include Lookbook::Engine.routes.url_helpers
5
+
6
+ def initialize(lookup_path = nil)
7
+ @lookup_path = lookup_path
8
+ end
9
+
10
+ def id
11
+ Utils.id(fetch_config(:id) { lookup_path.tr("/", "-") })
12
+ end
13
+
14
+ def name
15
+ @_name ||= Utils.name(File.basename(@lookup_path))
16
+ end
17
+
18
+ def label
19
+ @_label ||= fetch_config(:label) { name.titleize }
20
+ end
21
+
22
+ def lookup_path
23
+ return @_lookup_path if @_lookup_path
24
+
25
+ directory = fetch_config(:logical_path) do
26
+ dir = File.dirname(@lookup_path)
27
+ dir if !dir.start_with?(".")
28
+ end
29
+ @_lookup_path ||= PathUtils.strip_slashes(PathUtils.to_path(directory, name))
30
+ end
31
+
32
+ def url_path
33
+ nil
34
+ end
35
+
36
+ def type
37
+ @_type ||= self.class.name.demodulize.underscore.downcase.to_sym
38
+ end
39
+
40
+ def <=>(other)
41
+ label <=> other.label
42
+ end
43
+
44
+ alias_method :path, :lookup_path
45
+ alias_method :logical_path, :lookup_path
46
+
47
+ protected
48
+
49
+ def fetch_config(key, fallback = nil, &block)
50
+ Utils.value_or_fallback(nil, fallback, &block)
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,80 @@
1
+ module Lookbook
2
+ class Page < Entity
3
+ include Locatable
4
+ include Navigable
5
+
6
+ attr_reader :content, :sections
7
+
8
+ def initialize(file_path)
9
+ @file_path = Pathname(file_path)
10
+ @base_directories = Engine.page_paths
11
+ @lookup_path = PathUtils.to_lookup_path(relative_file_path)
12
+ @frontmatter, @content = FrontmatterExtractor.call(file_contents)
13
+ @position_prefixes = true
14
+ @sections = []
15
+ end
16
+
17
+ def title
18
+ @_title ||= fetch_config(:title, label)
19
+ end
20
+
21
+ def landing?
22
+ @_landing ||= fetch_config(:landing, false)
23
+ end
24
+
25
+ def markdown?
26
+ @_markdown ||= fetch_config(:markdown) { file_path.to_s.match?(/(.*)\.md\.(.*)$/) }
27
+ end
28
+
29
+ def header?
30
+ @_header ||= fetch_config(:header, true)
31
+ end
32
+
33
+ def footer?
34
+ @_footer ||= fetch_config(:footer, true)
35
+ end
36
+
37
+ def data
38
+ return @_data if @_data
39
+
40
+ config_data = fetch_config(:data, {})
41
+ @_data ||= config_data.is_a?(Hash) ? Store.new(config_data) : config_data
42
+ end
43
+
44
+ def search_terms
45
+ label
46
+ end
47
+
48
+ def url_path
49
+ lookbook_page_path(path)
50
+ end
51
+
52
+ def add_section(section)
53
+ @sections << section
54
+ @sections.sort_by! { |section| [section.position, section.label] }
55
+ end
56
+
57
+ def method_missing(method_name, *args, &block)
58
+ method_name.to_s.end_with?("=") ? super : frontmatter.fetch(method_name, nil)
59
+ end
60
+
61
+ def respond_to_missing?(method_name, include_private = false)
62
+ frontmatter.key?(method_name) || super
63
+ end
64
+
65
+ protected
66
+
67
+ def fetch_config(key, fallback = nil, &block)
68
+ value = frontmatter[key]
69
+ Utils.value_or_fallback(value, fallback, &block)
70
+ end
71
+
72
+ def file_contents
73
+ @_file_contents ||= File.read(file_path)
74
+ end
75
+
76
+ def frontmatter
77
+ @_merged_frontmatter ||= Lookbook.config.page_options.deep_merge(@frontmatter.to_h).deep_symbolize_keys
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,43 @@
1
+ module Lookbook
2
+ class PageSection < Page
3
+ attr_accessor :parent
4
+
5
+ def initialize(file_path)
6
+ @file_path = Pathname(file_path)
7
+ @parent = nil
8
+ super
9
+ end
10
+
11
+ def name
12
+ Utils.name(name_parts[:name])
13
+ end
14
+
15
+ def lookup_path
16
+ directory = if relative_directory_path.present? && !relative_directory_path.to_s.start_with?(".")
17
+ relative_directory_path
18
+ end
19
+
20
+ path = PathUtils.to_path(directory, name_parts[:parent_name])
21
+ PathUtils.to_lookup_path(path)
22
+ end
23
+
24
+ def landing?
25
+ false
26
+ end
27
+
28
+ def url_path
29
+ nil
30
+ end
31
+
32
+ alias_method :page, :parent
33
+
34
+ protected
35
+
36
+ def name_parts
37
+ return @_name_parts if @_name_parts
38
+
39
+ matches = file_name(true).match(/(?<parent_name>.*)\[(?<name>.*)\]/)
40
+ @_name_parts ||= {name: matches[:name], parent_name: matches[:parent_name]}
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,87 @@
1
+ module Lookbook
2
+ class Preview < Entity
3
+ include Annotatable
4
+ include Locatable
5
+ include Navigable
6
+
7
+ delegate :render_args, to: :preview_class
8
+
9
+ attr_reader :preview_class
10
+
11
+ def initialize(code_object)
12
+ @code_object = code_object
13
+ @preview_class = code_object.path.constantize
14
+ @file_path = Pathname(code_object.file)
15
+ @base_directories = Engine.preview_paths
16
+
17
+ cleaned_path = relative_file_path.to_s
18
+ .gsub(/\/(component_preview|preview)(\..*)$/, "")
19
+ .gsub(/_component_preview(\..*)$/, "")
20
+
21
+ @lookup_path = PathUtils.to_lookup_path(cleaned_path)
22
+ end
23
+
24
+ def examples
25
+ @_examples ||= PreviewExampleCollection.new(load_examples)
26
+ end
27
+
28
+ def example(example_name)
29
+ examples.find { |m| m.name == example_name.to_s }
30
+ end
31
+
32
+ def visible_examples
33
+ @_visible_examples ||= PreviewExampleCollection.new(examples.select(&:visible?))
34
+ end
35
+
36
+ def default_example
37
+ visible_examples.first
38
+ end
39
+
40
+ def components
41
+ @_components ||= ComponentCollection.new(examples.flat_map(&:components).uniq(&:path))
42
+ end
43
+
44
+ def component
45
+ components.first
46
+ end
47
+
48
+ def display_options
49
+ global_options = Lookbook.config.preview_display_options
50
+ global_options.deep_merge(fetch_config(:display_options, {}))
51
+ end
52
+
53
+ def layout
54
+ preview_class.instance_variable_get(:@layout)
55
+ end
56
+
57
+ def url_path
58
+ lookbook_inspect_path(path)
59
+ end
60
+
61
+ def preview_class_name
62
+ preview_class.name
63
+ end
64
+
65
+ def guess_components
66
+ [preview_class.name.chomp("Preview").constantize]
67
+ rescue
68
+ []
69
+ end
70
+
71
+ protected
72
+
73
+ def load_examples
74
+ return example_entities unless code_object.groups.any?
75
+
76
+ example_entities.group_by(&:group).flat_map do |group_name, grouped_examples|
77
+ group_name.nil? ? grouped_examples : PreviewGroup.new(group_name.presence || label.pluralize, grouped_examples, self)
78
+ end
79
+ end
80
+
81
+ def example_entities
82
+ public_methods = preview_class.public_instance_methods(false)
83
+ method_objects = code_object.meths.select { |m| public_methods.include?(m.name) }
84
+ method_objects.map.with_index { |code_object, i| PreviewExample.new(code_object, self, position: i) }
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,100 @@
1
+ module Lookbook
2
+ class PreviewExample < Entity
3
+ include Inspectable
4
+ include Annotatable
5
+ include Navigable
6
+
7
+ delegate :group, to: :code_object
8
+
9
+ attr_reader :preview
10
+
11
+ def initialize(code_object, preview, position: nil)
12
+ @code_object = code_object
13
+ @preview = preview
14
+ @default_position = position
15
+ @lookup_path = "#{parent.lookup_path}/#{name}"
16
+ end
17
+
18
+ def id
19
+ @_id ||= Utils.id(fetch_config(:id) { "#{parent.id}-#{code_object.name}" })
20
+ end
21
+
22
+ def name
23
+ @_name ||= Utils.name(code_object.name)
24
+ end
25
+
26
+ def display_options
27
+ parent.display_options.merge(fetch_config(:display_options, {}))
28
+ end
29
+
30
+ def components
31
+ @_components ||= ComponentCollection.new(load_components)
32
+ end
33
+
34
+ def component
35
+ components.first
36
+ end
37
+
38
+ def examples
39
+ [self]
40
+ end
41
+
42
+ def template_source(template_path)
43
+ source_path = template_file_path(template_path)
44
+ source_path ? File.read(source_path) : nil
45
+ end
46
+
47
+ def template_lang(template_path)
48
+ path = template_file_path(template_path)
49
+ Lookbook::Lang.guess(path) || Lookbook::Lang.find(:html)
50
+ end
51
+
52
+ def search_terms
53
+ [parent.label, label]
54
+ end
55
+
56
+ def url_path
57
+ lookbook_inspect_path(path)
58
+ end
59
+
60
+ def type
61
+ :example
62
+ end
63
+
64
+ alias_method :parent, :preview
65
+ alias_method :lang, :source_lang
66
+
67
+ protected
68
+
69
+ def sort_handler(other_entity)
70
+ if Lookbook.config.sort_examples
71
+ label <=> other_entity.label
72
+ else
73
+ [position, label] <=> [other_entity.position, other_entity.label]
74
+ end
75
+ end
76
+
77
+ def format_source(source)
78
+ source.sub(/^def \w+\s?(\([^)]+\))?/m, "").split("\n")[0..-2].join("\n")
79
+ end
80
+
81
+ def template_file_path(template_path)
82
+ return full_template_path(template_path) if respond_to?(:full_template_path, true)
83
+
84
+ template_path = template_path.to_s.sub(/\..*$/, "")
85
+ base_path = Engine.preview_paths.detect do |p|
86
+ Dir["#{p}/#{template_path}.html.*"].first
87
+ end
88
+ path = Dir["#{base_path}/#{template_path}.html.*"].first
89
+ Pathname(path) if path
90
+ end
91
+
92
+ def load_components
93
+ component_classes = [*fetch_config(:components, []), *preview.send(:fetch_config, :components, [])]
94
+ component_classes = preview.guess_components if component_classes.empty?
95
+
96
+ components = component_classes.map { |klass| Component.new(klass) }
97
+ components.uniq(&:path)
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,48 @@
1
+ module Lookbook
2
+ class PreviewGroup < Entity
3
+ include Navigable
4
+
5
+ attr_reader :examples, :preview
6
+
7
+ def initialize(name, examples, preview)
8
+ @name = Utils.name(name)
9
+ @examples = PreviewExampleCollection.new(examples)
10
+ @preview = preview
11
+ @lookup_path = "#{parent.lookup_path}/#{@name}"
12
+ end
13
+
14
+ def display_options
15
+ merged = {}
16
+ examples.to_a.reverse.map do |example|
17
+ merged.merge!(example.display_options)
18
+ end
19
+ merged
20
+ end
21
+
22
+ def components
23
+ @_components ||= ComponentCollection.new(examples.flat_map(&:components).uniq(&:path))
24
+ end
25
+
26
+ def search_terms
27
+ [parent.label, label]
28
+ end
29
+
30
+ def tags(tag_name = nil)
31
+ examples.flat_map { |example| example.tags(tag_name) }
32
+ end
33
+
34
+ def tag(tag_name = nil)
35
+ tags(tag_name).first
36
+ end
37
+
38
+ def url_path
39
+ lookbook_inspect_path(path)
40
+ end
41
+
42
+ def type
43
+ :group
44
+ end
45
+
46
+ alias_method :parent, :preview
47
+ end
48
+ end
@@ -8,7 +8,7 @@ module Lookbook
8
8
  end
9
9
 
10
10
  def watch(paths, extensions = ".*", opts = nil, &block)
11
- paths = PathUtils.normalize_all(paths)
11
+ paths = PathUtils.normalize_paths(paths)
12
12
 
13
13
  if paths.any?
14
14
  opts = opts.to_h
data/lib/lookbook/lang.rb CHANGED
@@ -1,46 +1,23 @@
1
1
  module Lookbook
2
2
  module Lang
3
3
  class << self
4
- LANGUAGES = [
5
- {
6
- name: "ruby",
7
- ext: ".rb",
8
- label: "Ruby",
9
- comment: "# %s"
10
- },
11
- {
12
- name: "html",
13
- ext: ".html",
14
- label: "HTML",
15
- comment: "<!-- %s -->"
16
- },
17
- {
18
- name: "erb",
19
- ext: ".erb",
20
- label: "ERB",
21
- comment: "<%%# %s %%>"
22
- },
23
- {
24
- name: "haml",
25
- ext: ".haml",
26
- label: "Haml",
27
- comment: "<!-- %s -->"
28
- },
29
- {
30
- name: "slim",
31
- ext: ".slim",
32
- label: "Slim",
33
- comment: "<!-- %s -->"
34
- }
35
- ]
4
+ CONFIG_FILE = "config/languages.yml"
5
+ LANGUAGES = [] # retained for backwards compatability
36
6
 
37
7
  def find(name)
38
- LANGUAGES.find { |l| l[:name] == name.to_s }
8
+ languages.find { |l| l[:name] == name.to_s }
39
9
  end
40
10
 
41
- def guess(path)
11
+ def guess(path, fallback_name = nil)
42
12
  ext = File.extname(path)
43
- LANGUAGES.find { |l| l[:ext] == ext }
13
+ lang = languages.find { |l| l[:ext] == ext }
14
+ lang || (find(fallback_name) if fallback_name)
15
+ end
16
+
17
+ protected
18
+
19
+ def languages
20
+ @_languages ||= [*ConfigLoader.call(CONFIG_FILE).definitions, *LANGUAGES]
44
21
  end
45
22
  end
46
23
  end
@@ -33,10 +33,10 @@ module Lookbook
33
33
  end
34
34
 
35
35
  def input_options
36
- return @input_options if @input_options
36
+ return @_input_options if @_input_options
37
37
 
38
38
  runtime_options = options.except([*methods, :name, :value_default, :description])
39
- @input_options ||= Store.new(input_config.options.merge(runtime_options))
39
+ @_input_options ||= Store.new(input_config.options.merge(runtime_options))
40
40
  end
41
41
 
42
42
  def input_partial
@@ -26,7 +26,7 @@ module Lookbook
26
26
  end
27
27
 
28
28
  def paths
29
- PathUtils.normalize_all(@paths).map { |path| "#{path}/**/*preview.rb" }
29
+ PathUtils.normalize_paths(@paths).map { |path| "#{path}/**/*preview.rb" }
30
30
  end
31
31
 
32
32
  protected
@@ -0,0 +1,37 @@
1
+ module Lookbook
2
+ class RenderedExample
3
+ delegate_missing_to :example
4
+
5
+ attr_reader :output, :example
6
+
7
+ def initialize(example, output, params)
8
+ @example = example
9
+ @params = params
10
+ @output = output
11
+ end
12
+
13
+ def source
14
+ has_custom_template? ? template_source(template) : example.source
15
+ end
16
+
17
+ def source_lang
18
+ has_custom_template? ? template_lang(template) : example.source_lang
19
+ end
20
+
21
+ protected
22
+
23
+ attr_reader :params
24
+
25
+ def render_args
26
+ @_render_args ||= preview.render_args(example.name, params: params)
27
+ end
28
+
29
+ def template
30
+ render_args[:template]
31
+ end
32
+
33
+ def has_custom_template?
34
+ template != "view_components/preview" && !custom_source?
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,14 @@
1
+ module Lookbook
2
+ class CodeIndenter < Service
3
+ def initialize(source)
4
+ @source = source.to_s
5
+ end
6
+
7
+ def call
8
+ source = @source.chomp
9
+ last = source.split(/\r?\n/).last
10
+ indent = last ? last[/^([ \t]*)/, 1].length : 0
11
+ source.gsub(/^[ \t]{#{indent}}/, "")
12
+ end
13
+ end
14
+ end
@@ -11,8 +11,8 @@ module Lookbook
11
11
  @permit_eval = permit_eval
12
12
  @fail_silently = fail_silently
13
13
  @fallback = fallback
14
- @base_dir = base_dir
15
- @file = file
14
+ @base_dir = base_dir.to_s
15
+ @file = file.to_s
16
16
  end
17
17
 
18
18
  def call
@@ -22,7 +22,7 @@ module Lookbook
22
22
  end
23
23
 
24
24
  def resolve_path(path, base_dir)
25
- path.start_with?(".") ? File.expand_path(path, base_dir) : Rails.root.join(path)
25
+ Pathname(path.start_with?(".") ? File.expand_path(path, base_dir) : Rails.root.join(path))
26
26
  end
27
27
  end
28
28
  end