@@ -73,48 +73,32 @@ private class ActionViewParamsCall extends ActionViewContextCall, ParamsCall { }
7373abstract class RenderCall extends MethodCall {
7474 RenderCall ( ) { this .getMethodName ( ) = "render" }
7575
76- private string getWorkingDirectory ( ) {
77- result = this .getLocation ( ) .getFile ( ) .getParentContainer ( ) .getAbsolutePath ( )
76+ private Expr getTemplatePathArgument ( ) {
77+ // TODO: support other ways of specifying paths (e.g. `file`)
78+ result = [ this .getKeywordArgument ( [ "partial" , "template" , "action" ] ) , this .getArgument ( 0 ) ]
7879 }
7980
80- bindingset [ templatePath]
81- private string templatePathPattern ( string templatePath ) {
82- exists ( string basename , string relativeRoot |
83- // everything after the final slash, or the whole string if there is no slash
84- basename = templatePath .regexpCapture ( "^(?:.*/)?([^/]*)$" , 1 ) and
85- // everything up to and including the final slash
86- relativeRoot = templatePath .regexpCapture ( "^(.*/)?(?:[^/]*?)$" , 1 )
87- |
88- (
89- // path relative to <source_prefix>/app/views/
90- result = "%/app/views/" + relativeRoot + "%" + basename + "%"
91- or
92- // relative to file containing call
93- result = this .getWorkingDirectory ( ) + "%" + templatePath + "%"
94- )
95- )
81+ private string getTemplatePathValue ( ) {
82+ result = this .getTemplatePathArgument ( ) .( StringlikeLiteral ) .getValueText ( )
9683 }
9784
98- private string getTemplatePathPatterns ( ) {
99- exists ( string templatePath |
100- exists ( Expr arg |
101- // TODO: support other ways of specifying paths (e.g. `file`)
102- arg = this .getKeywordArgument ( "partial" ) or
103- arg = this .getKeywordArgument ( "template" ) or
104- arg = this .getKeywordArgument ( "action" ) or
105- arg = this .getArgument ( 0 )
106- |
107- templatePath = arg .( StringlikeLiteral ) .getValueText ( )
108- )
109- |
110- result = this .templatePathPattern ( templatePath )
111- )
85+ // everything up to and including the final slash, but ignoring any leading slash
86+ private string getSubPath ( ) {
87+ result = this .getTemplatePathValue ( ) .regexpCapture ( "^/?(.*/)?(?:[^/]*?)$" , 1 )
88+ }
89+
90+ // everything after the final slash, or the whole string if there is no slash
91+ private string getBaseName ( ) {
92+ result = this .getTemplatePathValue ( ) .regexpCapture ( "^/?(?:.*/)?([^/]*?)$" , 1 )
11293 }
11394
11495 /**
115- * Get the template file to be rendered by this call, if any.
96+ * Gets the template file to be rendered by this call, if any.
11697 */
117- ErbFile getTemplateFile ( ) { result .getAbsolutePath ( ) .matches ( this .getTemplatePathPatterns ( ) ) }
98+ ErbFile getTemplateFile ( ) {
99+ result .getTemplateName ( ) = this .getBaseName ( ) and
100+ result .getRelativePath ( ) .matches ( "%/" + this .getSubPath ( ) + "%" )
101+ }
118102
119103 /**
120104 * Get the local variables passed as context to the renderer
0 commit comments