<commit_before># frozen_string_literal: true

require_dependency "gobierto_core"

module GobiertoCore
  class SiteTemplate < ApplicationRecord
    belongs_to :template
    belongs_to :site

    def self.current_site_has_custom_template?(site, template_path)
      GobiertoCore::SiteTemplate.current_site_custom_template(site, template_path).any?
    end

    def self.current_site_custom_template(site, template_path)
      GobiertoCore::SiteTemplate.joins(:template).where("#{table_name}.site_id = ? AND gcore_templates.template_path = ?",
                                                        site.id, template_path)
    end

    def self.liquid_str(site, liquid_path)
      if GobiertoCore::SiteTemplate.current_site_has_custom_template?(site, liquid_path)
        GobiertoCore::SiteTemplate.current_site_custom_template(site, liquid_path).first.markup
      elsif File.exist?("app/views/" + liquid_path + ".liquid")
        File.read("app/views/" + liquid_path + ".liquid")
      else
        liquid_path
      end
    end
  end
end
<commit_msg>Check if liquid_str is a path<commit_after># frozen_string_literal: true

require_dependency "gobierto_core"

module GobiertoCore
  class SiteTemplate < ApplicationRecord
    belongs_to :template
    belongs_to :site

    def self.current_site_has_custom_template?(site, template_path)
      GobiertoCore::SiteTemplate.current_site_custom_template(site, template_path).any?
    end

    def self.current_site_custom_template(site, template_path)
      GobiertoCore::SiteTemplate.joins(:template).where("#{table_name}.site_id = ? AND gcore_templates.template_path = ?",
                                                        site.id, template_path)
    end

    def self.liquid_str(site, liquid_path)
      if /\A\w+\/\w+\/\w+/.match(liquid_path)
        if GobiertoCore::SiteTemplate.current_site_has_custom_template?(site, liquid_path)
          GobiertoCore::SiteTemplate.current_site_custom_template(site, liquid_path).first.markup
        elsif File.exist?("app/views/" + liquid_path + ".liquid")
          File.read("app/views/" + liquid_path + ".liquid")
        end
      else
        liquid_path
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.09340659340659341, 'fraction_numerical': 0.0, 'mean_word_length': 3.218146718146718, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2221819', 'n_tokens_mistral': 667, 'n_tokens_neox': 651, 'n_words': 108}