<commit_before>package com.energizedwork.midcenturyipsum

import com.google.inject.Inject
import org.ratpackframework.handling.*
import static groovy.json.JsonOutput.toJson
import static org.ratpackframework.groovy.Template.groovyTemplate

class IpsumHandler implements Handler {

	public static final int DEFAULT_PARAGRAPHS = 4

	private final IpsumGenerator generator

	@Inject
	IpsumHandler(IpsumGenerator generator) {
		this.generator = generator
	}

	@Override
	void handle(Context context) {
		try {
			context.with {
				int paras = pathTokens.paras?.toInteger() ?: DEFAULT_PARAGRAPHS
				paras = Math.min(paras, 25)
				def ipsum = generator.paragraphs(paras)

				respond byContent.plainText {
					response.send ipsum.join("\n")
				}
				.json {
					response.send toJson(ipsum)
				}
				.html {
					render groovyTemplate("index.html", ipsum: ipsum.collect { "<p>$it</p>" }.join(""), paras: paras)
				}
			}
		} catch (NumberFormatException e) {
			context.clientError 400
		}
	}

}<commit_msg>use new PathTokens method<commit_after>package com.energizedwork.midcenturyipsum

import com.google.inject.Inject
import org.ratpackframework.handling.*
import static groovy.json.JsonOutput.toJson
import static org.ratpackframework.groovy.Template.groovyTemplate

class IpsumHandler implements Handler {

	public static final int DEFAULT_PARAGRAPHS = 4

	private final IpsumGenerator generator

	@Inject
	IpsumHandler(IpsumGenerator generator) {
		this.generator = generator
	}

	@Override
	void handle(Context context) {
		try {
			context.with {
				int paras = pathTokens.getAsInt("paras") ?: DEFAULT_PARAGRAPHS
				paras = Math.min(paras, 25)
				def ipsum = generator.paragraphs(paras)

				respond byContent.plainText {
					response.send ipsum.join("\n")
				}
				.json {
					response.send toJson(ipsum)
				}
				.html {
					render groovyTemplate("index.html", ipsum: ipsum.collect { "<p>$it</p>" }.join(""), paras: paras)
				}
			}
		} catch (NumberFormatException e) {
			context.clientError 400
		}
	}

}
{'fraction_non_alphanumeric': 0.10360138135175136, 'fraction_numerical': 0.0059200789343857915, 'mean_word_length': 3.817102137767221, 'pattern_counts': {'":': 0, '<': 7, '<?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': '2277611', 'n_tokens_mistral': 784, 'n_tokens_neox': 655, 'n_words': 139}