Class: Bidi2pdfRails::Services::RenderOptionsHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/bidi2pdf_rails/services/render_options_handler.rb

Constant Summary collapse

PDF_OPTIONS =
PdfRenderer::PDF_OPTIONS
PdfRenderer::PRINT_URL_OPTIONS

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, options, controller, bidi2pdf_rails_config: Bidi2pdfRails.config) ⇒ RenderOptionsHandler

Returns a new instance of RenderOptionsHandler.



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/bidi2pdf_rails/services/render_options_handler.rb', line 15

def initialize(filename, options, controller, bidi2pdf_rails_config: Bidi2pdfRails.config)
  @original_options = options.deep_dup # Store original options

  pdf_opts = options.slice(*PDF_OPTIONS)
  print_url_opts = options.slice(*PRINT_URL_OPTIONS)
  html_opts = options.except(*PDF_OPTIONS + PRINT_URL_OPTIONS)

  @pdf = PdfOptions.new(filename, pdf_opts, controller, bidi2pdf_rails_config:)
  @url = PrintUrlOptions.new(print_url_opts, controller, bidi2pdf_rails_config:)
  @html = HtmlOptions.new(html_opts, @pdf, controller)
end

Instance Attribute Details

#htmlObject (readonly)

Returns the value of attribute html.



13
14
15
# File 'lib/bidi2pdf_rails/services/render_options_handler.rb', line 13

def html
  @html
end

#pdfObject (readonly)

Returns the value of attribute pdf.



13
14
15
# File 'lib/bidi2pdf_rails/services/render_options_handler.rb', line 13

def pdf
  @pdf
end

#urlObject (readonly)

Returns the value of attribute url.



13
14
15
# File 'lib/bidi2pdf_rails/services/render_options_handler.rb', line 13

def url
  @url
end

Instance Method Details

#inline_rendering_needed?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/bidi2pdf_rails/services/render_options_handler.rb', line 27

def inline_rendering_needed?
  !(@url.url? || @original_options[:inline])
end

#job_optionsObject



39
40
41
# File 'lib/bidi2pdf_rails/services/render_options_handler.rb', line 39

def job_options
  @original_options
end

#render_inline!Object

Call this method to render the HTML inline, within the controller, in cases where you want to render within the current controller context.



33
34
35
36
37
# File 'lib/bidi2pdf_rails/services/render_options_handler.rb', line 33

def render_inline!
  return unless inline_rendering_needed?

  @original_options[:inline] = html.html
end