Skip to content

Instantly share code, notes, and snippets.

@ilopmar
Last active August 29, 2015 14:16
Show Gist options
  • Select an option

  • Save ilopmar/a752644419fb8d2f2221 to your computer and use it in GitHub Desktop.

Select an option

Save ilopmar/a752644419fb8d2f2221 to your computer and use it in GitHub Desktop.
speakers_data.csv
package com.greachconf
import groovy.text.SimpleTemplateEngine
@Grab('com.xlson.groovycsv:groovycsv:1.0')
import com.xlson.groovycsv.CsvParser
@Grab('com.github.slugify:slugify:2.1.3')
import com.github.slugify.Slugify
String merge(String template, Map values) {
def engine = new SimpleTemplateEngine()
def templateBuilder = engine.createTemplate(template).make(values)
return templateBuilder.toString()
}
String bioTemplate = '''
[title_bar sub_heading="Greach 2015" heading="${title}"]
${abstractTalk}
[clear]
[title_bar sub_heading="${position}" heading="${name}"]
<span class="img-wrap alignleft nopadding push-right-large"><img class="rounded scale-with-grid" alt="${name}" src="${photoUrl}" width="158" /></span>
${bio}
'''
Slugify slugGenerator = new Slugify()
def data = "https://gist.githubusercontent.com/lmivan/a752644419fb8d2f2221/raw/27f5fbf7f0099f32716b7f0cb4984932c7136dd2/speakers_data.csv".toURL().text
def speakers = CsvParser.parseCsv(data)
speakers.each {
println "="*100
def speakerInfo = this.merge(bioTemplate,
[title: it.title,
abstractTalk: it.abstractTalk,
position: it.position,
name: it.name,
photoUrl: it.pictureUrl,
bio: it.bio]
)
println speakerInfo
println "-"*20
println it.title
println it.name
println "/speakers/" + slugGenerator.slugify("${it.name}-${it.title}")
println slugGenerator.slugify("${it.name}-${it.title}")
println "-"*20
}
name title position twitter pictureUrl bio abstractTalk talkUrl
Andres Almiray The Groovy Ecosystem Canoo Fellow aalmiray /wp-content/uploads/2014/01/andres-almiray.jpg Andres is a Java/Groovy developer and Java Champion, with more than 15 years of experience in software design and development. He has been involved in web and desktop application developments since the early days of Java. He is a true believer of open source and has participated in popular projects like Groovy, Griffon, JMatter and DbUnit, as well as starting his own projects (Json-lib, EZMorph, GraphicsBuilder, JideBuilder). Founding member and current project lead of the Griffon framework. Groovy is a well established player in the JVM since a few years ago. It's increased popularity across the years has spawned several projects that conform the Groovy Ecosystem. You've probably heard of Grails, Gradle, Griffon and Spock. But what about the rest of projects that are just waiting around the corner to be discovered and make your life easier? This talk presents them tools and libraries that use Groovy as the main driving force to get the job done. /speakers/andres-almiray-the-groovy-ecosystem/
Alexander (Sascha) Klein Groovy on the Shell Principal Consultant saschaklein /wp-content/uploads/2014/01/alexander-klein.jpg Alexander Klein is Principal Consultant at codecentric AG in germany. He works for more than 15 years in the java-ecosystem as developer, architect and trainer. His interests are UI-development and -ergonomy and development efficency. He is an avowed opensource and Groovy follower and Griffon commiter. Groovy is a powerfull development language with a lot of features and almost all we need. As we all are familiar with Java, Groovy and many libraries, why don't we use it to write scripts for system-automation? This session will show the best practices and how to overcome some obstacles when writing shell-scripts using Groovy. /speakers/alexander-sascha-klein-groovy-on-the-shell/
Alonso Torres Ortiz DSL'ing your Groovy Engineer alotor /wp-content/uploads/2014/01/alonso-torres.jpg Software engineer at Kaleidos Open Source. Alonso has been developing on JVM and Java ecosystem more than 8 years. Nowadays he is a full-time Groovy/Grails developer and is co-author and collaborator of several Open Source Grails plugins. Behind each good Groovy library or framework there is a good DSL (Domain Specific Language). And this is not by chance, one of the most exciting features of Groovy is its amazing syntax flexibility and metaprogramming capabilities that allow us do things in a highly expressive manner through DSLs. In this talk I'll explain the basics of doing DLS's with Groovy. What you'll need to start and what to investigate deeper. Also, we'll check some of the most well known ones libraries like Spock, Gradle or Grails so you can use their techniques in your own Groovy projects. /speakers/alonso-torres-dsl-ing-your-groovy/
@ilopmar
Copy link
Copy Markdown
Author

ilopmar commented Mar 4, 2015

This is a very small but powerful example of how to use Groovy SimpleTemplateEngine, CSVParser and Slugify libraries to generate the HMTL for every speaker page for the Greach Conference.

Run:

groovy SpeakersPageGenerator.groovy

It will print the HTML needed to create the pages using the speakers_data.csv file. In this example I only show 3 talks. You can check them only here and see that the source code is the same as the script generates.

http://greachconf.com/speakers/andres-almiray-the-groovy-ecosystem/
http://greachconf.com/speakers/alexander-sascha-klein-groovy-on-the-shell/
http://greachconf.com/speakers/alonso-torres-dsl-ing-your-groovy/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment