<commit_before>require "active_support/inflector/methods"
require_relative "future"

module Tint
	module Input
		def self.select_options(site, key)
			site.config.dig("options", key)
		end

		def self.type(key, value, site)
			return unless scalarish?(value)

			if select_options(site, key)
				MultipleSelect
			elsif select_options(site, ActiveSupport::Inflector.pluralize(key.to_s))
				Select
			elsif [true, false].include? value
				Checkbox
			elsif key.to_s.end_with?("_path") || key.to_s.end_with?("_paths")
				File
			elsif key.to_s.downcase.end_with?("_datetime") || key.to_s.downcase == "datetime" || value.is_a?(::Time)
				DateTime
			elsif key.to_s.downcase.end_with?("_date") || key.to_s.downcase == "date" || value.is_a?(::Date)
				Date
			elsif value.is_a?(String) && value.length > 50
				Textarea
			else
				Text
			end
		end

		def self.scalarish?(value)
			!value.is_a?(Enumerable) || (value.is_a?(Array) && value.all? { |v| !v.is_a?(Enumerable) })
		end

		Base = Struct.new(:key, :name, :value, :site) do
			def render
				Slim::Template.new("app/views/inputs/#{template}.slim").render(self)
			end

			def template
				self.class.name.downcase.split("::").last
			end
		end

		class Checkbox < Base
		end

		class Text < Base
		end

		class Textarea < Base
		end

		class File < Base
			def file
				Tint::File.new(site, value)
			end

			def encoded_image
				Base64.encode64(file.path.open.read) if file.image? && file.size / 2**20 < 10
			end
		end
<commit_msg>If _path key is nil, do not crash<commit_after>require "active_support/inflector/methods"
require_relative "future"

module Tint
	module Input
		def self.select_options(site, key)
			site.config.dig("options", key)
		end

		def self.type(key, value, site)
			return unless scalarish?(value)

			if select_options(site, key)
				MultipleSelect
			elsif select_options(site, ActiveSupport::Inflector.pluralize(key.to_s))
				Select
			elsif [true, false].include? value
				Checkbox
			elsif key.to_s.end_with?("_path") || key.to_s.end_with?("_paths")
				File
			elsif key.to_s.downcase.end_with?("_datetime") || key.to_s.downcase == "datetime" || value.is_a?(::Time)
				DateTime
			elsif key.to_s.downcase.end_with?("_date") || key.to_s.downcase == "date" || value.is_a?(::Date)
				Date
			elsif value.is_a?(String) && value.length > 50
				Textarea
			else
				Text
			end
		end

		def self.scalarish?(value)
			!value.is_a?(Enumerable) || (value.is_a?(Array) && value.all? { |v| !v.is_a?(Enumerable) })
		end

		Base = Struct.new(:key, :name, :value, :site) do
			def render
				Slim::Template.new("app/views/inputs/#{template}.slim").render(self)
			end

			def template
				self.class.name.downcase.split("::").last
			end
		end

		class Checkbox < Base
		end

		class Text < Base
		end

		class Textarea < Base
		end

		class File < Base
			def file
				Tint::File.new(site, value) if value
			end

			def encoded_image
				Base64.encode64(file.path.open.read) if file && file.image? && file.size / 2**20 < 10
			end
		end

{'fraction_non_alphanumeric': 0.14058881905391996, 'fraction_numerical': 0.007277538868673503, 'mean_word_length': 3.4081632653061225, 'pattern_counts': {'":': 2, '<': 13, '<?xml version=': 0, '>': 5, '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': '6289012', 'n_tokens_mistral': 1312, 'n_tokens_neox': 1113, 'n_words': 234}