@@ -73,48 +73,30 @@ private class ActionViewParamsCall extends ActionViewContextCall, ParamsCall { }
73
73
abstract class RenderCall extends MethodCall {
74
74
RenderCall ( ) { this .getMethodName ( ) = "render" }
75
75
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 ) ]
78
79
}
79
80
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 ( ) { result = this .getTemplatePathArgument ( ) .getValueText ( ) }
82
+
83
+ // everything up to and including the final slash, but ignoring any leading slash
84
+ private string getSubPath ( ) {
85
+ result = this .getTemplatePathValue ( ) .regexpCapture ( "^/?(.*/)?(?:[^/]*?)$" , 1 )
96
86
}
97
87
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
- )
88
+ // everything after the final slash, or the whole string if there is no slash
89
+ private string getBaseName ( ) {
90
+ result = this .getTemplatePathValue ( ) .regexpCapture ( "^/?(?:.*/)?([^/]*?)$" , 1 )
112
91
}
113
92
114
93
/**
115
- * Get the template file to be rendered by this call, if any.
94
+ * Gets the template file to be rendered by this call, if any.
116
95
*/
117
- ErbFile getTemplateFile ( ) { result .getAbsolutePath ( ) .matches ( this .getTemplatePathPatterns ( ) ) }
96
+ ErbFile getTemplateFile ( ) {
97
+ result .getTemplateName ( ) = this .getBaseName ( ) and
98
+ result .getRelativePath ( ) .matches ( "%app/views/" + this .getSubPath ( ) + "%" )
99
+ }
118
100
119
101
/**
120
102
* Get the local variables passed as context to the renderer
0 commit comments