Class: MakePDF::Processor
- Inherits:
-
Object
- Object
- MakePDF::Processor
- Defined in:
- lib/make_pdf/jekyll.rb
Overview
MakePDF Jekyll plugin
Defined Under Namespace
Classes: Site
Instance Attribute Summary collapse
-
#doc ⇒ Object
readonly
Returns the value of attribute doc.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#reason ⇒ Object
readonly
Returns the value of attribute reason.
Instance Method Summary collapse
- #check_failure(condition, message) ⇒ Object
- #filter_options(document, **options) ⇒ Object
-
#initialize(site, current_doc, **options) ⇒ Processor
constructor
A new instance of Processor.
- #method_missing(method_name, *args, **options) ⇒ Object
- #output_dir ⇒ Object
- #process(**options) ⇒ Object
- #render_option(**options) ⇒ Object
- #targets ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(site, current_doc, **options) ⇒ Processor
Returns a new instance of Processor.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/make_pdf/jekyll.rb', line 40 def initialize(site, current_doc, **) @site = site @file = current_doc.destination(@base_source) @options = (current_doc, **) @name = current_doc.name logger.debug("base_paths: input → #{@options[:input_base_url]} output → #{@options[:output_base_path]} host → #{@options[:input_host]}") = (@options, , (current_doc)) logger.debug("options : #{}") return if check_failure([:disabled], "MakePDF disabled") return if check_failure(File.extname(@file) != '.html', "#{@file} is not an html") return if check_failure([:make_pdf].nil? && !@opt_in, "#{current_doc.name} has not opted in") return if check_failure([:make_pdf] == false, "#{current_doc.name} has opted out") writer = [:writer] || site.[:writer] return if check_failure(writer.nil?, "No writer defined for #{current_doc.name} (#{writer})") @writer = MakePDF.const_get(writer.capitalize).new(logger:, **) @doc = current_doc end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, **options) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/make_pdf/jekyll.rb', line 75 def method_missing(method_name, *args, **) if @options.include?(method_name) return @options[method_name] elsif not @site..nil? and @site..include?(method_name) return @site.[method_name] elsif @site.respond_to?(method_name, false) return @site.send(method_name, *args, **) else super end end |
Instance Attribute Details
#doc ⇒ Object (readonly)
Returns the value of attribute doc.
10 11 12 |
# File 'lib/make_pdf/jekyll.rb', line 10 def doc @doc end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
10 11 12 |
# File 'lib/make_pdf/jekyll.rb', line 10 def name @name end |
#reason ⇒ Object (readonly)
Returns the value of attribute reason.
10 11 12 |
# File 'lib/make_pdf/jekyll.rb', line 10 def reason @reason end |
Instance Method Details
#check_failure(condition, message) ⇒ Object
16 17 18 19 |
# File 'lib/make_pdf/jekyll.rb', line 16 def check_failure(condition, ) @reason = if condition condition end |
#filter_options(document, **options) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/make_pdf/jekyll.rb', line 21 def (document, **) document.data.filter_map do |key, value| key = key.to_s if key == "make-pdf" possible = { "" => true, "true" => true, "yes" => true, "false" => false, "no" => false } [ key, possible[value.to_s.downcase] ] else [ key.sub("make-pdf-", "").to_sym, value ] if key.start_with?("make-pdf-") end end.to_h.merge() end |
#output_dir ⇒ Object
67 68 69 |
# File 'lib/make_pdf/jekyll.rb', line 67 def output_dir @writer.output_dir end |
#process(**options) ⇒ Object
107 108 109 110 111 112 113 114 |
# File 'lib/make_pdf/jekyll.rb', line 107 def process(**) render_option(**) unless self.targets.nil? self.targets.split(",").each do |option| render_option(version: option.split(","), **) end end end |
#render_option(**options) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/make_pdf/jekyll.rb', line 87 def render_option(**) logger.debug("MakePDF rendering options #{}") attempted = 0 begin logger.info("processing #{@file}") @writer.process(@file, **.merge(@options)) rescue => error attempted += 1 if attempted <= 2 logger.warn("Failed to generate #{@file} retrying #{attempted}") logger.warn("ERROR: #{error}") retry else logger.warn("Skipping generation of #{@file} with #{}") raise error end end end |
#targets ⇒ Object
71 72 73 |
# File 'lib/make_pdf/jekyll.rb', line 71 def targets @options[:targets] || "" end |
#valid? ⇒ Boolean
12 13 14 |
# File 'lib/make_pdf/jekyll.rb', line 12 def valid? @reason.nil? end |