lib/octopress/page.rb in octopress-3.0.0.rc.11 vs lib/octopress/page.rb in octopress-3.0.0.rc.12
- old
+ new
@@ -80,17 +80,17 @@
abort error.message
end
end
end
- # Load the user provide or default template for a new post or page.
+ # Load the user provided or default template for a new post or page.
#
def content
# Handle case where user passes the full path
#
- file = @options['template']
+ file = @options['template'] || default_template
if file
file.sub(/^_templates\//, '')
file = File.join(source, '_templates', file) if file
if File.exist? file
@@ -101,24 +101,29 @@
else
parse_template default_content
end
end
+ def default_template
+ 'page'
+ end
+
# Render Liquid vars in YAML front-matter.
def parse_template(input)
Octopress::Utils.titlecase!(@options['title']) if @config['titlecase']
# If possible only parse the YAML front matter.
# If YAML front-matter dashes aren't present parse the whole
# template and add dashes.
#
- parsed = if input =~ /\A-{3}\s+(.+?)\s+-{3}\s+(.+)/m
+
+ parsed = if input =~ /\A-{3}\s+(.+?)\s+-{3}(.+)?/m
template = Liquid::Template.parse($1)
- "---\n#{template.render(@options).strip}\n---\n\n#{$2}"
+ "---\n#{template.render(@options).strip}\n---\n#{$2}"
else
template = Liquid::Template.parse(input)
- "---\n#{template.render(@options).strip}\n---\n\n"
+ "---\n#{template.render(@options).strip}\n---\n"
end
end
def date_slug
@options['date'].split('T')[0]
@@ -133,10 +138,14 @@
end
# Page template defaults
#
def default_content
- front_matter %w{layout title date}
+ if @options['date']
+ front_matter %w{layout title date}
+ else
+ front_matter %w{layout title}
+ end
end
end
end