<commit_before>require 'erb'	

class Scaffold

	attr_accessor :template_contents, :route_contents

	def initialize(name, module_name, fields, argv, with, level)
		# @f, template variable of frontground
		# @a, template variable of background
		@route_contents = @template_contents = @argv = @with = @f = @a = {}
		@name 			= name
		@module_name	= module_name
		@fields 		= fields
		@functions 		= []
		@level 			= level

		_process_data(with, argv)
		unless @functions.empty?
			#preprocess data
			@functions.each do |function|
				send("preprocess_#{function}") if self.respond_to?("preprocess_#{function}", true)
			end

			@functions.each do |function|
				#process route
				@route_contents[grn(@name)] += "\n#\t\t\t=== #{function} ===\n"
				@route_contents[grn(@name)] += get_erb_content(function, 'routes')

				#process template
				if self.respond_to?("process_#{function}", true)
					send("process_#{function}") 
				else
					@template_contents[gtn(function)] = get_erb_content(function)
				end
			end
		end
	end

	private

		def _process_data(with, argv)

			#function name => parameter name
			display = {}
			display['view'] 	= ['view_by', 'view', 'show_by', 'show']
			display['pager'] 	= ['page_size', 'pager', 'page', 'ps']
			display['search'] 	= ['search_by', 'search', 'src']
			display['rm'] 		= ['delete_by', 'delete', 'rm', 'remove', 'remove_by']
			display['edit'] 	= ['update_by', 'up', 'update', 'edit', 'edit_by']
			display['new'] 		= ['new', 'create']
			display['admin'] 	= ['admin']

			#enable default option
			@functions << 'view'
			@functions << 'admin'
			display.each do |key, val|
				val.each do |item|
					if with.include?(item)
						@with[display[key][0]] = with[item] if item != 'enable'
						@functions.delete(key) if item == 'disable' and @functions.include?(key)
						break
					end
				end
			end

			@f = @a = @with

			if argv.count > 0
				# For example,
				# primary_key:pid
				# Integer:aid
				# String:title
				# String:body
				argv.each do |item|
					key, val = item.split(":")
					@argv[val] = key 
				end
			end

			@f['insert_sql'] = ''
			@f['update_sql'] = ''

		end

		def process_view
			@template_contents[gtn('view')] = get_erb_content('view')
		end

		def process_pager
			@template_contents[gtn('view')] += get_erb_content('pager')
		end

		def process_search
			@template_contents[gtn('view')] = get_erb_content('search') + @template_contents[gtn('view')]
		end

		def process_admin
		end

		#get route name
		def grn(name)
			"modules/#{@module_name}/routes/#{name}.rb"
		end

		#get template name
		def gtn(name)
			"modules/#{@module_name}/views/#{@name}_#{name}.slim"
		end

		def get_erb_content(name, type = 'views')
			path = ROOTPATH + "/docs/scaffolds/#{type}/#{name}.tt"
			if File.exists?(path)
				t = ERB.new(path)
				t.result(binding)
			else
				say("Nothing at path : #{path}", "\e[31m")
			end
		end

end
<commit_msg>updating scaffold<commit_after>require 'erb'	

class Scaffold

	attr_accessor :template_contents, :route_contents

	def initialize(name, module_name, fields, argv, with, level)
		#@t, template variable in frontground
		#@a, template variable in background
		@route_contents = @template_contents = @argv = @with = @a = @t = {}
		@name 			= name
		@module_name	= module_name
		@fields 		= fields
		@functions 		= []
		@level 			= level

		#The word is a condition for deleting, updeting, editting
		@keyword		= ''

		_process_data(with, argv)
		unless @functions.empty?
			#preprocess data
			@functions.each do |function|
				send("preprocess_#{function}") if self.respond_to?("preprocess_#{function}", true)
			end

			@functions.each do |function|
				#process route
				foo = '='*50
				@route_contents[grn(@name)] += "\n#== #{function} #{foo}\n"
				@route_contents[grn(@name)] += get_erb_content(function, 'routes')

				#process template
				if self.respond_to?("process_#{function}", true)
					send("process_#{function}") 
				else
					@template_contents[gtn(function)] = get_erb_content(function)
				end
			end
		end
	end

	private

		def _process_data(with, argv)

			#function name => parameter name
			display = {}
			display['view'] 	= ['view_by', 'view', 'show_by', 'show']
			display['pager'] 	= ['page_size', 'pager', 'page', 'ps']
			display['search'] 	= ['search_by', 'search', 'src']
			display['rm'] 		= ['delete_by', 'delete', 'rm', 'remove', 'remove_by']
			display['edit'] 	= ['update_by', 'up', 'update', 'edit', 'edit_by']
			display['new'] 		= ['new', 'create']
			display['admin'] 	= ['admin']

			#enable default option
			@functions << 'view'
			@functions << 'admin'
			display.each do |key, val|
				val.each do |item|
					if with.include?(item)
						@with[display[key][0]] = with[item] if item != 'enable'
						@functions.delete(key) if item == 'disable' and @functions.include?(key)
						break
					end
				end
			end

			@t = @with

			keyword = ['primary_key', 'Integer', 'index', 'foreign_key', 'unique']
			if argv.count > 0
				# For example,
				# primary_key:pid
				# Integer:aid
				# String:title
				# String:body
				argv.each do |item|
					key, val = item.split(":")
					@argv[val] = key 
					if @keyword == ''
						@keyword = val if keyword.include?(key)
					end
				end
			end

			@keyword = @fields[0] if @keyword == ''

		end

		def preprocess_new
			@t['insert_sql'] = ''
		end

		def preprocess_rm
			@t['delete_by'] = @keyword unless @t.include?('delete_by')
		end

		def preprocess_edit
			@t['update_sql'] = ''
			@t['update_by'] = @keyword unless @t.include?('update_by')
		end

		def process_view
			@template_contents[gtn('view')] = get_erb_content('view')
		end

		def process_pager
			@template_contents[gtn('view')] += get_erb_content('pager')
		end

		def process_search
			@template_contents[gtn('view')] = get_erb_content('search') + @template_contents[gtn('view')]
		end

		def process_admin
			@a = @t
		end

		#get route name
		def grn(name)
			"modules/#{@module_name}/routes/#{name}.rb"
		end

		#get template name
		def gtn(name)
			"modules/#{@module_name}/views/#{@name}_#{name}.slim"
		end

		def get_erb_content(name, type = 'views')
			path = ROOTPATH + "/docs/scaffolds/#{type}/#{name}.tt"
			if File.exists?(path)
				t = ERB.new(path)
				t.result(binding)
			else
				say("Nothing at path : #{path}", "\e[31m")
			end
		end

end

{'fraction_non_alphanumeric': 0.1665614145879381, 'fraction_numerical': 0.0017366592990211557, 'mean_word_length': 3.464411557434813, 'pattern_counts': {'":': 2, '<': 11, '<?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': '2847505', 'n_tokens_mistral': 2743, 'n_tokens_neox': 2279, 'n_words': 504}