Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow URLs as images #1308

Closed
wants to merge 2 commits into from

Conversation

bgvo
Copy link

@bgvo bgvo commented Aug 8, 2023

Using Prawn in an environment where assets are served dynamically can be painful. This aims to solve it.

For instance, using Rails' ActionController helper asset_path to retrieve a specific image is convenient. Trying to come up with rules to assess the asset relative path looks brittle. Precisely, frameworks like the Asset Pipeline solves this. However, Prawn lacks support for these scenarios.

An example of how this can be useful:

class Reports::Client
  include ActionView::Helpers::AssetUrlHelper

  attr_reader :client
  def initialize(client)
    @client = client
  end

  def as_pdf
    Prawn::Document.new do |pdf|
      pdf.image ActionController::Base.helpers.asset_path("logo.png")
      pdf.text "Home Safety Report"
      pdf.text "Prepared for: #{client.name}"

      pdf.image client.image_url, width: 200, height: 200
    end
  end
end

@pointlessone
Copy link
Member

Thank you for your contribution.

However, URI.open is generally considered unsecure. I'm not claiming Prawn is absolutely secure but I don't want to open this particular door. It's not that much of a code for the user to implement. If they want to go this route, I'd rather they make this decision consciously.

@bgvo bgvo force-pushed the feature/support_urls_for_images branch from fefd1d2 to 68d0ec3 Compare August 8, 2023 13:08
Using Prawn in an environment where assets are served
dynamically can be painful. This aims to solve it.

For instance, it is convenient to use Rails' ActionController
helper asset_path to retrieve a specific image. Trying to come
up with rules to assess the asset relative path looks brittle.
Precisely, frameworks like the Asset Pipeline solves this.
However, Prawn lacks support for these scenarios.
@bgvo bgvo force-pushed the feature/support_urls_for_images branch from 68d0ec3 to 0ea0aa7 Compare August 8, 2023 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants