lib/nitro/part.rb in nitro-0.31.0 vs lib/nitro/part.rb in nitro-0.40.0

- old
+ new

@@ -1,5 +1,7 @@ +require 'facets/core/class/descendents' + module Nitro # A part is a module of reusable functionality encapsulated as # a mini site/app. You can require (include) multiple parts in # your application. A part is in essence a high level component. @@ -56,20 +58,63 @@ # if a template is not found in the applications normal template # root. In essence, by requiring a part a target application, # 'inherits' its templates. If you want to customize (override) # one template, just place a template with the same name in the # respective directory in the application template root. - +# +#-- +# TODO: +# +# * add support for autoload +# * add support for install/uninstall +#++ + class Part - # Require (include) a part in the current application. + # Perform part initialization, just before the server is + # started. Override this in your parts. + + def initialize + end + + # Perform part finalization. + + def finalize + end - def self.require name - Logger.debug "Requiring part '#{name}'." if $DBG - Kernel.require 'part/' + name + '/run.rb' + # Perform part initialization when the part is installed, + # ie you add this in your application. Here comes one time + # initialization code. + + def install end + + # Perform part cleanup when you want to remove the part + # from your application. + + def uninstall + end + alias cleanup uninstall -end + class << self + + # Require (include) a part in the current application. + def require(name) + Logger.debug "Requiring part '#{name}'." if $DBG + Kernel.require 'part/' + name + '/run.rb' + end + + # Call the initialization code of all parts. Typically + # called just before the server starts. + + def setup + for klass in self.descendents + p = klass.new + end + end + + end + end -# * George Moschovitis <gm@navel.gr> +end