Module: Jekyll::DistorteD::Molecule::PDF
- Includes:
- Cooltrainer::DistorteD::PDF
- Defined in:
- lib/distorted-jekyll/molecule/pdf.rb
Instance Method Summary collapse
-
#pdf_open_params ⇒ Object
Generate a Hash of our PDF Open Params based on any given to the Liquid tag and any loaded from the defaults.
-
#pdf_open_params_url ⇒ Object
Generate the URL fragment version of the PDF Open Params.
- #render_to_output_buffer(context, output) ⇒ Object
Instance Method Details
#pdf_open_params ⇒ Object
Generate a Hash of our PDF Open Params based on any given to the Liquid tag and any loaded from the defaults. www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/pdf_open_parameters.pdf
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/distorted-jekyll/molecule/pdf.rb', line 17 def pdf_open_params PDF_OPEN_PARAMS.map{ |p| if ATTRIBUTES_VALUES.dig(p) == BOOLEAN_ATTR_VALUES # Support multiple ways people might want to express a boolean if Set[0, '0'.freeze, false, 'false'.freeze].include?(abstract(p)) [p, '0'.freeze] elsif Set[1, '1'.freeze, true, 'true'.freeze].include?(abstract(p)) [p, '1'.freeze] end else [p, abstract(p)] end }.to_h end |
#pdf_open_params_url ⇒ Object
Generate the URL fragment version of the PDF Open Params. This would be difficult / impossible to construct within Liquid from the individual variables, so let’s just do it out here.
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/distorted-jekyll/molecule/pdf.rb', line 35 def pdf_open_params_url pdf_open_params.keep_if{ |p,v| v != nil && v != "" }.map{ |k,v| # The PDF Open Params docs specify `search` should be quoted. if k == :search "#{k}=\"#{v}\"" else "#{k}=#{v}" end }.join('&') end |
#render_to_output_buffer(context, output) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/distorted-jekyll/molecule/pdf.rb', line 48 def render_to_output_buffer(context, output) super begin # TODO: iOS treats our <object> like an <img>, # showing only the first page with transparency and stretched to the # size of the container element. # We will need something like PDF.js in an <iframe> to handle this. output << parse_template.render({ 'name' => @name, 'path' => @relative_dest, 'alt' => abstract(:alt), 'title' => abstract(:title), 'height' => abstract(:height), 'width' => abstract(:width), 'caption' => abstract(:caption), 'pdf_open_params' => pdf_open_params_url, }) rescue Liquid::SyntaxError => l unless Jekyll.env == 'production'.freeze output << parse_template(name: 'error_code'.freeze).render({ 'message' => l., }) end end output end |