Sha256: 2bc5845837e589e27080e50773dd26b9e43cd8ec56c479d8f6b3a30b6e1cb67a

Contents?: true

Size: 666 Bytes

Versions: 1

Compression:

Stored size: 666 Bytes

Contents

# encoding: utf-8

module PagesCore
  class FileEmbedder
    include ActionView::Helpers::AssetTagHelper

    attr_reader :files

    def initialize(files)
      @files = Array(files)
    end

    def to_html
      embed_files(files.map { |f| embed_file(f) })
    end

    def embed_files(embedded_files)
      embedded_files.join(", ")
    end

    def embed_file(file)
      content_tag(
        :a,
        file.name,
        class: "file",
        href: file_path(file)
      )
    end

    private

    def file_path(file)
      Rails.application.routes.url_helpers.page_file_path(
        file.locale,
        file.page,
        file
      )
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pages_core-3.5.1 lib/pages_core/file_embedder.rb