From f0e24682491836a307ffee67c9726ea3c8293b96 Mon Sep 17 00:00:00 2001 From: "maul.esel" Date: Mon, 22 Jul 2013 16:02:42 +0200 Subject: [PATCH 01/15] simplify some code with Hash#fetch --- lib/jekyll/page.rb | 2 +- lib/jekyll/post.rb | 10 +++------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/jekyll/page.rb b/lib/jekyll/page.rb index 56119e07..5d1a9ea3 100644 --- a/lib/jekyll/page.rb +++ b/lib/jekyll/page.rb @@ -118,7 +118,7 @@ module Jekyll self.data.deep_merge({ "url" => self.url, "content" => self.content, - "path" => self.data['path'] || path }) + "path" => self.data.fetch('path', path) }) end # The path to the source file diff --git a/lib/jekyll/post.rb b/lib/jekyll/post.rb index 1b70e31e..411f54de 100644 --- a/lib/jekyll/post.rb +++ b/lib/jekyll/post.rb @@ -106,18 +106,14 @@ module Jekyll # # Returns excerpt string. def excerpt - if self.data.has_key? 'excerpt' - self.data['excerpt'] - else - self.extracted_excerpt.to_s - end + self.data.fetch('excerpt', self.extracted_excerpt.to_s) end # Public: the Post title, from the YAML Front-Matter or from the slug # # Returns the post title def title - self.data["title"] || self.slug.split('-').select {|w| w.capitalize! || w }.join(' ') + self.data.fetch("title", self.slug.split('-').select {|w| w.capitalize! || w }.join(' ')) end # Public: the path to the post relative to the site source, @@ -127,7 +123,7 @@ module Jekyll # # Returns the path to the file relative to the site source def path - self.data['path'] || File.join(@dir, '_posts', @name).sub(/\A\//, '') + self.data.fetch('path', File.join(@dir, '_posts', @name).sub(/\A\//, '')) end # Compares Post objects. First compares the Post date. If the dates are From 08567b109153ceb69d814b5db181cc0fe13c7ea5 Mon Sep 17 00:00:00 2001 From: "maul.esel" Date: Mon, 22 Jul 2013 15:03:00 +0200 Subject: [PATCH 02/15] move path handling in pages to the `path` method, as in posts --- lib/jekyll/page.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/jekyll/page.rb b/lib/jekyll/page.rb index 5d1a9ea3..162a7fbe 100644 --- a/lib/jekyll/page.rb +++ b/lib/jekyll/page.rb @@ -118,14 +118,14 @@ module Jekyll self.data.deep_merge({ "url" => self.url, "content" => self.content, - "path" => self.data.fetch('path', path) }) + "path" => self.path }) end # The path to the source file # # Returns the path to the source file def path - File.join(@dir, @name).sub(/\A\//, '') + self.data.fetch('path', File.join(@dir, @name).sub(/\A\//, '')) end # Obtain destination path. From 5d777eb9e939106bb831c09a8e9e75f8191f143c Mon Sep 17 00:00:00 2001 From: "maul.esel" Date: Mon, 22 Jul 2013 15:14:53 +0200 Subject: [PATCH 03/15] With the move of path handling, Page#to_liquid can be simplified --- lib/jekyll/page.rb | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/jekyll/page.rb b/lib/jekyll/page.rb index 162a7fbe..4f48ffc7 100644 --- a/lib/jekyll/page.rb +++ b/lib/jekyll/page.rb @@ -7,6 +7,13 @@ module Jekyll attr_accessor :name, :ext, :basename attr_accessor :data, :content, :output + # Attributes for Liquid templates + ATTRIBUTES_FOR_LIQUID = %w[ + url + content + path + ] + # Initialize a new Page. # # site - The Site object. @@ -115,10 +122,10 @@ module Jekyll # # Returns the Hash representation of this Page. def to_liquid - self.data.deep_merge({ - "url" => self.url, - "content" => self.content, - "path" => self.path }) + further_data = Hash[ATTRIBUTES_FOR_LIQUID.map { |attribute| + [attribute, send(attribute)] + }] + data.deep_merge(further_data) end # The path to the source file From fd907fa63105f66d3c96222b80e22b3a660cc1ca Mon Sep 17 00:00:00 2001 From: "maul.esel" Date: Mon, 22 Jul 2013 15:29:36 +0200 Subject: [PATCH 04/15] simplify coderay option handling --- lib/jekyll/converters/markdown/kramdown_parser.rb | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/jekyll/converters/markdown/kramdown_parser.rb b/lib/jekyll/converters/markdown/kramdown_parser.rb index b4237881..1d4d2d3a 100644 --- a/lib/jekyll/converters/markdown/kramdown_parser.rb +++ b/lib/jekyll/converters/markdown/kramdown_parser.rb @@ -14,14 +14,10 @@ module Jekyll def convert(content) # Check for use of coderay if @config['kramdown']['use_coderay'] - @config['kramdown'].merge!({ - :coderay_wrap => @config['kramdown']['coderay']['coderay_wrap'], - :coderay_line_numbers => @config['kramdown']['coderay']['coderay_line_numbers'], - :coderay_line_number_start => @config['kramdown']['coderay']['coderay_line_number_start'], - :coderay_tab_width => @config['kramdown']['coderay']['coderay_tab_width'], - :coderay_bold_every => @config['kramdown']['coderay']['coderay_bold_every'], - :coderay_css => @config['kramdown']['coderay']['coderay_css'] - }) + %w[wrap line_numbers line_numbers_start tab_width bold_every css].each do |opt| + key = "coderay_#{opt}" + @config['kramdown'][key.to_sym] = @config['kramdown']['coderay'][key] unless @config['kramdown'].has_key? key + end end Kramdown::Document.new(content, @config["kramdown"].symbolize_keys).to_html From 955f913f0415d3806cd892e14a527169000ad303 Mon Sep 17 00:00:00 2001 From: "maul.esel" Date: Mon, 22 Jul 2013 15:36:25 +0200 Subject: [PATCH 05/15] simplify Site#initialize --- lib/jekyll/site.rb | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index f7a8c379..1c62bdb6 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -15,20 +15,14 @@ module Jekyll def initialize(config) self.config = config.clone - self.safe = config['safe'] + %w[safe lsi pygments baseurl exclude include future show_drafts limit_posts keep_files].each do |opt| + self.send("#{opt}=", config[opt]) + end + self.source = File.expand_path(config['source']) self.dest = File.expand_path(config['destination']) self.plugins = plugins_path - self.lsi = config['lsi'] - self.pygments = config['pygments'] - self.baseurl = config['baseurl'] self.permalink_style = config['permalink'].to_sym - self.exclude = config['exclude'] - self.include = config['include'] - self.future = config['future'] - self.show_drafts = config['show_drafts'] - self.limit_posts = config['limit_posts'] - self.keep_files = config['keep_files'] self.reset self.setup From 5efadd6674002f8c9f4cb75fbf832f386eb88849 Mon Sep 17 00:00:00 2001 From: "maul.esel" Date: Mon, 22 Jul 2013 15:50:18 +0200 Subject: [PATCH 06/15] Support missing kramdown coderay option --- lib/jekyll/converters/markdown/kramdown_parser.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jekyll/converters/markdown/kramdown_parser.rb b/lib/jekyll/converters/markdown/kramdown_parser.rb index 1d4d2d3a..2aefdf8f 100644 --- a/lib/jekyll/converters/markdown/kramdown_parser.rb +++ b/lib/jekyll/converters/markdown/kramdown_parser.rb @@ -14,7 +14,7 @@ module Jekyll def convert(content) # Check for use of coderay if @config['kramdown']['use_coderay'] - %w[wrap line_numbers line_numbers_start tab_width bold_every css].each do |opt| + %w[wrap line_numbers line_numbers_start tab_width bold_every css default_lang].each do |opt| key = "coderay_#{opt}" @config['kramdown'][key.to_sym] = @config['kramdown']['coderay'][key] unless @config['kramdown'].has_key? key end From 21de43090a0b120bc18d39841d949f8868758001 Mon Sep 17 00:00:00 2001 From: "maul.esel" Date: Mon, 22 Jul 2013 16:23:40 +0200 Subject: [PATCH 07/15] Posts: move slug to title in a separate method --- lib/jekyll/post.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/jekyll/post.rb b/lib/jekyll/post.rb index 411f54de..5d08807f 100644 --- a/lib/jekyll/post.rb +++ b/lib/jekyll/post.rb @@ -113,7 +113,12 @@ module Jekyll # # Returns the post title def title - self.data.fetch("title", self.slug.split('-').select {|w| w.capitalize! || w }.join(' ')) + self.data.fetch("title", self.titleize_slug) + end + + # Turns the post slug into a suitable title + def titleize_slug + self.slug.split('-').select {|w| w.capitalize! || w }.join(' ') end # Public: the path to the post relative to the site source, From 75d6587d27d1642cf05ad6bac7a04580636749b6 Mon Sep 17 00:00:00 2001 From: "maul.esel" Date: Mon, 22 Jul 2013 16:34:01 +0200 Subject: [PATCH 08/15] Move #to_liquid to Convertible --- lib/jekyll/convertible.rb | 10 ++++++++++ lib/jekyll/page.rb | 10 ---------- lib/jekyll/post.rb | 10 ---------- 3 files changed, 10 insertions(+), 20 deletions(-) diff --git a/lib/jekyll/convertible.rb b/lib/jekyll/convertible.rb index b247ac4e..e2564464 100644 --- a/lib/jekyll/convertible.rb +++ b/lib/jekyll/convertible.rb @@ -84,6 +84,16 @@ module Jekyll raise e end + # Convert this Convertible's data to a Hash suitable for use by Liquid. + # + # Returns the Hash representation of this Convertible. + def to_liquid + further_data = Hash[self.class::ATTRIBUTES_FOR_LIQUID.map { |attribute| + [attribute, send(attribute)] + }] + data.deep_merge(further_data) + end + # Recursively render layouts # # layouts - a list of the layouts diff --git a/lib/jekyll/page.rb b/lib/jekyll/page.rb index 4f48ffc7..fb4a8fb0 100644 --- a/lib/jekyll/page.rb +++ b/lib/jekyll/page.rb @@ -118,16 +118,6 @@ module Jekyll do_layout(payload, layouts) end - # Convert this Page's data to a Hash suitable for use by Liquid. - # - # Returns the Hash representation of this Page. - def to_liquid - further_data = Hash[ATTRIBUTES_FOR_LIQUID.map { |attribute| - [attribute, send(attribute)] - }] - data.deep_merge(further_data) - end - # The path to the source file # # Returns the path to the source file diff --git a/lib/jekyll/post.rb b/lib/jekyll/post.rb index 5d08807f..cdedccfd 100644 --- a/lib/jekyll/post.rb +++ b/lib/jekyll/post.rb @@ -270,16 +270,6 @@ module Jekyll path end - # Convert this post into a Hash for use in Liquid templates. - # - # Returns the representative Hash. - def to_liquid - further_data = Hash[ATTRIBUTES_FOR_LIQUID.map { |attribute| - [attribute, send(attribute)] - }] - data.deep_merge(further_data) - end - # Returns the shorthand String identifier of this Post. def inspect "" From 86e007f970de01f1e41bdfb2d5431d46ca2cf8b3 Mon Sep 17 00:00:00 2001 From: "maul.esel" Date: Tue, 23 Jul 2013 11:18:15 +0200 Subject: [PATCH 09/15] remove no-longer needed LSI accessor LSI has been moved to another class (Jekyll::RelatedPosts), but this was left in Post. --- lib/jekyll/post.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/jekyll/post.rb b/lib/jekyll/post.rb index cdedccfd..29a847ac 100644 --- a/lib/jekyll/post.rb +++ b/lib/jekyll/post.rb @@ -3,10 +3,6 @@ module Jekyll include Comparable include Convertible - class << self - attr_accessor :lsi - end - # Valid post name regex. MATCHER = /^(.+\/)*(\d+-\d+-\d+)-(.*)(\.[^.]+)$/ From ba5db5ad5b3fececafee06b82286b87ebc9b2dfb Mon Sep 17 00:00:00 2001 From: "maul.esel" Date: Tue, 23 Jul 2013 14:23:33 +0200 Subject: [PATCH 10/15] refactor Include tag file validation Split validation into a separate method, and give a more descriptive error on symlinks. --- lib/jekyll/tags/include.rb | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/lib/jekyll/tags/include.rb b/lib/jekyll/tags/include.rb index ce1350b1..b094b7df 100644 --- a/lib/jekyll/tags/include.rb +++ b/lib/jekyll/tags/include.rb @@ -51,6 +51,21 @@ eos def render(context) includes_dir = File.join(context.registers[:site].source, '_includes') + error = self.validate_file(includes_dir) + unless error.nil? + return error + end + + source = File.read(File.join(includes_dir, @file)) + partial = Liquid::Template.parse(source) + + context.stack do + context['include'] = parse_params(context) if @params + partial.render(context) + end + end + + def validate_file(includes_dir) if File.symlink?(includes_dir) return "Includes directory '#{includes_dir}' cannot be a symlink" end @@ -59,20 +74,14 @@ eos return "Include file '#{@file}' contains invalid characters or sequences" end - Dir.chdir(includes_dir) do - choices = Dir['**/*'].reject { |x| File.symlink?(x) } - if choices.include?(@file) - source = File.read(@file) - partial = Liquid::Template.parse(source) - - context.stack do - context['include'] = parse_params(context) if @params - partial.render(context) - end - else - "Included file '#{@file}' not found in _includes directory" - end + file = File.join(includes_dir, @file) + if !File.exists?(file) + return "Included file #{@file} not found in _includes directory" + elsif File.symlink?(file) + return "Included file #{@file} is a symlink" end + + nil end end end From d815e2b2a210159020a8ef43b36f8e7521599311 Mon Sep 17 00:00:00 2001 From: "maul.esel" Date: Wed, 24 Jul 2013 16:28:03 +0200 Subject: [PATCH 11/15] coding style preferences (@parkr) --- lib/jekyll/converters/markdown/kramdown_parser.rb | 2 +- lib/jekyll/post.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/jekyll/converters/markdown/kramdown_parser.rb b/lib/jekyll/converters/markdown/kramdown_parser.rb index 2aefdf8f..be9e80b4 100644 --- a/lib/jekyll/converters/markdown/kramdown_parser.rb +++ b/lib/jekyll/converters/markdown/kramdown_parser.rb @@ -16,7 +16,7 @@ module Jekyll if @config['kramdown']['use_coderay'] %w[wrap line_numbers line_numbers_start tab_width bold_every css default_lang].each do |opt| key = "coderay_#{opt}" - @config['kramdown'][key.to_sym] = @config['kramdown']['coderay'][key] unless @config['kramdown'].has_key? key + @config['kramdown'][key.to_sym] = @config['kramdown']['coderay'][key] unless @config['kramdown'].has_key?(key) end end diff --git a/lib/jekyll/post.rb b/lib/jekyll/post.rb index 29a847ac..7777ab57 100644 --- a/lib/jekyll/post.rb +++ b/lib/jekyll/post.rb @@ -109,11 +109,11 @@ module Jekyll # # Returns the post title def title - self.data.fetch("title", self.titleize_slug) + self.data.fetch("title", self.titleized_slug) end # Turns the post slug into a suitable title - def titleize_slug + def titleized_slug self.slug.split('-').select {|w| w.capitalize! || w }.join(' ') end From 6c6dd173c7b8f755d3784ee34368904faa4cd2bf Mon Sep 17 00:00:00 2001 From: "maul.esel" Date: Wed, 24 Jul 2013 16:30:24 +0200 Subject: [PATCH 12/15] Post + Page: extract real path retrieval into separate method (@parkr) --- lib/jekyll/page.rb | 7 ++++++- lib/jekyll/post.rb | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/jekyll/page.rb b/lib/jekyll/page.rb index fb4a8fb0..9c728d56 100644 --- a/lib/jekyll/page.rb +++ b/lib/jekyll/page.rb @@ -122,7 +122,12 @@ module Jekyll # # Returns the path to the source file def path - self.data.fetch('path', File.join(@dir, @name).sub(/\A\//, '')) + self.data.fetch('path', self.relative_path.sub(/\A\//, '')) + end + + # The path to the page source file, relative to the site source + def relative_path + File.join(@dir, @name) end # Obtain destination path. diff --git a/lib/jekyll/post.rb b/lib/jekyll/post.rb index 7777ab57..415a3f66 100644 --- a/lib/jekyll/post.rb +++ b/lib/jekyll/post.rb @@ -124,7 +124,12 @@ module Jekyll # # Returns the path to the file relative to the site source def path - self.data.fetch('path', File.join(@dir, '_posts', @name).sub(/\A\//, '')) + self.data.fetch('path', self.relative_path.sub(/\A\//, '')) + end + + # The path to the post source file, relative to the site source + def relative_path + File.join(@dir, '_posts', @name) end # Compares Post objects. First compares the Post date. If the dates are From 01922a10acf44bb35cecaccc2b9066054c492600 Mon Sep 17 00:00:00 2001 From: "maul.esel" Date: Sun, 28 Jul 2013 21:18:54 +0200 Subject: [PATCH 13/15] Convertible#to_liquid: allow an alternate attribute set to be passed --- lib/jekyll/convertible.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/jekyll/convertible.rb b/lib/jekyll/convertible.rb index e2564464..2ac9d0b4 100644 --- a/lib/jekyll/convertible.rb +++ b/lib/jekyll/convertible.rb @@ -87,8 +87,8 @@ module Jekyll # Convert this Convertible's data to a Hash suitable for use by Liquid. # # Returns the Hash representation of this Convertible. - def to_liquid - further_data = Hash[self.class::ATTRIBUTES_FOR_LIQUID.map { |attribute| + def to_liquid(attrs = nil) + further_data = Hash[(attrs || self.class::ATTRIBUTES_FOR_LIQUID).map { |attribute| [attribute, send(attribute)] }] data.deep_merge(further_data) From 95719fa4ce071b72d1c61020f85f53f84c33589b Mon Sep 17 00:00:00 2001 From: "maul.esel" Date: Sat, 17 Aug 2013 16:24:06 +0200 Subject: [PATCH 14/15] improve error handling in include tag * Reduce condition to one-liner * Remove `self` * Implicit return value * Explicit error message for symlinks --- lib/jekyll/tags/include.rb | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/lib/jekyll/tags/include.rb b/lib/jekyll/tags/include.rb index b094b7df..29f69296 100644 --- a/lib/jekyll/tags/include.rb +++ b/lib/jekyll/tags/include.rb @@ -51,10 +51,7 @@ eos def render(context) includes_dir = File.join(context.registers[:site].source, '_includes') - error = self.validate_file(includes_dir) - unless error.nil? - return error - end + return error if error = validate_file(includes_dir) source = File.read(File.join(includes_dir, @file)) partial = Liquid::Template.parse(source) @@ -78,10 +75,8 @@ eos if !File.exists?(file) return "Included file #{@file} not found in _includes directory" elsif File.symlink?(file) - return "Included file #{@file} is a symlink" + return "Symlink #{@file} must not be included" end - - nil end end end From 506cdc5179aacedbc7903e424a45af31acc2c57f Mon Sep 17 00:00:00 2001 From: "maul.esel" Date: Sun, 18 Aug 2013 17:08:42 +0200 Subject: [PATCH 15/15] include: more helpful error message for symlinks --- lib/jekyll/tags/include.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jekyll/tags/include.rb b/lib/jekyll/tags/include.rb index 29f69296..74858b0a 100644 --- a/lib/jekyll/tags/include.rb +++ b/lib/jekyll/tags/include.rb @@ -75,7 +75,7 @@ eos if !File.exists?(file) return "Included file #{@file} not found in _includes directory" elsif File.symlink?(file) - return "Symlink #{@file} must not be included" + return "The included file '_includes/#{@file}' should not be a symlink" end end end