masterview_generator 0.0.17 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/USAGE +3 -4
- data/masterview_generator.rb +263 -31
- data/templates/list_line_scaffold.rhtml +3 -3
- data/templates/masterview.rhtml +55 -76
- data/templates/mvpreview.js +42 -6
- metadata +2 -2
data/USAGE
CHANGED
@@ -4,9 +4,8 @@ Description:
|
|
4
4
|
code is equivalent to the "scaffold :model" declaration, making it easy
|
5
5
|
to migrate when you wish to customize your controller and views.
|
6
6
|
|
7
|
-
The generator takes a model name
|
8
|
-
|
9
|
-
automatically. Any views left over generate empty stubs.
|
7
|
+
The generator takes a model name and an optional controller name
|
8
|
+
as arguments. Scaffolded actions and views are created automatically.
|
10
9
|
|
11
10
|
The scaffolded actions and views are:
|
12
11
|
index, list, show, new, create, edit, update, destroy
|
@@ -23,7 +22,7 @@ Description:
|
|
23
22
|
an partial. It also offers a lot more css hooks for customization.
|
24
23
|
|
25
24
|
Example:
|
26
|
-
./script/generate masterview Account Bank
|
25
|
+
./script/generate masterview Account Bank
|
27
26
|
|
28
27
|
This will generate an Account model and BankController with a full test
|
29
28
|
suite and a basic user interface. Now create the accounts table in your
|
data/masterview_generator.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'masterview'
|
2
|
+
|
1
3
|
class ScaffoldingSandbox
|
2
4
|
include ActionView::Helpers::ActiveRecordHelper
|
3
5
|
|
@@ -63,6 +65,69 @@ module Rails
|
|
63
65
|
module Generator
|
64
66
|
module Commands
|
65
67
|
class Create < Base
|
68
|
+
def string_to_file(content, relative_destination, file_options = {}, &block)
|
69
|
+
# Determine full paths for source and destination files.
|
70
|
+
destination = destination_path(relative_destination)
|
71
|
+
destination_exists = File.exists?(destination)
|
72
|
+
|
73
|
+
# If source and destination are identical then we're done.
|
74
|
+
if destination_exists and content == File.readlines(destination).join
|
75
|
+
return logger.identical(relative_destination)
|
76
|
+
end
|
77
|
+
|
78
|
+
# Check for and resolve file collisions.
|
79
|
+
if destination_exists
|
80
|
+
|
81
|
+
# Make a choice whether to overwrite the file. :force and
|
82
|
+
# :skip already have their mind made up, but give :ask a shot.
|
83
|
+
choice = case (file_options[:collision] || options[:collision]).to_sym #|| :ask
|
84
|
+
when :ask then force_file_collision?(relative_destination)
|
85
|
+
when :force then :force
|
86
|
+
when :skip then :skip
|
87
|
+
else raise "Invalid collision option: #{options[:collision].inspect}"
|
88
|
+
end
|
89
|
+
|
90
|
+
# Take action based on our choice. Bail out if we chose to
|
91
|
+
# skip the file; otherwise, log our transgression and continue.
|
92
|
+
case choice
|
93
|
+
when :force then logger.force(relative_destination)
|
94
|
+
when :skip then return(logger.skip(relative_destination))
|
95
|
+
else raise "Invalid collision choice: #{choice}.inspect"
|
96
|
+
end
|
97
|
+
|
98
|
+
# File doesn't exist so log its unbesmirched creation.
|
99
|
+
else
|
100
|
+
logger.create relative_destination
|
101
|
+
end
|
102
|
+
|
103
|
+
# If we're pretending, back off now.
|
104
|
+
return if options[:pretend]
|
105
|
+
|
106
|
+
# Write destination file with optional shebang. Yield for content
|
107
|
+
# if block given so templaters may render the source file. If a
|
108
|
+
# shebang is requested, replace the existing shebang or insert a
|
109
|
+
# new one.
|
110
|
+
File.open(destination, 'wb') do |df|
|
111
|
+
if block_given?
|
112
|
+
df.write(yield(content))
|
113
|
+
else
|
114
|
+
if file_options[:shebang]
|
115
|
+
df.puts("#!#{file_options[:shebang]}")
|
116
|
+
df.puts(line) if content !~ /^#!/
|
117
|
+
end
|
118
|
+
df.write(content)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
# Optionally change permissions.
|
123
|
+
if file_options[:chmod]
|
124
|
+
FileUtils.chmod(file_options[:chmod], destination)
|
125
|
+
end
|
126
|
+
|
127
|
+
# Optionally add file to subversion
|
128
|
+
system("svn add #{destination}") if options[:svn]
|
129
|
+
end
|
130
|
+
|
66
131
|
def multi_include_template(relative_source, relative_destination, template_options = {}, multi_assign_options = {})
|
67
132
|
options = template_options.dup
|
68
133
|
options[:assigns] ||= {}
|
@@ -71,11 +136,37 @@ module Rails
|
|
71
136
|
end
|
72
137
|
template(relative_source, relative_destination, options)
|
73
138
|
end
|
139
|
+
|
140
|
+
def multi_file_multi_include_template(relative_source, relative_destination_map, template_options = {}, multi_assign_options = {})
|
141
|
+
options = template_options.dup
|
142
|
+
options[:assigns] ||= {}
|
143
|
+
multi_assign_options.each do |k,v|
|
144
|
+
options[:assigns][k] = render_template_part(v)
|
145
|
+
end
|
146
|
+
vars = options[:assigns] || {}
|
147
|
+
b = binding
|
148
|
+
vars.each { |k,v| eval "#{k} = vars[:#{k}] || vars['#{k}']", b }
|
149
|
+
|
150
|
+
# Render the source file with the temporary binding.
|
151
|
+
src_io = File.new( source_path(relative_source) )
|
152
|
+
combined_contents = ERB.new(src_io.read, nil, '-').result(b)
|
153
|
+
content_hash = {}
|
154
|
+
MasterView::TemplateSpec.scan_template(combined_contents, nil, content_hash)
|
155
|
+
relative_destination_map.each do |page_type, relative_destination|
|
156
|
+
template_spec = MasterView::TemplateSpec.new(relative_destination)
|
157
|
+
yield(page_type, template_spec) #allow the template_spec to be modified
|
158
|
+
content = template_spec.rebuild_template(content_hash)
|
159
|
+
string_to_file(content, relative_destination, template_options)
|
160
|
+
end
|
161
|
+
end
|
74
162
|
end
|
75
163
|
|
76
164
|
class Destroy < RewindBase
|
77
165
|
def multi_include_template(relative_source, relative_destination, template_options = {}, multi_assign_options = {})
|
78
166
|
end
|
167
|
+
|
168
|
+
def multi_file_multi_include_template(relative_source, relative_destination_map, template_options = {}, multi_assign_options = {})
|
169
|
+
end
|
79
170
|
end
|
80
171
|
|
81
172
|
class List < Base
|
@@ -84,12 +175,21 @@ module Rails
|
|
84
175
|
multi_assign_options.each do |k,v|
|
85
176
|
str << v[:insert] << ' '
|
86
177
|
end
|
87
|
-
logger.template "#{str} inside #{relative_destination}"
|
88
|
-
end
|
178
|
+
logger.template "#{str} inside #{relative_destination.inspect}"
|
179
|
+
end
|
180
|
+
|
181
|
+
def multi_file_multi_include_template(relative_source, relative_destination_map, template_options = {}, multi_assign_options = {})
|
182
|
+
str = ""
|
183
|
+
multi_assign_options.each do |k,v|
|
184
|
+
str << v[:insert] << ' '
|
185
|
+
end
|
186
|
+
logger.template "#{str} inside #{relative_destination_map.inspect}"
|
187
|
+
end
|
89
188
|
end
|
90
189
|
|
91
190
|
class Update < Create
|
92
191
|
def multi_include_template(relative_source, relative_destination, template_options = {}, multi_assign_options = {})
|
192
|
+
return if relative_source.is_a?(StringIO) && relative_destination.is_a?(StringIO)
|
93
193
|
begin
|
94
194
|
dest_file = destination_path(relative_destination)
|
95
195
|
source_to_update = File.readlines(dest_file).join
|
@@ -108,6 +208,9 @@ module Rails
|
|
108
208
|
end
|
109
209
|
File.open(dest_file, 'w') { |file| file.write(source_to_update) }
|
110
210
|
end
|
211
|
+
|
212
|
+
def multi_file_multi_include_template(relative_source, relative_destination_map, template_options = {}, multi_assign_options = {})
|
213
|
+
end
|
111
214
|
end
|
112
215
|
end
|
113
216
|
end
|
@@ -142,13 +245,25 @@ class MasterviewGenerator < Rails::Generator::NamedBase
|
|
142
245
|
|
143
246
|
def design_time_stylesheets
|
144
247
|
dts = ''
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
248
|
+
if full_options[:single_file]
|
249
|
+
com = <<-END
|
250
|
+
<!--
|
251
|
+
These stylesheets below are for design time use to allow working with only one visible section at a time, especially
|
252
|
+
when trying to use absolute positioning. You may comment/uncomment which ever section you wish to work with.
|
253
|
+
You may comment all of them out to work with all at design time. These stylesheets will not be used at runtime
|
254
|
+
-->
|
255
|
+
END
|
256
|
+
|
257
|
+
dts << com
|
258
|
+
|
259
|
+
dts << html_comment( '<link rel="stylesheet" type="text/css" href="./extra/show_only_new.css" mv:preview="remove" mv:replace=""/>',
|
260
|
+
full_options[:showSection] != :new )
|
261
|
+
dts << html_comment( '<link rel="stylesheet" type="text/css" href="./extra/show_only_edit.css" mv:preview="remove" mv:replace=""/>', true)
|
262
|
+
dts << html_comment( '<link rel="stylesheet" type="text/css" href="./extra/show_only_show.css" mv:preview="remove" mv:replace=""/>', true)
|
263
|
+
dts << html_comment( '<link rel="stylesheet" type="text/css" href="./extra/show_only_list.css" mv:preview="remove" mv:replace=""/>',
|
264
|
+
full_options[:showSection] != :list )
|
265
|
+
dts << html_comment( '<link rel="stylesheet" type="text/css" href="./extra/show_only_destroy.css" mv:preview="remove" mv:replace=""/>', true)
|
266
|
+
end
|
152
267
|
end
|
153
268
|
|
154
269
|
def html_comment(orig, comment_out)
|
@@ -159,6 +274,21 @@ class MasterviewGenerator < Rails::Generator::NamedBase
|
|
159
274
|
t << "\n"
|
160
275
|
end
|
161
276
|
|
277
|
+
def design_time_javascript
|
278
|
+
dtj = ''
|
279
|
+
if full_options[:single_file]
|
280
|
+
dtj << %Q[ <script type="text/javascript" mv:replace="" src="./extra/mvpreview.js"></script>\n]
|
281
|
+
dtj << %Q[ <script type="text/javascript" mv:replace="">\n]
|
282
|
+
dtj << %Q[ mvpreview.preparePage( '#{controller_file_name}', {showOneSection: '#{controller_file_name}_list', single_file: true } );\n]
|
283
|
+
dtj << %Q[ </script>\n]
|
284
|
+
else
|
285
|
+
dtj << %Q[ <script type="text/javascript" mv:replace="" src="./extra/mvpreview.js"></script>\n]
|
286
|
+
dtj << %Q[ <script type="text/javascript" mv:replace="">\n]
|
287
|
+
dtj << %Q[ mvpreview.preparePage( '#{controller_file_name}', {} );\n]
|
288
|
+
dtj << %Q[ </script>\n]
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|
162
292
|
def stylesheets
|
163
293
|
ss = ''
|
164
294
|
if full_options[:stylesheets]
|
@@ -173,6 +303,20 @@ class MasterviewGenerator < Rails::Generator::NamedBase
|
|
173
303
|
ss
|
174
304
|
end
|
175
305
|
|
306
|
+
def messages
|
307
|
+
if full_options[:stylesheets]
|
308
|
+
mess = <<-END
|
309
|
+
messages here - Note: Other page sections in this MasterView file are hidden at design time, disable the stylesheet 'extra/show_only_new.css' or uncomment different extra/*.css to work with other page sections (other stylesheets are show_only_edit.css, show_only_show.css, show_only_list.css, show_only_destroy.css and they are commented out in this masterview file's head section)
|
310
|
+
END
|
311
|
+
else
|
312
|
+
mess = <<-END
|
313
|
+
messages here - Note: Parts of these pages can be imported from other pages to allow for design time editing in full page context. View the MasterView Admin page, run the rake mv:list_all command, or view the source to learn which parts this file controls.
|
314
|
+
END
|
315
|
+
end
|
316
|
+
mess
|
317
|
+
end
|
318
|
+
|
319
|
+
|
176
320
|
def manifest
|
177
321
|
record do |m|
|
178
322
|
# Depend on model generator but skip if the model exists.
|
@@ -206,37 +350,123 @@ class MasterviewGenerator < Rails::Generator::NamedBase
|
|
206
350
|
"#{controller_file_name}_helper.rb")
|
207
351
|
|
208
352
|
# MasterView
|
209
|
-
|
210
|
-
{
|
353
|
+
if full_options[:single_file]
|
354
|
+
m.multi_include_template "masterview.rhtml","app/views/masterview/#{controller_masterview_name}.html", {},
|
355
|
+
{
|
211
356
|
'form_inclusion' =>
|
212
357
|
{ :insert => 'form_scaffold.rhtml',
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
358
|
+
:sandbox => lambda { create_multi_sandbox('ScaffoldingSandbox') },
|
359
|
+
:begin_mark => 'form',
|
360
|
+
:end_mark => 'eoform',
|
361
|
+
:mark_id => singular_name
|
362
|
+
},
|
363
|
+
'list_head_inclusion' =>
|
364
|
+
{ :insert => 'list_head_scaffold.rhtml',
|
365
|
+
:sandbox => lambda { create_multi_sandbox('ListHeadScaffoldingSandbox') },
|
366
|
+
:begin_mark => 'listhead',
|
367
|
+
:end_mark => 'eolisthead',
|
368
|
+
:mark_id => singular_name
|
369
|
+
},
|
370
|
+
'list_line_inclusion' =>
|
371
|
+
{ :insert => 'list_line_scaffold.rhtml',
|
372
|
+
:sandbox => lambda { create_multi_sandbox('ListLineScaffoldingSandbox') },
|
373
|
+
:begin_mark => 'listline',
|
374
|
+
:end_mark => 'eolistline',
|
375
|
+
:mark_id => singular_name
|
376
|
+
},
|
377
|
+
'show_inclusion' =>
|
378
|
+
{ :insert => 'show_scaffold.rhtml',
|
379
|
+
:sandbox => lambda { create_multi_sandbox('ShowScaffoldingSandbox') },
|
380
|
+
:begin_mark => 'show',
|
381
|
+
:end_mark => 'eoshow',
|
382
|
+
:mark_id => singular_name
|
383
|
+
}
|
384
|
+
}
|
385
|
+
else #multi file
|
386
|
+
m.multi_file_multi_include_template "masterview.rhtml",
|
387
|
+
{
|
388
|
+
:list => "app/views/masterview/#{controller_masterview_name}_list.html",
|
389
|
+
:new => "app/views/masterview/#{controller_masterview_name}_new.html",
|
390
|
+
:edit => "app/views/masterview/#{controller_masterview_name}_edit.html",
|
391
|
+
:show => "app/views/masterview/#{controller_masterview_name}_show.html",
|
392
|
+
:destroy => "app/views/masterview/#{controller_masterview_name}_destroy.html",
|
393
|
+
},
|
394
|
+
{},
|
395
|
+
{
|
396
|
+
'form_inclusion' =>
|
397
|
+
{ :insert => 'form_scaffold.rhtml',
|
398
|
+
:sandbox => lambda { create_multi_sandbox('ScaffoldingSandbox') },
|
399
|
+
:begin_mark => 'form',
|
400
|
+
:end_mark => 'eoform',
|
401
|
+
:mark_id => singular_name
|
217
402
|
},
|
218
403
|
'list_head_inclusion' =>
|
219
404
|
{ :insert => 'list_head_scaffold.rhtml',
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
405
|
+
:sandbox => lambda { create_multi_sandbox('ListHeadScaffoldingSandbox') },
|
406
|
+
:begin_mark => 'listhead',
|
407
|
+
:end_mark => 'eolisthead',
|
408
|
+
:mark_id => singular_name
|
224
409
|
},
|
225
410
|
'list_line_inclusion' =>
|
226
411
|
{ :insert => 'list_line_scaffold.rhtml',
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
412
|
+
:sandbox => lambda { create_multi_sandbox('ListLineScaffoldingSandbox') },
|
413
|
+
:begin_mark => 'listline',
|
414
|
+
:end_mark => 'eolistline',
|
415
|
+
:mark_id => singular_name
|
231
416
|
},
|
232
417
|
'show_inclusion' =>
|
233
418
|
{ :insert => 'show_scaffold.rhtml',
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
419
|
+
:sandbox => lambda { create_multi_sandbox('ShowScaffoldingSandbox') },
|
420
|
+
:begin_mark => 'show',
|
421
|
+
:end_mark => 'eoshow',
|
422
|
+
:mark_id => singular_name
|
238
423
|
}
|
239
|
-
|
424
|
+
} do |page_type, template_spec|
|
425
|
+
case page_type
|
426
|
+
when :list
|
427
|
+
template_spec.build_list << MasterView::Analyzer::ListEntry.new("layouts/#{controller_file_name}.rhtml", 0, false)
|
428
|
+
template_spec.build_list << MasterView::Analyzer::ListEntry.new("#{controller_view_dir_name}/list.rhtml", 0, false)
|
429
|
+
template_spec.build_list << MasterView::Analyzer::ListEntry.new("#{controller_view_dir_name}/_messages.rhtml", -1, false)
|
430
|
+
template_spec.build_list << MasterView::Analyzer::ListEntry.new("#{controller_view_dir_name}/list.rhtml", 1, false)
|
431
|
+
template_spec.build_list << MasterView::Analyzer::ListEntry.new("#{controller_view_dir_name}/_#{singular_name}.rhtml", -1, false)
|
432
|
+
template_spec.build_list << MasterView::Analyzer::ListEntry.new("#{controller_view_dir_name}/list.rhtml", -1, false)
|
433
|
+
template_spec.build_list << MasterView::Analyzer::ListEntry.new("layouts/#{controller_file_name}.rhtml", -1, false)
|
434
|
+
when :new
|
435
|
+
template_spec.build_list << MasterView::Analyzer::ListEntry.new("layouts/#{controller_file_name}.rhtml", 0, true)
|
436
|
+
template_spec.build_list << MasterView::Analyzer::ListEntry.new("#{controller_view_dir_name}/new.rhtml", 0, false)
|
437
|
+
template_spec.build_list << MasterView::Analyzer::ListEntry.new("#{controller_view_dir_name}/_messages.rhtml", -1, true)
|
438
|
+
template_spec.build_list << MasterView::Analyzer::ListEntry.new("#{controller_view_dir_name}/new.rhtml", 1, false)
|
439
|
+
template_spec.build_list << MasterView::Analyzer::ListEntry.new("#{controller_view_dir_name}/_form.rhtml", -1, false)
|
440
|
+
template_spec.build_list << MasterView::Analyzer::ListEntry.new("#{controller_view_dir_name}/new.rhtml", -1, false)
|
441
|
+
template_spec.build_list << MasterView::Analyzer::ListEntry.new("layouts/#{controller_file_name}.rhtml", -1, true)
|
442
|
+
when :edit
|
443
|
+
template_spec.build_list << MasterView::Analyzer::ListEntry.new("layouts/#{controller_file_name}.rhtml", 0, true)
|
444
|
+
template_spec.build_list << MasterView::Analyzer::ListEntry.new("#{controller_view_dir_name}/edit.rhtml", 0, false)
|
445
|
+
template_spec.build_list << MasterView::Analyzer::ListEntry.new("#{controller_view_dir_name}/_messages.rhtml", -1, true)
|
446
|
+
template_spec.build_list << MasterView::Analyzer::ListEntry.new("#{controller_view_dir_name}/edit.rhtml", 1, false)
|
447
|
+
template_spec.build_list << MasterView::Analyzer::ListEntry.new("#{controller_view_dir_name}/_form.rhtml", -1, true)
|
448
|
+
template_spec.build_list << MasterView::Analyzer::ListEntry.new("#{controller_view_dir_name}/edit.rhtml", -1, false)
|
449
|
+
template_spec.build_list << MasterView::Analyzer::ListEntry.new("layouts/#{controller_file_name}.rhtml", -1, true)
|
450
|
+
when :show
|
451
|
+
template_spec.build_list << MasterView::Analyzer::ListEntry.new("layouts/#{controller_file_name}.rhtml", 0, true)
|
452
|
+
template_spec.build_list << MasterView::Analyzer::ListEntry.new("#{controller_view_dir_name}/show.rhtml", 0, false)
|
453
|
+
template_spec.build_list << MasterView::Analyzer::ListEntry.new("#{controller_view_dir_name}/_messages.rhtml", -1, true)
|
454
|
+
template_spec.build_list << MasterView::Analyzer::ListEntry.new("#{controller_view_dir_name}/show.rhtml", 1, false)
|
455
|
+
template_spec.build_list << MasterView::Analyzer::ListEntry.new("#{controller_view_dir_name}/_show.rhtml", -1, false)
|
456
|
+
template_spec.build_list << MasterView::Analyzer::ListEntry.new("#{controller_view_dir_name}/show.rhtml", -1, false)
|
457
|
+
template_spec.build_list << MasterView::Analyzer::ListEntry.new("layouts/#{controller_file_name}.rhtml", -1, true)
|
458
|
+
when :destroy
|
459
|
+
template_spec.build_list << MasterView::Analyzer::ListEntry.new("layouts/#{controller_file_name}.rhtml", 0, true)
|
460
|
+
template_spec.build_list << MasterView::Analyzer::ListEntry.new("#{controller_view_dir_name}/destroy.rhtml", 0, false)
|
461
|
+
template_spec.build_list << MasterView::Analyzer::ListEntry.new("#{controller_view_dir_name}/_messages.rhtml", -1, true)
|
462
|
+
template_spec.build_list << MasterView::Analyzer::ListEntry.new("#{controller_view_dir_name}/destroy.rhtml", 1, false)
|
463
|
+
template_spec.build_list << MasterView::Analyzer::ListEntry.new("#{controller_view_dir_name}/_show.rhtml", -1, true)
|
464
|
+
template_spec.build_list << MasterView::Analyzer::ListEntry.new("#{controller_view_dir_name}/destroy.rhtml", -1, false)
|
465
|
+
template_spec.build_list << MasterView::Analyzer::ListEntry.new("layouts/#{controller_file_name}.rhtml", -1, true)
|
466
|
+
end
|
467
|
+
end
|
468
|
+
end
|
469
|
+
|
240
470
|
|
241
471
|
m.template 'style.css', 'public/stylesheets/scaffold.css'
|
242
472
|
m.template 'sidebox.css', 'public/stylesheets/sidebox.css'
|
@@ -257,14 +487,16 @@ class MasterviewGenerator < Rails::Generator::NamedBase
|
|
257
487
|
protected
|
258
488
|
# Override with your own usage banner.
|
259
489
|
def banner
|
260
|
-
"Usage: #{$0} masterview ModelName [ControllerName] [
|
490
|
+
"Usage: #{$0} masterview ModelName [ControllerName] [--style [cssStylesheet]] [--single-file] [--show-all | --show-only list]"
|
261
491
|
end
|
262
492
|
|
263
493
|
def add_options!(opt)
|
264
|
-
opt.on('-
|
494
|
+
opt.on('-C', '--single-file', 'Generate masterview template as a single combined file'){ options[:single_file] = true }
|
495
|
+
opt.on('-A', '--show-all', 'Generate with ALL sections visible at design time (no css hiding)',
|
496
|
+
'(valid only in conjunction with --single-file') { options[:showSection] = :all }
|
265
497
|
opt.on("-O", "--show-only SECTION_NAME",
|
266
498
|
"Generate with only sectionName section visible at design time (rest hidden with css)",
|
267
|
-
" (Valid options are: new, list)",
|
499
|
+
" (Valid options are: new, list) (Only valid if used with --single-file)",
|
268
500
|
" (example: --showOnly list - would generate to show only 'list' section at design time)" ) do |section|
|
269
501
|
options[:showSection] = section.to_sym
|
270
502
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
|
2
2
|
<%= all_input_tags(@model_instance, @singular_name, {}) %>
|
3
|
-
<td class="operation"><a class="show_link" href="
|
4
|
-
<td class="operation"><a class="edit_link" href="
|
5
|
-
<td class="operation"><a class="destroy_link" href="
|
3
|
+
<td class="operation"><a class="show_link" href="admin_show.html" mv:link_to=":action => 'show<%= suffix %>', :id => <%= singular_name %>">Show</a></td>
|
4
|
+
<td class="operation"><a class="edit_link" href="admin_edit.html" mv:link_to=":action => 'edit<%= suffix %>', :id => <%= singular_name %>">Edit</a></td>
|
5
|
+
<td class="operation"><a class="destroy_link" href="admin_destroy.html" mv:link_to=":action => 'destroy', :id => <%= singular_name %>">Destroy</a></td>
|
6
6
|
|
data/templates/masterview.rhtml
CHANGED
@@ -4,11 +4,6 @@
|
|
4
4
|
|
5
5
|
<%= stylesheets -%>
|
6
6
|
|
7
|
-
<!--
|
8
|
-
These stylesheets below are for design time use to allow working with only one visible section at a time, especially
|
9
|
-
when trying to use absolute positioning. You may comment/uncomment which ever section you wish to work with.
|
10
|
-
You may comment all of them out to work with all at design time. These stylesheets will not be used at runtime
|
11
|
-
-->
|
12
7
|
<%= design_time_stylesheets -%>
|
13
8
|
|
14
9
|
<script type="text/javascript" src="../../../public/javascripts/prototype.js" mv:javascript_include=":defaults"></script>
|
@@ -24,7 +19,7 @@
|
|
24
19
|
<div id="header">
|
25
20
|
<span class="headerTitle"><%= controller_class_name %></span>
|
26
21
|
<div class="menuBar">
|
27
|
-
<a href="
|
22
|
+
<a href="<%= controller_file_name %>_list.html" mv:link_to=":action => :index">Home</a>
|
28
23
|
<!-- | <a href="">Another link</a> -->
|
29
24
|
</div>
|
30
25
|
</div>
|
@@ -33,16 +28,47 @@
|
|
33
28
|
<div class="main">
|
34
29
|
<div id="<%= controller_file_name %>_content" mv:replace="@content_for_layout">
|
35
30
|
|
31
|
+
<!-- ###### Main Content Starts ###### -->
|
36
32
|
|
33
|
+
<div id="<%= controller_file_name %>_list" mv:generate="<%= controller_view_dir_name %>/list.rhtml" mv:preview="showOne" class="list_div"> <!-- ###### List ###### -->
|
34
|
+
<div class="<%= controller_file_name %>_list sidebar LHS">
|
35
|
+
<h2>Tasks:</h2>
|
36
|
+
<ul>
|
37
|
+
<li><a class="new_link" href="<%= controller_file_name %>_new.html" mv:link_to=":action => 'new<%= suffix %>'">Create new <%= singular_name %></a></li>
|
38
|
+
</ul>
|
39
|
+
</div>
|
37
40
|
|
38
|
-
|
41
|
+
<div class="<%= controller_file_name %>_list content">
|
42
|
+
<h1><%= plural_name.capitalize %></h1>
|
39
43
|
|
40
|
-
|
44
|
+
<div id="<%= controller_file_name %>_messages" class="messages" mv:gen_render=":partial => '<%= controller_view_dir_name %>/messages'" mv:if="@flash[:notice]" mv:content="@flash[:notice]">
|
45
|
+
<%= messages %>
|
46
|
+
</div>
|
47
|
+
|
48
|
+
<div class="list">
|
49
|
+
<table border="1" class="<%= controller_file_name %>_list_table" cellpadding="5">
|
50
|
+
<tr>
|
51
|
+
<%= list_head_inclusion %>
|
52
|
+
</tr>
|
53
|
+
<tr mv:gen_render=":partial => '<%= controller_view_dir_name %>/<%= singular_name %>', :collection => @<%= plural_name %>">
|
54
|
+
<%= list_line_inclusion %>
|
55
|
+
</tr>
|
56
|
+
</table>
|
57
|
+
|
58
|
+
<a class="previous_link" href="<%= controller_file_name %>_list.html" mv:if="@<%= singular_name %>_pages.current.previous" mv:link_to=":page => @<%= singular_name %>_pages.current.previous">Previous page</a>
|
59
|
+
<a class="next_link" href="<%= controller_file_name %>_list.html" mv:if="@<%= singular_name %>_pages.current.next" mv:link_to=":page => @<%= singular_name %>_pages.current.next">Next page</a>
|
60
|
+
|
61
|
+
</div>
|
62
|
+
</div>
|
63
|
+
</div>
|
64
|
+
|
65
|
+
|
66
|
+
<div id="<%= controller_file_name %>_new" mv:generate="<%= controller_view_dir_name %>/new.rhtml" mv:preview="showOne" class="new_div"> <!-- ###### New ###### -->
|
41
67
|
|
42
68
|
<div class="<%= controller_file_name %>_new sidebar LHS">
|
43
69
|
<h2>Tasks:</h2>
|
44
70
|
<ul>
|
45
|
-
<li><a class="list_link" href="
|
71
|
+
<li><a class="list_link" href="<%= controller_file_name %>_list.html" mv:link_to=":action => 'list<%= suffix %>'">Back to overview</a></li>
|
46
72
|
</ul>
|
47
73
|
</div>
|
48
74
|
|
@@ -54,9 +80,9 @@
|
|
54
80
|
<div class="form">
|
55
81
|
<h2>Creating <%= singular_name %></h2>
|
56
82
|
|
57
|
-
|
58
|
-
|
59
|
-
|
83
|
+
<div class="messages" mv:import_render=":partial => '<%= controller_view_dir_name %>/messages'" mv:preview="copyOf:<%= controller_file_name %>_messages">
|
84
|
+
copyOf:<%= controller_file_name %>_messages
|
85
|
+
</div>
|
60
86
|
|
61
87
|
<div id="<%= controller_file_name %>_form" mv:gen_render=":partial => '<%= controller_view_dir_name %>/form'">
|
62
88
|
<div class="error_messages" mv:replace="error_messages_for :<%= singular_name %>">
|
@@ -79,14 +105,11 @@
|
|
79
105
|
</div>
|
80
106
|
|
81
107
|
|
82
|
-
|
83
|
-
<!-- ###### Edit ###### -->
|
84
|
-
|
85
|
-
<div id="<%= controller_file_name %>_edit" mv:generate="<%= controller_view_dir_name %>/edit.rhtml" mv:preview="showOne" class="edit_div">
|
108
|
+
<div id="<%= controller_file_name %>_edit" mv:generate="<%= controller_view_dir_name %>/edit.rhtml" mv:preview="showOne" class="edit_div"> <!-- ###### Edit ###### -->
|
86
109
|
<div class="<%= controller_file_name %>_edit sidebar LHS">
|
87
110
|
<h2>Tasks:</h2>
|
88
111
|
<ul>
|
89
|
-
<li><a class="list_link" href="
|
112
|
+
<li><a class="list_link" href="<%= controller_file_name %>_list.html" mv:link_to=":action => 'list<%= suffix %>'">Back to overview</a></li>
|
90
113
|
</ul>
|
91
114
|
</div>
|
92
115
|
|
@@ -99,11 +122,11 @@
|
|
99
122
|
<div class="form">
|
100
123
|
<h2>Editing <%= singular_name %></h2>
|
101
124
|
|
102
|
-
<div class="messages" mv:
|
125
|
+
<div class="messages" mv:import_render=":partial => '<%= controller_view_dir_name %>/messages'" mv:preview="copyOf:<%= controller_file_name %>_messages">
|
103
126
|
copyOf:<%= controller_file_name %>_messages
|
104
127
|
</div>
|
105
128
|
|
106
|
-
<div mv:
|
129
|
+
<div mv:import_render=":partial => '<%= controller_view_dir_name %>/form'" mv:preview="copyOf:<%= controller_file_name %>_form">
|
107
130
|
copyOf:<%= controller_file_name %>_form
|
108
131
|
</div>
|
109
132
|
</div>
|
@@ -118,58 +141,19 @@
|
|
118
141
|
</div>
|
119
142
|
|
120
143
|
|
121
|
-
|
122
|
-
<!-- ###### List ###### -->
|
123
|
-
|
124
|
-
<div id="<%= controller_file_name %>_list" mv:generate="<%= controller_view_dir_name %>/list.rhtml" mv:preview="showOne" class="list_div">
|
125
|
-
<div class="<%= controller_file_name %>_list sidebar LHS">
|
126
|
-
<h2>Tasks:</h2>
|
127
|
-
<ul>
|
128
|
-
<li><a class="new_link" href="#" mv:link_to=":action => 'new<%= suffix %>'">Create new <%= singular_name %></a></li>
|
129
|
-
</ul>
|
130
|
-
</div>
|
131
|
-
|
132
|
-
<div class="<%= controller_file_name %>_list content">
|
133
|
-
<h1><%= plural_name.capitalize %></h1>
|
134
|
-
|
135
|
-
<div class="messages" mv:replace="render :partial => 'messages'" mv:preview="copyOf:<%= controller_file_name %>_messages">
|
136
|
-
copyOf:<%= controller_file_name %>_messages
|
137
|
-
</div>
|
138
|
-
|
139
|
-
<div class="list">
|
140
|
-
<table border="1" class="<%= controller_file_name %>_list_table" cellpadding="5">
|
141
|
-
<tr>
|
142
|
-
<%= list_head_inclusion %>
|
143
|
-
</tr>
|
144
|
-
<tr mv:gen_render=":partial => '<%= controller_view_dir_name %>/<%= singular_name %>', :collection => @<%= plural_name %>">
|
145
|
-
<%= list_line_inclusion %>
|
146
|
-
</tr>
|
147
|
-
</table>
|
148
|
-
|
149
|
-
<a class="previous_link" href="#" mv:if="@<%= singular_name %>_pages.current.previous" mv:link_to=":page => @<%= singular_name %>_pages.current.previous">Previous page</a>
|
150
|
-
<a class="next_link" href="#" mv:if="@<%= singular_name %>_pages.current.next" mv:link_to=":page => @<%= singular_name %>_pages.current.next">Next page</a>
|
151
|
-
|
152
|
-
</div>
|
153
|
-
</div>
|
154
|
-
</div>
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
<!-- ###### Show ###### -->
|
159
|
-
|
160
|
-
<div id="<%= controller_file_name %>_show" mv:generate="<%= controller_view_dir_name %>/show.rhtml" mv:preview="showOne" class="show_div">
|
144
|
+
<div id="<%= controller_file_name %>_show" mv:generate="<%= controller_view_dir_name %>/show.rhtml" mv:preview="showOne" class="show_div"> <!-- ###### Show ###### -->
|
161
145
|
<div class="<%= controller_file_name %>_show sidebar LHS">
|
162
146
|
<h2>Tasks:</h2>
|
163
147
|
<ul>
|
164
|
-
<li><a class="list_link" href="
|
165
|
-
<li><a class="edit_link" href="
|
148
|
+
<li><a class="list_link" href="<%= controller_file_name %>_list.html" mv:link_to=":action => 'list<%= suffix %>'">Back to overview</a></li>
|
149
|
+
<li><a class="edit_link" href="<%= controller_file_name %>_edit.html" mv:link_to=":action => 'edit<%= suffix %>', :id => @<%= singular_name %>.id">Edit this <%= singular_name %></a></li>
|
166
150
|
</ul>
|
167
151
|
</div>
|
168
152
|
|
169
153
|
<div class="<%= controller_file_name %>_show content">
|
170
154
|
<h1><%= plural_name.capitalize %></h1>
|
171
155
|
|
172
|
-
<div class="messages" mv:
|
156
|
+
<div class="messages" mv:import_render=":partial => '<%= controller_view_dir_name %>/messages'" mv:preview="copyOf:<%= controller_file_name %>_messages">
|
173
157
|
copyOf:<%= controller_file_name %>_messages
|
174
158
|
</div>
|
175
159
|
|
@@ -181,22 +165,19 @@
|
|
181
165
|
</div>
|
182
166
|
|
183
167
|
|
184
|
-
|
185
|
-
<!-- ###### Destroy ###### -->
|
186
|
-
|
187
|
-
<div id="<%= controller_file_name %>_destroy" mv:generate="<%= controller_view_dir_name %>/destroy.rhtml" mv:preview="showOne" class="destroy_div">
|
168
|
+
<div id="<%= controller_file_name %>_destroy" mv:generate="<%= controller_view_dir_name %>/destroy.rhtml" mv:preview="showOne" class="destroy_div"> <!-- ###### Destroy ###### -->
|
188
169
|
<div class="<%= controller_file_name %>_destroy sidebar LHS">
|
189
170
|
<h2>Tasks:</h2>
|
190
171
|
<ul>
|
191
|
-
<li><a class="list_link" href="
|
192
|
-
<li><a class="show_link" href="
|
172
|
+
<li><a class="list_link" href="<%= controller_file_name %>_list.html" mv:link_to=":action => 'list<%= suffix %>'">Back to overview</a></li>
|
173
|
+
<li><a class="show_link" href="<%= controller_file_name %>_show.html" mv:link_to=":action => 'show<%= suffix %>', :id => @<%= singular_name %>.id">Show this <%= singular_name %></a></li>
|
193
174
|
</ul>
|
194
175
|
</div>
|
195
176
|
|
196
177
|
<div class="<%= controller_file_name %>_destroy content">
|
197
178
|
<h1><%= plural_name.capitalize %></h1>
|
198
179
|
|
199
|
-
<div class="messages" mv:
|
180
|
+
<div class="messages" mv:import_render=":partial => '<%= controller_view_dir_name %>/messages'" mv:preview="copyOf:<%= controller_file_name %>_messages">
|
200
181
|
copyOf:<%= controller_file_name %>_messages
|
201
182
|
</div>
|
202
183
|
|
@@ -207,7 +188,7 @@
|
|
207
188
|
<div class="messages">Are you sure you want to delete this item?</div>
|
208
189
|
<br/>
|
209
190
|
<form mv:form=":action => 'destroy', :id => @<%= singular_name %>.id">
|
210
|
-
<div mv:
|
191
|
+
<div mv:import_render=":partial => '<%= controller_view_dir_name %>/show'" mv:preview="copyOf:<%= controller_file_name %>_show_partial">
|
211
192
|
copyOf:<%= controller_file_name %>_show_partial
|
212
193
|
</div>
|
213
194
|
|
@@ -219,11 +200,13 @@
|
|
219
200
|
</form>
|
220
201
|
</div>
|
221
202
|
</div>
|
203
|
+
|
204
|
+
<!-- ###### Main Content Ends ###### -->
|
205
|
+
|
222
206
|
</div>
|
223
207
|
</div>
|
224
208
|
|
225
209
|
|
226
|
-
|
227
210
|
<!-- ###### Footer ###### -->
|
228
211
|
|
229
212
|
<div id="footer">
|
@@ -245,11 +228,7 @@
|
|
245
228
|
</div>
|
246
229
|
|
247
230
|
|
248
|
-
|
249
|
-
<script type="text/javascript" mv:replace="">
|
250
|
-
mvpreview.preparePage( '<%= controller_file_name %>', {showOneSection: '<%= controller_file_name %>_list' } );
|
251
|
-
</script>
|
252
|
-
|
231
|
+
<%= design_time_javascript %>
|
253
232
|
</body>
|
254
233
|
</html>
|
255
234
|
|
data/templates/mvpreview.js
CHANGED
@@ -30,9 +30,13 @@
|
|
30
30
|
|
31
31
|
mvpreview.sections = mvpreview.preview_divs.findAll( function(elem){ return (elem.getAttribute('mv:preview') == 'showOne'); });
|
32
32
|
|
33
|
-
mvpreview.
|
33
|
+
mvpreview.change_messages_single_page = function(prefix){
|
34
34
|
$(prefix+'_messages').innerHTML = 'messages would be here - You are currently running this in browser preview mode. Javascript has overridden the links and buttons so that you can click on any of them to view other pages for this controller. This is to simulate app operation as a standalone prototype.';
|
35
35
|
}
|
36
|
+
|
37
|
+
mvpreview.change_messages = function(prefix){
|
38
|
+
$(prefix+'_messages').innerHTML = 'messages would be here - You are currently running this in browser preview mode. Javascript has overridden the buttons so that you can click on any of them to view other pages for this controller. This is to simulate app operation as a standalone prototype.';
|
39
|
+
}
|
36
40
|
|
37
41
|
mvpreview.hideSections = function(){
|
38
42
|
this.sections.each( function(elem){ window.Element.hide(elem); } );
|
@@ -92,11 +96,43 @@
|
|
92
96
|
);
|
93
97
|
}
|
94
98
|
|
99
|
+
|
100
|
+
mvpreview.registerShowPageLink = function(elemOrId, pageToShow){
|
101
|
+
var elem = $(elemOrId);
|
102
|
+
if(elem){
|
103
|
+
if(elem.getAttribute('onclick')) elem.setAttribute('onclick', ''); //clear out any existing onclick
|
104
|
+
Event.observe( elem, 'click', function(e){ window.location = pageToShow; Event.stop(e); }, false );
|
105
|
+
}
|
106
|
+
}
|
107
|
+
|
108
|
+
mvpreview.registerButtonsMultipage = function( prefix ){
|
109
|
+
var regexSave = new RegExp( "(^|\\s)" + 'save_button' + "(\\s|$)" );
|
110
|
+
var regexCancel = new RegExp( "(^|\\s)" + 'cancel_button' + "(\\s|$)" );
|
111
|
+
var allInputsAndButtons = $A( document.getElementsByTagName('input') ).concat( $A( document.getElementsByTagName('button') ));
|
112
|
+
allInputsAndButtons.each(
|
113
|
+
function(button){
|
114
|
+
var className = button.className;
|
115
|
+
if(className){
|
116
|
+
if(className.match(regexSave)) mvpreview.registerShowPageLink(button, prefix+'_list.html');
|
117
|
+
else if(className.match(regexCancel)) mvpreview.registerShowPageLink(button, prefix+'_list.html');
|
118
|
+
}
|
119
|
+
}
|
120
|
+
);
|
121
|
+
}
|
122
|
+
|
95
123
|
|
96
124
|
mvpreview.preparePage = function(prefix, options){
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
125
|
+
if( options && options.single_file ) {
|
126
|
+
mvpreview.change_messages_single_page(prefix);
|
127
|
+
mvpreview.copySections();
|
128
|
+
mvpreview.removeSections();
|
129
|
+
mvpreview.registerShowOneSectionLinks(prefix);
|
130
|
+
if(options && options.showOneSection) mvpreview.showOneSection(options.showOneSection);
|
131
|
+
}else{
|
132
|
+
mvpreview.change_messages(prefix);
|
133
|
+
mvpreview.copySections();
|
134
|
+
mvpreview.removeSections();
|
135
|
+
mvpreview.registerButtonsMultipage(prefix);
|
136
|
+
}
|
137
|
+
|
102
138
|
}
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
|
|
3
3
|
specification_version: 1
|
4
4
|
name: masterview_generator
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.0
|
7
|
-
date: 2006-05-
|
6
|
+
version: 0.1.0
|
7
|
+
date: 2006-05-29 00:00:00 -05:00
|
8
8
|
summary: A (x)html friendly template engine for rails with the power of layouts, and partials. MasterView Generator for GEM
|
9
9
|
require_paths:
|
10
10
|
- .
|