lookbook 1.0.0 → 1.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +4 -4
  3. data/app/assets/lookbook/js/app.js +1 -0
  4. data/app/assets/lookbook/js/lib/socket.js +9 -5
  5. data/app/components/lookbook/base_component.rb +10 -2
  6. data/app/components/lookbook/copy_button/component.rb +1 -1
  7. data/app/components/lookbook/dimensions_display/component.rb +1 -4
  8. data/app/components/lookbook/embed/component.html.erb +5 -5
  9. data/app/components/lookbook/embed/component.rb +2 -2
  10. data/app/components/lookbook/header/component.html.erb +4 -4
  11. data/app/components/lookbook/icon/component.html.erb +1 -1
  12. data/app/components/lookbook/icon/component.rb +1 -5
  13. data/app/components/lookbook/inspector_panel/component.rb +1 -2
  14. data/app/components/lookbook/nav/component.html.erb +1 -1
  15. data/app/components/lookbook/nav/item/component.rb +2 -2
  16. data/app/components/lookbook/params_editor/field/component.rb +1 -1
  17. data/app/components/lookbook/tabs/component.js +2 -2
  18. data/app/controllers/lookbook/application_controller.rb +10 -1
  19. data/app/controllers/lookbook/pages_controller.rb +0 -1
  20. data/app/controllers/lookbook/previews_controller.rb +29 -24
  21. data/app/helpers/lookbook/component_helper.rb +5 -0
  22. data/app/views/layouts/lookbook/application.html.erb +6 -36
  23. data/app/views/lookbook/index.html.erb +3 -3
  24. data/app/views/lookbook/previews/show.html.erb +3 -3
  25. data/config/routes.rb +2 -2
  26. data/lib/lookbook/component.rb +4 -0
  27. data/lib/lookbook/config.rb +7 -3
  28. data/lib/lookbook/data.rb +2 -2
  29. data/lib/lookbook/engine.rb +80 -75
  30. data/lib/lookbook/page.rb +4 -4
  31. data/lib/lookbook/parser.rb +19 -11
  32. data/lib/lookbook/preview.rb +28 -78
  33. data/lib/lookbook/preview_controller.rb +19 -1
  34. data/lib/lookbook/preview_example.rb +12 -5
  35. data/lib/lookbook/source_inspector.rb +2 -2
  36. data/lib/lookbook/store.rb +2 -2
  37. data/lib/lookbook/version.rb +1 -1
  38. data/lib/tasks/lookbook_tasks.rake +1 -2
  39. data/public/lookbook-assets/css/lookbook.css +8 -34
  40. data/public/lookbook-assets/css/lookbook.css.map +1 -1
  41. data/public/lookbook-assets/js/lookbook.js +175 -121
  42. data/public/lookbook-assets/js/lookbook.js.map +1 -1
  43. metadata +2 -2
@@ -5,7 +5,7 @@ require "lookbook/store"
5
5
  module Lookbook
6
6
  class Config
7
7
  def initialize
8
- @options = Store.new
8
+ @options = Store.new({}, true)
9
9
 
10
10
  @options.set({
11
11
  project_name: "Lookbook",
@@ -24,6 +24,7 @@ module Lookbook
24
24
  preview_display_params: {},
25
25
  preview_srcdoc: nil,
26
26
  preview_tags: {},
27
+ preview_disable_action_view_annotations: true,
27
28
  sort_examples: false,
28
29
 
29
30
  listen: Rails.env.development?,
@@ -31,10 +32,9 @@ module Lookbook
31
32
  listen_extensions: ["rb", "html.*"],
32
33
  listen_use_polling: false,
33
34
 
34
- cable_mount_path: "/lookbook-cable",
35
+ cable_mount_path: "/cable",
35
36
  cable_logger: Lookbook.logger,
36
37
 
37
- runtime_parsing: !Rails.env.production?,
38
38
  parser_registry_path: "tmp/storage/.yardoc",
39
39
 
40
40
  ui_theme: "indigo",
@@ -104,6 +104,10 @@ module Lookbook
104
104
  })
105
105
  end
106
106
 
107
+ def runtime_parsing=(value)
108
+ Lookbook.logger.warn "The `runtime_parsing` config option has been deprecated and will be removed in v2.0"
109
+ end
110
+
107
111
  def project_name
108
112
  @options.project_name == false ? nil : @options.project_name
109
113
  end
data/lib/lookbook/data.rb CHANGED
@@ -1,11 +1,11 @@
1
1
  module Lookbook
2
2
  module Data
3
3
  def data
4
- @data ||= Store.new
4
+ @data ||= Store.new({}, true)
5
5
  end
6
6
 
7
7
  def data=(props)
8
- @data = Store.new(props)
8
+ @data = Store.new(props, true)
9
9
  end
10
10
  end
11
11
  end
@@ -1,7 +1,6 @@
1
1
  require "view_component"
2
2
  require "action_cable/engine"
3
3
  require "listen"
4
- require "rake"
5
4
 
6
5
  module Lookbook
7
6
  autoload :Config, "lookbook/config"
@@ -36,7 +35,7 @@ module Lookbook
36
35
  {
37
36
  version: version,
38
37
  env: Rails.env.to_s,
39
- config: config
38
+ config: config.to_h
40
39
  }
41
40
  end
42
41
 
@@ -44,18 +43,10 @@ module Lookbook
44
43
  Preview.all
45
44
  end
46
45
 
47
- def previews?
48
- Preview.any?
49
- end
50
-
51
46
  def pages
52
47
  Page.all
53
48
  end
54
49
 
55
- def pages?
56
- Page.any?
57
- end
58
-
59
50
  def broadcast(event_name, data = {})
60
51
  Engine.websocket&.broadcast(event_name.to_s, data)
61
52
  end
@@ -100,6 +91,11 @@ module Lookbook
100
91
  @preview_controller = Lookbook.config.preview_controller.constantize
101
92
  @preview_controller.include(Lookbook::PreviewController)
102
93
 
94
+ parser.after_parse do |registry|
95
+ Preview.load!(registry.all(:class))
96
+ reload_ui
97
+ end
98
+
103
99
  if Gem::Version.new(Rails.version) >= Gem::Version.new("6.1.3.1")
104
100
  # Rails.application.server is only available for newer Rails versions
105
101
  Rails.application.server do
@@ -107,89 +103,82 @@ module Lookbook
107
103
  end
108
104
  else
109
105
  # Fallback for older Rails versions - don't start listeners if running in a rake task.
110
- unless File.basename($0) == "rake" || Rake.application.top_level_tasks.any?
106
+ unless Lookbook::Engine.prevent_listening?
111
107
  init_listeners
112
108
  end
113
109
  end
114
110
 
115
- if config.lookbook.runtime_parsing
116
- Lookbook::Engine.parser.parse
117
- else
118
- unless File.exist?(config.lookbook.parser_registry_path)
119
- Lookbook.logger.warn "
120
- Runtime parsing is disabled but no registry file has been found.
121
- Did you run `rake lookbook:preparse` before starting the app?
122
- Expected to find registry file at #{config.lookbook.parser_registry_path}
123
- "
124
- end
111
+ parser.parse do
112
+ Lookbook::Engine.run_hooks(:after_initialize)
125
113
  end
126
-
127
- Lookbook::Engine.run_hooks(:after_initialize)
128
- end
129
-
130
- def init_listeners
131
- return unless config.lookbook.listen == true
132
- Listen.logger = Lookbook.logger
133
- Lookbook.logger.info "Initializing listeners"
134
-
135
- preview_listener = Listen.to(
136
- *config.lookbook.listen_paths,
137
- only: /\.(#{config.lookbook.listen_extensions.join("|")})$/,
138
- force_polling: config.lookbook.listen_use_polling
139
- ) do |modified, added, removed|
140
- changes = {modified: modified, added: added, removed: removed}
141
- begin
142
- Lookbook::Engine.parser.parse
143
- rescue
144
- end
145
- Lookbook::Preview.clear_cache
146
- Lookbook::Engine.reload_ui(changes)
147
- Lookbook::Engine.run_hooks(:after_change, changes)
148
- end
149
- Lookbook::Engine.register_listener(preview_listener)
150
-
151
- page_listener = Listen.to(
152
- *config.lookbook.page_paths,
153
- only: /\.(html.*|md.*)$/,
154
- force_polling: config.lookbook.listen_use_polling
155
- ) do |modified, added, removed|
156
- changes = {modified: modified, added: added, removed: removed}
157
- Lookbook::Engine.reload_ui(changes)
158
- Lookbook::Engine.run_hooks(:after_change, changes)
159
- end
160
- Lookbook::Engine.register_listener(page_listener)
161
114
  end
162
115
 
163
116
  at_exit do
164
117
  if Lookbook::Engine.listeners.any?
165
118
  Lookbook.logger.debug "Stopping listeners"
166
- Lookbook::Engine.listeners.each { |listener| listener.stop }
119
+ Lookbook::Engine.stop_listeners
167
120
  end
168
121
  Lookbook::Engine.run_hooks(:before_exit)
169
122
  end
170
123
 
171
124
  class << self
125
+ def init_listeners
126
+ config = Lookbook.config
127
+ return unless config.listen == true
128
+ Listen.logger = Lookbook.logger
129
+
130
+ listen_paths = config.listen_paths.uniq
131
+ if listen_paths.any?
132
+ preview_listener = Listen.to(*listen_paths,
133
+ only: /\.(#{config.listen_extensions.join("|")})$/,
134
+ force_polling: config.listen_use_polling) do |modified, added, removed|
135
+ parser.parse do
136
+ run_hooks(:after_change, {modified: modified, added: added, removed: removed})
137
+ end
138
+ end
139
+ register_listener(preview_listener)
140
+ end
141
+
142
+ page_paths = config.page_paths.uniq
143
+ if page_paths.any?
144
+ page_listener = Listen.to(*page_paths,
145
+ only: /\.(html.*|md.*)$/,
146
+ force_polling: config.listen_use_polling) do |modified, added, removed|
147
+ changes = {modified: modified, added: added, removed: removed}
148
+ reload_ui
149
+ run_hooks(:after_change, changes)
150
+ end
151
+ register_listener(page_listener)
152
+ end
153
+ end
154
+
172
155
  def websocket
156
+ config = Lookbook.config
173
157
  return @websocket unless @websocket.nil?
174
- if config.lookbook.auto_refresh
175
- cable = ActionCable::Server::Configuration.new
176
- cable.cable = {adapter: "async"}.with_indifferent_access
177
- cable.mount_path = config.lookbook.cable_mount_path
178
- cable.connection_class = -> { Lookbook::Connection }
179
- cable.logger = config.lookbook.cable_logger
180
-
181
- @websocket ||= if Rails.version.to_f >= 6.0
182
- ActionCable::Server::Base.new(config: cable)
183
- else
184
- ws = ActionCable::Server::Base.new
185
- ws.config = cable
186
- ws
187
- end
158
+ return unless config.auto_refresh == true && config.listen == true && !Rails.env.test?
159
+ Lookbook.logger.info "Initializing websocket"
160
+
161
+ cable = ActionCable::Server::Configuration.new
162
+ cable.cable = {adapter: "async"}.with_indifferent_access
163
+ cable.mount_path = nil
164
+ cable.connection_class = -> { Lookbook::Connection }
165
+ cable.logger = config.cable_logger
166
+
167
+ @websocket ||= if Gem::Version.new(Rails.version) >= Gem::Version.new(6.0)
168
+ ActionCable::Server::Base.new(config: cable)
169
+ else
170
+ ws = ActionCable::Server::Base.new
171
+ ws.config = cable
172
+ ws
188
173
  end
189
174
  end
190
175
 
191
176
  def websocket_mount_path
192
- "#{mounted_path}#{config.lookbook.cable_mount_path}" if websocket
177
+ "#{mounted_path}#{config.lookbook.cable_mount_path}".gsub("//", "/") if websocket?
178
+ end
179
+
180
+ def websocket?
181
+ websocket.present?
193
182
  end
194
183
 
195
184
  def mounted_path
@@ -197,7 +186,7 @@ module Lookbook
197
186
  end
198
187
 
199
188
  def parser
200
- @parser ||= Lookbook::Parser.new(config.lookbook.preview_paths, config.lookbook.parser_registry_path)
189
+ @parser ||= Lookbook::Parser.new(config.lookbook.preview_paths)
201
190
  end
202
191
 
203
192
  def log_level
@@ -222,14 +211,30 @@ module Lookbook
222
211
  @listeners ||= []
223
212
  end
224
213
 
214
+ def stop_listeners
215
+ listeners.each { |listener| listener.stop }
216
+ end
217
+
225
218
  def run_hooks(event_name, *args)
226
219
  config.lookbook.hooks[event_name].each do |hook|
227
220
  hook.call(Lookbook, *args)
228
221
  end
229
222
  end
230
223
 
231
- def reload_ui(changed = {})
232
- websocket&.broadcast("reload", changed)
224
+ def reload_ui
225
+ websocket&.broadcast("reload", {})
226
+ end
227
+
228
+ def prevent_listening?
229
+ Rails.env.test? || running_in_rake_task?
230
+ end
231
+
232
+ def running_in_rake_task?
233
+ if defined?(Rake) && Rake.respond_to?(:application)
234
+ File.basename($0) == "rake" || Rake.application.top_level_tasks.any?
235
+ else
236
+ false
237
+ end
233
238
  end
234
239
 
235
240
  attr_reader :preview_controller
data/lib/lookbook/page.rb CHANGED
@@ -13,7 +13,7 @@ module Lookbook
13
13
  :data
14
14
  ]
15
15
 
16
- attr_reader :errors
16
+ attr_reader :errors, :rel_path
17
17
  attr_accessor :sections
18
18
 
19
19
  def initialize(path, base_path)
@@ -23,8 +23,8 @@ module Lookbook
23
23
  @errors = []
24
24
  @sections = []
25
25
  @page_name = remove_position_prefix(path_name)
26
- rel_path = @pathname.relative_path_from(@base_path)
27
- page_path = rel_path.dirname.to_s == "." ? @page_name : "#{rel_path.dirname}/#{@page_name}"
26
+ @rel_path = @pathname.relative_path_from(@base_path)
27
+ page_path = @rel_path.dirname.to_s == "." ? @page_name : "#{@rel_path.dirname}/#{@page_name}"
28
28
  super(page_path)
29
29
  end
30
30
 
@@ -33,7 +33,7 @@ module Lookbook
33
33
  end
34
34
 
35
35
  def full_path
36
- Rails.root.join(@pathname.to_s)
36
+ Pathname.new Rails.root.join(@pathname.to_s)
37
37
  end
38
38
 
39
39
  def name
@@ -3,24 +3,32 @@ require "yard"
3
3
  module Lookbook
4
4
  class Parser
5
5
  attr_reader :registry_path
6
- def initialize(paths, registry_path)
6
+ def initialize(paths)
7
7
  @paths = paths.map { |p| "#{p}/**/*preview.rb" }
8
- @registry_path = registry_path.to_s
9
- YARD::Registry.yardoc_file = registry_path
8
+ @after_parse_callbacks = []
9
+ @after_parse_once_callbacks = []
10
+ @parsing = false
11
+
12
+ YARD::Parser::SourceParser.after_parse_list do
13
+ [*@after_parse_callbacks, *@after_parse_once_callbacks].each do |callback|
14
+ callback.call(YARD::Registry)
15
+ end
16
+ @after_parse_once_callbacks = []
17
+ @parsing = false
18
+ end
10
19
  end
11
20
 
12
- def parse
13
- YARD::Registry.clear
14
- YARD::Registry.lock_for_writing do
21
+ def parse(&block)
22
+ unless @parsing
23
+ @parsing = true
24
+ @after_parse_once_callbacks << block if block
25
+ YARD::Registry.clear
15
26
  YARD.parse(@paths)
16
- YARD::Registry.save(false, registry_path)
17
27
  end
18
28
  end
19
29
 
20
- def get_code_object(path)
21
- registry = YARD::RegistryStore.new
22
- registry.load!(registry_path)
23
- registry.get(path)
30
+ def after_parse(&block)
31
+ @after_parse_callbacks << block
24
32
  end
25
33
 
26
34
  class << self
@@ -5,9 +5,9 @@ module Lookbook
5
5
  delegate :name, :render_args, to: :@preview
6
6
  delegate :position, :group, :notes, :hidden?, :tags, :tag, to: :@preview_inspector
7
7
 
8
- def initialize(preview)
8
+ def initialize(preview, code_object)
9
9
  @preview = preview
10
- @preview_inspector = SourceInspector.new(@preview.name)
10
+ @preview_inspector = SourceInspector.new(code_object)
11
11
  super(preview_class_path(@preview.name))
12
12
  end
13
13
 
@@ -35,7 +35,7 @@ module Lookbook
35
35
  return @examples if @examples.present?
36
36
  public_methods = @preview.public_instance_methods(false)
37
37
  public_method_objects = @preview_inspector&.methods&.select { |m| public_methods.include?(m.name) }
38
- examples = (public_method_objects || []).map { |m| PreviewExample.new(m.name.to_s, self) }
38
+ examples = (public_method_objects || []).map { |m| PreviewExample.new(m.name.to_s, self, m) }
39
39
  sorted = Lookbook.config.sort_examples ? examples.sort_by(&:label) : examples
40
40
  @examples = []
41
41
  if @preview_inspector&.groups&.any?
@@ -61,11 +61,15 @@ module Lookbook
61
61
  examples.first
62
62
  end
63
63
 
64
+ def rel_path
65
+ "#{name.underscore}.rb"
66
+ end
67
+
64
68
  def full_path
65
69
  base_path = Array(Lookbook.config.preview_paths).detect do |preview_path|
66
- Dir["#{preview_path}/#{name.underscore}.rb"].first
70
+ Dir["#{preview_path}/#{rel_path}"].first
67
71
  end
68
- Pathname.new(Dir["#{base_path}/#{name.underscore}.rb"].first)
72
+ Pathname.new(Dir["#{base_path}/#{rel_path}"].first)
69
73
  end
70
74
 
71
75
  def url_path
@@ -105,6 +109,9 @@ module Lookbook
105
109
 
106
110
  protected
107
111
 
112
+ @preview_objects = nil
113
+ @previews = nil
114
+
108
115
  def guess_component
109
116
  name.chomp("Preview").constantize
110
117
  rescue
@@ -125,26 +132,20 @@ module Lookbook
125
132
  end
126
133
 
127
134
  def all
128
- load_previews if preview_files.size > ViewComponent::Preview.descendants.size
129
-
130
- @previews = nil if cache_stale?
131
- return @previews unless @previews.nil?
132
-
133
- previews = ViewComponent::Preview.descendants.map do |p|
134
- new(p)
135
- rescue
136
- Rails.logger.error "[lookbook] error instantiating preview\n#{exception.full_message}"
137
- end
138
-
139
- if errors.any?
140
- errors.each do |error|
141
- Rails.logger.error "[lookbook] preview error\n#{error.full_message}\n"
142
- end
135
+ if @previews.nil? && @preview_objects.present?
136
+ previews = @preview_objects.map do |code_object|
137
+ klass = code_object.path.constantize
138
+ new(klass, code_object) if klass.ancestors.include?(ViewComponent::Preview)
139
+ rescue => exception
140
+ Lookbook.logger.error Lookbook::Error.new(exception)
141
+ nil
142
+ end.compact
143
+
144
+ sorted_previews = previews.compact.sort_by { |preview| [preview.position, preview.label] }
145
+ @previews = PreviewCollection.new(sorted_previews)
146
+ else
147
+ PreviewCollection.new([])
143
148
  end
144
-
145
- sorted_previews = previews.compact.sort_by { |preview| [preview.position, preview.label] }
146
- @previews = PreviewCollection.new(sorted_previews)
147
- mark_as_cached if Lookbook.config.listen == true
148
149
  @previews
149
150
  end
150
151
 
@@ -152,60 +153,9 @@ module Lookbook
152
153
  @errors ||= []
153
154
  end
154
155
 
155
- def clear_cache
156
- cache_dir = File.dirname(cache_marker_path)
157
- FileUtils.mkdir_p(cache_dir) unless File.exist?(cache_dir)
158
- File.write(cache_marker_path, Time.now.to_i)
159
- end
160
-
161
- protected
162
-
163
- def cache_marker_path
164
- Rails.root.join("tmp/cache/lookbook-previews")
165
- end
166
-
167
- def cache_stale?
168
- return false if !File.exist?(cache_marker_path)
169
- cache_timestamp = File.read(cache_marker_path).to_i
170
- if @last_cache_timestamp.nil? || cache_timestamp > @last_cache_timestamp
171
- @last_cache_timestamp = cache_timestamp
172
- true
173
- else
174
- false
175
- end
176
- end
177
-
178
- def mark_as_cached
179
- cache_dir = File.dirname(cache_marker_path)
180
- FileUtils.mkdir_p(cache_dir) unless File.exist?(cache_dir)
181
- File.write(cache_marker_path, Time.now)
182
- end
183
-
184
- def load_previews
185
- @errors = []
186
- preview_files.each do |file|
187
- require_dependency file[:path]
188
- rescue SyntaxError, StandardError => exception
189
- @errors.push(
190
- Lookbook::Error.new(exception,
191
- title: "Preview #{exception.class}",
192
- file_name: file[:rel_path],
193
- file_path: file[:path])
194
- )
195
- end
196
- end
197
-
198
- def preview_files
199
- files = Array(Lookbook.config.preview_paths).map do |preview_path|
200
- Dir["#{preview_path}/**/*preview.rb"].map do |path|
201
- {
202
- path: path,
203
- base_path: preview_path,
204
- rel_path: Pathname(path).relative_path_from(Pathname.new(preview_path)).to_s
205
- }
206
- end
207
- end
208
- files.flatten
156
+ def load!(preview_objects)
157
+ @preview_objects = preview_objects
158
+ @previews = nil
209
159
  end
210
160
  end
211
161
 
@@ -11,7 +11,10 @@ module Lookbook
11
11
  opts = {}
12
12
  opts[:layout] = nil
13
13
  opts[:locals] = locals if locals.present?
14
- render html: render_to_string(template, **opts)
14
+
15
+ with_optional_annotations do
16
+ render html: render_to_string(template, **opts)
17
+ end
15
18
  end
16
19
 
17
20
  def render_in_layout_to_string(template, locals, opts = {})
@@ -22,5 +25,20 @@ module Lookbook
22
25
  end
23
26
  render html: html
24
27
  end
28
+
29
+ def with_optional_annotations
30
+ if ActionView::Base.respond_to?(:annotate_rendered_view_with_filenames) && Lookbook.config.preview_disable_action_view_annotations
31
+ original_value = ActionView::Base.annotate_rendered_view_with_filenames
32
+ ActionView::Base.annotate_rendered_view_with_filenames = false
33
+
34
+ res = yield
35
+
36
+ ActionView::Base.annotate_rendered_view_with_filenames = original_value
37
+
38
+ res
39
+ else
40
+ yield
41
+ end
42
+ end
25
43
  end
26
44
  end
@@ -3,10 +3,10 @@ module Lookbook
3
3
  attr_reader :name, :preview
4
4
  delegate :params, :position, :group, :notes, :hidden?, :source, :tags, :tag, to: :@example_inspector
5
5
 
6
- def initialize(name, preview)
6
+ def initialize(name, preview, code_object)
7
7
  @name = name
8
8
  @preview = preview
9
- @example_inspector = SourceInspector.new("#{@preview.name}##{name}")
9
+ @example_inspector = SourceInspector.new(code_object)
10
10
  super("#{@preview.path}/#{name}")
11
11
  end
12
12
 
@@ -27,7 +27,7 @@ module Lookbook
27
27
  end
28
28
 
29
29
  def method_source
30
- @example_inspector.source.split("\n")[1..-2].join("\n").strip_heredoc
30
+ @example_inspector.source.sub(/^def \w+\s?(\([^)]+\))?/m, "").split("\n")[0..-2].join("\n").strip_heredoc.strip
31
31
  end
32
32
 
33
33
  def lang
@@ -35,7 +35,8 @@ module Lookbook
35
35
  end
36
36
 
37
37
  def template_source(template_path)
38
- File.read(full_template_path(template_path))
38
+ source_path = full_template_path(template_path)
39
+ source_path ? File.read(source_path) : nil
39
40
  end
40
41
 
41
42
  def template_lang(template_path)
@@ -56,11 +57,17 @@ module Lookbook
56
57
 
57
58
  protected
58
59
 
60
+ def strip_ext(path)
61
+ path.sub(/\..*$/, "")
62
+ end
63
+
59
64
  def full_template_path(template_path)
65
+ template_path = strip_ext template_path
60
66
  base_path = Array(Lookbook.config.preview_paths).detect do |p|
61
67
  Dir["#{p}/#{template_path}.html.*"].first
62
68
  end
63
- Pathname.new(Dir["#{base_path}/#{template_path}.html.*"].first)
69
+ path = Dir["#{base_path}/#{template_path}.html.*"].first
70
+ path ? Pathname.new(path) : nil
64
71
  end
65
72
 
66
73
  class << self
@@ -5,8 +5,8 @@ module Lookbook
5
5
  attr_reader :code_object
6
6
  delegate :groups, :source, to: :@code_object, allow_nil: true
7
7
 
8
- def initialize(taggable_object_path)
9
- @code_object = Lookbook::Engine.parser.get_code_object(taggable_object_path)
8
+ def initialize(code_object)
9
+ @code_object = code_object
10
10
  end
11
11
 
12
12
  def hidden?
@@ -1,6 +1,6 @@
1
1
  module Lookbook
2
2
  class Store < ActiveSupport::OrderedOptions
3
- def initialize(data = {}, deep = true)
3
+ def initialize(data = {}, deep = false)
4
4
  super()
5
5
  @deep = deep
6
6
  set(data) if data.present?
@@ -42,7 +42,7 @@ module Lookbook
42
42
  end
43
43
 
44
44
  def normalize_value(value)
45
- @deep && value.is_a?(Hash) ? Store.new(value) : value
45
+ @deep && !value.is_a?(Store) && value.is_a?(Hash) ? Store.new(value, @deep) : value
46
46
  end
47
47
  end
48
48
  end
@@ -1,3 +1,3 @@
1
1
  module Lookbook
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.8"
3
3
  end
@@ -4,8 +4,7 @@ namespace :lookbook do
4
4
  namespace :previews do
5
5
  desc "Preparse the previews"
6
6
  task preparse: :environment do
7
- Lookbook::Engine.parser.parse
8
- puts "Lookbook preview parsing complete"
7
+ puts "The lookbook:preparse task is no longer required and will be removed in v2.0"
9
8
  end
10
9
  end
11
10
  end