class JekyllAsciidoctorPdf::BuildTask
Attributes
absolute_config_file[R]
absolute_cover_page[R]
absolute_output_path[R]
absolute_source_path[R]
absolute_theme_pdf[R]
absolute_working_path[R]
base_url[R]
description[RW]
@return [#to_s] description of the task.
git_info[R]
name[RW]
@return [#to_sym] name of the task.
parameters[RW]
permalinks[RW]
quiet[R]
Public Class Methods
callable_attr(attr_name, default_value = nil, &default_block)
click to toggle source
@private Defines attribute accessor with optional default value. When attribute's value is a Proc
with arity 0, then the attribute reader calls it and returns the result.
@param attr_name [#to_s] name of the attribute to define. @param default_value [Object] the default value (optional). @yield When the block is given, then it's used as a default value.
It takes precedence over the +default_value+. It's evaluated in an instance context.
# File lib/jekyll_asciidoctor_pdf/commands.rb, line 32 def self.callable_attr(attr_name, default_value = nil, &default_block) var_name = "@#{attr_name}".sub('?', '').to_sym define_method attr_name do value = instance_variable_get(var_name) if value.nil? && default_block do_in_working_dir { instance_eval &default_block } elsif value.nil? default_value elsif value.is_a?(Proc) && value.arity.zero? do_in_working_dir &value else value end end attr_writer attr_name.to_s.sub('?', '') end
new(name = :build_pdf) { |self| ... }
click to toggle source
# File lib/jekyll_asciidoctor_pdf/commands.rb, line 81 def initialize(name = :build_pdf) @name = name @description = 'Generate PDF files for each *.adoc in the source_list ' @absolute_working_path = Dir.pwd @permalinks = Hash.new @quiet = { verbose: true } yield self if block_given? @git_info = GitInfo.new(git_token, 'NetAppDocs/' + repo_name) @base_url = 'https://docs.netapp.com/us-en/'+ repo_name + '/' @absolute_config_file = File.join(@absolute_working_path, jekyll_config_file); do_jekyll_config_ok? do |t| @absolute_source_path = File.join(@absolute_working_path, @parameters['source_path']); @absolute_output_path = File.join(@absolute_working_path, @parameters['output_path']); @absolute_sidebar_path = File.join(@absolute_working_path, @parameters['sidebar_path']); @absolute_cover_page = File.join(@absolute_output_path, 'assets','cover_page_background.jpg'); @absolute_theme_pdf = File.join(@absolute_output_path, 'assets','pdf-theme.yml'); define_task! end end
Public Instance Methods
assert(condition, message)
click to toggle source
Assert function
# File lib/jekyll_asciidoctor_pdf/commands.rb, line 308 def assert(condition, message) if not condition output(message) exit 1 end end
assert_key(array, key, message)
click to toggle source
# File lib/jekyll_asciidoctor_pdf/commands.rb, line 157 def assert_key(array, key, message) if not array.has_key? key output(message) exit 1 end end
clean()
click to toggle source
# File lib/jekyll_asciidoctor_pdf/commands.rb, line 179 def clean output("Removing files & output directories ...") rm_rf(absolute_output_path, quiet) end
define_task!()
click to toggle source
# File lib/jekyll_asciidoctor_pdf/commands.rb, line 110 def define_task! desc "Print information variables" task :info do print_variables end desc "Cleaning files & directories" task :clean do clean end desc "Initialize files & directories" task :init => [ :clean ] do init end desc description task name.to_sym => [:clean, :init] do generate_individual_pdf generate_fullsite_adoc undo_init end end
do_jekyll_config_ok?() { || ... }
click to toggle source
Check if Jekyll configuration is Okay
# File lib/jekyll_asciidoctor_pdf/commands.rb, line 143 def do_jekyll_config_ok? config = YAML.load_file(absolute_config_file) assert_key(config, 'jap_config', "Expected key 'jap_config' to exist, but does not") @parameters = config['jap_config'] assert_key(@parameters, 'source_path' , "Expected key 'jap_config.source_path' to exist, but does not") assert_key(@parameters, 'output_path' , "Expected key 'jap_config.output_path' to exist, but does not") assert_key(@parameters, 'sidebar_path', "Expected key 'jap_config.sidebar_path' to exist, but does not") yield end
generate_fullsite_adoc()
click to toggle source
Loop over each YAML file in the sidebar_path
Steps:
- Execute generateContent to create all sections and one file with the whole content of the sitebar
Output directories:
<output_path> |__ <sidebar>/<section>.pdf -> Section output |__ fullsite/<sidebar>.pdf -> whole sidebar content (a.k.a. fullsite PDF)
# File lib/jekyll_asciidoctor_pdf/commands.rb, line 277 def generate_fullsite_adoc FileList[absolute_sidebar_path + "*.yml"].each do |file| output("Generating content for " + File.basename(file)) name = File.basename(file).ext('') JekyllAsciidoctorPdf::SidebarYAML.new( product_name, name, file, permalinks, parameters, absolute_output_path, absolute_source_path, absolute_cover_page, absolute_theme_pdf ) #cd absolute_working_path #sidebar.generatePdf() end end
generate_individual_pdf()
click to toggle source
Loop over each AsciiDoctor file recursively
Steps:
getPdfTheme()
click to toggle source
Load the asciidoctor-pdf theme from the jekyll _config.yml
# File lib/jekyll_asciidoctor_pdf/commands.rb, line 327 def getPdfTheme() return parameters['pdf_theme'].to_yaml end
init()
click to toggle source
# File lib/jekyll_asciidoctor_pdf/commands.rb, line 187 def init output("Initialize files & output directories ...") output_pages = File.join(absolute_output_path, '/pages') output_assets = File.join(absolute_output_path, '/assets') mkdir_p(absolute_output_path, quiet) mkdir_p(output_pages,quiet) mkdir_p(output_assets,quiet) fullsite_config = parameters['fullsite'] background_image = File.join(absolute_working_path, fullsite_config['background_image']) cp_r(background_image, absolute_cover_page, quiet) File.open(absolute_theme_pdf, "w") { |file| file.write(getPdfTheme() ) } end
last_modified_at_unix(file)
click to toggle source
Taken from jekyll-last-modified-at
# File lib/jekyll_asciidoctor_pdf/commands.rb, line 217 def last_modified_at_unix(file) last_commit_date = value = %x[ git log -1 --pretty="format:%ct" #{file} ] # last_commit_date can be nil iff the file was not committed. last_commit_date.nil? || last_commit_date.empty? ? File.mtime(file) : Time.at(last_commit_date.to_i) end
mkdir_p_if_not_exist(dir)
click to toggle source
Create a directory only if its necessary
# File lib/jekyll_asciidoctor_pdf/commands.rb, line 318 def mkdir_p_if_not_exist(dir) mkdir_p(dir, quiet) unless File.exists?(dir) end
output(string)
click to toggle source
# File lib/jekyll_asciidoctor_pdf/commands.rb, line 331 def output(string) puts ' * ' + string end
print_variables()
click to toggle source
Only to debug
# File lib/jekyll_asciidoctor_pdf/commands.rb, line 168 def print_variables output("Current directory: " + absolute_working_path) output("Jekyll Config File: " + absolute_config_file) output("Source directory: " + absolute_source_path) output("Sidebar directory: " + absolute_sidebar_path) output("Building directory: " + absolute_output_path) end
undo_init()
click to toggle source
# File lib/jekyll_asciidoctor_pdf/commands.rb, line 207 def undo_init output("Removing auxiliaries files & directories ...") output_assets = File.join(absolute_output_path, '/assets') rm_rf(output_assets, quiet) end