@@ -9,8 +9,6 @@ namespace WebApiToTypeScript.Views
9
9
{
10
10
public class ViewsService : ServiceAware
11
11
{
12
- private string ViewsSourceDirectory { get ; set ; }
13
-
14
12
private List < ViewNode > FeatureViews { get ; }
15
13
= new List < ViewNode > ( ) ;
16
14
@@ -21,14 +19,24 @@ public TypeScriptBlock CreateViewsBlock()
21
19
22
20
public TypeScriptBlock WriteViewsToBlock ( TypeScriptBlock viewsBlock )
23
21
{
24
- ViewsSourceDirectory = Path . GetFullPath ( Config . ViewsSourceDirectory ) ;
22
+ foreach ( var featureView in FeatureViews )
23
+ {
24
+ WriteViewEntry ( viewsBlock , featureView ) ;
25
+ }
26
+
27
+ return viewsBlock ;
28
+ }
29
+
30
+ public void AddViews ( )
31
+ {
32
+ var viewsSourceDirectory = Path . GetFullPath ( Config . ViewsSourceDirectory ) ;
25
33
26
- var viewFiles = Directory . GetFiles ( ViewsSourceDirectory , "*.view. *", SearchOption . AllDirectories ) ;
34
+ var viewFiles = Directory . GetFiles ( viewsSourceDirectory , $ "* { Config . ViewsPattern } *", SearchOption . AllDirectories ) ;
27
35
28
36
foreach ( var viewFile in viewFiles )
29
37
{
30
38
var featureViewPath = Path . GetFullPath ( viewFile )
31
- . Split ( new [ ] { $@ "{ ViewsSourceDirectory } \" } , StringSplitOptions . RemoveEmptyEntries )
39
+ . Split ( new [ ] { $@ "{ viewsSourceDirectory } \" } , StringSplitOptions . RemoveEmptyEntries )
32
40
. Last ( ) ;
33
41
34
42
var parts = featureViewPath
@@ -54,7 +62,7 @@ public TypeScriptBlock WriteViewsToBlock(TypeScriptBlock viewsBlock)
54
62
. ToList ( ) ;
55
63
56
64
var viewNode = FeatureViews . Single ( v => v . Name == featureNamespace ) ;
57
- var nameThusFar = subFeatures . Count == 0 // instead should i skip last or first or something
65
+ var nameThusFar = subFeatures . Count == 0
58
66
? featureNamespace
59
67
: string . Empty ;
60
68
@@ -81,7 +89,7 @@ public TypeScriptBlock WriteViewsToBlock(TypeScriptBlock viewsBlock)
81
89
82
90
var fullViewNameInKebabCase = parts
83
91
. Last ( )
84
- . Split ( new [ ] { ".view." } , StringSplitOptions . RemoveEmptyEntries )
92
+ . Split ( new [ ] { Config . ViewsPattern } , StringSplitOptions . RemoveEmptyEntries )
85
93
. First ( ) ;
86
94
87
95
var fullViewNameInPascalCase = Helpers . ToPascalCaseFromKebabCase ( fullViewNameInKebabCase ) ;
@@ -90,25 +98,19 @@ public TypeScriptBlock WriteViewsToBlock(TypeScriptBlock viewsBlock)
90
98
? Regex . Replace ( fullViewNameInPascalCase , $ "^{ nameThusFar } ", string . Empty )
91
99
: fullViewNameInPascalCase ;
92
100
93
- viewNode . ViewEntries . Add ( new ViewEntry {
101
+ viewNode . ViewEntries . Add ( new ViewEntry
102
+ {
94
103
Name = viewName ,
95
104
Path = featureViewPath . Replace ( @"\" , "/" )
96
105
} ) ;
97
106
}
98
-
99
- foreach ( var featureView in FeatureViews )
100
- {
101
- WriteViewEntry ( viewsBlock , featureView ) ;
102
- }
103
-
104
- return viewsBlock ;
105
107
}
106
108
107
109
private void WriteViewEntry ( TypeScriptBlock viewsBlock , ViewNode featureViewNode , bool isChild = false )
108
110
{
109
- var viewNamespace = isChild
110
- ? string . Empty
111
- : ".Views" ;
111
+ var viewNamespace = Config . UseViewsGroupingNamespace && ! isChild
112
+ ? ".Views"
113
+ : string . Empty ;
112
114
113
115
var featureBlock = viewsBlock
114
116
. AddAndUseBlock ( $ "export namespace { featureViewNode . Name } { viewNamespace } ") ;
0 commit comments