Skip to content

Commit

Permalink
fixes problem in issue 64 fix where pages like about.md would be outp…
Browse files Browse the repository at this point in the history
…ut as about.md/index.html. provides the output extension as a method rather than replacing the ext attribute as part of transform
  • Loading branch information
krisb committed Feb 27, 2010
1 parent 4fd2b54 commit f73dac1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
1 change: 1 addition & 0 deletions cucumber.yml
@@ -0,0 +1 @@
default: --format progress
19 changes: 16 additions & 3 deletions lib/jekyll/convertible.rb
Expand Up @@ -3,6 +3,7 @@
#
# Requires
# self.site -> Jekyll::Site
# self.content
# self.content=
# self.data=
# self.ext=
Expand Down Expand Up @@ -31,20 +32,32 @@ def read_yaml(base, name)
self.data ||= {}
end

# Transform the contents based on the file extension.
# Transform the contents based on the content type.
#
# Returns nothing
def transform
case self.content_type
when 'textile'
self.ext = ".html"
self.content = self.site.textile(self.content)
when 'markdown'
self.ext = ".html"
self.content = self.site.markdown(self.content)
end
end

# Determine the extension depending on content_type
#
# Returns the extensions for the output file
def output_ext
case self.content_type
when 'textile'
".html"
when 'markdown'
".html"
else
self.ext
end
end

# Determine which formatting engine to use based on this convertible's
# extension
#
Expand Down
19 changes: 14 additions & 5 deletions lib/jekyll/page.rb
Expand Up @@ -43,10 +43,10 @@ def permalink
end

def template
if self.site.permalink_style == :pretty && !index?
"/:name/"
if self.site.permalink_style == :pretty && !index? && html?
"/:basename/"
else
"/:name.html"
"/:basename:output_ext"
end
end

Expand All @@ -57,7 +57,12 @@ def template
def url
return permalink if permalink

@url ||= (ext == '.html') ? template.gsub(':name', basename) : "/#{name}"
@url ||= {
"basename" => self.basename,
"output_ext" => self.output_ext,
}.inject(template) { |result, token|
result.gsub(/:#{token.first}/, token.last)
}.gsub(/\/\//, "/")
end

# Extract information from the page filename
Expand Down Expand Up @@ -91,7 +96,7 @@ def write(dest_prefix, dest_suffix = nil)

# The url needs to be unescaped in order to preserve the correct filename
path = File.join(dest, CGI.unescape(self.url))
if self.ext == '.html' && self.url[/\.html$/].nil?
if self.url =~ /\/$/
FileUtils.mkdir_p(path)
path = File.join(path, "index.html")
end
Expand All @@ -107,6 +112,10 @@ def inspect

private

def html?
output_ext == '.html'
end

def index?
basename == 'index'
end
Expand Down

0 comments on commit f73dac1

Please sign in to comment.