Class: Jekyll::GeneratorSingleSource::Source::Base

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/jekyll/generator-single-source/source/base.rb

Direct Known Subclasses

DirSource, FileSource

Constant Summary collapse

SRC_PATH =
'_src'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(i18n_file, site) ⇒ Base

Returns a new instance of Base.



28
29
30
31
# File 'lib/jekyll/generator-single-source/source/base.rb', line 28

def initialize(i18n_file, site)
  @i18n_file = i18n_file
  @site = site
end

Class Method Details

.make_for(path:, site:, locale:) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/jekyll/generator-single-source/source/base.rb', line 11

def self.make_for(path:, site:, locale:)
  md_path = "#{path.delete_suffix('/')}.md"
  dir_path = File.join(path.delete_suffix('/'), "index.md")

  # Read the source file, either `<src>.md or <src>/index.md`
  if I18nFile.exists?(file: md_path, locale:, src_path: SRC_PATH, site:)
    FileSource.new(I18nFile.new(file: md_path, locale:, src_path: SRC_PATH, site:), site)
  elsif I18nFile.exists?(file: dir_path, locale:, src_path: SRC_PATH, site:)
    DirSource.new(I18nFile.new(file: dir_path, locale:, src_path: SRC_PATH, site:), site)
  else
    raise "Could not find a source file at '_src/#{md_path}' or '_src/#{dir_path}'"
  end
end

Instance Method Details

#file_pathObject



33
34
35
# File 'lib/jekyll/generator-single-source/source/base.rb', line 33

def file_path
  @file_path ||= @i18n_file.relative_file_path
end