<commit_before>require 'erubis'

module BlocWorks
	class Controller
		def initialize(env)
			@env = env
		end

		def render(view, locals = {})
			filename = File.join("app", "views", controller_dir, "#{view}.html.erb")
			template = File.read(filename)
			eruby = Erubis::Eruby.new(template)
			eruby.result(locals.merge(env: @env))
		end

		def controller_dir
			klass = self.class.to_s
			klass.slice!("Controller")
			BlocWorks.snake_case(klass)
		end

		def redirect(location)
			# here because BooksController inherits from BlocWorks::Controller
			# do I need to link this to :call in bloc_works.rb
			[302, {'Location' => location.to_s, 'Content-Type' => 'text/html'}, ['Redirecting']]
			self.render location.to_sym
		end
	end
end<commit_msg>add instance variable support to controller<commit_after>require 'erubis'

module BlocWorks
	class Controller
		def initialize(env)
			@env = env
		end

		def render(view, locals = {})
			filename = File.join("app", "views", controller_dir, "#{view}.html.erb")
			template = File.read(filename)
			eruby = Erubis::Eruby.new(template)
			# get the instance variables of the controller with #instance_variables
			# this returns an array of instance_variables
			# iterate, use #instance_variable_get to get values & add to {locals}
			self.instance_variables.each do |var|
				locals[var] = self.instance_variable_get(var)
			end
			eruby.result(locals.merge(env: @env))
		end

		def controller_dir
			klass = self.class.to_s
			klass.slice!("Controller")
			BlocWorks.snake_case(klass)
		end

		def redirect(location)
			# here because BooksController inherits from BlocWorks::Controller
			# do I need to link this to :call in bloc_works.rb
			[302, {'Location' => location.to_s, 'Content-Type' => 'text/html'}, ['Redirecting']]
			self.render location.to_sym
		end
	end
end
{'fraction_non_alphanumeric': 0.11671232876712329, 'fraction_numerical': 0.0032876712328767125, 'mean_word_length': 4.11484593837535, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '4094187', 'n_tokens_mistral': 694, 'n_tokens_neox': 605, 'n_words': 158}