lookbook 0.9.1 → 1.0.0.beta.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (206) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +43 -859
  3. data/app/assets/lookbook/css/lookbook.css +55 -0
  4. data/app/assets/lookbook/css/themes/blue.css +42 -0
  5. data/app/assets/lookbook/css/themes/indigo.css +42 -0
  6. data/app/assets/lookbook/css/themes/zinc.css +42 -0
  7. data/app/assets/lookbook/css/{tooltip_theme.css → tooltip.css} +14 -8
  8. data/app/assets/lookbook/js/app.js +64 -63
  9. data/app/assets/lookbook/js/components/clipboard.js +47 -0
  10. data/app/assets/lookbook/js/components/tooltip.js +30 -0
  11. data/app/assets/lookbook/js/config.js +7 -4
  12. data/app/assets/lookbook/js/helpers/build.js +22 -0
  13. data/app/assets/lookbook/js/helpers/dom.js +45 -0
  14. data/app/assets/lookbook/js/helpers/layout.js +21 -0
  15. data/app/assets/lookbook/js/helpers/request.js +16 -0
  16. data/app/assets/lookbook/js/helpers/string.js +11 -0
  17. data/app/assets/lookbook/js/lib/socket.js +4 -3
  18. data/app/assets/lookbook/js/lib/tippy.js +8 -0
  19. data/app/assets/lookbook/js/lookbook.js +61 -0
  20. data/app/assets/lookbook/js/plugins/logger.js +39 -0
  21. data/app/assets/lookbook/js/stores/filter.js +2 -2
  22. data/app/assets/lookbook/js/stores/inspector.js +22 -16
  23. data/app/assets/lookbook/js/stores/layout.js +101 -5
  24. data/app/assets/lookbook/js/stores/nav.js +17 -16
  25. data/app/assets/lookbook/js/stores/pages.js +4 -2
  26. data/app/assets/lookbook/js/stores/settings.js +7 -0
  27. data/app/assets/lookbook/js/stores/workbench.js +29 -0
  28. data/app/components/lookbook/button/component.html.erb +28 -0
  29. data/app/components/lookbook/button/component.js +55 -0
  30. data/app/components/lookbook/button/component.rb +39 -0
  31. data/app/components/lookbook/button_group/component.html.erb +3 -0
  32. data/app/components/lookbook/button_group/component.rb +18 -0
  33. data/app/components/lookbook/code/component.css +57 -0
  34. data/app/components/lookbook/code/component.html.erb +10 -0
  35. data/app/components/lookbook/code/component.js +3 -0
  36. data/app/components/lookbook/code/component.rb +56 -0
  37. data/app/components/lookbook/code/highlight_github_light.css +217 -0
  38. data/app/components/lookbook/component.rb +41 -0
  39. data/app/components/lookbook/copy_button/component.html.erb +11 -0
  40. data/app/components/lookbook/copy_button/component.js +16 -0
  41. data/app/components/lookbook/copy_button/component.rb +23 -0
  42. data/app/components/lookbook/dimensions_display/component.html.erb +10 -0
  43. data/app/components/lookbook/dimensions_display/component.js +30 -0
  44. data/app/components/lookbook/dimensions_display/component.rb +18 -0
  45. data/app/components/lookbook/embed/component.html.erb +50 -0
  46. data/app/components/lookbook/embed/component.js +39 -0
  47. data/app/components/lookbook/embed/component.rb +22 -0
  48. data/app/components/lookbook/filter/component.html.erb +17 -0
  49. data/app/components/lookbook/filter/component.js +21 -0
  50. data/app/components/lookbook/filter/component.rb +15 -0
  51. data/app/components/lookbook/header/component.html.erb +79 -0
  52. data/app/components/lookbook/header/component.rb +9 -0
  53. data/app/components/lookbook/icon/component.css +11 -0
  54. data/app/components/lookbook/icon/component.html.erb +5 -0
  55. data/app/components/lookbook/icon/component.js +5 -0
  56. data/app/components/lookbook/icon/component.rb +23 -0
  57. data/app/components/lookbook/nav/component.html.erb +33 -0
  58. data/app/components/lookbook/nav/component.js +52 -0
  59. data/app/components/lookbook/nav/component.rb +37 -0
  60. data/app/components/lookbook/nav/item/component.html.erb +23 -0
  61. data/app/components/lookbook/nav/item/component.js +66 -0
  62. data/app/components/lookbook/nav/item/component.rb +84 -0
  63. data/app/components/lookbook/params_editor/component.html.erb +3 -0
  64. data/app/components/lookbook/params_editor/component.js +12 -0
  65. data/app/components/lookbook/params_editor/component.rb +11 -0
  66. data/app/components/lookbook/params_editor/field/component.html.erb +50 -0
  67. data/app/components/lookbook/params_editor/field/component.js +36 -0
  68. data/app/components/lookbook/params_editor/field/component.rb +41 -0
  69. data/app/components/lookbook/prose/component.css +12 -0
  70. data/app/components/lookbook/prose/component.html.erb +3 -0
  71. data/app/components/lookbook/prose/component.rb +26 -0
  72. data/app/components/lookbook/split_layout/component.html.erb +13 -0
  73. data/app/components/lookbook/split_layout/component.js +151 -0
  74. data/app/components/lookbook/split_layout/component.rb +11 -0
  75. data/app/components/lookbook/tabbed_content/component.html.erb +5 -0
  76. data/app/components/lookbook/tabbed_content/component.js +21 -0
  77. data/app/components/lookbook/tabbed_content/component.rb +20 -0
  78. data/app/components/lookbook/tabbed_content/section/component.html.erb +8 -0
  79. data/app/components/lookbook/tabbed_content/section/component.rb +9 -0
  80. data/app/components/lookbook/tabs/component.css +8 -0
  81. data/app/components/lookbook/tabs/component.html.erb +14 -0
  82. data/app/components/lookbook/tabs/component.js +107 -0
  83. data/app/components/lookbook/tabs/component.rb +30 -0
  84. data/app/components/lookbook/tabs/dropdown_tab/component.html.erb +14 -0
  85. data/app/components/lookbook/tabs/dropdown_tab/component.rb +16 -0
  86. data/app/components/lookbook/tabs/tab/component.html.erb +18 -0
  87. data/app/components/lookbook/tabs/tab/component.rb +16 -0
  88. data/app/components/lookbook/tag_component.rb +29 -0
  89. data/app/components/lookbook/toolbar/component.css +16 -0
  90. data/app/components/lookbook/toolbar/component.html.erb +5 -0
  91. data/app/components/lookbook/toolbar/component.rb +26 -0
  92. data/app/components/lookbook/viewport/component.css +11 -0
  93. data/app/components/lookbook/viewport/component.html.erb +57 -0
  94. data/app/{assets/lookbook/js/components/preview-window.js → components/lookbook/viewport/component.js} +57 -14
  95. data/app/components/lookbook/viewport/component.rb +21 -0
  96. data/app/controllers/lookbook/application_controller.rb +16 -5
  97. data/app/controllers/lookbook/pages_controller.rb +18 -10
  98. data/app/controllers/lookbook/previews_controller.rb +62 -25
  99. data/app/helpers/lookbook/application_helper.rb +7 -3
  100. data/app/helpers/lookbook/component_helper.rb +22 -10
  101. data/app/helpers/lookbook/output_helper.rb +8 -4
  102. data/app/helpers/lookbook/page_helper.rb +13 -21
  103. data/app/views/layouts/lookbook/application.html.erb +76 -28
  104. data/app/views/layouts/lookbook/inspector.html.erb +7 -0
  105. data/app/views/layouts/lookbook/page.html.erb +53 -0
  106. data/app/views/layouts/lookbook/shell.html.erb +64 -0
  107. data/app/views/layouts/lookbook/skeleton.html.erb +27 -10
  108. data/app/views/layouts/lookbook/standalone.html.erb +5 -0
  109. data/app/views/lookbook/404.html.erb +15 -0
  110. data/app/views/lookbook/error.html.erb +34 -34
  111. data/app/views/lookbook/index.html.erb +11 -6
  112. data/app/views/lookbook/pages/show.html.erb +29 -93
  113. data/app/views/{layouts/lookbook → lookbook}/preview.html.erb +3 -5
  114. data/app/views/lookbook/previews/panels/_notes.html.erb +19 -25
  115. data/app/views/lookbook/previews/panels/_output.html.erb +7 -18
  116. data/app/views/lookbook/previews/panels/_params.html.erb +13 -15
  117. data/app/views/lookbook/previews/panels/_preview.html.erb +6 -52
  118. data/app/views/lookbook/previews/panels/_source.html.erb +7 -16
  119. data/app/views/lookbook/previews/show.html.erb +130 -24
  120. data/config/routes.rb +7 -7
  121. data/lib/lookbook/code_formatter.rb +37 -13
  122. data/lib/lookbook/collection.rb +19 -16
  123. data/lib/lookbook/config.rb +125 -0
  124. data/lib/lookbook/engine.rb +66 -59
  125. data/lib/lookbook/entity.rb +47 -0
  126. data/lib/lookbook/error.rb +1 -2
  127. data/lib/lookbook/features.rb +1 -1
  128. data/lib/lookbook/markdown.rb +3 -4
  129. data/lib/lookbook/page.rb +26 -43
  130. data/lib/lookbook/page_collection.rb +8 -0
  131. data/lib/lookbook/params.rb +14 -3
  132. data/lib/lookbook/preview.rb +16 -7
  133. data/lib/lookbook/preview_collection.rb +8 -0
  134. data/lib/lookbook/preview_controller.rb +6 -2
  135. data/lib/lookbook/preview_example.rb +5 -6
  136. data/lib/lookbook/preview_group.rb +4 -9
  137. data/lib/lookbook/{code_inspector.rb → source_inspector.rb} +2 -2
  138. data/lib/lookbook/theme.rb +22 -0
  139. data/lib/lookbook/utils.rb +11 -3
  140. data/lib/lookbook/version.rb +1 -1
  141. data/lib/lookbook.rb +4 -1
  142. data/lib/tasks/lookbook_tasks.rake +12 -0
  143. data/public/lookbook-assets/css/app.css +2340 -1
  144. data/public/lookbook-assets/css/app.css.map +11 -1
  145. data/public/lookbook-assets/css/lookbook.css +3040 -0
  146. data/public/lookbook-assets/css/lookbook.css.map +1 -0
  147. data/public/lookbook-assets/css/themes/blue.css +44 -0
  148. data/public/lookbook-assets/css/themes/blue.css.map +1 -0
  149. data/public/lookbook-assets/css/themes/indigo.css +44 -0
  150. data/public/lookbook-assets/css/themes/indigo.css.map +1 -0
  151. data/public/lookbook-assets/css/themes/zinc.css +44 -0
  152. data/public/lookbook-assets/css/themes/zinc.css.map +1 -0
  153. data/public/lookbook-assets/js/app.js +10861 -1
  154. data/public/lookbook-assets/js/app.js.map +2571 -1
  155. data/public/lookbook-assets/js/embed.js +895 -1
  156. data/public/lookbook-assets/js/embed.js.map +1 -1
  157. data/public/lookbook-assets/js/lookbook.js +13529 -0
  158. data/public/lookbook-assets/js/lookbook.js.map +1 -0
  159. metadata +128 -116
  160. data/app/assets/lookbook/css/app.css +0 -161
  161. data/app/assets/lookbook/css/code_theme.css +0 -214
  162. data/app/assets/lookbook/js/components/app.js +0 -55
  163. data/app/assets/lookbook/js/components/code.js +0 -5
  164. data/app/assets/lookbook/js/components/copy.js +0 -20
  165. data/app/assets/lookbook/js/components/embed.js +0 -89
  166. data/app/assets/lookbook/js/components/filter.js +0 -35
  167. data/app/assets/lookbook/js/components/inspector.js +0 -66
  168. data/app/assets/lookbook/js/components/nav-group.js +0 -47
  169. data/app/assets/lookbook/js/components/nav-item.js +0 -29
  170. data/app/assets/lookbook/js/components/nav.js +0 -28
  171. data/app/assets/lookbook/js/components/page-tabs.js +0 -9
  172. data/app/assets/lookbook/js/components/page.js +0 -25
  173. data/app/assets/lookbook/js/components/param.js +0 -34
  174. data/app/assets/lookbook/js/components/sidebar.js +0 -18
  175. data/app/assets/lookbook/js/components/sizes.js +0 -16
  176. data/app/assets/lookbook/js/components/splitter.js +0 -25
  177. data/app/assets/lookbook/js/components/tabs.js +0 -52
  178. data/app/assets/lookbook/js/lib/split.js +0 -15
  179. data/app/assets/lookbook/js/stores/sidebar.js +0 -26
  180. data/app/views/layouts/lookbook/basic.html.erb +0 -7
  181. data/app/views/lookbook/components/_branding.html.erb +0 -8
  182. data/app/views/lookbook/components/_code.html.erb +0 -17
  183. data/app/views/lookbook/components/_copy_button.html.erb +0 -11
  184. data/app/views/lookbook/components/_drawer.html.erb +0 -112
  185. data/app/views/lookbook/components/_embed.html.erb +0 -39
  186. data/app/views/lookbook/components/_errors.html.erb +0 -13
  187. data/app/views/lookbook/components/_filter.html.erb +0 -18
  188. data/app/views/lookbook/components/_header.html.erb +0 -6
  189. data/app/views/lookbook/components/_icon.html.erb +0 -5
  190. data/app/views/lookbook/components/_nav.html.erb +0 -16
  191. data/app/views/lookbook/components/_nav_collection.html.erb +0 -5
  192. data/app/views/lookbook/components/_nav_group.html.erb +0 -14
  193. data/app/views/lookbook/components/_nav_item.html.erb +0 -24
  194. data/app/views/lookbook/components/_nav_page.html.erb +0 -22
  195. data/app/views/lookbook/components/_nav_preview.html.erb +0 -13
  196. data/app/views/lookbook/components/_not_found.html.erb +0 -11
  197. data/app/views/lookbook/components/_param.html.erb +0 -21
  198. data/app/views/lookbook/components/_preview.html.erb +0 -77
  199. data/app/views/lookbook/components/_sidebar.html.erb +0 -69
  200. data/app/views/lookbook/pages/not_found.html.erb +0 -15
  201. data/app/views/lookbook/previews/error.html.erb +0 -1
  202. data/app/views/lookbook/previews/inputs/_select.html.erb +0 -7
  203. data/app/views/lookbook/previews/inputs/_text.html.erb +0 -8
  204. data/app/views/lookbook/previews/inputs/_textarea.html.erb +0 -8
  205. data/app/views/lookbook/previews/inputs/_toggle.html.erb +0 -13
  206. data/app/views/lookbook/previews/not_found.html.erb +0 -23
@@ -34,8 +34,7 @@ module Lookbook
34
34
 
35
35
  {
36
36
  code: relevant_lines.join("\n").lstrip,
37
- start_line: start_line - empty_start_lines,
38
- end_line: end_line - empty_start_lines,
37
+ start_line: start_line,
39
38
  highlighted_line: highlighted_line - empty_start_lines
40
39
  }
41
40
  end
@@ -1,6 +1,6 @@
1
1
  module Lookbook
2
2
  module Features
3
- EXPERIMENTAL_FEATURES = [:pages]
3
+ EXPERIMENTAL_FEATURES = []
4
4
 
5
5
  def self.experimental_feature?(name)
6
6
  EXPERIMENTAL_FEATURES.include?(name.to_sym)
@@ -19,12 +19,11 @@ module Lookbook
19
19
  class Renderer < Redcarpet::Render::HTML
20
20
  def block_code(code, language = "ruby")
21
21
  line_numbers = language.to_s.end_with? "-numbered"
22
- ApplicationController.render "lookbook/components/_code", locals: {
23
- code: code,
22
+ ApplicationController.render(Lookbook::Code::Component.new(**{
23
+ source: code,
24
24
  language: language.to_s.chomp("-numbered"),
25
25
  line_numbers: line_numbers
26
- },
27
- layout: nil
26
+ }), layout: nil)
28
27
  end
29
28
  end
30
29
  end
data/lib/lookbook/page.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  module Lookbook
2
- class Page
3
- include Utils
2
+ class Page < Entity
4
3
 
5
4
  FRONTMATTER_FIELDS = [
6
5
  :id,
@@ -16,26 +15,19 @@ module Lookbook
16
15
  ]
17
16
 
18
17
  attr_reader :errors
19
- attr_accessor :tabs
20
18
 
21
19
  def initialize(path, base_path)
22
20
  @pathname = Pathname.new path
23
- @base_path = Pathname.new base_path
21
+ @base_path = base_path
24
22
  @options = nil
25
23
  @errors = []
26
- @tabs = []
27
- end
28
-
29
- def path
30
24
  rel_path = @pathname.relative_path_from(@base_path)
31
-
32
- _path = (rel_path.dirname.to_s == "." ? name : "#{rel_path.dirname}/#{name}")
33
- _path.gsub!("[#{tab}]", "") if tab?
34
- _path
25
+ page_path = (rel_path.dirname.to_s == "." ? name : "#{rel_path.dirname}/#{name}")
26
+ super(page_path)
35
27
  end
36
28
 
37
- def lookup_path
38
- @lookup_path ||= to_lookup_path(path)
29
+ def url_path
30
+ page_path lookup_path
39
31
  end
40
32
 
41
33
  def full_path
@@ -74,25 +66,28 @@ module Lookbook
74
66
  normalize_matchers(label)
75
67
  end
76
68
 
77
- def hierarchy_depth
78
- path.split("/").size
79
- end
80
-
81
69
  def parent_collections_names
82
70
  File.dirname(path).split("/")
83
71
  end
84
72
 
85
73
  def type
86
- tab? ? :tab : :page
74
+ :page
87
75
  end
88
76
 
89
- def tab
90
- matches = full_path.to_s.match(%r{\[(?<tab>\w+)\]})
91
- matches ? remove_position_prefix(matches[:tab]) : nil
77
+ def id
78
+ options[:id]
92
79
  end
93
80
 
94
- def tab?
95
- tab.present?
81
+ def position
82
+ options[:position]
83
+ end
84
+
85
+ def hidden
86
+ options[:hidden]
87
+ end
88
+
89
+ def label
90
+ options[:label]
96
91
  end
97
92
 
98
93
  def method_missing(method_name, *args, &block)
@@ -128,7 +123,7 @@ module Lookbook
128
123
  end
129
124
  @options = Lookbook.config.page_options.deep_merge(frontmatter).with_indifferent_access
130
125
  @options[:id] = @options[:id] ? generate_id(@options[:id]) : generate_id(lookup_path)
131
- @options[:label] ||= (tab? ? tab : name).titleize
126
+ @options[:label] ||= name.titleize
132
127
  @options[:title] ||= @options[:label]
133
128
  @options[:hidden] ||= false
134
129
  @options[:landing] ||= false
@@ -157,29 +152,17 @@ module Lookbook
157
152
  end
158
153
 
159
154
  def all
160
- pages, tabs =
161
- Array(page_paths).flat_map do |dir|
162
- Dir["#{dir}/**/*.html.*", "#{dir}/**/*.md.*"].sort.map do |page|
163
- page = Lookbook::Page.new(page, dir)
164
- end
165
- end.partition { |page| page.type == :page }
166
-
167
- sorted_pages = pages
168
- .uniq { |page| page.path }
169
- .sort_by { |page| [page.position, page.label] }
170
-
171
- page_dict = sorted_pages.index_by(&:path)
172
- sorted_tabs = tabs.sort_by { |tab| [tab.position, tab.label] }
173
-
174
- sorted_tabs.each do |tab|
175
- page_dict[tab.path].tabs << tab
155
+ pages = Array(page_paths).map do |dir|
156
+ Dir["#{dir}/**/*.html.*", "#{dir}/**/*.md.*"].sort.map do |page|
157
+ Lookbook::Page.new(page, dir)
158
+ end
176
159
  end
177
-
160
+ sorted_pages = pages.flatten.uniq { |p| p.path }.sort_by { |page| [page.position, page.label] }
178
161
  PageCollection.new(sorted_pages)
179
162
  end
180
163
 
181
164
  def page_paths
182
- Lookbook.config.page_paths.select { |dir| Dir.exist? dir }
165
+ Lookbook.config.page_paths.filter { |dir| Dir.exist? dir }
183
166
  end
184
167
  end
185
168
  end
@@ -4,6 +4,14 @@ module Lookbook
4
4
  generate_id("page-collection", lookup_path || "root")
5
5
  end
6
6
 
7
+ def label
8
+ "Pages"
9
+ end
10
+
11
+ def type
12
+ :page_collection
13
+ end
14
+
7
15
  def self.describe_as
8
16
  "pages"
9
17
  end
@@ -1,10 +1,21 @@
1
+ require "active_model"
2
+
1
3
  module Lookbook
2
4
  module Params
3
5
  class << self
4
- def build_param(param, default)
6
+ def build_param(param, default: nil, **opts)
5
7
  input, options_str = param.text.present? ? param.text.split(" ", 2) : [nil, ""]
6
8
  type = param.types&.first
7
- options = YAML.safe_load(options_str || "~")
9
+ options = if options_str.present? && options_str.end_with?(".json")
10
+ json_path = if options_str.start_with?(".")
11
+ File.expand_path(options_str, File.dirname(param.object.files.first[0]))
12
+ else
13
+ Rails.root.join(options_str)
14
+ end
15
+ JSON.parse(File.read(json_path))
16
+ else
17
+ YAML.safe_load(options_str || "~")
18
+ end
8
19
  input ||= guess_input(type, default)
9
20
  type ||= guess_type(input, default)
10
21
  {
@@ -93,7 +104,7 @@ module Lookbook
93
104
  "tel",
94
105
  "text",
95
106
  "url"
96
- ].include? input
107
+ ].include? input.to_s
97
108
  end
98
109
 
99
110
  def safe_parse_yaml(value, fallback)
@@ -1,5 +1,5 @@
1
1
  module Lookbook
2
- class Preview
2
+ class Preview < Collection
3
3
  include Utils
4
4
 
5
5
  delegate :name, :render_args, to: :@preview
@@ -7,7 +7,8 @@ module Lookbook
7
7
 
8
8
  def initialize(preview)
9
9
  @preview = preview
10
- @preview_inspector = CodeInspector.new(@preview.name)
10
+ @preview_inspector = SourceInspector.new(@preview.name)
11
+ super(preview_class_name(preview_class_basename(@preview.name)))
11
12
  end
12
13
 
13
14
  def id
@@ -33,7 +34,7 @@ module Lookbook
33
34
  def examples
34
35
  return @examples if @examples.present?
35
36
  public_methods = @preview.public_instance_methods(false)
36
- public_method_objects = @preview_inspector&.methods&.select { |m| public_methods.include?(m.name) }
37
+ public_method_objects = @preview_inspector&.methods&.filter { |m| public_methods.include?(m.name) }
37
38
  examples = (public_method_objects || []).map { |m| PreviewExample.new(m.name.to_s, self) }
38
39
  sorted = Lookbook.config.sort_examples ? examples.sort_by(&:label) : examples
39
40
  @examples = []
@@ -52,12 +53,12 @@ module Lookbook
52
53
  @examples = @examples.compact
53
54
  end
54
55
 
55
- def default_example
56
- examples.first
56
+ def items
57
+ examples.reject { |i| i.hidden? }
57
58
  end
58
59
 
59
- def path
60
- preview_class_name(preview_class_basename(name))
60
+ def default_example
61
+ examples.first
61
62
  end
62
63
 
63
64
  def full_path
@@ -67,6 +68,10 @@ module Lookbook
67
68
  Pathname.new(Dir["#{base_path}/#{name.underscore}.rb"].first)
68
69
  end
69
70
 
71
+ def url_path
72
+ inspect_path lookup_path
73
+ end
74
+
70
75
  def preview_paths
71
76
  ViewComponent::Base.preview_paths
72
77
  end
@@ -87,6 +92,10 @@ module Lookbook
87
92
  Lookbook.config.preview_display_params.deep_merge(@preview_inspector&.display_params)
88
93
  end
89
94
 
95
+ def collapsible?
96
+ true
97
+ end
98
+
90
99
  class << self
91
100
  def find(path)
92
101
  all.find { |p| p.lookup_path == path }
@@ -4,10 +4,18 @@ module Lookbook
4
4
  generate_id("preview-collection", lookup_path || "root")
5
5
  end
6
6
 
7
+ def label
8
+ "Previews"
9
+ end
10
+
7
11
  def find_example(path)
8
12
  Lookbook::PreviewExample.all.find { |e| e.lookup_path == path }
9
13
  end
10
14
 
15
+ def type
16
+ :preview_collection
17
+ end
18
+
11
19
  def self.describe_as
12
20
  "previews"
13
21
  end
@@ -14,9 +14,13 @@ module Lookbook
14
14
  render html: render_to_string(template, **opts)
15
15
  end
16
16
 
17
- def render_in_layout_to_string(template, locals, layout = nil)
17
+ def render_in_layout_to_string(template, locals, **opts)
18
18
  append_view_path Lookbook::Engine.root.join("app/views")
19
- render html: render_to_string(template, locals: locals, **determine_layout(layout))
19
+ html = render_to_string(template, locals: locals, **determine_layout(opts[:layout]))
20
+ if opts[:append_html].present?
21
+ html += opts[:append_html]
22
+ end
23
+ render html: html
20
24
  end
21
25
  end
22
26
  end
@@ -1,22 +1,21 @@
1
1
  module Lookbook
2
- class PreviewExample
3
- include Utils
4
-
2
+ class PreviewExample < Entity
5
3
  attr_reader :name, :preview
6
4
  delegate :params, :position, :group, :notes, :hidden?, :source, to: :@example_inspector
7
5
 
8
6
  def initialize(name, preview)
9
7
  @name = name
10
8
  @preview = preview
11
- @example_inspector = CodeInspector.new("#{@preview.name}##{name}")
9
+ @example_inspector = SourceInspector.new("#{@preview.name}##{name}")
10
+ super("#{@preview.path}/#{name}")
12
11
  end
13
12
 
14
13
  def id
15
14
  generate_id(@preview.id, name)
16
15
  end
17
16
 
18
- def path
19
- "#{@preview.path}/#{name}"
17
+ def url_path
18
+ inspect_path lookup_path
20
19
  end
21
20
 
22
21
  def label
@@ -1,21 +1,16 @@
1
1
  module Lookbook
2
- class PreviewGroup
3
- include Utils
4
-
2
+ class PreviewGroup < Entity
5
3
  attr_reader :name, :examples, :preview
6
4
 
7
5
  def initialize(name, preview, examples)
8
6
  @name = name
9
7
  @preview = preview
10
8
  @examples = examples
9
+ super("#{@preview.path}/#{name}")
11
10
  end
12
11
 
13
- def id
14
- generate_id(lookup_path)
15
- end
16
-
17
- def path
18
- "#{@preview.path}/#{name}"
12
+ def url_path
13
+ inspect_path lookup_path
19
14
  end
20
15
 
21
16
  def label
@@ -1,5 +1,5 @@
1
1
  module Lookbook
2
- class CodeInspector
2
+ class SourceInspector
3
3
  include Utils
4
4
 
5
5
  attr_reader :code_object
@@ -62,7 +62,7 @@ module Lookbook
62
62
 
63
63
  def params
64
64
  code_object&.tags("param")&.map do |param|
65
- Lookbook::Params.build_param(param, parameter_defaults[param.name])
65
+ Lookbook::Params.build_param(param, default: parameter_defaults[param.name])
66
66
  end
67
67
  end
68
68
 
@@ -0,0 +1,22 @@
1
+ module Lookbook
2
+ class Theme
3
+ def initialize(config = {})
4
+ @config = config
5
+ @css = nil
6
+ end
7
+
8
+ def to_css
9
+ return @css unless @css.nil?
10
+ @css ||= if @config.present?
11
+ styles = [":root {"]
12
+ styles << @config.map do |key, value|
13
+ " --lookbook-#{key.to_s.underscore.gsub("_","-")}: #{value};"
14
+ end
15
+ styles.push "}"
16
+ styles.join("\n")
17
+ else
18
+ ""
19
+ end
20
+ end
21
+ end
22
+ end
@@ -1,17 +1,19 @@
1
1
  module Lookbook
2
2
  module Utils
3
+ include Lookbook::Engine.routes.url_helpers
4
+
3
5
  POSITION_PREFIX_REGEX = /^(\d+?)[-_]/
4
6
  FRONTMATTER_REGEX = /\A---(.|\n)*?---/
5
7
 
6
8
  protected
7
9
 
8
10
  def generate_id(*args)
9
- parts = args.map { |arg| arg.to_s.force_encoding("UTF-8").parameterize.underscore }
10
- parts.join("-").tr("/", "-").tr("_", "-").delete_prefix("-").delete_suffix("-").gsub("--", "-")
11
+ parts = args.map { |arg| arg.to_s.parameterize.underscore }
12
+ parts.join("-").tr("/_", "-").delete_prefix("-").delete_suffix("-").gsub("--", "-")
11
13
  end
12
14
 
13
15
  def preview_class_basename(klass)
14
- class_name(klass).to_s.chomp("ComponentPreview").chomp("Component::Preview").chomp("::Preview").chomp("Component").chomp("::")
16
+ class_name(klass).to_s.chomp("ComponentPreview").chomp("Component::Preview").chomp("::Preview").chomp("Component").chomp("Preview").chomp("::")
15
17
  end
16
18
 
17
19
  def preview_class_name(klass)
@@ -50,6 +52,12 @@ module Lookbook
50
52
  args.flatten.map { |arg| preview_class_name(arg) }.join("/")
51
53
  end
52
54
 
55
+ protected
56
+
57
+ def default_url_options
58
+ {}
59
+ end
60
+
53
61
  private
54
62
 
55
63
  def parse_frontmatter(content)
@@ -1,3 +1,3 @@
1
1
  module Lookbook
2
- VERSION = "0.9.1"
2
+ VERSION = "1.0.0.beta.0"
3
3
  end
data/lib/lookbook.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require "active_support/dependencies/autoload"
2
2
  require "lookbook/engine"
3
3
  require "lookbook/version"
4
+ require "view_component/engine"
4
5
 
5
6
  module Lookbook
6
7
  extend ActiveSupport::Autoload
@@ -13,15 +14,17 @@ module Lookbook
13
14
  autoload :PageCollection, "lookbook/page_collection"
14
15
  autoload :Features, "lookbook/features"
15
16
  autoload :Collection, "lookbook/collection"
17
+ autoload :Entity, "lookbook/entity"
16
18
  autoload :Parser, "lookbook/parser"
17
19
  autoload :Preview, "lookbook/preview"
18
20
  autoload :PreviewCollection, "lookbook/preview_collection"
19
21
  autoload :PreviewController, "lookbook/preview_controller"
20
22
  autoload :PreviewExample, "lookbook/preview_example"
21
23
  autoload :PreviewGroup, "lookbook/preview_group"
22
- autoload :CodeInspector, "lookbook/code_inspector"
24
+ autoload :SourceInspector, "lookbook/source_inspector"
23
25
  autoload :CodeFormatter, "lookbook/code_formatter"
24
26
  autoload :Markdown, "lookbook/markdown"
27
+ autoload :Theme, "lookbook/theme"
25
28
 
26
29
  class << self
27
30
  include Utils
@@ -2,6 +2,18 @@ require_relative "../lookbook"
2
2
 
3
3
  namespace :lookbook do
4
4
 
5
+ desc "Run the rspec tests"
6
+ task :test do
7
+ sh "bundle exec rspec"
8
+ end
9
+
10
+ namespace :test do
11
+ desc "Start a server to view the test app"
12
+ task :serve do
13
+ sh "bundle exec rackup"
14
+ end
15
+ end
16
+
5
17
  namespace :previews do
6
18
  desc "Preparse the previews"
7
19
  task :preparse do