<commit_before>require 'rho/rhoapplication'
require 'rho/rhocontroller'

module Rho
  class RhoController

	def self.layout(name)
		@layout = name
	end

	def self.get_layout_name
		@layout.nil? ? 'layout' : @layout
	end

    def self.renderfile(filename)
        res = ""
      	if File.extname(filename) == '.iseq'
	    	res = render_index(filename)
	  	else
        	res = IO.read(filename)
		end
		RhoController.start_objectnotify()
		
		res
	end

	def inst_render_index(filename)
        @request, @response = {}
        @params = {}
	
		layout = File.dirname(filename) + "/layout_erb.iseq"
		@content = eval_compiled_file(filename, binding)
		@content = eval_compiled_file(layout, binding) if File.exist?(layout)
	    @content
	end

	def self.render_index(filename)
	    (RhoController.new).inst_render_index(filename)
	end

    def render(options = nil)
    	options = {} if options.nil? or !options.is_a?(Hash)
		options[:action] = :index if options[:action].nil?

		@content = eval_compiled_file(@request[:modelpath]+options[:action].to_s+'_erb.iseq', binding )
        puts 'render content: ' + @content.length.to_s
		if xhr? and options[:use_layout_on_ajax] != true
			options[:layout] = false
		elsif options[:layout].nil? or options[:layout] == true
			options[:layout] = self.class.get_layout_name
		end

		if options[:layout] != false
			layoutfile = RhoApplication::get_app_path(@request['application']) + options[:layout].to_s + "_erb.iseq"
			@content = eval_compiled_file(layoutfile, binding ) if File.exist?(layoutfile)
			puts 'Layout file: ' + layoutfile + '. Content size: ' + @content.length.to_s
		end

        RhoController.start_objectnotify()
        
		@content
    end

    @@m_arObjectNotify = []
    @@m_arSrcIDNotify = []
    def add_objectnotify(arg)
        return unless arg
        
        if arg.is_a? (Array)
            arg.each do |item|
                @@m_arObjectNotify.push(strip_braces(item.object))
                @@m_arSrcIDNotify.push(item.source_id)
            end
        else
            @@m_arObjectNotify.push(strip_braces(arg.object))
            @@m_arSrcIDNotify.push(arg.source_id)<commit_msg>add :back parameter to render<commit_after>require 'rho/rhoapplication'
require 'rho/rhocontroller'

module Rho
  class RhoController

	def self.layout(name)
		@layout = name
	end

	def self.get_layout_name
		@layout.nil? ? 'layout' : @layout
	end

    def self.renderfile(filename)
        res = ""
      	if File.extname(filename) == '.iseq'
	    	res = render_index(filename)
	  	else
        	res = IO.read(filename)
		end
		RhoController.start_objectnotify()
		
		res
	end

	def inst_render_index(filename)
        @request, @response = {}
        @params = {}
	
		layout = File.dirname(filename) + "/layout_erb.iseq"
		@content = eval_compiled_file(filename, binding)
		@content = eval_compiled_file(layout, binding) if File.exist?(layout)
	    @content
	end

	def self.render_index(filename)
	    (RhoController.new).inst_render_index(filename)
	end

    def render(options = nil)
    	options = {} if options.nil? or !options.is_a?(Hash)
		options[:action] = :index if options[:action].nil?

		@content = eval_compiled_file(@request[:modelpath]+options[:action].to_s+'_erb.iseq', binding )
        puts 'render content: ' + @content.length.to_s
		if xhr? and options[:use_layout_on_ajax] != true
			options[:layout] = false
		elsif options[:layout].nil? or options[:layout] == true
			options[:layout] = self.class.get_layout_name
		end

		if options[:layout] != false
			layoutfile = RhoApplication::get_app_path(@request['application']) + options[:layout].to_s + "_erb.iseq"
			@content = eval_compiled_file(layoutfile, binding ) if File.exist?(layoutfile)
			puts 'Layout file: ' + layoutfile + '. Content size: ' + @content.length.to_s
		end

        RhoController.start_objectnotify()
        @back_action = options[:back] if options[:back]
        
		@content
    end

    @@m_arObjectNotify = []
    @@m_arSrcIDNotify = []
    def add_objectnotify(arg)
        return unless arg
        
        if arg.is_a? (Array)
            arg.each do |item|
                @@m_arObjectNotify.push(strip_braces(item.object))
                @@m_arSrcIDNotify.push(item.source_id)
            end
        else
            @@m_arObjectNotify.push(strip_braces(arg.object))
            @@m_arSrcIDNotify.push(arg.source_id)
{'fraction_non_alphanumeric': 0.12220191868433075, 'fraction_numerical': 0.0, 'mean_word_length': 3.1389413988657844, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6858287', 'n_tokens_mistral': 1530, 'n_tokens_neox': 1418, 'n_words': 271}