Class: Jekyll::GeneratorSingleSource::SingleSourcePage
- Inherits:
-
Page
- Object
- Page
- Jekyll::GeneratorSingleSource::SingleSourcePage
- Defined in:
- lib/jekyll/generator-single-source/single_source_page.rb
Instance Method Summary collapse
-
#initialize(nav_item) ⇒ SingleSourcePage
constructor
rubocop:disable Lint/MissingSuper, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/AbcSize, Metrics/PerceivedComplexity.
- #to_version(input) ⇒ Object
Constructor Details
#initialize(nav_item) ⇒ SingleSourcePage
rubocop:disable Lint/MissingSuper, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/AbcSize, Metrics/PerceivedComplexity
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/jekyll/generator-single-source/single_source_page.rb', line 6 def initialize(nav_item) # rubocop:disable Lint/MissingSuper, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/AbcSize, Metrics/PerceivedComplexity # Configure variables that Jekyll depends on @site = nav_item.site # Set self.ext and self.basename by extracting information from the page filename process('index.md') # Override Jekyll::Page's @dir # This is the directory that we're going to write the output file to @dir = nav_item.dest.file_path file_path = if nav_item.translation_fallback? nav_item.source.full_file_path_in_default_locale else nav_item.source.full_file_path_in_locale end content = File.read(file_path) # Load content + frontmatter from the file if content =~ Jekyll::Document::YAML_FRONT_MATTER_REGEXP @content = Regexp.last_match.post_match @data = SafeYAML.load(Regexp.last_match(1)) end # Make it clear that this content comes from a generated file @data['is_dir_index'] = nav_item.source.dir? # Set the current release and concrete version release = nav_item.release @data['release'] = Liquid::Drops::Release.new(release) @data['edition'] = release.edition @data['version'] = release.default_version @data['versions'] = release.versions # Set i18n related data # locale in which the page is locale = if nav_item.translation_fallback? I18n.default_locale.to_s else @site.config['locale'] end @data['translation_fallback'] = nav_item.translation_fallback? @data['full_file_path_in_locale'] = nav_item.source.full_file_path_in_locale @data['file_path'] = nav_item.source.file_path @data['locale'] = locale @data['nav_items'] = nav_item.nav_items_in_locale(locale) # Set the "Edit on GitHub" link url @data['edit_link'] = nav_item.source.file_path unless nav_item.translation_fallback? # Set the layout if it's not already provided @data['layout'] ||= GeneratorConfig.new(@site).layout # Apply any overrides current = to_version(release.value) @data['overrides']&.each do |key, entries| entries.each do |value, conditions| gte = conditions['gte'] ? to_version(conditions['gte']) : nil lte = conditions['lte'] ? to_version(conditions['lte']) : nil eq = conditions['eq'] ? to_version(conditions['eq']) : nil if gte && lte @data[key] = value if current >= gte && current <= lte elsif gte @data[key] = value if current >= gte elsif lte @data[key] = value if current <= lte elsif eq @data[key] = value if current == eq end end end # Needed so that regeneration works for single sourced pages # It must be set to the source file # Also, @path MUST NOT be set, it falls back to @relative_path @relative_path = nav_item.relative_path end |
Instance Method Details
#to_version(input) ⇒ Object
85 86 87 |
# File 'lib/jekyll/generator-single-source/single_source_page.rb', line 85 def to_version(input) Gem::Version.new(input.to_s.gsub(/\.x$/, '.0')) end |