-
Notifications
You must be signed in to change notification settings - Fork 67
/
generateReadme.groovy
78 lines (58 loc) · 1.89 KB
/
generateReadme.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
@Grapes(
@Grab(group='com.google.guava', module='guava', version='18.0')
)
import com.google.common.base.CaseFormat
def file = new File("resources/liveTemplates/Bootstrap3.xml")
def root = new XmlParser().parse(file)
def templates = root.template
def components = templates.collect {
new Component(text:it.'@description', code: it.'@name', context:findMainContext(it))
}
def sorted = components.sort { it.code }
def groups = splitInGroups(sorted)
printToc(groups)
printComponents(groups)
void printToc(groups) {
groups.each {
println "- [${it.name}](#${CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, it.name)})"
}
}
void printComponents(groups) {
groups.each { group ->
println ""
println "### ${group.name}"
println ""
println "| Component | Snippet code | Context |"
println "|------------------------------- | -------------------------------| ------- |"
group.components.each {
println "| ${String.format("%-30s", it.text)} | ${String.format("%-30s", it.code)} | ${String.format("%-7s", it.context)} |"
}
}
}
def findMainContext(template) {
template.context.option.'@name'.contains('HTML') ? "HTML" : "CSS"
}
private List<Group> splitInGroups(components) {
def groups = []
Group lastGroup = null
components.each { component ->
def groupName = component.code.split(':')[0][4..-1].capitalize()
def group = new Group(name:groupName)
if(lastGroup == null || group.name != lastGroup.name) {
lastGroup = new Group(name:groupName)
groups << lastGroup
}
lastGroup.components.add(component)
}
return groups
}
class Group {
String name
List components = []
}
class Component {
String text, code, context
String getText() {
text ?: 'No description'
}
}