lib/jekyll.rb in matflores-jekyll-0.4.3 vs lib/jekyll.rb in matflores-jekyll-0.5.0
- old
+ new
@@ -11,27 +11,11 @@
# stdlib
# 3rd party
require 'liquid'
require 'redcloth'
-begin
- require 'maruku'
- require 'maruku/ext/math'
- # Switch off MathML output
- MaRuKu::Globals[:html_math_output_mathml] = false
- MaRuKu::Globals[:html_math_engine] = 'none'
- # Turn on math to PNG support with blahtex
- # Resulting PNGs stored in `images/latex`
- MaRuKu::Globals[:html_math_output_png] = true
- MaRuKu::Globals[:html_png_engine] = 'blahtex'
- MaRuKu::Globals[:html_png_dir] = 'images/latex'
- MaRuKu::Globals[:html_png_url] = '/images/latex/'
-rescue LoadError
- puts "The maruku gem is required for markdown support!"
-end
-
# internal requires
require 'jekyll/core_ext'
require 'jekyll/site'
require 'jekyll/convertible'
require 'jekyll/layout'
@@ -43,26 +27,58 @@
require 'jekyll/tags/highlight'
require 'jekyll/tags/include'
require 'jekyll/albino'
module Jekyll
- class << self
- attr_accessor :source, :dest, :lsi, :pygments, :markdown_proc, :content_type, :permalink_style
+ # Default options. Overriden by values in _config.yaml or command-line opts.
+ # (Strings rather symbols used for compatability with YAML)
+ DEFAULTS = {
+ 'auto' => false,
+ 'server' => false,
+ 'server_port' => 4000,
+
+ 'source' => '.',
+ 'destination' => File.join('.', '_site'),
+
+ 'lsi' => false,
+ 'pygments' => false,
+ 'markdown' => 'maruku',
+ 'permalink' => 'date',
+
+ 'maruku' => {
+ 'use_tex' => false,
+ 'use_divs' => false,
+ 'png_engine' => 'blahtex',
+ 'png_dir' => 'images/latex',
+ 'png_url' => '/images/latex'
+ }
+ }
+
+ # Generate a Jekyll configuration Hash by merging the default options
+ # with anything in _config.yml, and adding the given options on top
+ # +override+ is a Hash of config directives
+ #
+ # Returns Hash
+ def self.configuration(override)
+ # _config.yml may override default source location, but until
+ # then, we need to know where to look for _config.yml
+ source = override['source'] || Jekyll::DEFAULTS['source']
+
+ # Get configuration from <source>/_config.yaml
+ config = {}
+ config_file = File.join(source, '_config.yml')
+ begin
+ config = YAML.load_file(config_file)
+ puts "Configuration from #{config_file}"
+ rescue => err
+ puts "WARNING: Could not read configuration. Using defaults (and options)."
+ puts "\t" + err
+ end
+
+ # Merge DEFAULTS < _config.yml < override
+ Jekyll::DEFAULTS.deep_merge(config).deep_merge(override)
end
-
- Jekyll.lsi = false
- Jekyll.pygments = false
- Jekyll.markdown_proc = Proc.new { |x| Maruku.new(x).to_html }
- Jekyll.permalink_style = :date
-
- def self.process(source, dest)
- require 'classifier' if Jekyll.lsi
-
- Jekyll.source = source
- Jekyll.dest = dest
- Jekyll::Site.new(source, dest).process
- end
-
+
def self.version
yml = YAML.load(File.read(File.join(File.dirname(__FILE__), *%w[.. VERSION.yml])))
"#{yml[:major]}.#{yml[:minor]}.#{yml[:patch]}"
end
end