Skip to content
This repository has been archived by the owner on Feb 22, 2024. It is now read-only.

Commit

Permalink
added styles.css generation #102
Browse files Browse the repository at this point in the history
  • Loading branch information
Falk Sippach authored and ascheman committed Feb 22, 2020
1 parent 564b9be commit bb25eab
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package org.dukecon.server.convert

import com.fasterxml.jackson.databind.ObjectMapper
import groovy.text.SimpleTemplateEngine
import groovy.transform.CompileStatic
import groovy.util.logging.Slf4j
import org.dukecon.model.Conference
import org.dukecon.model.CoreImages
import org.dukecon.model.Styles
import org.dukecon.server.conference.ConferencesConfiguration
import org.dukecon.server.conference.SpeakerImageService
import org.dukecon.server.convert.impl.StylesCssResource
Expand All @@ -16,7 +18,6 @@ import org.dukecon.server.util.ResourcesFinder
import java.nio.file.Files
import java.time.format.DateTimeFormatter


@CompileStatic
@Slf4j
class GenerateDukecon {
Expand Down Expand Up @@ -64,15 +65,21 @@ class GenerateDukecon {
objectMapper.writeValue(imageResourcesJson, getImageResourcesJsonContent(conferenceConfig))
log.info("Created {}", imageResourcesJson.absolutePath)

ResourceFileProvider<String> stylesCssResource = new StylesCssResource(conferenceConfig.id, conferenceConfig.styles, '/templates/styles.ftl')
File stylesCssFile = new File("${conferenceStartDirectoryName}/${stylesCssResource.fileName}")
stylesCssFile.getParentFile().mkdirs()
stylesCssFile.write(stylesCssResource.getContent())
log.info("Created {}", stylesCssFile.absolutePath)

def cssStyles = generateStylesCssContent(conferenceConfig)
File stylesCss = new File("${conferenceStartDirectoryName}/styles.css")
stylesCss.write(cssStyles)
log.info("Created {}", stylesCss.absolutePath)
}
}

private static String generateStylesCssContent(ConferencesConfiguration.Conference conference) {
Styles styles = new Styles(conference.getStyles())

def templateEngine = new SimpleTemplateEngine()
def template = templateEngine.createTemplate(new File('C:\\03-projects\\dukecon\\dukecon_server_stable\\converters\\src\\main\\resources\\templates\\styles.gtl').text);
return template.make([styles: styles])
}

private static CoreImages getImageResourcesJsonContent(ConferencesConfiguration.Conference c) {
def images = CoreImages.builder().build()
def resourceDir = "img/${c.id}"
Expand Down
64 changes: 64 additions & 0 deletions converters/src/main/resources/templates/styles.gtl
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
.dark {
color: ${styles.dark};
fill: ${styles.dark};
border-color: ${styles.dark};
}
.darkBack {
background-color: ${styles.dark};
}
.darkLink {
color: ${styles.darkLink};
fill: ${styles.darkLink};
border-color: ${styles.darkLink};
}
.darkLinkBack {
background-color: ${styles.darkLink};
}
.reverse {
color: ${styles.reverse};
fill: ${styles.reverse};
}
.reverseBack {
background-color: ${styles.reverse};
}
.highlight {
color: ${styles.highlight};
fill: ${styles.highlight};
}
.highlightBack {
background-color: ${styles.highlight};
}
.alternate {
color: ${styles.alternate};
fill: ${styles.alternate};
}
.alternateBack {
background-color: ${styles.alternate};
fill: ${styles.alternate};
}
a {
color: ${styles.darkLink};
fill: ${styles.darkLink};
}
a:hover, a:focus {
color: ${styles.hoverLink};
}
h1 a:hover, h1 a:focus {
background-color:${styles.reverse};
color: ${styles.dark};
fill: ${styles.dark};
}
h1 a.active:hover, h1 a.active:focus {
background-color:${styles.reverse};
color: ${styles.dark};
fill: ${styles.dark};
}
button.highlightBack:hover, button.highlightBack:focus {
background-color: ${styles.highlight};
}
#login-area a.button:hover svg path.line, #login-area a.button:focus svg path.line {
fill: ${styles.dark};
}
h1 #mainmenu-button svg:hover, h1 #mainmenu-button svg:focus {
fill: ${styles.dark};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.dukecon.server.conference

import spock.lang.Specification

/**
* @author Falk Sippach, [email protected], @sippsack
*/
class ImageWithNameSpec extends Specification {

def "test write image to disk" () {
given:
def image = new SpeakerImageService.ImageWithName("abc.jpeg", [] as byte[])
def path = File.createTempDir().getAbsolutePath()
when:
image.writeToDisk(path)
then:
new File(path + File.separator + image.filename).exists()
}

}

0 comments on commit bb25eab

Please sign in to comment.