Skip to content

Commit

Permalink
rename _arg to defaultArgument so there is no confusion with _XXXX ge…
Browse files Browse the repository at this point in the history
…ts it so ${_XXXX}$ does NOT get html escaped such that the field tag still works properly
  • Loading branch information
deanhiller committed Aug 11, 2016
1 parent 2cdbd22 commit 442e312
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 15 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# webpieces

To try the webserver

1. Download the release, unzip
2. run ./createProject.sh
3.

A project containing all the web pieces (WITH apis) to create a web server (and an actual web server, and an actual http proxy and an http client and an independent async http parser1.1 and independent http parser2......getting the idea yet, self contained pieces). This webserver is also made to be extremely Test Driven Development for web app developers such that tests can be written that will test all your filters, controllers, views, redirects and everything all together in one for GREAT whitebox QE type testing that can be done by the developer. Don't write brittle low layer tests and instead write high layer tests that are less brittle then their fine grained counter parts (something many of us do at twitter)

This project is essentially pieces that can be used to build any http related software and full stacks as well.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private String fetchArgs(Token token) {
tagArgs = expr.substring(indexOfSpace + 1).trim();
if (!tagArgs.matches("^[_a-zA-Z0-9]+\\s*:.*$")) {
//this is for the form #{tag 'something'} or #{tag variable}
tagArgs = "_arg:" + tagArgs;
tagArgs = "defaultArgument:" + tagArgs;
}

//TODO: record the tag used and source location to be verified at build time(ie. test will verify)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static String convertTemplatePathToClass(String fullPath) {

public static String serialize(Map<?, ?> args, String... unless) {
Set<String> unlessSet = new HashSet<String>(Arrays.asList(unless));
unlessSet.add("_arg");
unlessSet.add("defaultArgument");
StringBuilder attrs = new StringBuilder();
for (Object key : args.keySet()) {
String keyStr = key.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class ExtendsTag implements HtmlTag {

@Override
public void runTag(Map<Object, Object> args, Closure<?> body, PrintWriter out, GroovyTemplateSuperclass template, String srcLocation) {
Object name = args.get("_arg");
Object name = args.get("defaultArgument");
if(name == null)
throw new IllegalArgumentException("#{extends/}# tag must contain a template name like #{extends '../template.html'/}#. "+srcLocation);
else if(body != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ protected Map<String, Object> convertTagArgs(Map<Object, Object> tagArgs, Map<St
else if(tagArgs.get("field") != null)
throw new IllegalArgumentException("tag "+getName()+" must not define an argument of 'field' as that is reserved and will be overwritten ");

String _arg = tagArgs.get("_arg").toString();
Map<String, Object> field = createFieldData(_arg, pageArgs);
String fieldName = tagArgs.get("defaultArgument").toString();
Map<String, Object> field = createFieldData(fieldName, pageArgs);

Map<String, Object> copy = new HashMap<>();
for(Map.Entry<Object, Object> entry : tagArgs.entrySet()) {
Expand All @@ -58,20 +58,26 @@ else if(tagArgs.get("field") != null)
return copy;
}

private Map<String, Object> createFieldData(String _arg, Map<String, Object> pageArgs) {
/**
*
* @param fieldName Is the argument like 'user.account.name'
* @param pageArgs
* @return
*/
private Map<String, Object> createFieldData(String fieldName, Map<String, Object> pageArgs) {
Map<String, Object> field = new HashMap<String, Object>();
field.put("name", _arg);
field.put("id", _arg.replace('.', '_'));
//field.put("flash", Flash.current().get(_arg));
field.put("name", fieldName);
field.put("id", fieldName.replace('.', '_'));
//field.put("flash", Flash.current().get(fieldName));
//field.put("flashArray", field.get("flash") != null && !StringUtils.isEmpty(field.get("flash").toString()) ? field.get("flash")
// .toString().split(",") : new String[0]);
//field.put("error", Validation.error(_arg));
//field.put("error", Validation.error(fieldName));
//field.put("errorClass", field.get("error") != null ? "hasError" : "");
String[] pieces = _arg.split("\\.");
String[] pieces = fieldName.split("\\.");
Object obj = pageArgs.get(pieces[0]);
if (pieces.length > 1) {
try {
String path = _arg.substring(_arg.indexOf(".") + 1);
String path = fieldName.substring(fieldName.indexOf(".") + 1);
Object value = PropertyUtils.getProperty(obj, path);
field.put("value", value);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class HtmlGetTag implements HtmlTag {

@Override
public void runTag(Map<Object, Object> args, Closure<?> body, PrintWriter out, GroovyTemplateSuperclass template, String srcLocation) {
Object name = args.get("_arg");
Object name = args.get("defaultArgument");
if(name == null)
name = args.get("key");
if (name == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class HtmlSetTag implements HtmlTag {
@Override
public void runTag(Map<Object, Object> args, Closure<?> body, PrintWriter out, GroovyTemplateSuperclass template, String srcLocation) {
// Body case. Users should not be using _ as prefix to variable names so _arg only exists if it is just a body
Object name = args.get("_arg");
Object name = args.get("defaultArgument");
if (name != null && body != null) {
String value = ClosureUtil.toString(body);
template.putSetTagProperty(name, value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void runTag(Map<Object, Object> tagArgs, Closure<?> body, PrintWriter out
protected abstract Map<String, Object> convertTagArgs(Map<Object, Object> tagArgs, Map<String, Object> pageArgs, Closure<?> body, String srcLocation);

protected String getFilePath(GroovyTemplateSuperclass callingTemplate, Map<Object, Object> args, String srcLocation) {
Object name = args.get("_arg");
Object name = args.get("defaultArgument");
if(name == null)
throw new IllegalArgumentException("#{"+getName()+"/}# tag must contain a template name like #{"+getName()+" '../template.html'/}#. "+srcLocation);

Expand Down

0 comments on commit 442e312

Please sign in to comment.