Tests working now.
This commit is contained in:
parent
68c252d077
commit
158e87942c
@ -1,30 +1,9 @@
|
||||
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 {
|
||||
|
||||
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)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6,10 +6,14 @@ import com.jessebrault.ssg.util.FileNameHandler
|
||||
import com.jessebrault.ssg.util.RelativePathHandler
|
||||
import org.slf4j.Logger
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.slf4j.Marker
|
||||
import org.slf4j.MarkerFactory
|
||||
|
||||
class StaticSiteGeneratorImpl implements StaticSiteGenerator {
|
||||
|
||||
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 TextFilesFactory textFilesFactory
|
||||
@ -23,8 +27,10 @@ class StaticSiteGeneratorImpl implements StaticSiteGenerator {
|
||||
|
||||
@Override
|
||||
void generate(SiteSpec spec) {
|
||||
logger.trace(enter, 'spec: {}', spec)
|
||||
def textFiles = this.textFilesFactory.getTextFiles(spec.textsDir)
|
||||
def pageTemplates = this.pageTemplatesFactory.getTemplates(spec.templatesDir)
|
||||
logger.debug('textFiles: {}, pageTemplates: {}', textFiles, pageTemplates)
|
||||
textFiles.each {
|
||||
logger.info('processing textFile: {}', it.relativePath)
|
||||
def fileNameHandler = new FileNameHandler(it.file)
|
||||
@ -67,6 +73,7 @@ class StaticSiteGeneratorImpl implements StaticSiteGenerator {
|
||||
logger.info('writing result to {}', outFile)
|
||||
outFile.write(result)
|
||||
}
|
||||
logger.trace(exit, '')
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ class FileNameHandler {
|
||||
private final File file
|
||||
|
||||
String getExtension() {
|
||||
this.file.name.substring(this.file.name.lastIndexOf('.') + 1)
|
||||
this.file.name.substring(this.file.name.lastIndexOf('.'))
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,6 +8,8 @@ import com.jessebrault.ssg.text.MarkdownRenderer
|
||||
import com.jessebrault.ssg.text.TextFileType
|
||||
import com.jessebrault.ssg.text.TextFilesFactoryImpl
|
||||
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.assertTrue
|
||||
|
@ -6,7 +6,9 @@ import static org.junit.jupiter.api.Assertions.assertEquals
|
||||
|
||||
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
|
||||
void findsTemplate() {
|
||||
@ -19,6 +21,7 @@ class PageTemplatesFactoryTests {
|
||||
def t0 = r[0]
|
||||
assertEquals('test.gsp', t0.relativePath)
|
||||
assertEquals('<% out << text %>', t0.file.text)
|
||||
assertEquals(gspType, t0.type)
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -35,6 +38,7 @@ class PageTemplatesFactoryTests {
|
||||
def t0 = r[0]
|
||||
assertEquals('nested/nested.gsp', t0.relativePath)
|
||||
assertEquals('<%= text %>', t0.file.text)
|
||||
assertEquals(gspType, t0.type)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -6,7 +6,9 @@ import static org.junit.jupiter.api.Assertions.assertEquals
|
||||
|
||||
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
|
||||
void findsFile() {
|
||||
@ -19,7 +21,7 @@ class TextsFilesFactoryTests {
|
||||
def f0 = r[0]
|
||||
assertEquals('test.md', f0.relativePath)
|
||||
assertEquals('**Hello, World!**', f0.file.text)
|
||||
assertEquals(TextFile.Type.MARKDOWN, f0.type)
|
||||
assertEquals(markdownType, f0.type)
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -35,7 +37,7 @@ class TextsFilesFactoryTests {
|
||||
def f0 = r[0]
|
||||
assertEquals('nested/nested.md', f0.relativePath)
|
||||
assertEquals('**Hello!**', f0.file.text)
|
||||
assertEquals(TextFile.Type.MARKDOWN, f0.type)
|
||||
assertEquals(markdownType, f0.type)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
}
|
@ -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)
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user