Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Improve html builder generation code
Browse files Browse the repository at this point in the history
  • Loading branch information
chiquitinxx committed Sep 12, 2016
1 parent 068d225 commit b2fcaf7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
11 changes: 6 additions & 5 deletions src/main/groovy/org/grooscript/GenerateGrooscripTools.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ class JsGenerator {

public static final HTML_BUILDER_SOURCE = 'src/main/groovy/org/grooscript/builder/HtmlBuilder.groovy'

static void generateGrooscriptHtmlBuilderJs(String pathSource, String pathJsDestination) {
public static void generateHtmlBuilder(String pathJsDestination) {
generateGrooscriptConvertedJs(HTML_BUILDER_SOURCE, pathJsDestination)
}

private static void generateGrooscriptConvertedJs(String pathSource, String pathJsDestination) {
File source = new File(pathSource)
convertFile(source, pathJsDestination)
GsConsole.info("File $pathJsDestination has been generated.")
Expand All @@ -30,7 +34,4 @@ class JsGenerator {
}
}

JsGenerator.generateGrooscriptHtmlBuilderJs(
JsGenerator.HTML_BUILDER_SOURCE,
'src/main/resources/META-INF/resources/grooscript-html-builder.js'
)
JsGenerator.generateHtmlBuilder('src/main/resources/META-INF/resources/grooscript-html-builder.js')
26 changes: 21 additions & 5 deletions src/test/groovy/org/grooscript/JsGeneratorSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,30 @@
*/
package org.grooscript

import org.junit.Rule
import org.junit.rules.TemporaryFolder
import spock.lang.Specification

class JsGeneratorSpec extends Specification {
def 'test generation of js files'() {

@Rule
TemporaryFolder folder = new TemporaryFolder()

def 'test generation of html builder js file'() {
given:
String destination = folder.newFile('htmlbuilder.js').getPath()

expect:
JsGenerator.generateGrooscriptHtmlBuilderJs(
'src/main/groovy/org/grooscript/builder/HtmlBuilder.groovy',
'src/main/resources/META-INF/resources/grooscript-html-builder.js'
)
sizeOfDestinationFile(destination) == 0

when:
JsGenerator.generateHtmlBuilder(destination)

then:
sizeOfDestinationFile(destination) > 100
}

private int sizeOfDestinationFile(String destination) {
new File(destination).text.size()
}
}

0 comments on commit b2fcaf7

Please sign in to comment.