<commit_before>module Caffeine
  class PageDecorator < Draper::Decorator
    delegate_all
    decorates_association :children

    TEMPLATE_FILE_NAME = 'template'
    DEFAULT_TEMPLATE = "templates/default/#{TEMPLATE_FILE_NAME}"

    # First we check if page has an own dedicated template
    # Then we check if page has parents and their children template
    # Finally we take default template
    def page_template
      self_custom_template || parent_children_template || DEFAULT_TEMPLATE
    end

    def self_custom_template
      "templates/#{slug}/#{TEMPLATE_FILE_NAME}" if self_custom_template_exists?
    end

    def self_custom_template_exists?
      File.exist?("app/views/caffeine/pages/templates/#{slug}/_#{TEMPLATE_FILE_NAME}.html.slim")
    end

    def parent_children_template
      "templates/#{parents_path}/children_#{TEMPLATE_FILE_NAME}" if parent_children_template_exists?
    end
<commit_msg>Fix Page raising error when auto-decorating `children` association<commit_after>module Caffeine
  class PageDecorator < Draper::Decorator
    delegate_all
    decorates_association :children, with: Caffeine::PageDecorator

    TEMPLATE_FILE_NAME = 'template'
    DEFAULT_TEMPLATE = "templates/default/#{TEMPLATE_FILE_NAME}"

    # First we check if page has an own dedicated template
    # Then we check if page has parents and their children template
    # Finally we take default template
    def page_template
      self_custom_template || parent_children_template || DEFAULT_TEMPLATE
    end

    def self_custom_template
      "templates/#{slug}/#{TEMPLATE_FILE_NAME}" if self_custom_template_exists?
    end

    def self_custom_template_exists?
      File.exist?("app/views/caffeine/pages/templates/#{slug}/_#{TEMPLATE_FILE_NAME}.html.slim")
    end

    def parent_children_template
      "templates/#{parents_path}/children_#{TEMPLATE_FILE_NAME}" if parent_children_template_exists?
    end

{'fraction_non_alphanumeric': 0.07463465553235908, 'fraction_numerical': 0.0, 'mean_word_length': 4.33983286908078, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4613953', 'n_tokens_mistral': 574, 'n_tokens_neox': 569, 'n_words': 129}