lib/octopress/page.rb in octopress-3.0.0.rc.17 vs lib/octopress/page.rb in octopress-3.0.0.rc.18

- old
+ new

@@ -1,10 +1,22 @@ module Octopress class Page - def initialize(options) - @config = Octopress.config(options) + DEFAULT_OPTIONS = { + 'post_ext' => 'markdown', + 'page_ext' => 'html', + 'post_layout' => 'post', + 'page_layout' => 'page', + 'titlecase' => true + } + + attr_accessor :site + + def initialize(site, options) + @site = site + @site.plugin_manager.conscientious_require + @config = DEFAULT_OPTIONS.merge(site.config) @options = options set_default_options # Ensure title # @@ -29,22 +41,24 @@ if STDOUT.tty? puts "New #{@options['type']}: #{relative_path(path)}" # If path begins with an underscore the page is probably being added to a collection # - print_collection_tip($1) if dir =~ /#{source}\/_([^\/]+)/ + if @options['type'] == 'page' + print_collection_tip($1) if dir =~ /#{site.source}\/_([^\/]+)/ + end else puts path end end # Print instructions for setting up a new collection # def print_collection_tip(collection) # If Jekyll is not already configurated for this collection, print instructions # - if !jekyll_config['collections'] || !jekyll_config['collections'][collection] + if !@config['collections'] || !@config['collections'][collection] msg = "\nTIP: To create a new '#{collection}' collection, add this to your Jekyll configuration\n" msg += "----------------\n" msg += "collections:\n #{collection}:\n output: true" msg += "\n----------------" puts msg @@ -54,18 +68,14 @@ def relative_path(path) local = Dir.pwd + '/' path.sub(local, '') end - def jekyll_config - Configuration.jekyll_config(@options) + def site + @site end - def source - jekyll_config['source'] - end - def path return @path if @path file = @options['path'] raise "You must specify a path." unless file @@ -75,11 +85,11 @@ # if path has no extension, add the default extension # file += ".#{extension}" unless file =~ /\.\w+$/ - @path = File.join(source, file) + @path = File.join(site.source, file) end def extension @options['extension'].sub(/^\./, '') end @@ -116,11 +126,11 @@ # file = @options['template'] || default_template if file file.sub(/^_templates\//, '') - file = File.join(source, '_templates', file) if file + file = File.join(site.source, '_templates', file) if file if File.exist? file parse_template File.open(file).read elsif @options['template'] abort "No #{@options['type']} template found at #{file}" else @@ -179,8 +189,7 @@ front_matter %w{layout title date} else front_matter %w{layout title} end end - end end