Class: Jekyll::GeneratorSingleSource::DocNavItem::Base

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

Direct Known Subclasses

Src, WithoutSrc, WithoutSrcAndUrl

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(item_config, top_level_config) ⇒ Base

Returns a new instance of Base.



23
24
25
26
# File 'lib/jekyll/generator-single-source/doc_nav_item/base.rb', line 23

def initialize(item_config, top_level_config)
  @item_config      = item_config
  @top_level_config = top_level_config
end

Class Method Details

.make_for(item_config, top_level_config) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/jekyll/generator-single-source/doc_nav_item/base.rb', line 10

def self.make_for(item_config, top_level_config)
  if item_config['src']
    Src.new(item_config, top_level_config)
  elsif item_config['url']
    WithoutSrc.new(item_config, top_level_config)
  else
    WithoutSrcAndUrl.new(item_config, top_level_config)
  end
end

Instance Method Details

#destObject



63
64
65
# File 'lib/jekyll/generator-single-source/doc_nav_item/base.rb', line 63

def dest
  @dest ||= OpenStruct.new(file_path: dest_path)
end

#generate_pagesObject



28
29
30
31
32
33
34
35
36
# File 'lib/jekyll/generator-single-source/doc_nav_item/base.rb', line 28

def generate_pages
  return if skip_item?

  if generate_single_source_page?
    site.pages << SingleSourcePage.new(self)
  end

  items.map(&:generate_pages)
end

#itemsObject



49
50
51
52
53
# File 'lib/jekyll/generator-single-source/doc_nav_item/base.rb', line 49

def items
  @items ||= @item_config.fetch('items', []).map do |i|
    DocNavItem::Base.make_for(i, @top_level_config)
  end
end

#relative_pathObject



73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/jekyll/generator-single-source/doc_nav_item/base.rb', line 73

def relative_path
  @relative_path ||= begin
                       if !site.config['locale'] || site.config['locale'] == I18n.default_locale.to_s
                         source.file_path
                       else
                         if translation_fallback?
                           source.file_path
                         else
                           File.join(site.config['translated_content_path'], source.file_path)
                         end
                       end
                     end
end

#skip_item?Boolean

Returns:

  • (Boolean)


38
39
40
41
42
43
44
45
46
47
# File 'lib/jekyll/generator-single-source/doc_nav_item/base.rb', line 38

def skip_item?
  # If assume_generated is not set at the top level,
  # or it is set to true then all items will be generated
  return true if !@item_config['generate'] && !assume_generated?

  # If assume_generated is set to false,
  # then each item in the navigation that should be generated
  # will need generate: true to be set
  @item_config.key?('generate') && @item_config['generate'] == false
end

#sourceObject



55
56
57
58
59
60
61
# File 'lib/jekyll/generator-single-source/doc_nav_item/base.rb', line 55

def source
  @source ||= Source::Base.make_for(
    path: source_path,
    site: site,
    locale: site.config['locale']
  )
end

#translation_fallback?Boolean

Returns:

  • (Boolean)


67
68
69
70
71
# File 'lib/jekyll/generator-single-source/doc_nav_item/base.rb', line 67

def translation_fallback?
  return false if site.config['locale'] == I18n.default_locale.to_s

  missing_translation?
end