Module: PdfMyUrl
- Defined in:
- lib/pdf-my-url.rb,
lib/pdf-my-url/railtie.rb,
lib/pdf-my-url/version.rb
Defined Under Namespace
Classes: Railtie
Constant Summary collapse
- VERSION =
"1.0.1"
Instance Method Summary collapse
-
#pdf_my_url(name, url, options = {}) ⇒ Object
Create a link with the approriate parameters to the service.
Instance Method Details
#pdf_my_url(name, url, options = {}) ⇒ Object
Create a link with the approriate parameters to the service.
Options:
-
:protocol - set a custom protocol (the default is ‘http’ and ‘https’ is supported)
-
:filename - set a custom name to download (the default is the filename made from the url)
-
:orientation - set a document orientation to landscape (:landscape) or portrait (:portrait)
-
:proxy - set a custom proxy to access the url
-
:username - set a http authentication username used when accessing the url
-
:password - set a http authentication password used when accessing the url
-
:page
-
:size - set a page size (for example: ‘A4’ or ‘Letter’)
-
:width - set a page width (for example: ‘200mm’) with a default unit of millimeters
-
:height - set a page height (for example: ‘300mm’) with a default unit of millimeters
-
-
:margin
-
:top - set a margin (for example: ‘10mm’) or use the default 10mm
-
:left - set a margin (for example: ‘10mm’) or use the default 10mm
-
:right - set a margin (for example: ‘10mm’) or use the default 10mm
-
:bottom - set a margin (for example: ‘10mm’) or use the default 10mm
-
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/pdf-my-url.rb', line 26 def pdf_my_url(name, url, = {}) protocol = [:protocol] || 'http' [:page ] ||= {} [:margin] ||= {} parameters = "?url=#{url}" parameters += "&--filename=#{[:filename]}" if [:filename] parameters += "&--orientation=Portrait" if [:orientation] == :portrait parameters += "&--orientation=Landscape" if [:orientation] == :landscape parameters += "&--proxy=#{[:proxy]}" if [:proxy] parameters += "&--username=#{[:username]}" if [:username] parameters += "&--password=#{[:password]}" if [:password] parameters += "&--page-size=#{[:page][:size]}" if [:page][:size ] parameters += "&--page-width=#{[:page][:width]}" if [:page][:width ] parameters += "&--page-height=#{[:page][:height]}" if [:page][:height] parameters += "&--margin-top=#{[:margin][:top]}" if [:margin][:top ] parameters += "&--margin-left=#{[:margin][:left]}" if [:margin][:left ] parameters += "&--margin-right=#{[:margin][:right]}" if [:margin][:right ] parameters += "&--margin-bottom=#{[:margin][:bottom]}" if [:margin][:bottom] link_to name, "#{protocol}://pdfmyurl.com#{parameters}" end |