Skip to content

Commit

Permalink
implement include tag
Browse files Browse the repository at this point in the history
  • Loading branch information
mojombo committed Dec 14, 2008
1 parent 906ccbb commit 8b2aedc
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 8 deletions.
4 changes: 4 additions & 0 deletions History.txt
@@ -1,3 +1,7 @@
==
* Major Features
* Include files in _includes with {% include x.textile %}

== 0.1.5 / 2008-12-12
* Major Features
* Code highlighting with Pygments if --pygments is specified
Expand Down
5 changes: 4 additions & 1 deletion Manifest.txt
Expand Up @@ -6,7 +6,6 @@ bin/jekyll
jekyll.gemspec
lib/jekyll.rb
lib/jekyll/albino.rb
lib/jekyll/blocks.rb
lib/jekyll/converters/csv.rb
lib/jekyll/converters/mephisto.rb
lib/jekyll/convertible.rb
Expand All @@ -15,11 +14,15 @@ lib/jekyll/layout.rb
lib/jekyll/page.rb
lib/jekyll/post.rb
lib/jekyll/site.rb
lib/jekyll/tags/highlight.rb
lib/jekyll/tags/include.rb
test/helper.rb
test/source/_includes/sig.textile
test/source/_layouts/default.html
test/source/_layouts/simple.html
test/source/_posts/2008-10-18-foo-bar.textile
test/source/_posts/2008-11-21-complex.textile
test/source/_posts/2008-12-13-include.textile
test/source/css/screen.css
test/source/index.html
test/source/posts/2008-12-03-permalinked-post.textile
Expand Down
4 changes: 2 additions & 2 deletions jekyll.gemspec
Expand Up @@ -4,12 +4,12 @@ Gem::Specification.new do |s|

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Tom Preston-Werner"]
s.date = %q{2008-12-12}
s.date = %q{2008-12-13}
s.default_executable = %q{jekyll}
s.email = ["tom@mojombo.com"]
s.executables = ["jekyll"]
s.extra_rdoc_files = ["History.txt", "Manifest.txt"]
s.files = ["History.txt", "Manifest.txt", "README.textile", "Rakefile", "bin/jekyll", "jekyll.gemspec", "lib/jekyll.rb", "lib/jekyll/albino.rb", "lib/jekyll/blocks.rb", "lib/jekyll/converters/csv.rb", "lib/jekyll/converters/mephisto.rb", "lib/jekyll/convertible.rb", "lib/jekyll/filters.rb", "lib/jekyll/layout.rb", "lib/jekyll/page.rb", "lib/jekyll/post.rb", "lib/jekyll/site.rb", "test/helper.rb", "test/source/_layouts/default.html", "test/source/_layouts/simple.html", "test/source/_posts/2008-10-18-foo-bar.textile", "test/source/_posts/2008-11-21-complex.textile", "test/source/css/screen.css", "test/source/index.html", "test/source/posts/2008-12-03-permalinked-post.textile", "test/suite.rb", "test/test_jekyll.rb", "test/test_post.rb", "test/test_site.rb"]
s.files = ["History.txt", "Manifest.txt", "README.textile", "Rakefile", "bin/jekyll", "jekyll.gemspec", "lib/jekyll.rb", "lib/jekyll/albino.rb", "lib/jekyll/converters/csv.rb", "lib/jekyll/converters/mephisto.rb", "lib/jekyll/convertible.rb", "lib/jekyll/filters.rb", "lib/jekyll/layout.rb", "lib/jekyll/page.rb", "lib/jekyll/post.rb", "lib/jekyll/site.rb", "lib/jekyll/tags/highlight.rb", "lib/jekyll/tags/include.rb", "test/helper.rb", "test/source/_includes/sig.textile", "test/source/_layouts/default.html", "test/source/_layouts/simple.html", "test/source/_posts/2008-10-18-foo-bar.textile", "test/source/_posts/2008-11-21-complex.textile", "test/source/_posts/2008-12-13-include.textile", "test/source/css/screen.css", "test/source/index.html", "test/source/posts/2008-12-03-permalinked-post.textile", "test/suite.rb", "test/test_jekyll.rb", "test/test_post.rb", "test/test_site.rb"]
s.has_rdoc = true
s.rdoc_options = ["--main", "README.txt"]
s.require_paths = ["lib"]
Expand Down
7 changes: 5 additions & 2 deletions lib/jekyll.rb
Expand Up @@ -27,20 +27,23 @@
require 'jekyll/page'
require 'jekyll/post'
require 'jekyll/filters'
require 'jekyll/blocks'
require 'jekyll/tags/highlight'
require 'jekyll/tags/include'
require 'jekyll/albino'

module Jekyll
VERSION = '0.1.5'

class << self
attr_accessor :lsi, :pygments
attr_accessor :source, :dest, :lsi, :pygments
end

Jekyll.lsi = false
Jekyll.pygments = false

def self.process(source, dest)
Jekyll.source = source
Jekyll.dest = dest
Jekyll::Site.new(source, dest).process
end
end
4 changes: 2 additions & 2 deletions lib/jekyll/blocks.rb → lib/jekyll/tags/highlight.rb
@@ -1,6 +1,6 @@
module Jekyll

class Highlight < Liquid::Block
class HighlightBlock < Liquid::Block
include Liquid::StandardFilters

def initialize(tag_name, lang, tokens)
Expand Down Expand Up @@ -34,4 +34,4 @@ def render_codehighlighter(context, code)

end

Liquid::Template.register_tag('highlight', Jekyll::Highlight)
Liquid::Template.register_tag('highlight', Jekyll::HighlightBlock)
16 changes: 16 additions & 0 deletions lib/jekyll/tags/include.rb
@@ -0,0 +1,16 @@
module Jekyll

class IncludeTag < Liquid::Tag
def initialize(tag_name, file, tokens)
super
@file = file.strip
end

def render(context)
File.read(File.join(Jekyll.source, '_includes', @file))
end
end

end

Liquid::Template.register_tag('include', Jekyll::IncludeTag)
3 changes: 3 additions & 0 deletions test/source/_includes/sig.textile
@@ -0,0 +1,3 @@
--
Tom Preston-Werner
github.com/mojombo
6 changes: 6 additions & 0 deletions test/source/_posts/2008-12-13-include.textile
@@ -0,0 +1,6 @@
---
layout: default
title: Include
---

{% include sig.textile %}
9 changes: 9 additions & 0 deletions test/test_post.rb
Expand Up @@ -83,4 +83,13 @@ def test_data

assert_equal "<<< <p>url: /2008/11/21/complex.html<br />\ndate: Fri Nov 21 00:00:00 -0800 2008<br />\nid: /2008/11/21/complex</p> >>>", p.output
end

def test_include
Jekyll.source = File.join(File.dirname(__FILE__), *%w[source])
p = Post.new(File.join(File.dirname(__FILE__), *%w[source _posts]), "2008-12-13-include.textile")
layouts = {"default" => Layout.new(File.join(File.dirname(__FILE__), *%w[source _layouts]), "simple.html")}
p.add_layout(layouts, {"site" => {"posts" => []}})

assert_equal "<<< <p>&#8212;<br />\nTom Preston-Werner<br />\ngithub.com/mojombo</p> >>>", p.output
end
end
2 changes: 1 addition & 1 deletion test/test_site.rb
Expand Up @@ -19,7 +19,7 @@ def test_read_layouts
def test_read_posts
@s.read_posts

assert_equal 2, @s.posts.size
assert_equal 3, @s.posts.size
end

def test_write_posts
Expand Down

0 comments on commit 8b2aedc

Please sign in to comment.