Module: Nitro::Scaffolding::ClassMethods

Defined in:
lib/nitro/scaffolding.rb

Instance Method Summary collapse

Instance Method Details

#compile_scaffolding_codeObject

– This is the second phase of the scaffolding process ++



329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
# File 'lib/nitro/scaffolding.rb', line 329

def compile_scaffolding_code
  # load scaffolding for all og classes if specified

  if scaffold_all?
    options = scaffold_all_options
    Og.manager.manageable_classes.each do |klass|
      unless options[:except] && options[:except].include?(klass)
        scaffold(klass, options)
      end
    end
    scaffold_all false
  end
  
  # compile the scaffold methods
  
  scaffolding_classes.each do |klass, options|
    Scaffolding::ScaffoldCompiler.new(self, klass, options).scaffold
  end
end

#scaffold(klass, options = {}) ⇒ Object

This method modifies both the controller and the scaffolded Class.

Options

  • base/mount : mountpoint for the action, defines a prefix for the scaffolded action. If mount => true, the prefix is the plural of the scaffolded class name. If mount => :ROOT or nil, the actions are mounted at the root of the controller.

Example

scaffold Article

Actions/Methods added to the Controller

  • articles

  • edit_article

  • view_article

  • delete_article

  • search_artile

  • query_article

Methods added to the Class (ex: Article)

  • to_href

  • to_edit_href

– This is the first phase of the scaffolding proccess, scaffold targets are marked, and default options set.

FIXME: Rethink the options, make :ROOT the default. ++



310
311
312
313
314
315
316
317
318
319
320
321
322
323
# File 'lib/nitro/scaffolding.rb', line 310

def scaffold(klass, options = {})
  o = scaffolding_classes[klass] || {
    :pk => 'oid',
    :name => Scaffolding.class_to_method(klass),
    :plural_name => Scaffolding.class_to_list(klass),
    :mount => true
  }
  o.merge!(options)
  if scaffolding_classes.has_key? klass
    scaffolding_classes[klass].merge!(o)
  else
    scaffolding_classes[klass] = o
  end
end

#scaffold_all(options = {}) ⇒ Object

– set the options flag to trigger scaffolding of all classes in second phase. use exclude to ignore classes: scaffold_all :exclude => [Product, Category]

gmosx: I do NOT lke this, will remove this in a future version. ++



359
360
361
362
363
364
365
366
# File 'lib/nitro/scaffolding.rb', line 359

def scaffold_all(options = {})
  if options
    o = if options.kind_of? Hash then options else Hash.new end
  else
    o = nil
  end
  @scaffold_all_options = o
end

#scaffold_all_optionsObject Also known as: scaffold_all?

– Scaffold all classes flag ++



382
383
384
# File 'lib/nitro/scaffolding.rb', line 382

def scaffold_all_options
  @scaffold_all_options
end

#scaffolding_classesObject

– Keep track of scaffolded classes on this controller ++



372
373
374
375
376
# File 'lib/nitro/scaffolding.rb', line 372

def scaffolding_classes
  # TODO: maybe make this with a inhertitor?
  # although inhertited scaffolding might be pointless.
  @scaffolding_classes ||= {}
end