Class: Jekyll::GeneratorSingleSource::DocNavConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll/generator-single-source/doc_nav_config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(i18n_file:, site:) ⇒ DocNavConfig

Returns a new instance of DocNavConfig.



8
9
10
11
# File 'lib/jekyll/generator-single-source/doc_nav_config.rb', line 8

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

Instance Attribute Details

#siteObject (readonly)

Returns the value of attribute site.



6
7
8
# File 'lib/jekyll/generator-single-source/doc_nav_config.rb', line 6

def site
  @site
end

Instance Method Details

#assume_generated?Boolean

Returns:

  • (Boolean)


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

def assume_generated?
  # Assume that the whole file should be treated as generated
  config['assume_generated'].nil? || config['assume_generated']
end

#configObject



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

def config
  @config ||= begin
                config = NavConfig::Base.process(@i18n_file.full_file_path_in_default_locale)
                Jekyll.logger.debug("generated config: #{config.to_json}")
                config
              end
end

#generate_pagesObject



48
49
50
51
52
# File 'lib/jekyll/generator-single-source/doc_nav_config.rb', line 48

def generate_pages
  return if skip_generation?

  items.map(&:generate_pages)
end

#itemsObject



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

def items
  @items ||= (config.fetch('items', []) + ([config['unlisted']]))
    .flatten.compact
    .map { |i| DocNavItem::Base.make_for(i, self) }
end

#missing_translation?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/jekyll/generator-single-source/doc_nav_config.rb', line 13

def missing_translation?
  @i18n_file.missing_translation?
end


62
63
64
65
66
67
68
69
70
71
72
# File 'lib/jekyll/generator-single-source/doc_nav_config.rb', line 62

def nav_items_in_locale(locale)
  @nav_items_in_locale ||= Hash.new do |h, key|
    h[key] = if key == I18n.default_locale.to_s
               config
             else
               NavConfig::Base.process(@i18n_file.full_file_path_in_locale)
             end

  end
  @nav_items_in_locale[locale]
end

#productObject



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

def product
  @product ||= config['product']
end

#releaseObject



38
39
40
41
42
# File 'lib/jekyll/generator-single-source/doc_nav_config.rb', line 38

def release
  @release ||= edition.releases.detect do |r|
    r.value == config['release']
  end
end

#skip_generation?Boolean

Returns:

  • (Boolean)


17
18
19
20
21
# File 'lib/jekyll/generator-single-source/doc_nav_config.rb', line 17

def skip_generation?
  # skip if release is not available because it
  # was skipped using an ENV variable
  !(config.is_a?(Hash) && config['generate']) || release.nil?
end

#versionsObject



44
45
46
# File 'lib/jekyll/generator-single-source/doc_nav_config.rb', line 44

def versions
  @versions ||= release.versions
end