shaml 0.5.0.alpha → 0.5.0.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/shaml/command.rb +146 -44
- data/lib/shaml/mono_load.rb +24 -9
- data/lib/shaml/templates/Delete.haml +6 -2
- data/lib/shaml/templates/Index.haml +8 -4
- data/lib/shaml/templates/Show.haml +4 -4
- data/lib/shaml/templates/WebSample.cs +5 -1
- data/lib/shaml/templates/WebSampleMap.cs +22 -0
- data/lib/shaml/templates/WebSampleTests.cs +1 -0
- data/lib/shaml/templates/WebSamplesController.cs +52 -42
- data/lib/shaml/templates/WebSamplesControllerTests.cs +20 -16
- data/lib/shaml/templates/_WebSampleForm.haml +7 -6
- data/lib/shaml/templates/shaml_base_template.dat +0 -0
- metadata +4 -2
data/lib/shaml/command.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'zip/zip'
|
2
|
+
require 'rexml/document'
|
2
3
|
|
3
4
|
module Shaml
|
4
5
|
class CommandLoader
|
@@ -27,19 +28,40 @@ class CommandLoader
|
|
27
28
|
}
|
28
29
|
}
|
29
30
|
end
|
30
|
-
|
31
|
-
def convert_file(file, appname, modelname, propertydescriptor)
|
31
|
+
|
32
|
+
def convert_file(file, appname, modelname, propertydescriptor = nil)
|
32
33
|
out = ""
|
33
34
|
pstring = ""
|
35
|
+
propertydescriptor = "" if propertydescriptor.nil?
|
34
36
|
insideprop = false
|
35
37
|
file.each_line do |line|
|
36
|
-
|
38
|
+
if insideprop then
|
39
|
+
if line.strip =~ /__END__PROPERTY__/ then
|
40
|
+
propertydescriptor.split(";").each do |property|
|
41
|
+
p = property.split(":")
|
42
|
+
out << pstring.gsub("PropertyType",p[1]).gsub("Property",p[0])
|
43
|
+
end
|
44
|
+
insideprop = false
|
45
|
+
else
|
46
|
+
pstring << line.gsub("WebBase",appname).gsub("WebSample", camelcase(modelname)).gsub("websample", modelname);
|
47
|
+
end
|
48
|
+
else
|
49
|
+
if line.strip =~ /__BEGIN__PROPERTY__/ then
|
50
|
+
pstring = ""
|
51
|
+
insideprop = true
|
52
|
+
else
|
53
|
+
out << line.gsub("WebBase",appname).gsub("WebSample", camelcase(modelname)).gsub("websample", modelname);
|
54
|
+
end
|
55
|
+
end
|
37
56
|
end
|
38
57
|
out
|
39
58
|
end
|
40
59
|
|
41
|
-
|
60
|
+
|
61
|
+
def copy_file(from,to,appname,modelname,propertydescriptor,xmltochange,xmltype)
|
42
62
|
outfname = to.gsub("WebSample",camelcase(modelname))
|
63
|
+
outfname_w = outfname.gsub("/","\\")
|
64
|
+
addxml(xmltochange,outfname_w,xmltype)
|
43
65
|
FileUtils.mkdir_p(File.dirname(outfname))
|
44
66
|
File.open(from,"rb") do |infile|
|
45
67
|
File.open(outfname,"wb+") do |outfile|
|
@@ -49,6 +71,38 @@ class CommandLoader
|
|
49
71
|
end
|
50
72
|
end
|
51
73
|
|
74
|
+
# Fix files that depends on the existence of at least one model
|
75
|
+
def fix_with_model(modelname)
|
76
|
+
t = nil
|
77
|
+
appname = getappname
|
78
|
+
name = File.join("App","Data","Mapping","AutoPersistenceModelGenerator.cs")
|
79
|
+
File.open(name,"rb") { |f| t = f.read }; File.open(name,"wb+") { |f| f.write convert_file(t,appname,modelname) }
|
80
|
+
name = File.join("Config","ComponentRegistrar.cs")
|
81
|
+
File.open(name,"rb") { |f| t = f.read }; File.open(name,"wb+") { |f| f.write convert_file(t,appname,modelname) }
|
82
|
+
end
|
83
|
+
|
84
|
+
def addxml(file,content,type)
|
85
|
+
doc = nil
|
86
|
+
dir = File.split(file)[0].gsub("/","\\")
|
87
|
+
c = content.gsub(dir+"\\","")
|
88
|
+
File.open(file,"r") do |f|
|
89
|
+
doc = REXML::Document.new f.read
|
90
|
+
case type
|
91
|
+
when :content
|
92
|
+
el = doc.elements["//ItemGroup[Content]"]
|
93
|
+
cont = el.add_element("Content",{"Include"=>c})
|
94
|
+
stype = cont.add_element("SubType")
|
95
|
+
stype.text = "ASPXCodeBehind"
|
96
|
+
when :compile
|
97
|
+
el = doc.elements["//ItemGroup[Compile]"]
|
98
|
+
cont = el.add_element("Compile",{"Include"=>c})
|
99
|
+
end
|
100
|
+
end
|
101
|
+
File.open(file,"w+") do |f|
|
102
|
+
f.write doc.to_s
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
52
106
|
def run
|
53
107
|
if ARGV.length == 0 then
|
54
108
|
puts "S#aml architecture: ASP.NET MVC 2 and NHibernate 2.1 on mono 2.4.4+"
|
@@ -60,26 +114,31 @@ class CommandLoader
|
|
60
114
|
puts "Where command might be:"
|
61
115
|
puts " generate"
|
62
116
|
puts " app AppName : Create new shaml application"
|
63
|
-
puts " resource ResName
|
117
|
+
puts " resource ResName [desc] : Create new CRUD resource with"
|
64
118
|
puts " a model, a view and a controller"
|
65
119
|
puts " controller Controller : Create a standalone controller"
|
66
|
-
puts " model Model
|
120
|
+
puts " model Model [desc] : Create a standalone model"
|
67
121
|
puts
|
68
|
-
puts " compile : Compiles the solution using
|
122
|
+
puts " compile : Compiles the solution using {ms|x}build"
|
69
123
|
puts " server : Runs xsp2"
|
70
124
|
puts
|
125
|
+
puts " gconsole : Starts a gsharp console"
|
71
126
|
puts " console : Starts a csharp console"
|
72
|
-
puts " gconsole : Starts a gsharp console"
|
73
127
|
puts " runner script_name.cs : Runs the script"
|
128
|
+
puts " test : Runs the tests"
|
74
129
|
puts
|
75
130
|
puts "Examples: "
|
76
131
|
puts " shaml generate app Blog"
|
77
132
|
puts " shaml generate resource Post"
|
78
133
|
puts " shaml compile"
|
79
134
|
puts
|
80
|
-
puts "The console
|
135
|
+
puts "The console and runner parameters will preload the solutions"
|
81
136
|
puts "assemblies and configuration files, and loads everything you need to get"
|
82
137
|
puts "working with the domain objects"
|
138
|
+
puts
|
139
|
+
puts "The optional [desc] parameter describes the base schema of the model to"
|
140
|
+
puts "create the scaffold. Here is an example how it looks like:"
|
141
|
+
puts " name:string;email:string;birthdate:DateTime"
|
83
142
|
else
|
84
143
|
command = ARGV.shift
|
85
144
|
case command
|
@@ -111,32 +170,47 @@ class CommandLoader
|
|
111
170
|
when "resource"
|
112
171
|
desc = ARGV.shift || nil
|
113
172
|
appname = getappname
|
114
|
-
|
115
|
-
copy_file(File.join(TEMPLATEDIR,"
|
116
|
-
|
117
|
-
copy_file(File.join(TEMPLATEDIR,"
|
118
|
-
|
119
|
-
copy_file(File.join(TEMPLATEDIR,"
|
120
|
-
|
121
|
-
copy_file(File.join(TEMPLATEDIR,"
|
122
|
-
copy_file(File.join(TEMPLATEDIR,"
|
123
|
-
copy_file(File.join(TEMPLATEDIR,"
|
173
|
+
xmlname = File.join("App","Core","#{appname}.Core.csproj")
|
174
|
+
copy_file(File.join(TEMPLATEDIR,"WebSample.cs"),File.join("App","Core","WebSample.cs"),appname,name,desc,xmlname,:compile)
|
175
|
+
xmlname = File.join("App","Data","#{appname}.Data.csproj")
|
176
|
+
copy_file(File.join(TEMPLATEDIR,"WebSampleMap.cs"),File.join("App","Data","WebSampleMap.cs"),appname,name,desc,xmlname,:compile)
|
177
|
+
xmlname = File.join("App","Controllers","#{appname}.Controllers.csproj")
|
178
|
+
copy_file(File.join(TEMPLATEDIR,"WebSamplesController.cs"),File.join("App","Controllers","WebSamplesController.cs"),appname,name,desc,xmlname,:compile)
|
179
|
+
xmlname = "#{appname}.csproj"
|
180
|
+
copy_file(File.join(TEMPLATEDIR,"_WebSampleForm.haml"),File.join("App","Views","WebSamples","_WebSampleForm.haml"),appname,name,desc,xmlname,:content)
|
181
|
+
copy_file(File.join(TEMPLATEDIR,"Create.haml"),File.join("App","Views","WebSamples","Create.haml"),appname,name,desc,xmlname,:content)
|
182
|
+
copy_file(File.join(TEMPLATEDIR,"Delete.haml"),File.join("App","Views","WebSamples","Delete.haml"),appname,name,desc,xmlname,:content)
|
183
|
+
copy_file(File.join(TEMPLATEDIR,"Edit.haml"),File.join("App","Views","WebSamples","Edit.haml"),appname,name,desc,xmlname,:content)
|
184
|
+
copy_file(File.join(TEMPLATEDIR,"Index.haml"),File.join("App","Views","WebSamples","Index.haml"),appname,name,desc,xmlname,:content)
|
185
|
+
copy_file(File.join(TEMPLATEDIR,"Show.haml"),File.join("App","Views","WebSamples","Show.haml"),appname,name,desc,xmlname,:content)
|
186
|
+
xmlname = File.join("Tests","#{appname}.Tests.csproj")
|
187
|
+
copy_file(File.join(TEMPLATEDIR,"WebSampleTests.cs"),File.join("Tests","Core","WebSampleTests.cs"),appname,name,desc,xmlname,:compile)
|
188
|
+
copy_file(File.join(TEMPLATEDIR,"WebSamplesControllerTests.cs"),File.join("Tests","Controllers","WebSamplesControllerTests.cs"),appname,name,desc,xmlname,:compile)
|
189
|
+
fix_with_model(name)
|
124
190
|
when "model"
|
125
191
|
desc = ARGV.shift || nil
|
126
|
-
appname = getappname
|
127
|
-
|
128
|
-
copy_file(File.join(TEMPLATEDIR,"
|
192
|
+
appname = getappname
|
193
|
+
xmlname = File.join("App","Core","#{appname}.Core.csproj")
|
194
|
+
copy_file(File.join(TEMPLATEDIR,"WebSample.cs"),File.join("App","Core","WebSample.cs"),appname,name,desc,xmlname,:compile)
|
195
|
+
xmlname = File.join("App","Data","#{appname}.Data.csproj")
|
196
|
+
copy_file(File.join(TEMPLATEDIR,"WebSampleMap.cs"),File.join("App","Data","WebSampleMap.cs"),appname,name,desc,xmlname,:compile)
|
197
|
+
xmlname = File.join("Tests","#{appname}.Tests.csproj")
|
198
|
+
copy_file(File.join(TEMPLATEDIR,"WebSampleTests.cs"),File.join("Tests","Core","WebSampleTests.cs"),appname,name,desc,xmlname,:compile)
|
199
|
+
fix_with_model(name)
|
129
200
|
when "controller"
|
130
201
|
desc = ARGV.shift || nil
|
131
202
|
appname = getappname
|
132
|
-
|
133
|
-
copy_file(File.join(TEMPLATEDIR,"
|
134
|
-
|
135
|
-
copy_file(File.join(TEMPLATEDIR,"
|
136
|
-
copy_file(File.join(TEMPLATEDIR,"
|
137
|
-
copy_file(File.join(TEMPLATEDIR,"
|
138
|
-
copy_file(File.join(TEMPLATEDIR,"
|
139
|
-
copy_file(File.join(TEMPLATEDIR,"
|
203
|
+
xmlname = File.join("App","Controllers","#{appname}.Controllers.csproj")
|
204
|
+
copy_file(File.join(TEMPLATEDIR,"WebSamplesController.cs"),File.join("App","Controllers","WebSamplesController.cs"),appname,name,desc,xmlname,:compile)
|
205
|
+
xmlname = "#{appname}.csproj"
|
206
|
+
copy_file(File.join(TEMPLATEDIR,"_WebSampleForm.haml"),File.join("App","Views","WebSamples","_WebSampleForm.haml"),appname,name,desc,xmlname,:content)
|
207
|
+
copy_file(File.join(TEMPLATEDIR,"Create.haml"),File.join("App","Views","WebSamples","Create.haml"),appname,name,desc,xmlname,:content)
|
208
|
+
copy_file(File.join(TEMPLATEDIR,"Delete.haml"),File.join("App","Views","WebSamples","Delete.haml"),appname,name,desc,xmlname,:content)
|
209
|
+
copy_file(File.join(TEMPLATEDIR,"Edit.haml"),File.join("App","Views","WebSamples","Edit.haml"),appname,name,desc,xmlname,:content)
|
210
|
+
copy_file(File.join(TEMPLATEDIR,"Index.haml"),File.join("App","Views","WebSamples","Index.haml"),appname,name,desc,xmlname,:content)
|
211
|
+
copy_file(File.join(TEMPLATEDIR,"Show.haml"),File.join("App","Views","WebSamples","Show.haml"),appname,name,desc,xmlname,:content)
|
212
|
+
xmlname = File.join("Tests","#{appname}.Tests.csproj")
|
213
|
+
copy_file(File.join(TEMPLATEDIR,"WebSamplesControllerTests.cs"),File.join("Tests","Controllers","WebSamplesControllerTests.cs"),appname,name,desc,xmlname,:compile)
|
140
214
|
else
|
141
215
|
puts 'S#aml ERROR: unknown generate argument'
|
142
216
|
end
|
@@ -145,27 +219,55 @@ class CommandLoader
|
|
145
219
|
end
|
146
220
|
when "compile"
|
147
221
|
appname = getappname
|
148
|
-
puts "Copying libraries"
|
149
222
|
begin
|
150
|
-
FileUtils
|
223
|
+
FileUtils::rm_rf "bin"
|
151
224
|
rescue Exception => e
|
152
225
|
end
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
system("
|
226
|
+
if Mono.mono_found then
|
227
|
+
puts "Compiling using xbuild"
|
228
|
+
Mono.load_mono_app("/mono/2.0/xbuild.exe","#{appname}.sln")
|
229
|
+
else
|
230
|
+
puts "Mono not found. Compiling using msbuild"
|
231
|
+
system("msbuild #{appname}.sln")
|
159
232
|
end
|
233
|
+
puts "Compiling stylesheets"
|
234
|
+
system("compass -c Config/compass_config.rb")
|
160
235
|
when "server"
|
161
|
-
puts "Starting xsp2"
|
162
236
|
appname = getappname
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
237
|
+
puts "Starting xsp2 #{ARGV.join(" ")}"
|
238
|
+
if Mono.is_unix then
|
239
|
+
Mono.load_mono_app("/mono/2.0/xsp2.exe",ARGV.join(" "))
|
240
|
+
else
|
241
|
+
Mono.load_mono_app("/mono/2.0/WinHack/xsp2.exe",ARGV.join(" "))
|
168
242
|
end
|
243
|
+
puts "Done..."
|
244
|
+
when "test"
|
245
|
+
puts "Running tests"
|
246
|
+
appname = getappname
|
247
|
+
if Mono.mono_found then
|
248
|
+
Mono.load_app(File.join("libraries","nunit-console.exe"),File.join("bin","#{appname}.Tests.dll"))
|
249
|
+
else
|
250
|
+
system("#{File.join("libraries","nunit-console.exe")} #{File.join("bin","#{appname}.Tests.dll")}")
|
251
|
+
end
|
252
|
+
when "console"
|
253
|
+
appname = getappname
|
254
|
+
script = File.read(File.join("Scripts","setup","common.cs"))
|
255
|
+
script << File.read(File.join("Scripts","setup","csharp.cs"))
|
256
|
+
script = script.gsub("WebBase",appname);
|
257
|
+
Mono.load_csharp(script,"");
|
258
|
+
when "gconsole"
|
259
|
+
appname = getappname
|
260
|
+
script = File.read(File.join("Scripts","setup","common.cs"))
|
261
|
+
script << File.read(File.join("Scripts","setup","gsharp.cs"))
|
262
|
+
script = script.gsub("WebBase",appname);
|
263
|
+
Mono.load_gsharp(script,"");
|
264
|
+
when "runner"
|
265
|
+
appname = getappname
|
266
|
+
command = ARGV.shift
|
267
|
+
script = File.read(File.join("Scripts","setup","common.cs"))
|
268
|
+
script << File.read(File.join("Scripts","setup","runner.cs"))
|
269
|
+
script = script.gsub("WebBase",appname);
|
270
|
+
Mono.load_csharp(script,"#{command}");
|
169
271
|
else
|
170
272
|
puts 'S#aml ERROR: unknown command'
|
171
273
|
end
|
data/lib/shaml/mono_load.rb
CHANGED
@@ -3,18 +3,23 @@ require 'fileutils'
|
|
3
3
|
|
4
4
|
module Shaml
|
5
5
|
class MonoLoader
|
6
|
+
attr_reader :mono_found,:is_unix
|
7
|
+
|
6
8
|
def initialize
|
7
9
|
@mono_command = '/bin/mono'
|
8
10
|
@mono_directory = '/usr'
|
9
|
-
@mono_lib_directory = '/lib'
|
11
|
+
@mono_lib_directory = '/usr/lib'
|
10
12
|
@csharp_command = '/mono/2.0/csharp.exe'
|
11
13
|
@gsharp_command = '/gsharp/gsharp.exe'
|
12
|
-
@config_dir = '
|
14
|
+
@config_dir = "#{ENV['HOME']}/.config"
|
13
15
|
@init_script_name = 'shaml.cs'
|
16
|
+
@mono_found = true
|
17
|
+
@is_unix = true
|
14
18
|
|
15
19
|
# get mono path for Windows
|
16
20
|
if RbConfig::CONFIG['host_os'] =~ /mswin|windows|cygwin|mingw/i
|
17
21
|
begin
|
22
|
+
@is_unix = false
|
18
23
|
require 'win32/registry'
|
19
24
|
# Check in default location
|
20
25
|
base = "Software\\Novell\\Mono\\"
|
@@ -39,9 +44,10 @@ class MonoLoader
|
|
39
44
|
rescue Exception => e
|
40
45
|
STDERR.puts "Couldn't determine mono location under Windows!"
|
41
46
|
STDERR.puts e.inspect
|
47
|
+
@mono_found = false
|
42
48
|
end
|
43
49
|
else
|
44
|
-
if ENV['MONO_PREFIX']
|
50
|
+
if !ENV['MONO_PREFIX'].nil? and !ENV['MONO_PREFIX'].empty? then
|
45
51
|
@mono_directory = ENV['MONO_PREFIX']
|
46
52
|
@mono_lib_directory = File.join(@mono_directory,"lib")
|
47
53
|
end
|
@@ -70,23 +76,32 @@ class MonoLoader
|
|
70
76
|
end
|
71
77
|
|
72
78
|
# run csharp with an optional initialization script
|
73
|
-
def load_csharp(init_script = nil)
|
79
|
+
def load_csharp(init_script = nil, commands = "")
|
74
80
|
create_init_script(init_script,"csharp")
|
75
81
|
puts "Mono executable: \"#{File.join(@mono_directory,@mono_command)}\""
|
76
82
|
cs = File.join(@mono_lib_directory,@csharp_command)
|
77
83
|
puts "CSharp executable: \"#{cs}\""
|
78
|
-
system("\"#{File.join(@mono_directory,@mono_command)}\" \"#{cs}\"")
|
79
|
-
delete_init_script("csharp")
|
84
|
+
system("\"#{File.join(@mono_directory,@mono_command)}\" \"#{cs}\" #{commands}")
|
85
|
+
delete_init_script(init_script, "csharp")
|
80
86
|
end
|
81
87
|
|
82
88
|
# run gsharp with an optional initialization script
|
83
|
-
def load_gsharp(init_script = nil)
|
89
|
+
def load_gsharp(init_script = nil, commands = "")
|
84
90
|
create_init_script(init_script,"gsharp")
|
85
91
|
puts "Mono executable: \"#{File.join(@mono_directory,@mono_command)}\""
|
86
92
|
gs = File.join(@mono_lib_directory,@gsharp_command)
|
87
93
|
puts "GSharp executable: \"#{gs}\""
|
88
|
-
system("\"#{File.join(@mono_directory,@mono_command)}\" \"#{gs}\"")
|
89
|
-
delete_init_script("gsharp")
|
94
|
+
system("\"#{File.join(@mono_directory,@mono_command)}\" \"#{gs}\" #{commands}")
|
95
|
+
delete_init_script(init_script, "gsharp")
|
96
|
+
end
|
97
|
+
|
98
|
+
def load_mono_app(command,parameters = "")
|
99
|
+
cm = File.join(@mono_lib_directory,command)
|
100
|
+
system("\"#{File.join(@mono_directory,@mono_command)}\" \"#{cm}\" #{parameters}")
|
90
101
|
end
|
102
|
+
def load_app(command,parameters = "")
|
103
|
+
cm = command
|
104
|
+
system("\"#{File.join(@mono_directory,@mono_command)}\" \"#{cm}\" #{parameters}")
|
105
|
+
end
|
91
106
|
end
|
92
107
|
end
|
@@ -1,7 +1,11 @@
|
|
1
|
-
|
1
|
+
@namespace=WebBase.Core
|
2
|
+
@namespace=WebBase.Controllers
|
3
|
+
@namespace=Microsoft.Web.Mvc
|
4
|
+
@type=WebSample
|
5
|
+
%div
|
2
6
|
%h2 Delete WebSample
|
3
7
|
%p Are you sure?
|
4
8
|
- using (Html.BeginForm<WebSamplesController>(c => c.DeleteConfirmed(ViewData.Model.Id)))
|
5
|
-
|
9
|
+
/= Html.AntiForgeryToken()
|
6
10
|
%input{ type="submit" value="Yes" }
|
7
11
|
%input{ type="button" name="No" value="No" onclick="javascript:history.go(-1);"}
|
@@ -1,3 +1,7 @@
|
|
1
|
+
@namespace=WebBase.Core
|
2
|
+
@namespace=WebBase.Controllers
|
3
|
+
@namespace=Microsoft.Web.Mvc
|
4
|
+
@type=List<WebSample>
|
1
5
|
%div
|
2
6
|
%h2 WebSamples
|
3
7
|
- if (ViewContext.TempData["message"] != null)
|
@@ -5,16 +9,16 @@
|
|
5
9
|
%table
|
6
10
|
%thead
|
7
11
|
%tr
|
8
|
-
|
12
|
+
-// __BEGIN__PROPERTY__
|
9
13
|
%th Property
|
10
|
-
|
14
|
+
-// __END__PROPERTY__
|
11
15
|
%th{ colspan=3 } Action
|
12
16
|
%tbody
|
13
17
|
- foreach (WebSample websample in ViewData.Model)
|
14
18
|
%tr
|
15
|
-
|
19
|
+
-// __BEGIN__PROPERTY__
|
16
20
|
%td= websample.Property
|
17
|
-
|
21
|
+
-// __END__PROPERTY__
|
18
22
|
%td
|
19
23
|
= Html.ActionLink<WebSamplesController>( c => c.Show( websample.Id ), "Details ")
|
20
24
|
%td
|
@@ -2,9 +2,9 @@
|
|
2
2
|
%div
|
3
3
|
%h2 WebSample Details
|
4
4
|
%ul
|
5
|
-
//
|
5
|
+
// __BEGIN__PROPERTY__
|
6
6
|
%li
|
7
|
-
%label{ for="WebSample.
|
8
|
-
%span{ id="WebSample.
|
7
|
+
%label{ for="WebSample.Property" } Property:
|
8
|
+
%span{ id="WebSample.Property" }
|
9
9
|
= ViewData.Model.Property
|
10
|
-
//
|
10
|
+
// __END__PROPERTY__
|
@@ -1,14 +1,18 @@
|
|
1
1
|
using NHibernate.Validator.Constraints;
|
2
2
|
using Shaml.Core.DomainModel;
|
3
3
|
using Shaml.Core.PersistenceSupport;
|
4
|
+
using Shaml.Membership.Core;
|
4
5
|
using System;
|
5
6
|
|
6
7
|
namespace WebBase.Core
|
7
8
|
{
|
9
|
+
|
8
10
|
public class WebSample : Entity
|
9
11
|
{
|
10
12
|
public WebSample() { }
|
11
13
|
|
12
|
-
//
|
14
|
+
// __BEGIN__PROPERTY__
|
15
|
+
public virtual PropertyType Property { get; set; }
|
16
|
+
// __END__PROPERTY__
|
13
17
|
}
|
14
18
|
}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
using System;
|
2
|
+
using System.Collections.Generic;
|
3
|
+
using System.Linq;
|
4
|
+
using System.Text;
|
5
|
+
using FluentNHibernate.Automapping;
|
6
|
+
using FluentNHibernate.Automapping.Alterations;
|
7
|
+
using Shaml.Data.NHibernate.FluentNHibernate;
|
8
|
+
using Shaml.Membership.Core;
|
9
|
+
using WebBase.Core;
|
10
|
+
|
11
|
+
namespace WebBase.Data.Mapping
|
12
|
+
{
|
13
|
+
public class WebSampleMap : IAutoMappingOverride<WebSample>
|
14
|
+
{
|
15
|
+
public void Override(AutoMapping<WebSample> mapping)
|
16
|
+
{
|
17
|
+
// __BEGIN__PROPERTY__
|
18
|
+
// mapping.Map(x => x.Property).CustomType("StringClob").CustomSqlType("text");
|
19
|
+
// __END__PROPERTY__
|
20
|
+
}
|
21
|
+
}
|
22
|
+
}
|
@@ -1,36 +1,37 @@
|
|
1
1
|
using System.Web.Mvc;
|
2
2
|
using WebBase.Core;
|
3
|
-
using
|
4
|
-
using
|
3
|
+
using Shaml.Core.PersistenceSupport;
|
4
|
+
using Shaml.Core.DomainModel;
|
5
5
|
using System.Collections.Generic;
|
6
6
|
using System;
|
7
|
-
using
|
7
|
+
using Shaml.Web.NHibernate;
|
8
8
|
using NHibernate.Validator.Engine;
|
9
9
|
using System.Text;
|
10
|
-
using
|
11
|
-
using
|
10
|
+
using Shaml.Web.CommonValidator;
|
11
|
+
using Shaml.Core;
|
12
|
+
using System.Linq.Expressions;
|
12
13
|
|
13
14
|
namespace WebBase.Controllers
|
14
15
|
{
|
15
16
|
[HandleError]
|
16
17
|
public class WebSamplesController : Controller
|
17
18
|
{
|
18
|
-
public WebSamplesController(IRepository<WebSample>
|
19
|
-
Check.Require(
|
19
|
+
public WebSamplesController(IRepository<WebSample> WebSampleRepository) {
|
20
|
+
Check.Require(WebSampleRepository != null, "WebSampleRepository may not be null");
|
20
21
|
|
21
|
-
this.
|
22
|
+
this.WebSampleRepository = WebSampleRepository;
|
22
23
|
}
|
23
24
|
|
24
25
|
[Transaction]
|
25
26
|
public ActionResult Index() {
|
26
|
-
IList<WebSample>
|
27
|
-
return View(
|
27
|
+
IList<WebSample> WebSamples = WebSampleRepository.GetAll();
|
28
|
+
return View(WebSamples);
|
28
29
|
}
|
29
30
|
|
30
31
|
[Transaction]
|
31
32
|
public ActionResult Show(int id) {
|
32
|
-
WebSample
|
33
|
-
return View(
|
33
|
+
WebSample WebSample = WebSampleRepository.Get(id);
|
34
|
+
return View(WebSample);
|
34
35
|
}
|
35
36
|
|
36
37
|
public ActionResult Create() {
|
@@ -38,76 +39,86 @@ namespace WebBase.Controllers
|
|
38
39
|
return View(viewModel);
|
39
40
|
}
|
40
41
|
|
41
|
-
[ValidateAntiForgeryToken]
|
42
|
+
//[ValidateAntiForgeryToken]
|
42
43
|
[Transaction]
|
43
44
|
[AcceptVerbs(HttpVerbs.Post)]
|
44
|
-
public ActionResult Create(WebSample
|
45
|
-
if (ViewData.ModelState.IsValid &&
|
46
|
-
|
45
|
+
public ActionResult Create(WebSample WebSample) {
|
46
|
+
if (ViewData.ModelState.IsValid && WebSample.IsValid()) {
|
47
|
+
WebSampleRepository.SaveOrUpdate(WebSample);
|
47
48
|
|
48
49
|
TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()] =
|
49
|
-
"The
|
50
|
+
"The WebSample was successfully created.";
|
50
51
|
return RedirectToAction("Index");
|
51
52
|
}
|
52
53
|
|
53
54
|
WebSampleFormViewModel viewModel = WebSampleFormViewModel.CreateWebSampleFormViewModel();
|
54
|
-
viewModel.WebSample =
|
55
|
+
viewModel.WebSample = WebSample;
|
55
56
|
return View(viewModel);
|
56
57
|
}
|
57
58
|
|
58
59
|
[Transaction]
|
59
60
|
public ActionResult Edit(int id) {
|
60
61
|
WebSampleFormViewModel viewModel = WebSampleFormViewModel.CreateWebSampleFormViewModel();
|
61
|
-
viewModel.WebSample =
|
62
|
+
viewModel.WebSample = WebSampleRepository.Get(id);
|
62
63
|
return View(viewModel);
|
63
64
|
}
|
64
65
|
|
65
|
-
[ValidateAntiForgeryToken]
|
66
|
+
//[ValidateAntiForgeryToken]
|
66
67
|
[Transaction]
|
67
68
|
[AcceptVerbs(HttpVerbs.Post)]
|
68
|
-
public ActionResult Edit(WebSample
|
69
|
-
WebSample
|
70
|
-
TransferFormValuesTo(
|
69
|
+
public ActionResult Edit(WebSample WebSample) {
|
70
|
+
WebSample WebSampleToUpdate = WebSampleRepository.Get(WebSample.Id);
|
71
|
+
TransferFormValuesTo(WebSampleToUpdate, WebSample);
|
71
72
|
|
72
|
-
if (ViewData.ModelState.IsValid &&
|
73
|
+
if (ViewData.ModelState.IsValid && WebSample.IsValid()) {
|
73
74
|
TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()] =
|
74
|
-
"The
|
75
|
+
"The WebSample was successfully updated.";
|
75
76
|
return RedirectToAction("Index");
|
76
77
|
}
|
77
78
|
else {
|
78
|
-
|
79
|
+
WebSampleRepository.DbContext.RollbackTransaction();
|
79
80
|
|
80
81
|
WebSampleFormViewModel viewModel = WebSampleFormViewModel.CreateWebSampleFormViewModel();
|
81
|
-
viewModel.WebSample =
|
82
|
+
viewModel.WebSample = WebSample;
|
82
83
|
return View(viewModel);
|
83
84
|
}
|
84
85
|
}
|
85
86
|
|
86
|
-
private void TransferFormValuesTo(WebSample
|
87
|
-
|
87
|
+
private void TransferFormValuesTo(WebSample WebSampleToUpdate, WebSample WebSampleFromForm) {
|
88
|
+
// __BEGIN__PROPERTY__
|
89
|
+
WebSampleToUpdate.Property = WebSampleFromForm.Property;
|
90
|
+
// __END__PROPERTY__
|
88
91
|
}
|
89
92
|
|
90
|
-
|
93
|
+
|
94
|
+
[AcceptVerbs(HttpVerbs.Get)]
|
95
|
+
public ActionResult Delete(int id)
|
96
|
+
{
|
97
|
+
WebSample websampleToDelete = WebSampleRepository.Get(id);
|
98
|
+
return View(websampleToDelete);
|
99
|
+
}
|
100
|
+
|
101
|
+
//[ValidateAntiForgeryToken]
|
91
102
|
[Transaction]
|
92
103
|
[AcceptVerbs(HttpVerbs.Post)]
|
93
|
-
public ActionResult
|
94
|
-
string resultMessage = "The
|
95
|
-
WebSample
|
104
|
+
public ActionResult DeleteConfirmed(int id) {
|
105
|
+
string resultMessage = "The WebSample was successfully deleted.";
|
106
|
+
WebSample WebSampleToDelete = WebSampleRepository.Get(id);
|
96
107
|
|
97
|
-
if (
|
98
|
-
|
108
|
+
if (WebSampleToDelete != null) {
|
109
|
+
WebSampleRepository.Delete(WebSampleToDelete);
|
99
110
|
|
100
111
|
try {
|
101
|
-
|
112
|
+
WebSampleRepository.DbContext.CommitChanges();
|
102
113
|
}
|
103
114
|
catch {
|
104
|
-
resultMessage = "A problem was encountered preventing the
|
105
|
-
"Another item likely depends on this
|
106
|
-
|
115
|
+
resultMessage = "A problem was encountered preventing the WebSample from being deleted. " +
|
116
|
+
"Another item likely depends on this WebSample.";
|
117
|
+
WebSampleRepository.DbContext.RollbackTransaction();
|
107
118
|
}
|
108
119
|
}
|
109
120
|
else {
|
110
|
-
resultMessage = "The
|
121
|
+
resultMessage = "The WebSample could not be found for deletion. It may already have been deleted.";
|
111
122
|
}
|
112
123
|
|
113
124
|
TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()] = resultMessage;
|
@@ -127,14 +138,13 @@ namespace WebBase.Controllers
|
|
127
138
|
/// </summary>
|
128
139
|
public static WebSampleFormViewModel CreateWebSampleFormViewModel() {
|
129
140
|
WebSampleFormViewModel viewModel = new WebSampleFormViewModel();
|
130
|
-
|
131
141
|
return viewModel;
|
132
142
|
}
|
133
143
|
|
134
144
|
public WebSample WebSample { get; internal set; }
|
135
145
|
}
|
136
146
|
|
137
|
-
private readonly IRepository<WebSample>
|
147
|
+
private readonly IRepository<WebSample> WebSampleRepository;
|
138
148
|
}
|
139
149
|
}
|
140
150
|
|
@@ -4,6 +4,8 @@ using NUnit.Framework;
|
|
4
4
|
using Rhino.Mocks;
|
5
5
|
using Shaml.Core.PersistenceSupport;
|
6
6
|
using Shaml.Testing;
|
7
|
+
using Shaml.Testing.NUnit;
|
8
|
+
using Shaml.Membership.Core;
|
7
9
|
using System.Collections.Generic;
|
8
10
|
using System.Web.Mvc;
|
9
11
|
using WebBase;
|
@@ -54,8 +56,8 @@ namespace Tests.Blog.Web.Controllers
|
|
54
56
|
|
55
57
|
[Test]
|
56
58
|
public void CanEnsureWebSampleCreationIsValid() {
|
57
|
-
WebSample
|
58
|
-
ViewResult result = controller.Create(
|
59
|
+
WebSample WebSampleFromForm = new WebSample();
|
60
|
+
ViewResult result = controller.Create(WebSampleFromForm).AssertViewRendered();
|
59
61
|
|
60
62
|
result.ViewData.Model.ShouldNotBeNull();
|
61
63
|
result.ViewData.Model.ShouldBeOfType(typeof(WebSamplesController.WebSampleFormViewModel));
|
@@ -63,8 +65,8 @@ namespace Tests.Blog.Web.Controllers
|
|
63
65
|
|
64
66
|
[Test]
|
65
67
|
public void CanCreateWebSample() {
|
66
|
-
WebSample
|
67
|
-
RedirectToRouteResult redirectResult = controller.Create(
|
68
|
+
WebSample WebSampleFromForm = CreateTransientWebSample();
|
69
|
+
RedirectToRouteResult redirectResult = controller.Create(WebSampleFromForm)
|
68
70
|
.AssertActionRedirect().ToAction("Index");
|
69
71
|
controller.TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()].ToString()
|
70
72
|
.ShouldContain("was successfully created");
|
@@ -72,9 +74,9 @@ namespace Tests.Blog.Web.Controllers
|
|
72
74
|
|
73
75
|
[Test]
|
74
76
|
public void CanUpdateWebSample() {
|
75
|
-
WebSample
|
76
|
-
EntityIdSetter.SetIdOf<int>(
|
77
|
-
RedirectToRouteResult redirectResult = controller.Edit(
|
77
|
+
WebSample WebSampleFromForm = CreateTransientWebSample();
|
78
|
+
EntityIdSetter.SetIdOf<int>(WebSampleFromForm, 1);
|
79
|
+
RedirectToRouteResult redirectResult = controller.Edit(WebSampleFromForm)
|
78
80
|
.AssertActionRedirect().ToAction("Index");
|
79
81
|
controller.TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()].ToString()
|
80
82
|
.ShouldContain("was successfully updated");
|
@@ -91,7 +93,7 @@ namespace Tests.Blog.Web.Controllers
|
|
91
93
|
|
92
94
|
[Test]
|
93
95
|
public void CanDeleteWebSample() {
|
94
|
-
RedirectToRouteResult redirectResult = controller.
|
96
|
+
RedirectToRouteResult redirectResult = controller.DeleteConfirmed(1)
|
95
97
|
.AssertActionRedirect().ToAction("Index");
|
96
98
|
|
97
99
|
controller.TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()].ToString()
|
@@ -116,17 +118,17 @@ namespace Tests.Blog.Web.Controllers
|
|
116
118
|
}
|
117
119
|
|
118
120
|
private WebSample CreateWebSample() {
|
119
|
-
WebSample
|
120
|
-
EntityIdSetter.SetIdOf<int>(
|
121
|
-
return
|
121
|
+
WebSample WebSample = CreateTransientWebSample();
|
122
|
+
EntityIdSetter.SetIdOf<int>(WebSample, 1);
|
123
|
+
return WebSample;
|
122
124
|
}
|
123
125
|
|
124
126
|
private List<WebSample> CreateWebSamples() {
|
125
|
-
List<WebSample>
|
127
|
+
List<WebSample> WebSamples = new List<WebSample>();
|
126
128
|
|
127
129
|
// Create a number of domain object instances here and add them to the list
|
128
130
|
|
129
|
-
return
|
131
|
+
return WebSamples;
|
130
132
|
}
|
131
133
|
|
132
134
|
#endregion
|
@@ -135,11 +137,13 @@ namespace Tests.Blog.Web.Controllers
|
|
135
137
|
/// Creates a valid, transient WebSample; typical of something retrieved back from a form submission
|
136
138
|
/// </summary>
|
137
139
|
private WebSample CreateTransientWebSample() {
|
138
|
-
WebSample
|
139
|
-
|
140
|
+
WebSample WebSample = new WebSample() {
|
141
|
+
// __BEGIN__PROPERTY__
|
142
|
+
Property = new PropertyType(),
|
143
|
+
// __END__PROPERTY__
|
140
144
|
};
|
141
145
|
|
142
|
-
return
|
146
|
+
return WebSample;
|
143
147
|
}
|
144
148
|
|
145
149
|
private WebSamplesController controller;
|
@@ -1,16 +1,17 @@
|
|
1
|
-
@
|
1
|
+
@namespace=WebBase.Controllers
|
2
|
+
@type=WebSamplesController.WebSampleFormViewModel
|
2
3
|
= Html.ValidationSummary()
|
3
4
|
- using (Html.BeginForm())
|
4
|
-
|
5
|
-
= Html.Hidden("
|
5
|
+
/= Html.AntiForgeryToken()
|
6
|
+
= Html.Hidden("WebSample.Id", (Model.WebSample != null) ? Model.WebSample.Id : 0)
|
6
7
|
%ul
|
7
|
-
//
|
8
|
+
// __BEGIN__PROPERTY__
|
8
9
|
%li
|
9
10
|
%label{ for="WebSample_Property" }Property:
|
10
11
|
%div
|
11
|
-
= Html.TextBox("WebSample.Property",
|
12
|
+
= Html.TextBox("WebSample.Property", (Model.WebSample != null) ? Model.WebSample.Property.ToString() : "" )
|
12
13
|
= Html.ValidationMessage("WebSample.Property")
|
13
|
-
//
|
14
|
+
// __END__PROPERTY__
|
14
15
|
%li
|
15
16
|
%input{ type="submit" name="btnSave" value="Save WebSample"}/
|
16
17
|
%button{ name="btnCancel" onClick="window.location.href = '/WebSamples';"} Cancel
|
Binary file
|
metadata
CHANGED
@@ -6,8 +6,9 @@ version: !ruby/object:Gem::Version
|
|
6
6
|
- 0
|
7
7
|
- 5
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
|
9
|
+
- beta
|
10
|
+
- 1
|
11
|
+
version: 0.5.0.beta.1
|
11
12
|
platform: ruby
|
12
13
|
authors:
|
13
14
|
- Zsolt Sz. Sztupak
|
@@ -67,6 +68,7 @@ files:
|
|
67
68
|
- lib/shaml/templates/Show.haml
|
68
69
|
- lib/shaml/templates/_WebSampleForm.haml
|
69
70
|
- lib/shaml/templates/WebSample.cs
|
71
|
+
- lib/shaml/templates/WebSampleMap.cs
|
70
72
|
- lib/shaml/templates/WebSamplesController.cs
|
71
73
|
- lib/shaml/templates/WebSamplesControllerTests.cs
|
72
74
|
- lib/shaml/templates/WebSampleTests.cs
|