<commit_before>require 'markaby'

class SinatraMabWrapper
    attr_accessor :app_scope
    def method_missing(*args)
           app_scope.send(*args)
    end
    
    def respond_to?(*args)
        return false if args.include?(:builder)
        return true if app_scope.respond_to?(*args)
        false
    end  
end # === class 


class TemplateCache
    class << self
        def cache 
            @the_cache ||= {}
        end
        def reset
            @the_cache = {}
        end
    end # === class
end # === class

# =========================================================
# Set up Markaby customizations.
# =========================================================
class Markaby::Builder
  def save_to(name,  &new_proc)
        instance_variable_set( :"@#{name}" , capture(&new_proc) )       
  end # === save_to
  
  def add_template_root(new_template_dir)
    @template_roots ||= []
    @template_roots << new_template_dir
  end # === add_template_root

  def partial( raw_file_name )
    
    file_name = raw_file_name.to_s
    file_name += '.rb' if !file_name['.rb']
    
    # Find template file.
    if File.exists?(file_name)
      partial_filepath = file_name 
    elsif File.exists?(file_name + '.rb')
      partial_filepath = file_name + '.rb'
    else
      template_roots.each { |template_root|
        temp_file_path = File.join( template_root, file_name )
        if File.exists?( temp_file_path )
          partial_filepath = temp_file_path
          break
        end
      }
    end

    if !partial_filepath
      raise "Partial template file not found: #{file_name} in template roots: #{template_roots.join( '  ,  ' )}"
    end
    
    # Get & Render the contents of template file.
    the_app.dev_log_it "Rendering partial: #{partial_filepath}"
    text( 
        capture { 
            eval File.read(partial_filepath), nil, partial_filepath, 1  
        } 
    )
    ''
  end # === partial
  
end # === class Markaby::Builder
        


module Sinatra
    module RenderMab
        
        def self.registered(app)
            app.helpers RenderMab::Helpers
            Markaby::Builder.set(:indent, 1)  if !app.production?
            Markaby::Builder.set(:indent, 0)  if app.production?
        end
        
        module Helpers
            
            # ==================================================================
            # Template helpers.
            # ==================================================================
            
            def array_to_string(arr)
               
                  all_errors = arr.flatten
                  all_errors.size === 1 ?
                      all_errors.first  :
                      '* ' + all_errors.join("\n* ")   
               
            end
            
            def skin_name
                @skin_name ||= 'jinx'
            end
            
            def skins_dir
                File.join( options.views, 'skins' , skin_name )<commit_msg>Fixed major bug preventing views from being accessed.<commit_after>require 'markaby'

class SinatraMabWrapper
    attr_accessor :app_scope
    def method_missing(*args)
           app_scope.send(*args)
    end
    
    def respond_to?(*args)
        return false if args.include?(:builder)
        return true if app_scope.respond_to?(*args)
        false
    end  
end # === class 


class TemplateCache
    class << self
        def cache 
            @the_cache ||= {}
        end
        def reset
            @the_cache = {}
        end
    end # === class
end # === class

# =========================================================
# Set up Markaby customizations.
# =========================================================
class Markaby::Builder
  def save_to(name,  &new_proc)
        instance_variable_set( :"@#{name}" , capture(&new_proc) )       
  end # === save_to
  
  def add_template_root(new_template_dir)
    @template_roots ||= []
    @template_roots << new_template_dir
  end # === add_template_root

  def partial( raw_file_name )
    
    file_name = raw_file_name.to_s
    file_name += '.rb' if !file_name['.rb']
    
    # Find template file.
    if File.exists?(file_name)
      partial_filepath = file_name 
    elsif File.exists?(file_name + '.rb')
      partial_filepath = file_name + '.rb'
    else
      template_roots.each { |template_root|
        temp_file_path = File.join( template_root, file_name )
        if File.exists?( temp_file_path )
          partial_filepath = temp_file_path
          break
        end
      }
    end

    if !partial_filepath
      raise "Partial template file not found: #{file_name} in template roots: #{template_roots.join( '  ,  ' )}"
    end
    
    # Get & Render the contents of template file.
    the_app.dev_log_it "Rendering partial: #{partial_filepath}"
    text( 
        capture { 
            eval File.read(partial_filepath), nil, partial_filepath, 1  
        } 
    )
    ''
  end # === partial
  
end # === class Markaby::Builder
        


module Sinatra
    module RenderMab
        
        def self.registered(app)
            app.helpers RenderMab::Helpers
            Markaby::Builder.set(:indent, 1)  if !app.production?
            Markaby::Builder.set(:indent, 0)  if app.production?
        end
        
        module Helpers
            
            # ==================================================================
            # Template helpers.
            # ==================================================================
            
            def array_to_string(arr)
               
                  all_errors = arr.flatten
                  all_errors.size === 1 ?
                      all_errors.first  :
                      '* ' + all_errors.join("\n* ")   
               
            end
            
            def skin_name
                @skin_name ||= 'jinx'
            end
            
            def skins_dir
                File.join( options.views )
{'fraction_non_alphanumeric': 0.16854310199966394, 'fraction_numerical': 0.0013443118803562427, 'mean_word_length': 1.894941634241245, 'pattern_counts': {'":': 0, '<': 11, '<?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': '3803375', 'n_tokens_mistral': 1691, 'n_tokens_neox': 1629, 'n_words': 357}