class DocumentExporter::Base

Public Class Methods

new(document, options = {}) click to toggle source
# File lib/document_exporter/base.rb, line 9
def initialize(document, options = {})
  @document = document
  @options = options
end
pdf_key(type) click to toggle source
# File lib/document_exporter/base.rb, line 5
def self.pdf_key(type)
  type == 'full' ? 'pdf' : "pdf_#{type}"
end

Public Instance Methods

export() click to toggle source
# File lib/document_exporter/base.rb, line 14
def export
  raise NotImplementedError
end
included_materials(context_type: :default) click to toggle source

Take into consideration that in one component materilas are uniq. So just the first occurence of exluded material is removed

# File lib/document_exporter/base.rb, line 22
def included_materials(context_type: :default)
  parts = context_type == :default ? @document.document_parts.default : @document.document_parts.gdoc

  @included_materials ||= [].tap do |result|
    # Take non optional materials ONLY
    result.concat parts.general.pluck(:materials).flatten.compact

    @options[:excludes]&.each do |x|
      next unless (part = parts.find_by anchor: x)

      # if it's optional activity - add it
      # otherwise - delete it from result
      part.materials.compact.each do |id|
        part.optional? ? result.push(id) : result.delete_at(result.index(id))
      end
    end
  end.map(&:to_i)
end
ordered_materials(material_ids) click to toggle source
# File lib/document_exporter/base.rb, line 41
def ordered_materials(material_ids)
  @document.ordered_material_ids & material_ids
end

Private Instance Methods

base_path(name) click to toggle source
# File lib/document_exporter/base.rb, line 47
def base_path(name)
  File.join('documents', 'pdf', name)
end
render_template(path, layout:) click to toggle source
# File lib/document_exporter/base.rb, line 51
def render_template(path, layout:)
  field = path.starts_with?('/') ? :file : :template
  Lcms::Engine::ApplicationController.render(
    field => path,
    layout: layout,
    assigns: { document: @document, options: @options }
  )
end
template_path(name) click to toggle source
# File lib/document_exporter/base.rb, line 60
def template_path(name)
  base_path(name)
end