Removed untyped contructor from ComponentRegistration and add a protected setter.
[castle.git] / Experiments / Generator / Generators / Scaffold / ScaffoldGenerator.boo
blobf7902d35f1bfbba3f4a6bd07db0337b848b567e4
1 class ScaffoldGenerator(NamedGeneratorBase):
2 [Property(Area)] _area as string
3 [Property(Controller)] _controller as string
4 [Property(Model)] _model as string
6 def Run():
7 _model = Name
8 if Argv.Length > 0:
9 # controller name is specified
10 matches = /((\w+)\/|)(\w+)/.Match(Argv[0])
11 _area = matches.Groups[2].Value
12 _controller = matches.Groups[3].Value
13 else:
14 # controller name is not specified so
15 # it is plural of model name
16 _controller = _model.ToPlural()
18 if Area == "" or Area == null:
19 Area = null
20 controllerPath = ControllersBasePath
21 controllerTestPath = ControllersTestsBasePath
22 viewPath = "${ViewsBasePath}/${ControllerFileName}"
23 else:
24 controllerPath = "${ControllersBasePath}/${Area.ToLower()}"
25 controllerTestPath = "${ControllersTestsBasePath}/${Area.ToLower()}"
26 viewPath = "${ViewsBasePath}/${Area.ToLower()}/${ControllerFileName}"
28 MkDir(ControllersBasePath)
29 Process('ApplicationController.cs', "${ControllersBasePath}/ApplicationController.cs", true)
31 MkDir(controllerPath)
32 Process('Controller.cs', "${controllerPath}/${ControllerName}Controller.cs")
34 MkDir(controllerTestPath)
35 Process('Test.cs', "${controllerTestPath}/${ControllerName}ControllerTest.cs")
37 MkDir(HelpersBasePath)
38 Process('ScaffoldHelper.cs', "${HelpersBasePath}/ScaffoldHelper.cs", true)
40 MkDir(viewPath)
41 Process("views/list.${ViewEngineExtension}", "${viewPath}/list.${ViewEngineExtension}")
42 Process("views/edit.${ViewEngineExtension}", "${viewPath}/edit.${ViewEngineExtension}")
43 Process("views/view.${ViewEngineExtension}", "${viewPath}/view.${ViewEngineExtension}")
44 Process("views/new.${ViewEngineExtension}", "${viewPath}/new.${ViewEngineExtension}")
45 Process("views/_form.${ViewEngineExtension}", "${viewPath}/_form.${ViewEngineExtension}")
47 MkDir("${ViewsBasePath}/layouts")
48 Process("views/layout.${ViewEngineExtension}", "${ViewsBasePath}/layouts/${ControllerFileName}.${ViewEngineExtension}")
50 MkDir("${StaticContentBasePath}/stylesheets")
51 Process('style.css', "${StaticContentBasePath}/stylesheets/scaffold.css", true)
53 def Usage():
54 return 'ModelName [[area/]controller]'
56 def Help():
57 return 'Generates a CRUD actions controller for a specified model.'
59 ControllerName:
60 get:
61 return Controller.ToClassName()
63 ControllerFileName:
64 get:
65 return Controller.ToFileName()
67 ControllerLink:
68 get:
69 if Area != null:
70 return "${Area}/${ControllerFileName}"
71 return ControllerFileName
73 ModelClassName:
74 get:
75 return _model.ToClassName()
77 Namespace:
78 get:
79 if Area != null:
80 return "${ControllersNamespace}.${Area.ToClassName()}"
81 return ControllersNamespace
83 TestsNamespace:
84 get:
85 if Area != null:
86 return "${ControllersTestsNamespace}.${Area.ToClassName()}"
87 return ControllersTestsNamespace
89 ApplicationControllerNamespace:
90 get:
91 return ControllersNamespace
93 ModelsNamespace:
94 get:
95 return Config.ModelsNamespace
97 HelpersNamespace:
98 get:
99 return Config.HelpersNamespace
101 ContentBasePath:
102 get:
103 return StaticContentBaseUrl
105 ActionExtension:
106 get:
107 return Config.ActionExtension