masterview_generator 0.0.3

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/Rakefile ADDED
@@ -0,0 +1,313 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'rake'
4
+ require 'rake/testtask'
5
+ require 'rake/rdoctask'
6
+ require 'rake/gempackagetask'
7
+ require 'rake/contrib/rubyforgepublisher'
8
+
9
+ $LOAD_PATH.unshift( File.join( File.dirname(__FILE__), 'lib') )
10
+ require 'masterview'
11
+
12
+ RUBY_FORGE_PROJECT = "masterview"
13
+ RUBY_FORGE_USER = "jeffbski"
14
+ RUBY_FORGE_GROUPID = "1290"
15
+ RUBY_FORGE_PACKAGEID = "1581" #verify this from http://rubyforge.org/frs/admin/?group_id=1290
16
+
17
+ desc "Default Task"
18
+ task :default => [ :test ]
19
+
20
+ desc "Delete tar.gz / zip / rdoc"
21
+ task :cleanup => [ :rm_packages, :clobber_rdoc ]
22
+
23
+ # Run the unit tests
24
+ Rake::TestTask.new(:test) do |t|
25
+ t.libs << "lib"
26
+ t.libs << "test"
27
+ t.pattern = 'test/*_test.rb'
28
+ t.verbose = false
29
+ end
30
+
31
+ # Run parser on masterview html files
32
+ desc "Run parser on masterview html files"
33
+ task :mvparse do
34
+ TmpOutputDir = 'tmp/views'
35
+ filelist = Dir.glob('examples/**/*.html')
36
+ filelist.each do |file|
37
+ MasterView::Parser.parse_file( file, TmpOutputDir, :tidy => true )
38
+ end
39
+ end
40
+
41
+
42
+ task :install => [:package] do
43
+ `gem install pkg/#{PKG_FILE_NAME}.gem`
44
+ end
45
+
46
+ task :syntax do
47
+ filelist = Dir.glob('**/*.rb')
48
+ filelist.each do |file|
49
+ output = `ruby -c #{file}`
50
+ unless output =~ /Syntax OK/
51
+ puts "#{file}:"
52
+ puts " #{output}"
53
+ return
54
+ end
55
+ end
56
+ puts 'Syntax OK'
57
+ end
58
+
59
+ # Genereate the RDoc documentation
60
+ Rake::RDocTask.new { |rdoc|
61
+ rdoc.rdoc_dir = 'doc'
62
+ rdoc.title = "MasterView Template Engine"
63
+ rdoc.options << '--line-numbers' << '--inline-source'
64
+ rdoc.rdoc_files.include('README')
65
+ rdoc.rdoc_files.include('lib/**/*.rb')
66
+ }
67
+
68
+ task :lines do
69
+ lines = 0
70
+ codelines = 0
71
+ Dir.foreach("lib") { |file_name|
72
+ next unless file_name =~ /.*rb/
73
+
74
+ f = File.open("lib/" + file_name)
75
+
76
+ while line = f.gets
77
+ lines += 1
78
+ next if line =~ /^\s*$/
79
+ next if line =~ /^\s*#/
80
+ codelines += 1
81
+ end
82
+ }
83
+ puts "Lines #{lines}, LOC #{codelines}"
84
+ end
85
+
86
+
87
+ # Publish beta gem
88
+ #desc "Publish the gem"
89
+ #task :publish => [:rdoc, :package] do
90
+ # Rake::SshFilePublisher.new("foobar.com", "dist/pkg", "pkg", "#{PKG_FILE_NAME}.zip").upload
91
+ # Rake::SshFilePublisher.new("foobar.com", "dist/pkg", "pkg", "#{PKG_FILE_NAME}.tgz").upload
92
+ # Rake::SshFilePublisher.new("foobar.com", "dist/gems", "pkg", "#{PKG_FILE_NAME}.gem").upload
93
+ #
94
+ # Rake::SshDirPublisher.new("foobar.com", "dist/api/#{PKG_NAME}", "doc").upload
95
+ #end
96
+
97
+ desc 'Build all packages'
98
+ task :package_all => ['masterview_complete:package',
99
+ 'masterview:package',
100
+ 'masterview_parser:package',
101
+ 'masterview_generator:package',
102
+ 'masterview_gem_plugin_generator:package']
103
+
104
+ desc 'Re-build all packages'
105
+ task :repackage_all => ['masterview_complete:repackage',
106
+ 'masterview:repackage',
107
+ 'masterview_parser:repackage',
108
+ 'masterview_generator:repackage',
109
+ 'masterview_gem_plugin_generator:repackage']
110
+
111
+ namespace 'masterview_complete' do
112
+ module MasterViewComplete
113
+ PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
114
+ PKG_NAME = 'masterview_complete'
115
+ PKG_VERSION = MasterView::VERSION::STRING + PKG_BUILD
116
+ PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
117
+ PKG_DESTINATION = ENV["RAILS_PKG_DESTINATION"] || "../#{PKG_NAME}"
118
+ RELEASE_NAME = "REL #{PKG_VERSION}"
119
+ PKG_FILES = FileList[
120
+ "lib/**/*",
121
+ "generators/**/*",
122
+ "directives/**/*",
123
+ "test/**/*",
124
+ "example/**/*",
125
+ "[A-Z]*",
126
+ "Rakefile",
127
+ "init.rb"
128
+ ].exclude(/\bCVS\b|~$|\.svn|semantic.cache/)
129
+
130
+ spec = Gem::Specification.new do |s|
131
+ s.name = PKG_NAME
132
+ s.version = PKG_VERSION
133
+ s.summary = "A (x)html friendly template engine for rails with the power of layouts, and partials. This is the plugin version which contains everything."
134
+ s.has_rdoc = true
135
+ s.files = PKG_FILES
136
+ s.require_path = 'lib'
137
+ s.autorequire = 'masterview'
138
+ s.author = "Jeff Barczewski"
139
+ s.email = "jeff.barczewski@gmail.com"
140
+ s.homepage = "http://masterview.org/"
141
+ end
142
+
143
+ # Create Rubygem package
144
+ Rake::GemPackageTask.new(spec) do |p|
145
+ p.gem_spec = spec
146
+ p.need_tar = true
147
+ p.need_zip = true
148
+ end
149
+ end
150
+ end
151
+
152
+ namespace 'masterview' do
153
+ module MasterViewGem
154
+ PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
155
+ PKG_NAME = 'masterview'
156
+ PKG_VERSION = MasterView::VERSION::STRING + PKG_BUILD
157
+ PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
158
+ PKG_DESTINATION = ENV["RAILS_PKG_DESTINATION"] || "../#{PKG_NAME}"
159
+ RELEASE_NAME = "REL #{PKG_VERSION}"
160
+ PKG_FILES = FileList[
161
+ "[A-Z]*",
162
+ ].exclude(/\bCVS\b|~$|\.svn|semantic.cache/)
163
+
164
+ spec = Gem::Specification.new do |s|
165
+ s.name = PKG_NAME
166
+ s.version = PKG_VERSION
167
+ s.summary = "A (x)html friendly template engine for rails with the power of layouts, and partials. Main gem which requires all others"
168
+ s.has_rdoc = true
169
+ s.files = PKG_FILES
170
+ s.require_path = 'lib'
171
+ #s.autorequire = 'masterview'
172
+ s.add_dependency 'masterview_parser'
173
+ s.add_dependency 'masterview_generator'
174
+ s.add_dependency 'masterview_gem_plugin_generator'
175
+ s.author = "Jeff Barczewski"
176
+ s.email = "jeff.barczewski@gmail.com"
177
+ s.homepage = "http://masterview.org/"
178
+ end
179
+
180
+ # Create Rubygem package
181
+ Rake::GemPackageTask.new(spec) do |p|
182
+ p.gem_spec = spec
183
+ p.need_tar = false
184
+ p.need_zip = false
185
+ end
186
+ end
187
+ end
188
+
189
+ namespace 'masterview_parser' do
190
+ module MasterViewParser
191
+ PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
192
+ PKG_NAME = 'masterview_parser'
193
+ PKG_VERSION = MasterView::VERSION::STRING + PKG_BUILD
194
+ PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
195
+ PKG_DESTINATION = ENV["RAILS_PKG_DESTINATION"] || "../#{PKG_NAME}"
196
+ RELEASE_NAME = "REL #{PKG_VERSION}"
197
+ PKG_FILES = FileList[
198
+ "lib/**/*",
199
+ "directives/**/*",
200
+ "test/**/*",
201
+ "example/**/*",
202
+ "[A-Z]*",
203
+ "Rakefile",
204
+ "init.rb"
205
+ ].exclude(/\bCVS\b|~$|\.svn|semantic.cache/)
206
+
207
+ spec = Gem::Specification.new do |s|
208
+ s.name = PKG_NAME
209
+ s.version = PKG_VERSION
210
+ s.summary = "A (x)html friendly template engine for rails with the power of layouts, and partials. Parser gem"
211
+ s.has_rdoc = true
212
+ s.files = PKG_FILES
213
+ s.require_path = 'lib'
214
+ s.autorequire = 'masterview'
215
+ s.author = "Jeff Barczewski"
216
+ s.email = "jeff.barczewski@gmail.com"
217
+ s.homepage = "http://masterview.org/"
218
+ end
219
+
220
+ # Create Rubygem package
221
+ Rake::GemPackageTask.new(spec) do |p|
222
+ p.gem_spec = spec
223
+ p.need_tar = false
224
+ p.need_zip = false
225
+ end
226
+ end
227
+ end
228
+
229
+ namespace 'masterview_generator' do
230
+ module MasterViewGenerator
231
+ PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
232
+ PKG_NAME = 'masterview_generator'
233
+ PKG_VERSION = MasterView::VERSION::STRING + PKG_BUILD
234
+ PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
235
+ PKG_DESTINATION = ENV["RAILS_PKG_DESTINATION"] || "../#{PKG_NAME}"
236
+ RELEASE_NAME = "REL #{PKG_VERSION}"
237
+ PKG_FILES = FileList[
238
+ "generators/masterview/**/*",
239
+ "[A-Z]*"
240
+ ].exclude(/\bCVS\b|~$|\.svn|semantic.cache/)
241
+
242
+ spec = Gem::Specification.new do |s|
243
+ s.name = PKG_NAME
244
+ s.version = PKG_VERSION
245
+ s.summary = "A (x)html friendly template engine for rails with the power of layouts, and partials. MasterView Generator for GEM"
246
+ s.has_rdoc = true
247
+ s.files = PKG_FILES
248
+ s.require_path = 'generators/masterview'
249
+ #s.autorequire = 'masterview_generator'
250
+ s.add_dependency 'masterview_parser'
251
+ s.author = "Jeff Barczewski"
252
+ s.email = "jeff.barczewski@gmail.com"
253
+ s.homepage = "http://masterview.org/"
254
+ end
255
+
256
+ # Create Rubygem package
257
+ Rake::GemPackageTask.new(spec) do |p|
258
+ p.gem_spec = spec
259
+ p.need_tar = false
260
+ p.need_zip = false
261
+ end
262
+ end
263
+ end
264
+
265
+
266
+ namespace 'masterview_gem_plugin_generator' do
267
+ module MasterViewGemPluginGenerator
268
+ PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
269
+ PKG_NAME = 'masterview_gem_plugin_generator'
270
+ PKG_VERSION = MasterView::VERSION::STRING + PKG_BUILD
271
+ PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
272
+ PKG_DESTINATION = ENV["RAILS_PKG_DESTINATION"] || "../#{PKG_NAME}"
273
+ RELEASE_NAME = "REL #{PKG_VERSION}"
274
+ PKG_FILES = FileList[
275
+ "generators/masterview_gem_plugin/**/*",
276
+ "[A-Z]*"
277
+ ].exclude(/\bCVS\b|~$|\.svn|semantic.cache/)
278
+
279
+ spec = Gem::Specification.new do |s|
280
+ s.name = PKG_NAME
281
+ s.version = PKG_VERSION
282
+ s.summary = "A (x)html friendly template engine for rails with the power of layouts, and partials. MasterView Plugin Generator for GEM"
283
+ s.has_rdoc = true
284
+ s.files = PKG_FILES
285
+ s.require_path = 'generators/masterview_gem_plugin'
286
+ #s.autorequire = 'masterview_gem_plugin_generator'
287
+ s.add_dependency 'masterview_parser'
288
+ s.author = "Jeff Barczewski"
289
+ s.email = "jeff.barczewski@gmail.com"
290
+ s.homepage = "http://masterview.org/"
291
+ end
292
+
293
+ # Create Rubygem package
294
+ Rake::GemPackageTask.new(spec) do |p|
295
+ p.gem_spec = spec
296
+ p.need_tar = false
297
+ p.need_zip = false
298
+ end
299
+ end
300
+ end
301
+
302
+
303
+ # --- Ruby forge release manager by florian gross -------------------------------------------------
304
+ desc "Publish the release files to RubyForge."
305
+ task :release => [:gem, :package] do
306
+ files = ["zip", "tgz"].map { |ext| "pkg/#{PKG_FILE_NAME}.#{ext}" }
307
+
308
+ system("rubyforge login --username #{RUBY_FORGE_USER}")
309
+
310
+ files.each do |file|
311
+ system("rubyforge add_release #{RUBY_FORGE_GROUPID} #{RUBY_FORGE_PACKAGEID} \"#{RELEASE_NAME}\" #{file}")
312
+ end
313
+ end
@@ -0,0 +1,32 @@
1
+ Description:
2
+ The masterview generator creates a controller to interact with a model.
3
+ If the model does not exist, it creates the model as well. The generated
4
+ code is equivalent to the "scaffold :model" declaration, making it easy
5
+ to migrate when you wish to customize your controller and views.
6
+
7
+ The generator takes a model name, an optional controller name, and a
8
+ list of views as arguments. Scaffolded actions and views are created
9
+ automatically. Any views left over generate empty stubs.
10
+
11
+ The scaffolded actions and views are:
12
+ index, list, show, new, create, edit, update, destroy
13
+
14
+ If a controller name is not given, the plural form of the model name
15
+ will be used. The model and controller names may be given in CamelCase
16
+ or under_score and should not be suffixed with 'Model' or 'Controller'.
17
+ Both model and controller names may be prefixed with a module like a
18
+ file path; see the Modules Example for usage.
19
+
20
+ The masterview generator is heavily based on the shipped scaffold generator
21
+ and the postback_generator by Tobias Luetke which follows the
22
+ selfpostback style and moves the generated form into
23
+ an partial. It also offers a lot more css hooks for customization.
24
+
25
+ Example:
26
+ ./script/generate masterview Account Bank debit credit
27
+
28
+ This will generate an Account model and BankController with a full test
29
+ suite and a basic user interface. Now create the accounts table in your
30
+ database and browse to http://localhost/bank/ -- voila, you're on Rails!
31
+
32
+
@@ -0,0 +1,277 @@
1
+ class ScaffoldingSandbox
2
+ include ActionView::Helpers::ActiveRecordHelper
3
+
4
+ attr_accessor :singular_name, :suffix, :model_instance
5
+
6
+ def sandbox_binding
7
+ binding
8
+ end
9
+
10
+ def default_input_block
11
+ Proc.new { |record, column| "<tr><td class=\"label edit_label\"><label for=\"#{record}_#{column.name}\">#{column.human_name}:</label></td> <td class=\"field edit_field\">#{input(record, column.name)}</td></tr>" }
12
+ end
13
+ end
14
+
15
+ class ListHeadScaffoldingSandbox < ScaffoldingSandbox
16
+ def default_input_block
17
+ Proc.new { |record, column| "<th>#{column.human_name}</th>" }
18
+ end
19
+ end
20
+
21
+ class ListLineScaffoldingSandbox < ScaffoldingSandbox
22
+ def default_input_block
23
+ Proc.new { |record, column| "<td class=\"field list_field\" mv:content=\"h #{record}.send(:#{column.name})\">#{record} #{column.human_name}</td>" }
24
+ end
25
+ end
26
+
27
+ class ShowScaffoldingSandbox < ScaffoldingSandbox
28
+ def default_input_block
29
+ Proc.new { |record, column| "<tr><td class=\"label show_label\"><label>#{column.human_name}:</label></td> <td class=\"field show_field\"><span class=\"static\" mv:content=\"h @#{record}.send(:#{column.name})\">#{record} #{column.human_name}</span></td></tr>" }
30
+ end
31
+ end
32
+
33
+
34
+ class ActionView::Helpers::InstanceTag
35
+ def to_input_field_tag(field_type, options={})
36
+ field_meth = "#{field_type}_field"
37
+ case field_meth
38
+ when 'text_field'
39
+ %Q[<input type="text" name="#{@object_name}_#{@method_name}" mv:text_field="'#{@object_name}', '#{@method_name}'#{options.empty? ? '' : ', '+options.inspect}"/>]
40
+ when 'hidden_field'
41
+ %Q[<input type="hidden" name="#{@object_name}_#{@method_name}" mv:hidden_field="'#{@object_name}', '#{@method_name}'#{options.empty? ? '' : ', '+options.inspect}"/>]
42
+ when 'password_field'
43
+ %Q[<input type="password" name="#{@object_name}_#{@method_name}" mv:password_field="'#{@object_name}', '#{@method_name}'#{options.empty? ? '' : ', '+options.inspect}"/>]
44
+ end
45
+ end
46
+
47
+ def to_text_area_tag(options = {})
48
+ %Q[<textarea name="#{@object_name}_#{@method_name}" rows="5" mv:text_area="'#{@object_name}', '#{@method_name}'#{options.empty? ? '' : ', '+options.inspect}"></textarea>]
49
+ end
50
+
51
+ def to_date_select_tag(options = {})
52
+ %Q[<span mv:replace="date_select '#{@object_name}', '#{@method_name}' #{options.empty? ? '' : ', '+ options.inspect}">todo render date select</span>]
53
+ end
54
+
55
+ def to_datetime_select_tag(options = {})
56
+ %Q[<span mv:replace="datetime_select '#{@object_name}', '#{@method_name}' #{options.empty? ? '' : ', '+ options.inspect}">todo render date select</span>]
57
+ end
58
+ end
59
+
60
+ module Rails
61
+ module Generator
62
+ module Commands
63
+ class Create < Base
64
+ def multi_include_template(relative_source, relative_destination, template_options = {}, multi_assign_options = {})
65
+ options = template_options.dup
66
+ options[:assigns] ||= {}
67
+ multi_assign_options.each do |k,v|
68
+ options[:assigns][k] = render_template_part(v)
69
+ end
70
+ template(relative_source, relative_destination, options)
71
+ end
72
+ end
73
+
74
+ class Destroy < RewindBase
75
+ def multi_include_template(relative_source, relative_destination, template_options = {}, multi_assign_options = {})
76
+ end
77
+ end
78
+
79
+ class List < Base
80
+ def multi_include_template(relative_source, relative_destination, template_options = {}, multi_assign_options = {})
81
+ str = ""
82
+ multi_assign_options.each do |k,v|
83
+ str << v[:insert] << ' '
84
+ end
85
+ logger.template "#{str} inside #{relative_destination}"
86
+ end
87
+ end
88
+
89
+ class Update < Create
90
+ def multi_include_template(relative_source, relative_destination, template_options = {}, multi_assign_options = {})
91
+ begin
92
+ dest_file = destination_path(relative_destination)
93
+ source_to_update = File.readlines(dest_file).join
94
+ rescue Errno::ENOENT
95
+ logger.missing relative_destination
96
+ return
97
+ end
98
+ multi_assign_options.each do |k,v|
99
+ template_options = v
100
+ logger.refreshing "#{template_options[:insert].gsub(/\.rhtml/,'')} inside #{relative_destination}"
101
+ begin_mark = Regexp.quote(template_part_mark(template_options[:begin_mark], template_options[:mark_id]))
102
+ end_mark = Regexp.quote(template_part_mark(template_options[:end_mark], template_options[:mark_id]))
103
+ # Refreshing inner part of the template with freshly rendered part.
104
+ rendered_part = render_template_part(template_options)
105
+ source_to_update.gsub!(/#{begin_mark}.*?#{end_mark}/m, rendered_part)
106
+ end
107
+ File.open(dest_file, 'w') { |file| file.write(source_to_update) }
108
+ end
109
+ end
110
+ end
111
+ end
112
+ end
113
+
114
+ class MasterviewGenerator < Rails::Generator::NamedBase
115
+ attr_reader :controller_name,
116
+ :controller_class_path,
117
+ :controller_file_path,
118
+ :controller_class_nesting,
119
+ :controller_class_nesting_depth,
120
+ :controller_class_name,
121
+ :controller_singular_name,
122
+ :controller_plural_name
123
+ alias_method :controller_file_name, :controller_singular_name
124
+ alias_method :controller_view_dir_name, :controller_singular_name
125
+ alias_method :controller_masterview_name, :controller_singular_name
126
+ alias_method :controller_table_name, :controller_plural_name
127
+
128
+ def initialize(runtime_args, runtime_options = {})
129
+ super
130
+ @controller_name = args.shift || @name
131
+ base_name, @controller_class_path, @controller_file_path, @controller_class_nesting, @controller_class_nesting_depth = extract_modules(@controller_name)
132
+ @controller_class_name_without_nesting, @controller_singular_name, @controller_plural_name = inflect_names(base_name)
133
+ if @controller_class_nesting.empty?
134
+ @controller_class_name = @controller_class_name_without_nesting
135
+ else
136
+ @controller_class_name = "#{@controller_class_nesting}::#{@controller_class_name_without_nesting}"
137
+ end
138
+ end
139
+
140
+ def manifest
141
+ record do |m|
142
+ # Depend on model generator but skip if the model exists.
143
+ m.dependency 'model', [singular_name], :collision => :skip, :skip_migration => true
144
+
145
+ # Check for class naming collisions.
146
+ m.class_collisions controller_class_path, "#{controller_class_name}Controller", "#{controller_class_name}ControllerTest", "#{controller_class_name}Helper"
147
+
148
+ # Controller, helper, views, and test directories.
149
+ m.directory File.join('app/controllers', controller_class_path)
150
+ m.directory File.join('app/helpers', controller_class_path)
151
+ m.directory File.join('app/views', controller_class_path, controller_view_dir_name)
152
+ m.directory 'app/views/masterview'
153
+ m.directory File.join('test/functional', controller_class_path)
154
+
155
+ # Controller class, functional test, helper, and views.
156
+ m.template 'controller.rb',
157
+ File.join('app/controllers',
158
+ controller_class_path,
159
+ "#{controller_file_name}_controller.rb")
160
+
161
+ m.template 'functional_test.rb',
162
+ File.join('test/functional',
163
+ controller_class_path,
164
+ "#{controller_file_name}_controller_test.rb")
165
+
166
+ m.template 'helper.rb',
167
+ File.join('app/helpers',
168
+ controller_class_path,
169
+ "#{controller_file_name}_helper.rb")
170
+
171
+ # MasterView
172
+ m.template 'mvpreview.js',
173
+ File.join('public/javascripts',
174
+ "mvpreview.js")
175
+
176
+ m.multi_include_template "masterview.rhtml","app/views/masterview/#{controller_masterview_name}.html", {},
177
+ {
178
+ 'form_inclusion' =>
179
+ { :insert => 'form_scaffold.rhtml',
180
+ :sandbox => lambda { create_multi_sandbox('ScaffoldingSandbox') },
181
+ :begin_mark => 'form',
182
+ :end_mark => 'eoform',
183
+ :mark_id => singular_name
184
+ },
185
+ 'list_head_inclusion' =>
186
+ { :insert => 'fields_scaffold.rhtml',
187
+ :sandbox => lambda { create_multi_sandbox('ListHeadScaffoldingSandbox') },
188
+ :begin_mark => 'listhead',
189
+ :end_mark => 'eolisthead',
190
+ :mark_id => singular_name
191
+ },
192
+ 'list_line_inclusion' =>
193
+ { :insert => 'list_line_scaffold.rhtml',
194
+ :sandbox => lambda { create_multi_sandbox('ListLineScaffoldingSandbox') },
195
+ :begin_mark => 'listline',
196
+ :end_mark => 'eolistline',
197
+ :mark_id => singular_name
198
+ },
199
+ 'show_inclusion' =>
200
+ { :insert => 'show_scaffold.rhtml',
201
+ :sandbox => lambda { create_multi_sandbox('ShowScaffoldingSandbox') },
202
+ :begin_mark => 'show',
203
+ :end_mark => 'eoshow',
204
+ :mark_id => singular_name
205
+ }
206
+ }
207
+
208
+ m.template 'style.css', 'public/stylesheets/scaffold.css'
209
+
210
+ end
211
+ end
212
+
213
+ protected
214
+ # Override with your own usage banner.
215
+ def banner
216
+ "Usage: #{$0} masterview ModelName [ControllerName] [action, ...]"
217
+ end
218
+
219
+ def scaffold_views
220
+ %w(list show new edit destroy)
221
+ end
222
+
223
+ def scaffold_actions
224
+ scaffold_views + %w(index)
225
+ end
226
+
227
+ def unscaffolded_actions
228
+ args - scaffold_actions
229
+ end
230
+
231
+ def suffix
232
+ "_#{singular_name}" if options[:suffix]
233
+ end
234
+
235
+ def model_name
236
+ class_name.demodulize
237
+ end
238
+
239
+ def create_sandbox
240
+ sandbox = ScaffoldingSandbox.new
241
+ sandbox.singular_name = singular_name
242
+ begin
243
+ sandbox.model_instance = model_instance
244
+ sandbox.instance_variable_set("@#{singular_name}", sandbox.model_instance)
245
+ rescue ActiveRecord::StatementInvalid => e
246
+ logger.error "Before updating scaffolding from new DB schema, try creating a table for your model (#{class_name})"
247
+ raise SystemExit
248
+ end
249
+ sandbox.suffix = suffix
250
+ sandbox
251
+ end
252
+
253
+ def create_multi_sandbox( sandbox_class_name )
254
+ sandbox = eval("#{sandbox_class_name}.new")
255
+ sandbox.singular_name = singular_name
256
+ begin
257
+ sandbox.model_instance = model_instance
258
+ sandbox.instance_variable_set("@#{singular_name}", sandbox.model_instance)
259
+ rescue ActiveRecord::StatementInvalid => e
260
+ logger.error "Before updating scaffolding from new DB schema, try creating a table for your model (#{class_name})"
261
+ raise SystemExit
262
+ end
263
+ sandbox.suffix = suffix
264
+ sandbox
265
+ end
266
+
267
+ def model_instance
268
+ base = class_nesting.split('::').inject(Object) do |base, nested|
269
+ break base.const_get(nested) if base.const_defined?(nested)
270
+ base.const_set(nested, Module.new)
271
+ end
272
+ unless base.const_defined?(@class_name_without_nesting)
273
+ base.const_set(@class_name_without_nesting, Class.new(ActiveRecord::Base))
274
+ end
275
+ class_name.constantize.new
276
+ end
277
+ end
@@ -0,0 +1,50 @@
1
+ class <%= controller_class_name %>Controller < ApplicationController
2
+
3
+ <% unless suffix -%>
4
+ def index
5
+ list
6
+ render_action 'list'
7
+ end
8
+ <% end -%>
9
+
10
+ <% for action in unscaffolded_actions -%>
11
+ def <%= action %><%= suffix %>
12
+ end
13
+
14
+ <% end -%>
15
+ def list<%= suffix %>
16
+ @<%= singular_name %>_pages, @<%= plural_name %> = paginate :<%= plural_name %>, :per_page => 10
17
+ end
18
+
19
+ def show<%= suffix %>
20
+ @<%= singular_name %> = <%= model_name %>.find(@params['id'])
21
+ end
22
+
23
+ def new<%= suffix %>
24
+ @<%= singular_name %> = <%= model_name %>.new(@params["<%= singular_name %>"])
25
+
26
+ if @request.post? and @<%= singular_name %>.save
27
+ flash[:notice] = '<%= model_name %> was successfully created.'
28
+ redirect_to :action => 'list<%= suffix %>'
29
+ end
30
+ end
31
+
32
+ def edit<%= suffix %>
33
+ @<%= singular_name %> = <%= model_name %>.find(@params['id'])
34
+ @<%= singular_name %>.attributes = @params["<%= singular_name %>"]
35
+ if @request.post? and @<%= singular_name %>.save
36
+ flash[:notice] = '<%= model_name %> was successfully updated.'
37
+ redirect_to :action => 'list<%= suffix %>'
38
+ end
39
+ end
40
+
41
+ def destroy<%= suffix %>
42
+ @<%= singular_name %> = <%= model_name %>.find(@params['id'])
43
+ if @request.post?
44
+ @<%= singular_name %>.destroy
45
+ flash[:notice] = '<%= model_name %> was successfully deleted.'
46
+ redirect_to :action => 'list<%= suffix %>'
47
+ end
48
+ end
49
+
50
+ end
@@ -0,0 +1 @@
1
+ <%= all_input_tags(@model_instance, @singular_name, {}) %>
@@ -0,0 +1,3 @@
1
+ <table class="<%= singular_name %>_form_table" cellpadding="5">
2
+ <%= all_input_tags(@model_instance, @singular_name, {}) %>
3
+ </table>