lib/lookbook/entities/preview_example.rb in lookbook-1.4.0 vs lib/lookbook/entities/preview_example.rb in lookbook-1.4.1

- old
+ new

@@ -6,13 +6,14 @@ delegate :group, to: :code_object attr_reader :preview - def initialize(code_object, preview) + def initialize(code_object, preview, position: nil) @code_object = code_object @preview = preview + @default_position = position @lookup_path = "#{parent.lookup_path}/#{name}" end def id @_id ||= Utils.id(fetch_config(:id) { "#{parent.id}-#{code_object.name}" }) @@ -62,9 +63,17 @@ alias_method :parent, :preview alias_method :lang, :source_lang protected + + def sort_handler(other_entity) + if Lookbook.config.sort_examples + label <=> other_entity.label + else + [position, label] <=> [other_entity.position, other_entity.label] + end + end def format_source(source) source.sub(/^def \w+\s?(\([^)]+\))?/m, "").split("\n")[0..-2].join("\n") end