Class: MakePDF::Processor::Site

Inherits:
Object
  • Object
show all
Includes:
MakePDF::PathManip
Defined in:
lib/make_pdf/jekyll.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from MakePDF::PathManip

#relative_path

Constructor Details

#initialize(site, **options) ⇒ Site

Returns a new instance of Site.



140
141
142
143
144
145
146
147
# File 'lib/make_pdf/jekyll.rb', line 140

def initialize(site, **options)
  config = site.config["make-pdf"]||{}
  @logger = MakePDF::Logger.new(logger: ::Jekyll.logger, level: (config["log-map-level"] || :debug))
  @site         = site
  @options = default_options.merge(make_options(@site.config["make-pdf"], options))
  @queue        = []
  logger.debug("Initialized with #{self.options}.")
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



118
119
120
# File 'lib/make_pdf/jekyll.rb', line 118

def logger
  @logger
end

#optionsObject (readonly)

Returns the value of attribute options.



118
119
120
# File 'lib/make_pdf/jekyll.rb', line 118

def options
  @options
end

#siteObject (readonly)

Returns the value of attribute site.



118
119
120
# File 'lib/make_pdf/jekyll.rb', line 118

def site
  @site
end

Instance Method Details

#<<(doc) ⇒ Object



154
155
156
157
158
159
160
161
# File 'lib/make_pdf/jekyll.rb', line 154

def <<(doc)
  processor = Processor.new(self, doc, **@options)
  if processor.valid?
    queue(processor)
  else
    logger.info("Skip #{doc.name} => #{processor.reason}")
  end
end

#default_optionsObject



120
121
122
123
124
125
126
127
128
# File 'lib/make_pdf/jekyll.rb', line 120

def default_options
  return { 
    output_base_path: site.source, 
    input_location: path_of(site.dest),
    input_base_url: relative_path_of(site.baseurl[1..]),
    input_host: site.config["url"].match(Regexp.new("^[^:]*://\([^/]+\)/?.*$"))[1],
    input_scheme: "file"
  }.freeze
end

#make_options(options, *more_options) ⇒ Object



130
131
132
133
134
135
136
137
138
# File 'lib/make_pdf/jekyll.rb', line 130

def make_options(options, *more_options)
  return {} if options.nil?

  [ options, more_options ].flatten
    .reduce(:merge)
    .transform_keys do |key|
      key.to_s.sub("-", "_").to_sym
    end
end

#processObject



163
164
165
166
167
# File 'lib/make_pdf/jekyll.rb', line 163

def process
  @queue.each do |processor|
    processor.process(**@options)
  end
end

#queue(processor) ⇒ Object



149
150
151
152
# File 'lib/make_pdf/jekyll.rb', line 149

def queue(processor)
  logger.info("Adding #{processor.name} to queue")
  @queue.push(processor)
end