<commit_before>module Locomotive
  module Render

    extend ActiveSupport::Concern

    module InstanceMethods

      protected

      def render_locomotive_page
        if request.fullpath =~ /^\/admin\//
          render :template => '/locomotive/errors/404', :layout => '/admin/layouts/not_logged_in', :status => :not_found
        else
          @page = locomotive_page

          redirect_to(@page.redirect_url) and return if @page.present? && @page.redirect?

          render_no_page_error and return if @page.nil?

          output = @page.render(locomotive_context)

          self.prepare_and_set_response(output)
        end
      end

      def render_no_page_error
        render :template => '/locomotive/errors/no_page', :layout => false
      end

      def locomotive_page
        path = (params[:path] || params[:page_path] || request.fullpath).clone # TODO: params[:path] is more consistent
        path = path.split('?').first # take everything before the query string or the lookup fails
        path.gsub!(/\.[a-zA-Z][a-zA-Z0-9]{2,}$/, '') # remove the page extension
        path.gsub!(/^\//, '') # remove the leading slash

        path = 'index' if path.blank? || path == '_edit'

        if path != 'index'
          dirname = File.dirname(path).gsub(/^\.$/, '') # also look for templatized page path
          path = [path, File.join(dirname, 'content_type_template').gsub(/^\//, '')]
        end

        if page = current_site.pages.any_in(:fullpath => [*path]).first
          if not page.published? and current_locomotive_account.nil?
            page = nil
          else
            if page.templatized?
              @content_entry = page.content_type.entries.where(:_slug => File.basename(path.first)).first

              if @content_entry.nil? || (!@content_entry.visible? && current_locomotive_account.nil?) # content instance not found or not visible
                page = nil
              end
            end
          end
        end

        page || not_found_page
      end

      def locomotive_context
        assigns = {
          'site'              => current_site,
          'page'              => @page,
          'models'            => Locomotive::Liquid::Drops::ContentTypes.new,
          'contents'          => Locomotive::Liquid::Drops::ContentTypes.new, # DEPRECATED
          'current_page'      => self.params[:page],
          'params'            => self.params,
          'path'              => request.path,
          'url'               => request.url,
          'now'               => Time.now.utc,
          'today'             => Date.today,
          'locale'            => I18n.locale,
          'default_locale'    => current_site.default_locale.to_s,
          'locales'           => current_site.locales
        }

        assigns.merge!(Locomotive.config.context_assign_extensions)

        assigns.merge!(flash.to_hash.stringify_keys) # data from public submissions

        if @page.templatized? # add instance from content type
          assigns['entry'] = @content_entry
          assigns[@page.content_type.slug.singularize] = @content_entry # just here to help to write readable liquid code
        end

        registers = {
          :controller     => self,
          :site           => current_site,
          :page           => @page,
          :inline_editor  => self.editing_page?,
          :current_locomotive_account => current_locomotive_account
        }

        ::Liquid::Context.new({}, assigns, registers, true)
      end
<commit_msg>disable the rethrow exceptions option for the liquid templates<commit_after>module Locomotive
  module Render

    extend ActiveSupport::Concern

    module InstanceMethods

      protected

      def render_locomotive_page
        if request.fullpath =~ /^\/admin\//
          render :template => '/locomotive/errors/404', :layout => '/admin/layouts/not_logged_in', :status => :not_found
        else
          @page = locomotive_page

          redirect_to(@page.redirect_url) and return if @page.present? && @page.redirect?

          render_no_page_error and return if @page.nil?

          output = @page.render(locomotive_context)

          self.prepare_and_set_response(output)
        end
      end

      def render_no_page_error
        render :template => '/locomotive/errors/no_page', :layout => false
      end

      def locomotive_page
        path = (params[:path] || params[:page_path] || request.fullpath).clone # TODO: params[:path] is more consistent
        path = path.split('?').first # take everything before the query string or the lookup fails
        path.gsub!(/\.[a-zA-Z][a-zA-Z0-9]{2,}$/, '') # remove the page extension
        path.gsub!(/^\//, '') # remove the leading slash

        path = 'index' if path.blank? || path == '_edit'

        if path != 'index'
          dirname = File.dirname(path).gsub(/^\.$/, '') # also look for templatized page path
          path = [path, File.join(dirname, 'content_type_template').gsub(/^\//, '')]
        end

        if page = current_site.pages.any_in(:fullpath => [*path]).first
          if not page.published? and current_locomotive_account.nil?
            page = nil
          else
            if page.templatized?
              @content_entry = page.content_type.entries.where(:_slug => File.basename(path.first)).first

              if @content_entry.nil? || (!@content_entry.visible? && current_locomotive_account.nil?) # content instance not found or not visible
                page = nil
              end
            end
          end
        end

        page || not_found_page
      end

      def locomotive_context
        assigns = {
          'site'              => current_site,
          'page'              => @page,
          'models'            => Locomotive::Liquid::Drops::ContentTypes.new,
          'contents'          => Locomotive::Liquid::Drops::ContentTypes.new, # DEPRECATED
          'current_page'      => self.params[:page],
          'params'            => self.params,
          'path'              => request.path,
          'url'               => request.url,
          'now'               => Time.now.utc,
          'today'             => Date.today,
          'locale'            => I18n.locale,
          'default_locale'    => current_site.default_locale.to_s,
          'locales'           => current_site.locales
        }

        assigns.merge!(Locomotive.config.context_assign_extensions)

        assigns.merge!(flash.to_hash.stringify_keys) # data from public submissions

        if @page.templatized? # add instance from content type
          assigns['entry'] = @content_entry
          assigns[@page.content_type.slug.singularize] = @content_entry # just here to help to write readable liquid code
        end

        registers = {
          :controller     => self,
          :site           => current_site,
          :page           => @page,
          :inline_editor  => self.editing_page?,
          :current_locomotive_account => current_locomotive_account
        }

        ::Liquid::Context.new({}, assigns, registers, false) # pass false to true to enable the re-thrown exception flag
      end

{'fraction_non_alphanumeric': 0.11548117154811716, 'fraction_numerical': 0.0022315202231520223, 'mean_word_length': 1.9329243353783232, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 53, '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': '738344', 'n_tokens_mistral': 2056, 'n_tokens_neox': 1987, 'n_words': 444}