Skip to content

Commit

Permalink
Modified Freemarker output to write to files.
Browse files Browse the repository at this point in the history
  • Loading branch information
VineetReynolds committed Jan 25, 2013
1 parent 41f2a79 commit 739e3b6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
26 changes: 16 additions & 10 deletions src/main/java/org/jboss/forge/scaffold/html5/Html5Scaffold.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.File;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.StringWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -92,26 +93,27 @@ public List<Resource<?>> generateIndex(String targetDir, Resource<?> template, b
config.setClassForTemplateLoading(getClass(), "/scaffold/angularjs");
config.setObjectWrapper(new DefaultObjectWrapper());

List<String> entities = new ArrayList<String>();
ArrayList<Resource<?>> result = new ArrayList<Resource<?>>();
List<String> entityNames = new ArrayList<String>();
WebResourceFacet web = this.project.getFacet(WebResourceFacet.class);
FileResource<?> partialsDirectory = web.getWebResource("partials");
for (Resource<?> resource : partialsDirectory.listResources()) {
entities.add(resource.getName());
entityNames.add(resource.getName());
}
Map root = new HashMap();
root.put("entities", entities);
root.put("entityNames", entityNames);

try {
Template indexTemplate = config.getTemplate("index.html.ftl");
Writer out = new OutputStreamWriter(System.out);
indexTemplate.process(root, out);
out.flush();
Writer contents = new StringWriter();
indexTemplate.process(root, contents);
contents.flush();
result.add(ScaffoldUtil.createOrOverwrite(prompt, web.getWebResource("index.html"), contents.toString(), overwrite));
} catch (IOException e) {
throw new RuntimeException(e);
} catch (TemplateException e) {
throw new RuntimeException(e);
}
ArrayList<Resource<?>> result = new ArrayList<Resource<?>>();
return result;
}

Expand All @@ -122,22 +124,26 @@ public List<Resource<?>> generateFromEntity(String targetDir, Resource<?> templa
Configuration config = new Configuration();
config.setClassForTemplateLoading(getClass(), "/scaffold/angularjs");
config.setObjectWrapper(new DefaultObjectWrapper());


ArrayList<Resource<?>> result = new ArrayList<Resource<?>>();
WebResourceFacet web = this.project.getFacet(WebResourceFacet.class);
Map root = new HashMap();
root.put("entity", entity);

try {
Template indexTemplate = config.getTemplate("partials/detail.html.ftl");
Writer out = new OutputStreamWriter(System.out);
Writer out = new StringWriter();
indexTemplate.process(root, out);
out.flush();
result.add(ScaffoldUtil.createOrOverwrite(prompt,
web.getWebResource("/partials/" + entity.getName() + "/detail.html"), out.toString(), overwrite));
} catch (IOException e) {
throw new RuntimeException(e);
} catch (TemplateException e) {
throw new RuntimeException(e);
}
generateIndex(targetDir, template, overwrite);
return new ArrayList<Resource<?>>();
return result;
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/scaffold/angularjs/index.html.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
<img src="images/forge-logo.png" alt="JBoss Forge"></img>
<nav class="well sidebar-nav">
<ul id="sidebar-entries" class="nav nav-list">
<#list entities as entity>
<li><a href="#${entity.name}">${entity.name}</a></li>
<#list entityNames as entityName>
<li><a href="#${entityName}">${entityName}</a></li>
</#list>
</ul>
</nav>
Expand Down

0 comments on commit 739e3b6

Please sign in to comment.