Tests working now.

This commit is contained in:
JesseBrault0709 2023-01-04 11:05:13 -06:00
parent 68c252d077
commit 158e87942c
8 changed files with 54 additions and 27 deletions

View File

@ -1,30 +1,9 @@
package com.jessebrault.ssg package com.jessebrault.ssg
import com.jessebrault.ssg.text.MarkdownFrontMatterGetter
import com.jessebrault.ssg.pagetemplate.GspRenderer
import com.jessebrault.ssg.pagetemplate.PageTemplatesFactoryImpl
import com.jessebrault.ssg.text.TextFilesFactoryImpl
import com.jessebrault.ssg.text.MarkdownRenderer
class StaticSiteGeneratorCli { class StaticSiteGeneratorCli {
static void main(String[] args) { static void main(String[] args) {
// def config = new Config(
// textFilesFactory: new TextFilesFactoryImpl(),
// templatesFactory: new PageTemplatesFactoryImpl(),
// markdownFrontMatterGetter: new MarkdownFrontMatterGetter(),
// markdownRenderer: new MarkdownRenderer(),
// gspRenderer: new GspRenderer()
// )
// def ssg = new StaticSiteGeneratorImpl(config)
// def spec = new SiteSpec(
// buildDir: new File('build'),
// staticDir: new File('static'),
// textsDir: new File('texts'),
// templatesDir: new File('templates'),
// templatePartsDir: new File('templatePartsDir')
// )
// ssg.generate(spec)
} }
} }

View File

@ -6,10 +6,14 @@ import com.jessebrault.ssg.util.FileNameHandler
import com.jessebrault.ssg.util.RelativePathHandler import com.jessebrault.ssg.util.RelativePathHandler
import org.slf4j.Logger import org.slf4j.Logger
import org.slf4j.LoggerFactory import org.slf4j.LoggerFactory
import org.slf4j.Marker
import org.slf4j.MarkerFactory
class StaticSiteGeneratorImpl implements StaticSiteGenerator { class StaticSiteGeneratorImpl implements StaticSiteGenerator {
private static final Logger logger = LoggerFactory.getLogger(StaticSiteGeneratorImpl) private static final Logger logger = LoggerFactory.getLogger(StaticSiteGeneratorImpl)
private static final Marker enter = MarkerFactory.getMarker('ENTER')
private static final Marker exit = MarkerFactory.getMarker('EXIT')
private final Config config private final Config config
private final TextFilesFactory textFilesFactory private final TextFilesFactory textFilesFactory
@ -23,8 +27,10 @@ class StaticSiteGeneratorImpl implements StaticSiteGenerator {
@Override @Override
void generate(SiteSpec spec) { void generate(SiteSpec spec) {
logger.trace(enter, 'spec: {}', spec)
def textFiles = this.textFilesFactory.getTextFiles(spec.textsDir) def textFiles = this.textFilesFactory.getTextFiles(spec.textsDir)
def pageTemplates = this.pageTemplatesFactory.getTemplates(spec.templatesDir) def pageTemplates = this.pageTemplatesFactory.getTemplates(spec.templatesDir)
logger.debug('textFiles: {}, pageTemplates: {}', textFiles, pageTemplates)
textFiles.each { textFiles.each {
logger.info('processing textFile: {}', it.relativePath) logger.info('processing textFile: {}', it.relativePath)
def fileNameHandler = new FileNameHandler(it.file) def fileNameHandler = new FileNameHandler(it.file)
@ -67,6 +73,7 @@ class StaticSiteGeneratorImpl implements StaticSiteGenerator {
logger.info('writing result to {}', outFile) logger.info('writing result to {}', outFile)
outFile.write(result) outFile.write(result)
} }
logger.trace(exit, '')
} }
} }

View File

@ -8,7 +8,7 @@ class FileNameHandler {
private final File file private final File file
String getExtension() { String getExtension() {
this.file.name.substring(this.file.name.lastIndexOf('.') + 1) this.file.name.substring(this.file.name.lastIndexOf('.'))
} }
} }

View File

@ -8,6 +8,8 @@ import com.jessebrault.ssg.text.MarkdownRenderer
import com.jessebrault.ssg.text.TextFileType import com.jessebrault.ssg.text.TextFileType
import com.jessebrault.ssg.text.TextFilesFactoryImpl import com.jessebrault.ssg.text.TextFilesFactoryImpl
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import static org.junit.jupiter.api.Assertions.assertEquals import static org.junit.jupiter.api.Assertions.assertEquals
import static org.junit.jupiter.api.Assertions.assertTrue import static org.junit.jupiter.api.Assertions.assertTrue

View File

@ -6,7 +6,9 @@ import static org.junit.jupiter.api.Assertions.assertEquals
class PageTemplatesFactoryTests { class PageTemplatesFactoryTests {
private final PageTemplatesFactory templateFactory = new PageTemplatesFactoryImpl() private static final PageTemplateType gspType = new PageTemplateType(['.gsp'], null)
private final PageTemplatesFactory templateFactory = new PageTemplatesFactoryImpl([gspType])
@Test @Test
void findsTemplate() { void findsTemplate() {
@ -19,6 +21,7 @@ class PageTemplatesFactoryTests {
def t0 = r[0] def t0 = r[0]
assertEquals('test.gsp', t0.relativePath) assertEquals('test.gsp', t0.relativePath)
assertEquals('<% out << text %>', t0.file.text) assertEquals('<% out << text %>', t0.file.text)
assertEquals(gspType, t0.type)
} }
@Test @Test
@ -35,6 +38,7 @@ class PageTemplatesFactoryTests {
def t0 = r[0] def t0 = r[0]
assertEquals('nested/nested.gsp', t0.relativePath) assertEquals('nested/nested.gsp', t0.relativePath)
assertEquals('<%= text %>', t0.file.text) assertEquals('<%= text %>', t0.file.text)
assertEquals(gspType, t0.type)
} }
@Test @Test

View File

@ -6,7 +6,9 @@ import static org.junit.jupiter.api.Assertions.assertEquals
class TextsFilesFactoryTests { class TextsFilesFactoryTests {
private final TextFilesFactory textFilesFactory = new TextFilesFactoryImpl() private static final TextFileType markdownType = new TextFileType(['.md'], null, null)
private final TextFilesFactory textFilesFactory = new TextFilesFactoryImpl([markdownType])
@Test @Test
void findsFile() { void findsFile() {
@ -19,7 +21,7 @@ class TextsFilesFactoryTests {
def f0 = r[0] def f0 = r[0]
assertEquals('test.md', f0.relativePath) assertEquals('test.md', f0.relativePath)
assertEquals('**Hello, World!**', f0.file.text) assertEquals('**Hello, World!**', f0.file.text)
assertEquals(TextFile.Type.MARKDOWN, f0.type) assertEquals(markdownType, f0.type)
} }
@Test @Test
@ -35,7 +37,7 @@ class TextsFilesFactoryTests {
def f0 = r[0] def f0 = r[0]
assertEquals('nested/nested.md', f0.relativePath) assertEquals('nested/nested.md', f0.relativePath)
assertEquals('**Hello!**', f0.file.text) assertEquals('**Hello!**', f0.file.text)
assertEquals(TextFile.Type.MARKDOWN, f0.type) assertEquals(markdownType, f0.type)
} }
@Test @Test

View File

@ -0,0 +1,18 @@
package com.jessebrault.ssg.util
import org.junit.jupiter.api.Test
import static org.junit.jupiter.api.Assertions.assertEquals
class FileNameHandlerTests {
private final FileNameHandler fileNameHandler = new FileNameHandler()
@Test
void getsCorrectExtension() {
def file = new File('hello.txt')
def extension = new FileNameHandler(file).getExtension()
assertEquals('.txt', extension)
}
}

View File

@ -0,0 +1,15 @@
package com.jessebrault.ssg.util
import org.junit.jupiter.api.Test
import static org.junit.jupiter.api.Assertions.assertEquals
class RelativePathHandlerTests {
@Test
void stripsExtension() {
def stripped = new RelativePathHandler('hello.txt').getWithoutExtension()
assertEquals('hello', stripped)
}
}