Sha256: f0717da6843eb4bb788e052a25be3b3a5ddc7cc5beb7ec740510a050776417e6

Contents?: true

Size: 1.24 KB

Versions: 2

Compression:

Stored size: 1.24 KB

Contents

module Plotline
  class EntryPresenter < BasePresenter
    presents :entry

    def body_markdown
      text = parse_custom_markdown(@object.body.to_s)
      RDiscount.new(text, :smart, :footnotes).to_html.html_safe
    end

    def photoset_item(src:, alt:, attrs:)
      img = images_hash[src]
      attrs["class"] = "photoset-item " + attrs["class"].to_s

      photoset_item_html(img, src, alt, attrs, image_attrs(img))
    end

    def photoset_item_html(img, src, alt, attrs, image_attrs)
      content_tag(:figure, attrs) do
        concat image_tag(src, { alt: alt }.merge(image_attrs))
        concat content_tag(:figcaption, alt)
      end
    end

    def single_image_html(src:, alt:, attrs:)
      content_tag(:figure, attrs) do
        concat image_tag(src, alt: alt)
        concat content_tag(:figcaption, alt)
      end
    end

    def image_attrs(img)
      return { data: {} } unless img

      { data: { width: img.width, height: img.height, ratio: img.ratio } }
    end

    private

    def parse_custom_markdown(text)
      Plotline::CustomMarkdownParser.new(self).parse(text)
    end

    def images_hash
      @images_hash ||= Plotline::Image.all.each_with_object({}) do |img, hash|
        hash[img.image] = img
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
plotline-0.1.1 app/presenters/plotline/entry_presenter.rb
plotline-0.1.0 app/presenters/plotline/entry_presenter.rb