Sha256: a358274726a6f18244770d39713da3693948f6666686ce171830313f4f495f4e

Contents?: true

Size: 1.41 KB

Versions: 5

Compression:

Stored size: 1.41 KB

Contents

module Lookbook
  class PreviewExample
    include Taggable

    attr_reader :name

    def initialize(name, preview)
      @name = name
      @preview = preview
    end

    def id
      path.underscore.tr("_", "-")
    end

    def path
      "#{@preview.lookbook_path}/#{name}"
    end

    def label
      lookbook_label.presence || name.titleize
    end

    def method_source
      code_object.source.split("\n")[1..-2].join("\n").strip_heredoc
    end

    def source_lang
      Lookbook::Lang.find(:ruby)
    end

    def template_source(template_path)
      File.read(full_template_path(template_path))
    end

    def template_lang(template_path)
      Lookbook::Lang.guess(full_template_path(template_path)) || Lookbook::Lang.find(:html)
    end

    def type
      :example
    end

    def filter_match_string
      [*@preview.lookbook_parent_collections, @preview.label, label].join("/").gsub(/\s/, "").downcase
    end

    def hierarchy_depth
      @preview.lookbook_hierarchy_depth + 1
    end

    private

    def taggable_object_path
      "#{@preview.name}##{name}"
    end

    def full_template_path(template_path)
      base_path = Array(Lookbook.config.preview_paths).detect do |p|
        Dir["#{p}/#{template_path}.html.*"].first
      end
      Pathname.new(Dir["#{base_path}/#{template_path}.html.*"].first)
    end

    alias_method :notes, :lookbook_notes
    alias_method :hidden?, :lookbook_hidden?
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
lookbook-0.2.4 lib/lookbook/preview_example.rb
lookbook-0.2.3 lib/lookbook/preview_example.rb
lookbook-0.2.2 lib/lookbook/preview_example.rb
lookbook-0.2.1 lib/lookbook/preview_example.rb
lookbook-0.2.0 lib/lookbook/preview_example.rb