Class: Cabriolet::CHM::CommandHandler
- Inherits:
-
Cabriolet::Commands::BaseCommandHandler
- Object
- Cabriolet::Commands::BaseCommandHandler
- Cabriolet::CHM::CommandHandler
- Defined in:
- lib/cabriolet/chm/command_handler.rb
Overview
Command handler for CHM (Compiled HTML Help) format
This handler implements the unified command interface for CHM files, wrapping the existing CHM::Decompressor and CHM::Compressor classes.
Instance Method Summary collapse
-
#create(output, files = [], options = {}) ⇒ void
Create a new CHM archive.
-
#extract(file, output_dir = nil, _options = {}) ⇒ void
Extract files from CHM archive.
-
#info(file, _options = {}) ⇒ void
Display detailed CHM file information.
-
#list(file, _options = {}) ⇒ void
List CHM file contents.
-
#test(file, _options = {}) ⇒ void
Test CHM file integrity.
Methods inherited from Cabriolet::Commands::BaseCommandHandler
Constructor Details
This class inherits a constructor from Cabriolet::Commands::BaseCommandHandler
Instance Method Details
#create(output, files = [], options = {}) ⇒ void
This method returns an undefined value.
Create a new CHM archive
Creates a CHM file from HTML source files.
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/cabriolet/chm/command_handler.rb', line 80 def create(output, files = [], = {}) raise ArgumentError, "No files specified" if files.empty? files.each do |f| raise ArgumentError, "File does not exist: #{f}" unless File.exist?(f) end window_bits = [:window_bits] || 16 compressor = Compressor.new files.each do |f| # Default to compressed section for .html, uncompressed for images section = f.end_with?(".html", ".htm") ? :compressed : :uncompressed compressor.add_file(f, "/#{File.basename(f)}", section: section) end puts "Creating #{output} with #{files.size} file(s) (window_bits: #{window_bits})" if verbose? bytes = compressor.generate(output, window_bits: window_bits) puts "Created #{output} (#{bytes} bytes, #{files.size} files)" end |
#extract(file, output_dir = nil, _options = {}) ⇒ void
This method returns an undefined value.
Extract files from CHM archive
Extracts all non-system files from the CHM file to the specified output directory.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/cabriolet/chm/command_handler.rb', line 44 def extract(file, output_dir = nil, = {}) validate_file_exists(file) output_dir ||= "." output_dir = ensure_output_dir(output_dir) decompressor = Decompressor.new chm = decompressor.open(file) count = 0 chm.all_files.each do |f| next if f.system_file? output_path = File.join(output_dir, f.filename) output_subdir = File.dirname(output_path) FileUtils.mkdir_p(output_subdir) puts "Extracting: #{f.filename}" if verbose? decompressor.extract(f, output_path) count += 1 end decompressor.close puts "Extracted #{count} file(s) to #{output_dir}" end |
#info(file, _options = {}) ⇒ void
This method returns an undefined value.
Display detailed CHM file information
Shows comprehensive information about the CHM structure, including directory, sections, and files.
109 110 111 112 113 114 115 116 117 118 |
# File 'lib/cabriolet/chm/command_handler.rb', line 109 def info(file, = {}) validate_file_exists(file) decompressor = Decompressor.new chm = decompressor.open(file) display_chm_info(chm) decompressor.close end |
#list(file, _options = {}) ⇒ void
This method returns an undefined value.
List CHM file contents
Displays information about the CHM file including version, language, and lists all contained files with their sizes.
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/cabriolet/chm/command_handler.rb', line 23 def list(file, = {}) validate_file_exists(file) decompressor = Decompressor.new chm = decompressor.open(file) display_header(chm) display_files(chm.all_files) decompressor.close end |
#test(file, _options = {}) ⇒ void
This method returns an undefined value.
Test CHM file integrity
Verifies the CHM file structure.
127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/cabriolet/chm/command_handler.rb', line 127 def test(file, = {}) validate_file_exists(file) decompressor = Decompressor.new chm = decompressor.open(file) puts "Testing #{chm.filename}..." puts "OK: CHM file structure is valid (#{chm.all_files.size} files)" puts "Note: Full integrity validation not yet implemented" decompressor.close end |