Class | Webgen::WebSite |
In: |
lib/webgen/website.rb
|
Parent: | Object |
A WebSite object represents a webgen website directory and is used for manipulating it.
directory | [R] | The website directory. |
logger | [R] | The logger used for the website |
manager | [R] | The plugin manager used for this website. |
Create a website in the directory, using the template template_name and the style style_name.
# File lib/webgen/website.rb, line 219 219: def self.create_website( directory, template_name = 'default', style_name = 'default' ) 220: template = WebSiteTemplate.entries[template_name] 221: style = WebSiteStyle.entries[style_name] 222: raise ArgumentError.new( "Invalid website template '#{template}'" ) if template.nil? 223: raise ArgumentError.new( "Invalid website style '#{style}'" ) if style.nil? 224: 225: raise ArgumentError.new( "Directory <#{directory}> does already exist!") if File.exists?( directory ) 226: FileUtils.mkdir( directory ) 227: return template.copy_to( directory ) + style.copy_to( File.join( directory, Webgen::SRC_DIR) ) 228: end
Loads the configuration file from the directory.
# File lib/webgen/website.rb, line 210 210: def self.load_config_file( directory = Dir.pwd ) 211: begin 212: ConfigurationFile.new( File.join( directory, 'config.yaml' ) ) 213: rescue ConfigurationFileInvalid => e 214: nil 215: end 216: end
Creates a new WebSite object for the given directory and loads its plugins. If the plugin_config parameter is given, it is used to resolve the values for plugin parameters. Otherwise, a ConfigurationFile instance is used as plugin configuration.
# File lib/webgen/website.rb, line 169 169: def initialize( directory = Dir.pwd, plugin_config = nil ) 170: @directory = File.expand_path( directory ) 171: @logger = Webgen::Logger.new 172: 173: wrapper_mod = Module.new 174: wrapper_mod.module_eval { include DEFAULT_WRAPPER_MODULE } 175: @loader = PluginLoader.new( wrapper_mod ) 176: @loader.load_from_dir( File.join( @directory, Webgen::PLUGIN_DIR ) ) 177: 178: @manager = PluginManager.new( [DEFAULT_PLUGIN_LOADER, @loader], DEFAULT_PLUGIN_LOADER.plugin_classes + @loader.plugin_classes ) 179: @manager.logger = @logger 180: set_plugin_config( plugin_config ) 181: end
Copies the gallery style files for style to the source directory of the website directory overwritting exisiting files.
# File lib/webgen/website.rb, line 242 242: def self.use_gallery_style( directory, style_name ) 243: style = GalleryStyle.entries[style_name] 244: raise ArgumentError.new( "Invalid gallery style '#{style_name}'" ) if style.nil? 245: src_dir = File.join( directory, Webgen::SRC_DIR ) 246: plugin_dir = File.join( directory, Webgen::PLUGIN_DIR ) 247: raise ArgumentError.new( "Directory <#{src_dir}> does not exist!") unless File.exists?( src_dir ) 248: plugin_files = style.plugin_files 249: FileUtils.mkdir( plugin_dir ) unless File.exists?( plugin_dir ) 250: FileUtils.cp( plugin_files, plugin_dir ) 251: return style.copy_to( src_dir ) + plugin_files.collect {|f| File.join( plugin_dir, File.basename( f ) )} 252: end
Copies the sipttra style files for style to the source directory of the website directory overwritting exisiting files.
# File lib/webgen/website.rb, line 256 256: def self.use_sipttra_style( directory, style_name ) 257: style = SipttraStyle.entries[style_name] 258: raise ArgumentError.new( "Invalid sipttra style '#{style_name}'" ) if style.nil? 259: src_dir = File.join( directory, Webgen::SRC_DIR ) 260: raise ArgumentError.new( "Directory <#{src_dir}> does not exist!") unless File.exists?( src_dir ) 261: return style.copy_to( src_dir ) 262: end
Copies the style files for style to the source directory of the website directory overwritting exisiting files.
# File lib/webgen/website.rb, line 232 232: def self.use_website_style( directory, style_name ) 233: style = WebSiteStyle.entries[style_name] 234: raise ArgumentError.new( "Invalid website style '#{style_name}'" ) if style.nil? 235: src_dir = File.join( directory, Webgen::SRC_DIR ) 236: raise ArgumentError.new( "Directory <#{src_dir}> does not exist!") unless File.exists?( src_dir ) 237: return style.copy_to( src_dir ) 238: end
Returns a modified value for Configuration:srcDir, Configuration:outDir and Configuration:websiteDir.
# File lib/webgen/website.rb, line 184 184: def param_for_plugin( plugin_name, param ) 185: case [plugin_name, param] 186: when ['Core/Configuration', 'srcDir'] then @srcDir 187: when ['Core/Configuration', 'outDir'] then @outDir 188: when ['Core/Configuration', 'websiteDir'] then @directory 189: else 190: (@plugin_config ? @plugin_config.param_for_plugin( plugin_name, param ) : PluginParamValueNotFound) 191: end 192: end
Initializes all plugins and renders the website.
# File lib/webgen/website.rb, line 195 195: def render( files = [] ) 196: @logger.level = @manager.param_for_plugin( 'Core/Configuration', 'loggerLevel' ) 197: @manager.init 198: 199: @logger.info( 'WebSite#render' ) { "Starting rendering of website <#{directory}>..." } 200: @logger.info( 'WebSite#render' ) { "Using webgen data directory at <#{Webgen.data_dir}>!" } 201: if files.empty? 202: @manager['Core/FileHandler'].render_site 203: else 204: @manager['Core/FileHandler'].render_files( files ) 205: end 206: @logger.info( 'WebSite#render' ) { "Rendering of website <#{directory}> finished" } 207: end
# File lib/webgen/website.rb, line 268 268: def set_plugin_config( plugin_config ) 269: @manager.plugin_config = ( plugin_config ? plugin_config : self.class.load_config_file( @directory ) ) 270: @srcDir = File.join( @directory, Webgen::SRC_DIR ) 271: outDir = @manager.param_for_plugin( 'Core/Configuration', 'outDir' ) 272: @outDir = (/^(\/|[A-Za-z]:)/ =~ outDir ? outDir : File.join( @directory, outDir ) ) 273: @plugin_config = @manager.plugin_config 274: @manager.plugin_config = self 275: end