Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

replacing 8444RELATIVE8444 path in introduction chapters content

  • Loading branch information...
commit 97ddb87f117c6983a3946a309873eb22f551fb7b 1 parent 92157b7
@csokol csokol authored
View
9 src/main/java/br/com/caelum/tubaina/parser/html/kindle/IntroductionChaptersToKindle.java
@@ -20,23 +20,26 @@
private final TubainaHtmlDir bookRoot;
+ static final String RESOURCES_PATH = "introduction-chapters-resources";
+
public IntroductionChaptersToKindle(Parser parser, Configuration cfg, TubainaHtmlDir bookRoot) {
this.parser = parser;
this.cfg = cfg;
this.bookRoot = bookRoot;
}
- public StringBuffer generateIntroductionChapters(List<Chapter> chapters) {
+ public String generateIntroductionChapters(List<Chapter> chapters) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("parser", parser);
map.put("sanitizer", new HtmlSanitizer());
map.put("chapters", chapters);
for (Chapter chapter : chapters) {
- bookRoot.cd(Utilities.toDirectoryName(null, chapter.getTitle())).writeResources(
+ bookRoot.cd(Utilities.toDirectoryName(RESOURCES_PATH)).writeResources(
chapter.getResources());
}
StringBuffer processedContent = new FreemarkerProcessor(cfg).process(map, "introductionChapters.ftl");
- return processedContent;
+ String content = processedContent.toString().replace("$$RELATIVE$$", RESOURCES_PATH);
+ return content;
}
}
View
4 src/main/java/br/com/caelum/tubaina/parser/html/kindle/KindleGenerator.java
@@ -51,7 +51,7 @@ public void generate(Book book, File outputDir) throws IOException {
StringBuffer bookContent = generateHeader(book);
- StringBuffer introductionChaptersContent = generateIntroductionParts(book, bookRoot);
+ String introductionChaptersContent = generateIntroductionParts(book, bookRoot);
bookContent.append(introductionChaptersContent);
int partCount = 1;
@@ -68,7 +68,7 @@ public void generate(Book book, File outputDir) throws IOException {
bookRoot.writeIndex(bookContent);
}
- private StringBuffer generateIntroductionParts(Book book, TubainaHtmlDir bookRoot) {
+ private String generateIntroductionParts(Book book, TubainaHtmlDir bookRoot) {
return new IntroductionChaptersToKindle(parser, freeMarkerConfig, bookRoot)
.generateIntroductionChapters(book.getIntroductionChapters());
}
View
3  src/main/java/br/com/caelum/tubaina/util/Utilities.java
@@ -258,6 +258,9 @@ public static String toDirectoryName(final Integer num, String title) {
}
return title;
}
+ public static String toDirectoryName(String title) {
+ return toDirectoryName(null, title);
+ }
public static String titleSlug(String title) {
return new TitleSlug(title).toString();
View
2  src/test/java/br/com/caelum/tubaina/parser/html/kindle/KindleGeneratorTest.java
@@ -171,7 +171,7 @@ public void shouldCopyImagesFromIntroduction() throws IOException {
Book b = builder.build();
generator.generate(b, tempDir);
- File introDir = new File(tempDir, "intro");
+ File introDir = new File(tempDir, IntroductionChaptersToKindle.RESOURCES_PATH);
File copied = new File(introDir, imageName);
Assert.assertTrue(copied.exists());
Please sign in to comment.
Something went wrong with that request. Please try again.