Sha256: bdebaeccfcc86acab612b77a166764fa662197a7c24be565e794453e7b7d10bf

Contents?: true

Size: 857 Bytes

Versions: 1

Compression:

Stored size: 857 Bytes

Contents

# frozen_string_literal: true

module Scrapbook
  # View helpers for the Scrapbook gem. Doesn't use standard Rail's helper
  # modules to avoid any conflicts with host app
  class HelperForView
    def initialize(view)
      self.view = view
    end

    def short_path_to(pathname, scrapbook = nil)
      scrapbook ||= Scrapbook.find_scrapbook_for(pathname)

      if scrapbook.root == ::Scrapbook::Engine.config.scrapbook.paths.first
        view.short_page_path(scrapbook.relative_page_path_for(pathname))
      else
        view.book_page_path(scrapbook.relative_page_path_for(pathname), book: scrapbook.name)
      end
    end

    def remove_handler_exts_from(pathname)
      pathname.dirname.join(
        pathname.basename.sub(/(?:.#{view.lookup_context.handlers.join('|.')})+\z/, '')
      )
    end

    private

    attr_accessor :view
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
scrapbook-0.2.1 app/helpers/scrapbook/helper_for_view.rb