Module: Henshin
- Defined in:
- lib/henshin.rb,
lib/henshin/gen.rb,
lib/henshin/post.rb,
lib/henshin/site.rb,
lib/henshin/tags.rb,
lib/henshin/plugin.rb,
lib/henshin/static.rb,
lib/henshin/categories.rb
Defined Under Namespace
Classes: Category, Gen, Generator, LayoutParser, Post, Site, StandardPlugin, Static, Tag
Constant Summary collapse
- Defaults =
Default options for configuration
{:title => 'A site', :description => 'No description', :time_zone => 'GMT', :author => '', :layout => '', :file_name => '<{category}/>{title-with-dashes}.{extension}', :permalink => '/{year}/{month}/{date}/{title}.html', :plugins => ['maruku', 'liquid'], :root => '.', :target => '_site', :plugin_options => {}, :exclude => [] }
Class Method Summary collapse
-
.configure(override = {}) ⇒ Hash
Creates the configuration hash by merging defaults, supplied options and options read from the ‘options.yaml’ file.
-
.load_plugins(to_load, root, opts = {}) ⇒ Array
Loads the specified plugins.
-
.register!(plug) ⇒ Object
Each plugin will call this method when loaded from #load_plugins, these plugins then populate @registered_plugins, which is returned from #load_plugins.
-
.version ⇒ String
Current version.
Class Method Details
.configure(override = {}) ⇒ Hash
Creates the configuration hash by merging defaults, supplied options and options read from the ‘options.yaml’ file. Then loads the plugins
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/henshin.rb', line 41 def self.configure( override={} ) config_file = (override[:root] || Defaults[:root]) + '/options.yaml' begin config = YAML.load_file( config_file ). settings = Defaults.merge(config).merge(override) rescue => e $stderr.puts "\nCould not read configuration, falling back to defaults..." $stderr.puts "-> #{e.to_s}" settings = Defaults.merge(override) end # find the options for plugins, if any settings.each do |k, v| if settings[:plugins].include? k.to_s settings[:plugin_options][k] = v. end end loaded_plugins = Henshin.load_plugins( settings[:plugins], settings[:root], settings[:plugin_options] ) settings[:plugins] = {:generators => {}, :layout_parsers => []} loaded_plugins.each do |plugin| if plugin.is_a? Generator plugin.extensions[:input].each do |ext| settings[:plugins][:generators][ext] = plugin end end if plugin.is_a? LayoutParser settings[:plugins][:layout_parsers] << plugin end end settings end |
.load_plugins(to_load, root, opts = {}) ⇒ Array
Loads the specified plugins
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/henshin.rb', line 84 def self.load_plugins( to_load, root, opts={} ) plugins = [] to_load.each do |l| begin require 'henshin/plugins/' + l rescue LoadError require File.join(root, 'plugins/', l) end end # pass options to the plugins @registered_plugins.each do |plugin| if plugin.respond_to? :configure plugin.configure( opts[plugin.opts_name] ) end end @registered_plugins end |
.register!(plug) ⇒ Object
Each plugin will call this method when loaded from #load_plugins, these plugins then populate @registered_plugins, which is returned from #load_plugins. Complicated? Maybe, but it works!
104 105 106 107 |
# File 'lib/henshin.rb', line 104 def self.register!( plug ) @registered_plugins ||= [] @registered_plugins << plug.new end |
.version ⇒ String
Returns current version.
111 112 113 |
# File 'lib/henshin.rb', line 111 def self.version File.read( File.join(File.dirname(__FILE__), *%w[.. VERSION]) ) end |