Module: Jekyll::L10n::FileOperations

Defined in:
lib/jekyll-l10n/utils/file_operations.rb

Overview

File I/O operations with UTF-8 encoding.

FileOperations provides centralized file reading/writing and directory creation with automatic UTF-8 encoding. All PO files, HTML files, and configuration files are handled with UTF-8 encoding for internationalization.

Key responsibilities:

  • Read files with UTF-8 encoding

  • Write files with UTF-8 encoding

  • Create directory structures as needed

Examples:

content = FileOperations.read_utf8('_locales/es.po')
FileOperations.write_utf8('output.po', content)
FileOperations.ensure_directory('output/path/file.po')

Constant Summary collapse

ENCODING =
'UTF-8'

Class Method Summary collapse

Class Method Details

.ensure_directory(file_path) ⇒ void

This method returns an undefined value.

Ensure directory exists for a file path.

Creates all parent directories as needed for the given file path. Does nothing if directory already exists.

Parameters:

  • file_path (String)

    File path (directory is extracted from this)



49
50
51
52
# File 'lib/jekyll-l10n/utils/file_operations.rb', line 49

def self.ensure_directory(file_path)
  dir = ::File.dirname(file_path)
  ::FileUtils.mkdir_p(dir)
end

.read_utf8(path) ⇒ String

Read a file with UTF-8 encoding.

Parameters:

  • path (String)

    Path to file to read

Returns:

  • (String)

    File contents as UTF-8 string



29
30
31
# File 'lib/jekyll-l10n/utils/file_operations.rb', line 29

def self.read_utf8(path)
  ::File.read(path, encoding: ENCODING)
end

.write_utf8(path, content) ⇒ Integer

Write content to a file with UTF-8 encoding.

Parameters:

  • path (String)

    Path to file to write

  • content (String)

    Content to write

Returns:

  • (Integer)

    Number of bytes written



38
39
40
# File 'lib/jekyll-l10n/utils/file_operations.rb', line 38

def self.write_utf8(path, content)
  ::File.write(path, content, encoding: ENCODING)
end