Skip to content

Commit

Permalink
Merge remote branch 'remotes/mojombo/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Scott Hill committed Nov 19, 2010
2 parents a556e4f + e2d26ff commit 0014690
Show file tree
Hide file tree
Showing 24 changed files with 225 additions and 24 deletions.
17 changes: 17 additions & 0 deletions History.txt
@@ -1,3 +1,20 @@
== HEAD
* Minor Enhancements
* Add wordpress.com importer (#207)
* Add --limit-posts cli option (#212)
* Add uri_escape filter (#234)
* Add --base-url cli option (#235)
* Bug Fixes
* Fixed filename basename generation (#208)
* Set mode to UTF8 on Sequel connections (#237)

== 0.7.0 / 2010-08-24
* Minor Enhancements
* Add support for rdiscount extensions (#173)
* Bug Fixes
* Highlight should not be able to render local files
* The site configuration may not always provide a 'time' setting (#184)

== 0.6.2 / 2010-06-25
* Bug Fixes
* Fix Rakefile 'release' task (tag pushing was missing origin)
Expand Down
16 changes: 15 additions & 1 deletion bin/jekyll
Expand Up @@ -40,6 +40,10 @@ opts = OptionParser.new do |opts|
options['server_port'] = port unless port.nil?
end

opts.on("--base-url [BASE_URL]", "Serve website from a given base URL (default '/'") do |baseurl|
options['baseurl'] = baseurl
end

opts.on("--lsi", "Use LSI for better related posts") do
options['lsi'] = true
end
Expand Down Expand Up @@ -78,6 +82,16 @@ opts = OptionParser.new do |opts|
end
end

opts.on("--limit_posts [MAX_POSTS]", "Limit the number of posts to publish") do |limit_posts|
begin
options['limit_posts'] = limit_posts.to_i
raise ArgumentError if options['limit_posts'] < 1
rescue
puts 'you must specify a number of posts by page bigger than 0'
exit 0
end
end

opts.on("--url [URL]", "Set custom site.url") do |url|
options['url'] = url
end
Expand Down Expand Up @@ -166,9 +180,9 @@ if options['server']

s = HTTPServer.new(
:Port => options['server_port'],
:DocumentRoot => destination,
:MimeTypes => mime_types
)
s.mount(options['baseurl'], HTTPServlet::FileHandler, destination)
t = Thread.new {
s.start
}
Expand Down
4 changes: 2 additions & 2 deletions features/create_sites.feature
Expand Up @@ -89,6 +89,6 @@ Feature: Create sites
And I have an "_includes/about.textile" file that contains "Generated by {% include jekyll.textile %}"
And I have an "_includes/jekyll.textile" file that contains "Jekyll"
And I have an "index.html" page that contains "Basic Site with include tag: {% include about.textile %}"
When I run jekyll
When I debug jekyll
Then the _site directory should exist
And I should see "Basic Site with include tag: Generated by Jekyll" in "_site/index.html"
And I should see "Basic Site with include tag: Generated by Jekyll" in "_site/index.html"
16 changes: 16 additions & 0 deletions features/site_configuration.feature
Expand Up @@ -101,3 +101,19 @@ Feature: Site configuration
And I should see "Page Layout: 2 on 2010-01-01" in "_site/index.html"
And I should see "Post Layout: <p>content for entry1.</p>" in "_site/2007/12/31/entry1.html"
And I should see "Post Layout: <p>content for entry2.</p>" in "_site/2020/01/31/entry2.html"

Scenario: Limit the number of posts generated by most recent date
Given I have a _posts directory
And I have a configuration file with:
| key | value |
| limit_posts | 2 |
And I have the following posts:
| title | date | content |
| Apples | 3/27/2009 | An article about apples |
| Oranges | 4/1/2009 | An article about oranges |
| Bananas | 4/5/2009 | An article about bananas |
When I run jekyll
Then the _site directory should exist
And the "_site/2009/04/05/bananas.html" file should exist
And the "_site/2009/04/01/oranges.html" file should exist
And the "_site/2009/03/27/apples.html" file should not exist
5 changes: 3 additions & 2 deletions jekyll.gemspec
Expand Up @@ -4,8 +4,8 @@ Gem::Specification.new do |s|
s.rubygems_version = '1.3.5'

s.name = 'jekyll'
s.version = '0.6.2'
s.date = '2010-06-25'
s.version = '0.7.0'
s.date = '2010-08-24'
s.rubyforge_project = 'jekyll'

s.summary = "A simple, blog aware, static site generator."
Expand Down Expand Up @@ -123,6 +123,7 @@ Gem::Specification.new do |s|
test/test_page.rb
test/test_pager.rb
test/test_post.rb
test/test_rdiscount.rb
test/test_site.rb
test/test_tags.rb
]
Expand Down
5 changes: 4 additions & 1 deletion lib/jekyll.rb
Expand Up @@ -45,7 +45,7 @@ def require_all(path)
require_all 'jekyll/tags'

module Jekyll
VERSION = '0.6.2'
VERSION = '0.7.0'

# Default options. Overriden by values in _config.yml or command-line opts.
# (Strings rather symbols used for compatability with YAML).
Expand All @@ -71,6 +71,9 @@ module Jekyll
'png_engine' => 'blahtex',
'png_dir' => 'images/latex',
'png_url' => '/images/latex'
},
'rdiscount' => {
'extensions' => []
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/jekyll/albino.rb
Expand Up @@ -54,7 +54,7 @@ def self.colorize(*args)
end

def initialize(target, lexer = :text, format = :html)
@target = File.exists?(target) ? File.read(target) : target rescue target
@target = target
@options = { :l => lexer, :f => format, :O => 'encoding=utf-8' }
end

Expand Down
5 changes: 4 additions & 1 deletion lib/jekyll/converters/markdown.rb
Expand Up @@ -13,6 +13,9 @@ def setup
when 'rdiscount'
begin
require 'rdiscount'

# Load rdiscount extensions
@rdiscount_extensions = @config['rdiscount']['extensions'].map { |e| e.to_sym }
rescue LoadError
STDERR.puts 'You are missing a library required for Markdown. Please run:'
STDERR.puts ' $ [sudo] gem install rdiscount'
Expand Down Expand Up @@ -67,7 +70,7 @@ def convert(content)
setup
case @config['markdown']
when 'rdiscount'
RDiscount.new(content).to_html
RDiscount.new(content, *@rdiscount_extensions).to_html
when 'maruku'
Maruku.new(content).to_html
end
Expand Down
6 changes: 6 additions & 0 deletions lib/jekyll/filters.rb
@@ -1,3 +1,5 @@
require 'uri'

module Jekyll

module Filters
Expand Down Expand Up @@ -25,6 +27,10 @@ def cgi_escape(input)
CGI::escape(input)
end

def uri_escape(input)
URI.escape(input)
end

def number_of_words(input)
input.split.length
end
Expand Down
2 changes: 1 addition & 1 deletion lib/jekyll/migrators/mephisto.rb
Expand Up @@ -40,7 +40,7 @@ def self.postgres(c)
QUERY = "SELECT id, permalink, body, published_at, title FROM contents WHERE user_id = 1 AND type = 'Article' AND published_at IS NOT NULL ORDER BY published_at"

def self.process(dbname, user, pass, host = 'localhost')
db = Sequel.mysql(dbname, :user => user, :password => pass, :host => host)
db = Sequel.mysql(dbname, :user => user, :password => pass, :host => host, :encoding => 'utf8')

FileUtils.mkdir_p "_posts"

Expand Down
2 changes: 1 addition & 1 deletion lib/jekyll/migrators/mt.rb
Expand Up @@ -21,7 +21,7 @@ module MT
QUERY = "SELECT entry_id, entry_basename, entry_text, entry_text_more, entry_authored_on, entry_title, entry_convert_breaks FROM mt_entry"

def self.process(dbname, user, pass, host = 'localhost')
db = Sequel.mysql(dbname, :user => user, :password => pass, :host => host)
db = Sequel.mysql(dbname, :user => user, :password => pass, :host => host, :encoding => 'utf8')

FileUtils.mkdir_p "_posts"

Expand Down
2 changes: 1 addition & 1 deletion lib/jekyll/migrators/textpattern.rb
Expand Up @@ -17,7 +17,7 @@ module TextPattern
QUERY = "select Title, url_title, Posted, Body, Keywords from textpattern where Status = '4' or Status = '5'"

def self.process(dbname, user, pass, host = 'localhost')
db = Sequel.mysql(dbname, :user => user, :password => pass, :host => host)
db = Sequel.mysql(dbname, :user => user, :password => pass, :host => host, :encoding => 'utf8')

FileUtils.mkdir_p "_posts"

Expand Down
2 changes: 1 addition & 1 deletion lib/jekyll/migrators/typo.rb
Expand Up @@ -22,7 +22,7 @@ module Typo

def self.process dbname, user, pass, host='localhost'
FileUtils.mkdir_p '_posts'
db = Sequel.mysql dbname, :user => user, :password => pass, :host => host
db = Sequel.mysql(dbname, :user => user, :password => pass, :host => host, :encoding => 'utf8')
db[SQL].each do |post|
next unless post[:state] =~ /Published/

Expand Down
38 changes: 38 additions & 0 deletions lib/jekyll/migrators/wordpress.com.rb
@@ -0,0 +1,38 @@
require 'rubygems'
require 'hpricot'
require 'fileutils'

# This importer takes a wordpress.xml file,
# which can be exported from your
# wordpress.com blog (/wp-admin/export.php)

module Jekyll
module WordpressDotCom
def self.process(filename = "wordpress.xml")
FileUtils.mkdir_p "_posts"
posts = 0

doc = Hpricot::XML(File.read(filename))

(doc/:channel/:item).each do |item|
title = item.at(:title).inner_text
name = "#{Date.parse((doc/:channel/:item).first.at(:pubDate).inner_text).to_s("%Y-%m-%d")}-#{title.downcase.gsub('[^a-z0-9]', '-')}.html"

File.open("_posts/#{name}", "w") do |f|
f.puts <<-HEADER
---
layout: post
title: #{title}
---
HEADER
f.puts item.at('content:encoded').inner_text
end

posts += 1
end

"Imported #{posts} posts"
end
end
end
2 changes: 1 addition & 1 deletion lib/jekyll/migrators/wordpress.rb
Expand Up @@ -19,7 +19,7 @@ module WordPress
QUERY = "select post_title, post_name, post_date, post_content, post_excerpt, ID, guid from wp_posts where post_status = 'publish' and post_type = 'post'"

def self.process(dbname, user, pass, host = 'localhost')
db = Sequel.mysql(dbname, :user => user, :password => pass, :host => host)
db = Sequel.mysql(dbname, :user => user, :password => pass, :host => host, :encoding => 'utf8')

FileUtils.mkdir_p "_posts"

Expand Down
2 changes: 1 addition & 1 deletion lib/jekyll/page.rb
Expand Up @@ -71,7 +71,7 @@ def url
# Returns nothing
def process(name)
self.ext = File.extname(name)
self.basename = name.split('.')[0..-2].first
self.basename = name[0 .. -self.ext.length-1]
end

# Add any necessary layouts to this post
Expand Down
15 changes: 13 additions & 2 deletions lib/jekyll/site.rb
Expand Up @@ -3,7 +3,8 @@ module Jekyll
class Site
attr_accessor :config, :layouts, :posts, :pages, :static_files,
:categories, :exclude, :source, :dest, :lsi, :pygments,
:permalink_style, :tags, :time, :future, :safe, :plugins
:permalink_style, :tags, :time, :future, :safe, :plugins, :limit_posts

attr_accessor :converters, :generators

# Initialize the site
Expand All @@ -22,19 +23,26 @@ def initialize(config)
self.permalink_style = config['permalink'].to_sym
self.exclude = config['exclude'] || []
self.future = config['future']
self.limit_posts = config['limit_posts'] || nil

self.reset
self.setup
end

def reset
self.time = Time.parse(self.config['time'].to_s) || Time.now
self.time = if self.config['time']
Time.parse(self.config['time'].to_s)
else
Time.now
end
self.layouts = {}
self.posts = []
self.pages = []
self.static_files = []
self.categories = Hash.new { |hash, key| hash[key] = [] }
self.tags = Hash.new { |hash, key| hash[key] = [] }

raise ArgumentError, "Limit posts must be nil or >= 1" if !self.limit_posts.nil? && self.limit_posts < 1
end

def setup
Expand Down Expand Up @@ -118,6 +126,9 @@ def read_posts(dir)
end

self.posts.sort!

# limit the posts if :limit_posts option is set
self.posts = self.posts[-limit_posts, limit_posts] if limit_posts
end

def generate
Expand Down
8 changes: 8 additions & 0 deletions test/source/.htaccess
@@ -0,0 +1,8 @@
---
layout: nil
---
ErrorDocument 404 /404.html
ErrorDocument 500 /500.html
{% for post in site.posts %}
# {{ post.url }}
{% endfor %}
7 changes: 7 additions & 0 deletions test/source/deal.with.dots.html
@@ -0,0 +1,7 @@
---
title: Deal with dots
permalink: /deal.with.dots/
---

Let's test if jekyll deals properly with dots.

4 changes: 4 additions & 0 deletions test/test_filters.rb
Expand Up @@ -45,5 +45,9 @@ class JekyllFilter
should "escape special characters" do
assert_equal "hey%21", @filter.cgi_escape("hey!")
end

should "escape space as %20" do
assert_equal "my%20things", @filter.uri_escape("my things")
end
end
end
28 changes: 28 additions & 0 deletions test/test_generated_site.rb
Expand Up @@ -41,4 +41,32 @@ class TestGeneratedSite < Test::Unit::TestCase
assert File.exists?(dest_dir('/contacts.html'))
end
end

context "generating limited posts" do
setup do
clear_dest
stub(Jekyll).configuration do
Jekyll::DEFAULTS.merge({'source' => source_dir, 'destination' => dest_dir, 'limit_posts' => 5})
end

@site = Site.new(Jekyll.configuration)
@site.process
@index = File.read(dest_dir('index.html'))
end

should "generate only the specified number of posts" do
assert_equal 5, @site.posts.size
end

should "ensure limit posts is 1 or more" do
assert_raise ArgumentError do
clear_dest
stub(Jekyll).configuration do
Jekyll::DEFAULTS.merge({'source' => source_dir, 'destination' => dest_dir, 'limit_posts' => 0})
end

@site = Site.new(Jekyll.configuration)
end
end
end
end

0 comments on commit 0014690

Please sign in to comment.