lib/lookbook/preview_example.rb in lookbook-0.4.4 vs lib/lookbook/preview_example.rb in lookbook-0.4.5

- old
+ new

@@ -8,11 +8,11 @@ @name = name @preview = preview end def id - path.underscore.tr("_", "-") + path.underscore.tr("/", "-").tr("_", "-") end def path "#{@preview.lookbook_path}/#{name}" end @@ -23,10 +23,16 @@ def display_params @preview.display_params.merge(lookbook_display_params) end + def params + @params || code_object&.tags("param")&.map do |param| + Lookbook::Params.build_param(param, parameter_defaults[param.name]) + end + end + def method_source code_object.source.split("\n")[1..-2].join("\n").strip_heredoc end def source_lang @@ -52,9 +58,15 @@ def hierarchy_depth @preview.lookbook_hierarchy_depth + 1 end private + + def parameter_defaults + @parameter_defaults || code_object&.parameters&.map do |param_str| + Lookbook::Params.parse_method_param_str(param_str) + end&.compact&.to_h + end def taggable_object_path "#{@preview.name}##{name}" end