From 8b2aedc951bd0763b0a29f956053d59f5ab66a58 Mon Sep 17 00:00:00 2001 From: Tom Preston-Werner Date: Sat, 13 Dec 2008 17:12:38 -0800 Subject: [PATCH] implement include tag --- History.txt | 4 ++++ Manifest.txt | 5 ++++- jekyll.gemspec | 4 ++-- lib/jekyll.rb | 7 +++++-- lib/jekyll/{blocks.rb => tags/highlight.rb} | 4 ++-- lib/jekyll/tags/include.rb | 16 ++++++++++++++++ test/source/_includes/sig.textile | 3 +++ test/source/_posts/2008-12-13-include.textile | 6 ++++++ test/test_post.rb | 9 +++++++++ test/test_site.rb | 2 +- 10 files changed, 52 insertions(+), 8 deletions(-) rename lib/jekyll/{blocks.rb => tags/highlight.rb} (86%) create mode 100644 lib/jekyll/tags/include.rb create mode 100644 test/source/_includes/sig.textile create mode 100644 test/source/_posts/2008-12-13-include.textile diff --git a/History.txt b/History.txt index 74693172..afa7edcf 100644 --- a/History.txt +++ b/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 diff --git a/Manifest.txt b/Manifest.txt index b5e61574..f3059013 100644 --- a/Manifest.txt +++ b/Manifest.txt @@ -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 @@ -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 diff --git a/jekyll.gemspec b/jekyll.gemspec index a45bbbd2..0b2fffe2 100644 --- a/jekyll.gemspec +++ b/jekyll.gemspec @@ -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"] diff --git a/lib/jekyll.rb b/lib/jekyll.rb index 6ba0ade5..682b8945 100644 --- a/lib/jekyll.rb +++ b/lib/jekyll.rb @@ -27,20 +27,23 @@ require 'jekyll/layout' 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 diff --git a/lib/jekyll/blocks.rb b/lib/jekyll/tags/highlight.rb similarity index 86% rename from lib/jekyll/blocks.rb rename to lib/jekyll/tags/highlight.rb index 9cbc9e17..cd4121ae 100644 --- a/lib/jekyll/blocks.rb +++ b/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) @@ -34,4 +34,4 @@ module Jekyll end -Liquid::Template.register_tag('highlight', Jekyll::Highlight) \ No newline at end of file +Liquid::Template.register_tag('highlight', Jekyll::HighlightBlock) \ No newline at end of file diff --git a/lib/jekyll/tags/include.rb b/lib/jekyll/tags/include.rb new file mode 100644 index 00000000..f03ed177 --- /dev/null +++ b/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) \ No newline at end of file diff --git a/test/source/_includes/sig.textile b/test/source/_includes/sig.textile new file mode 100644 index 00000000..d280e8cc --- /dev/null +++ b/test/source/_includes/sig.textile @@ -0,0 +1,3 @@ +-- +Tom Preston-Werner +github.com/mojombo \ No newline at end of file diff --git a/test/source/_posts/2008-12-13-include.textile b/test/source/_posts/2008-12-13-include.textile new file mode 100644 index 00000000..ab773439 --- /dev/null +++ b/test/source/_posts/2008-12-13-include.textile @@ -0,0 +1,6 @@ +--- +layout: default +title: Include +--- + +{% include sig.textile %} \ No newline at end of file diff --git a/test/test_post.rb b/test/test_post.rb index ace67a96..f46dd8ca 100644 --- a/test/test_post.rb +++ b/test/test_post.rb @@ -83,4 +83,13 @@ class TestPost < Test::Unit::TestCase assert_equal "<<<

url: /2008/11/21/complex.html
\ndate: Fri Nov 21 00:00:00 -0800 2008
\nid: /2008/11/21/complex

>>>", 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 "<<<


\nTom Preston-Werner
\ngithub.com/mojombo

>>>", p.output + end end \ No newline at end of file diff --git a/test/test_site.rb b/test/test_site.rb index 48ec8f48..08317de5 100644 --- a/test/test_site.rb +++ b/test/test_site.rb @@ -19,7 +19,7 @@ class TestSite < Test::Unit::TestCase def test_read_posts @s.read_posts - assert_equal 2, @s.posts.size + assert_equal 3, @s.posts.size end def test_write_posts