class Epuber::Compiler::FileTypes::SourceFile
Attributes
abs_source_path[RW]
@return [String] absolute source path
file_request[RW]
@return [Epuber::Book::FileRequest]
source_path[R]
@return [String] relative source path (from project root)
Public Class Methods
new(source_path)
click to toggle source
@param [String] source_path
relative path from project root to source file
Calls superclass method
# File lib/epuber/compiler/file_types/source_file.rb, line 23 def initialize(source_path) super() @source_path = source_path end
resolve_relative_file(destination_path, pattern, file_resolver, group: nil, location: nil)
click to toggle source
# File lib/epuber/compiler/file_types/source_file.rb, line 122 def self.resolve_relative_file(destination_path, pattern, file_resolver, group: nil, location: nil) dirname = File.dirname(destination_path) begin new_path = file_resolver.dest_finder.find_file(pattern, groups: group, context_path: dirname) rescue FileFinders::FileNotFoundError, FileFinders::MultipleFilesFoundError begin new_path = XHTMLProcessor.resolved_link_to_file(pattern, group, dirname, file_resolver.source_finder).to_s rescue XHTMLProcessor::UnparseableLinkError, FileFinders::FileNotFoundError, FileFinders::MultipleFilesFoundError => e UI.error(e.to_s, location: location) return nil end end pkg_abs_path = File.expand_path(new_path, dirname).unicode_normalize pkg_new_path = Pathname.new(pkg_abs_path) .relative_path_from(Pathname.new(file_resolver.source_path)) .to_s file_class = FileResolver.file_class_for(File.extname(new_path)) file = file_class.new(pkg_new_path) file.path_type = :manifest file_resolver.add_file(file) FileResolver.renamed_file_with_path(new_path) end
Public Instance Methods
default_file_copy()
click to toggle source
# File lib/epuber/compiler/file_types/source_file.rb, line 89 def default_file_copy if destination_file_up_to_date? UI.print_processing_debug_info("Destination path #{pkg_destination_path} is up-to-date") else UI.print_processing_debug_info("Copying to #{pkg_destination_path}") self.class.file_copy!(abs_source_path, final_destination_path) end update_metadata! end
destination_file_exist?()
click to toggle source
Final destination path exist
@return [Bool]
# File lib/epuber/compiler/file_types/source_file.rb, line 76 def destination_file_exist? File.exist?(final_destination_path) end
destination_file_up_to_date?()
click to toggle source
Source file does not change from last build of this target
@return [Bool]
# File lib/epuber/compiler/file_types/source_file.rb, line 61 def destination_file_up_to_date? return false unless compilation_context.incremental_build? source_db = compilation_context.source_file_database target_db = compilation_context.target_file_database destination_file_exist? && # destination file must exist target_db.up_to_date?(source_path) && # source file must be up-to-date from last build of this target source_db.file_stat_for(source_path) == target_db.file_stat_for(source_path) end
find_dependencies()
click to toggle source
return [Array<String>]
# File lib/epuber/compiler/file_types/source_file.rb, line 31 def find_dependencies [] end
process(_compilation_context)
click to toggle source
# File lib/epuber/compiler/file_types/source_file.rb, line 35 def process(_compilation_context) # do nothing end
properties()
click to toggle source
@return [Set<Symbol>] list of properties
Calls superclass method
Epuber::Compiler::FileTypes::AbstractFile#properties
# File lib/epuber/compiler/file_types/source_file.rb, line 41 def properties file_request&.properties || super end
source_file_up_to_date?()
click to toggle source
Source file does not change from last build @warning Using only this method can cause not updating files that are different for targets
@return [Bool]
# File lib/epuber/compiler/file_types/source_file.rb, line 50 def source_file_up_to_date? return false unless compilation_context.incremental_build? source_db = compilation_context.source_file_database source_db.up_to_date?(source_path) end
update_metadata!()
click to toggle source
Updates information about source file in file databases
@return [nil]
# File lib/epuber/compiler/file_types/source_file.rb, line 84 def update_metadata! compilation_context.source_file_database.update_metadata(source_path) compilation_context.target_file_database.update_metadata(source_path) end
write_compiled(content)
click to toggle source
# File lib/epuber/compiler/file_types/source_file.rb, line 100 def write_compiled(content) if self.class.write_to_file?(content, final_destination_path) UI.print_processing_debug_info("Writing compiled version to #{pkg_destination_path}") self.class.write_to_file!(content, final_destination_path) else UI.print_processing_debug_info(<<~MSG) Not writing to disk ... compiled version at #{pkg_destination_path} is same MSG end end
write_processed(content)
click to toggle source
# File lib/epuber/compiler/file_types/source_file.rb, line 111 def write_processed(content) if self.class.write_to_file?(content, final_destination_path) UI.print_processing_debug_info("Writing processed version to #{pkg_destination_path}") self.class.write_to_file!(content, final_destination_path) else UI.print_processing_debug_info(<<~MSG) Not writing to disk ... processed version at #{pkg_destination_path} is same MSG end end