tigefa 1.0.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CONTRIBUTING.markdown +91 -0
- data/Gemfile +2 -0
- data/History.markdown +871 -0
- data/LICENSE +15 -14
- data/README.markdown +59 -0
- data/Rakefile +298 -0
- data/bin/tigefa +158 -0
- data/cucumber.yml +3 -0
- data/features/create_sites.feature +141 -0
- data/features/data.feature +65 -0
- data/features/drafts.feature +25 -0
- data/features/embed_filters.feature +60 -0
- data/features/include_tag.feature +57 -0
- data/features/markdown.feature +67 -0
- data/features/pagination.feature +82 -0
- data/features/permalinks.feature +85 -0
- data/features/post_data.feature +214 -0
- data/features/post_excerpts.feature +50 -0
- data/features/site_configuration.feature +235 -0
- data/features/site_data.feature +107 -0
- data/features/step_definitions/tigefa_steps.rb +189 -0
- data/features/support/env.rb +75 -0
- data/lib/site_template/.gitignore +1 -0
- data/lib/site_template/_config.yml +3 -0
- data/lib/site_template/_layouts/default.html +44 -0
- data/lib/site_template/_layouts/post.html +9 -0
- data/lib/site_template/_posts/0000-00-00-welcome-to-jekyll.markdown.erb +24 -0
- data/lib/site_template/css/main.css +160 -0
- data/lib/site_template/css/syntax.css +60 -0
- data/lib/site_template/index.html +13 -0
- data/lib/tigefa/cleaner.rb +73 -0
- data/lib/tigefa/command.rb +27 -0
- data/lib/tigefa/commands/build.rb +70 -0
- data/lib/tigefa/commands/doctor.rb +67 -0
- data/lib/tigefa/commands/new.rb +67 -0
- data/lib/tigefa/commands/serve.rb +65 -0
- data/lib/tigefa/configuration.rb +238 -0
- data/lib/tigefa/converter.rb +48 -0
- data/lib/tigefa/converters/identity.rb +21 -0
- data/lib/tigefa/converters/markdown/kramdown_parser.rb +29 -0
- data/lib/tigefa/converters/markdown/maruku_parser.rb +56 -0
- data/lib/tigefa/converters/markdown/rdiscount_parser.rb +37 -0
- data/lib/tigefa/converters/markdown/redcarpet_parser.rb +70 -0
- data/lib/tigefa/converters/markdown.rb +43 -0
- data/lib/tigefa/converters/textile.rb +50 -0
- data/lib/tigefa/convertible.rb +174 -0
- data/lib/tigefa/core_ext.rb +90 -0
- data/lib/tigefa/deprecator.rb +36 -0
- data/lib/tigefa/draft.rb +35 -0
- data/lib/tigefa/entry_filter.rb +35 -0
- data/lib/tigefa/errors.rb +4 -0
- data/lib/tigefa/excerpt.rb +113 -0
- data/lib/tigefa/filters.rb +174 -0
- data/lib/tigefa/generator.rb +4 -0
- data/lib/tigefa/generators/pagination.rb +217 -0
- data/lib/tigefa/layout.rb +45 -0
- data/lib/tigefa/mime.types +85 -0
- data/lib/tigefa/page.rb +160 -0
- data/lib/tigefa/plugin.rb +75 -0
- data/lib/tigefa/post.rb +312 -0
- data/lib/tigefa/related_posts.rb +59 -0
- data/lib/tigefa/site.rb +427 -0
- data/lib/tigefa/static_file.rb +70 -0
- data/lib/tigefa/stevenson.rb +89 -0
- data/lib/tigefa/tags/gist.rb +48 -0
- data/lib/tigefa/tags/highlight.rb +85 -0
- data/lib/tigefa/tags/include.rb +134 -0
- data/lib/tigefa/tags/post_url.rb +63 -0
- data/lib/tigefa/url.rb +69 -0
- data/lib/tigefa.rb +98 -4
- data/script/bootstrap +2 -0
- data/site/.gitignore +4 -0
- data/site/CNAME +1 -0
- data/site/README +1 -0
- data/site/_config.yml +6 -0
- data/site/_includes/analytics.html +32 -0
- data/site/_includes/docs_contents.html +16 -0
- data/site/_includes/docs_contents_mobile.html +23 -0
- data/site/_includes/docs_option.html +11 -0
- data/site/_includes/docs_ul.html +20 -0
- data/site/_includes/footer.html +15 -0
- data/site/_includes/header.html +18 -0
- data/site/_includes/news_contents.html +23 -0
- data/site/_includes/news_contents_mobile.html +11 -0
- data/site/_includes/news_item.html +24 -0
- data/site/_includes/primary-nav-items.html +14 -0
- data/site/_includes/section_nav.html +22 -0
- data/site/_includes/top.html +17 -0
- data/site/_layouts/default.html +12 -0
- data/site/_layouts/docs.html +23 -0
- data/site/_layouts/news.html +19 -0
- data/site/_layouts/news_item.html +27 -0
- data/site/_posts/2013-05-06-jekyll-1-0-0-released.markdown +23 -0
- data/site/_posts/2013-05-08-jekyll-1-0-1-released.markdown +27 -0
- data/site/_posts/2013-05-12-jekyll-1-0-2-released.markdown +28 -0
- data/site/_posts/2013-06-07-jekyll-1-0-3-released.markdown +25 -0
- data/site/_posts/2013-07-14-jekyll-1-1-0-released.markdown +27 -0
- data/site/_posts/2013-07-24-jekyll-1-1-1-released.markdown +31 -0
- data/site/_posts/2013-07-25-jekyll-1-0-4-released.markdown +20 -0
- data/site/_posts/2013-07-25-jekyll-1-1-2-released.markdown +20 -0
- data/site/_posts/2013-09-06-jekyll-1-2-0-released.markdown +23 -0
- data/site/_posts/2013-09-14-jekyll-1-2-1-released.markdown +19 -0
- data/site/_posts/2013-10-28-jekyll-1-3-0-rc1-released.markdown +19 -0
- data/site/_posts/2013-11-04-jekyll-1-3-0-released.markdown +43 -0
- data/site/_posts/2013-11-26-jekyll-1-3-1-released.markdown +21 -0
- data/site/_posts/2013-12-07-jekyll-1-4-0-released.markdown +30 -0
- data/site/_posts/2013-12-16-jekyll-1-4-2-released.markdown +18 -0
- data/site/_posts/2014-01-13-jekyll-1-4-3-released.markdown +27 -0
- data/site/css/gridism.css +110 -0
- data/site/css/normalize.css +1 -0
- data/site/css/pygments.css +70 -0
- data/site/css/style.css +946 -0
- data/site/docs/configuration.md +375 -0
- data/site/docs/contributing.md +128 -0
- data/site/docs/datafiles.md +63 -0
- data/site/docs/deployment-methods.md +109 -0
- data/site/docs/drafts.md +21 -0
- data/site/docs/extras.md +56 -0
- data/site/docs/frontmatter.md +180 -0
- data/site/docs/github-pages.md +91 -0
- data/site/docs/heroku.md +9 -0
- data/site/docs/history.md +866 -0
- data/site/docs/index.md +52 -0
- data/site/docs/installation.md +76 -0
- data/site/docs/migrations.md +11 -0
- data/site/docs/pages.md +86 -0
- data/site/docs/pagination.md +211 -0
- data/site/docs/permalinks.md +180 -0
- data/site/docs/plugins.md +534 -0
- data/site/docs/posts.md +181 -0
- data/site/docs/quickstart.md +32 -0
- data/site/docs/resources.md +46 -0
- data/site/docs/sites.md +29 -0
- data/site/docs/structure.md +190 -0
- data/site/docs/templates.md +339 -0
- data/site/docs/troubleshooting.md +150 -0
- data/site/docs/upgrading.md +146 -0
- data/site/docs/usage.md +63 -0
- data/site/docs/variables.md +322 -0
- data/site/favicon.png +0 -0
- data/site/feed.xml +36 -0
- data/site/freenode.txt +1 -0
- data/site/img/article-footer.png +0 -0
- data/site/img/footer-arrow.png +0 -0
- data/site/img/footer-logo.png +0 -0
- data/site/img/logo-2x.png +0 -0
- data/site/img/octojekyll.png +0 -0
- data/site/img/tube.png +0 -0
- data/site/img/tube1x.png +0 -0
- data/site/index.html +90 -0
- data/site/js/modernizr-2.5.3.min.js +4 -0
- data/site/news/index.html +10 -0
- data/site/news/releases/index.html +10 -0
- data/test/fixtures/broken_front_matter1.erb +5 -0
- data/test/fixtures/broken_front_matter2.erb +4 -0
- data/test/fixtures/broken_front_matter3.erb +7 -0
- data/test/fixtures/exploit_front_matter.erb +4 -0
- data/test/fixtures/front_matter.erb +4 -0
- data/test/helper.rb +65 -0
- data/test/source/+/foo.md +7 -0
- data/test/source/.htaccess +8 -0
- data/test/source/_config.dev.toml +2 -0
- data/test/source/_data/languages.yml +2 -0
- data/test/source/_data/members.yaml +7 -0
- data/test/source/_data/products.yml +1 -0
- data/test/source/_includes/params.html +7 -0
- data/test/source/_includes/sig.markdown +3 -0
- data/test/source/_includes/tmp +1 -0
- data/test/source/_layouts/default.html +27 -0
- data/test/source/_layouts/post/simple.html +1 -0
- data/test/source/_layouts/simple.html +1 -0
- data/test/source/_plugins/dummy.rb +8 -0
- data/test/source/_posts/2008-02-02-not-published.textile +8 -0
- data/test/source/_posts/2008-02-02-published.textile +8 -0
- data/test/source/_posts/2008-10-18-foo-bar.textile +8 -0
- data/test/source/_posts/2008-11-21-complex.textile +8 -0
- data/test/source/_posts/2008-12-03-permalinked-post.textile +9 -0
- data/test/source/_posts/2008-12-13-include.markdown +8 -0
- data/test/source/_posts/2009-01-27-array-categories.textile +10 -0
- data/test/source/_posts/2009-01-27-categories.textile +7 -0
- data/test/source/_posts/2009-01-27-category.textile +7 -0
- data/test/source/_posts/2009-01-27-empty-categories.textile +7 -0
- data/test/source/_posts/2009-01-27-empty-category.textile +7 -0
- data/test/source/_posts/2009-03-12-hash-#1.markdown +6 -0
- data/test/source/_posts/2009-05-18-empty-tag.textile +6 -0
- data/test/source/_posts/2009-05-18-empty-tags.textile +6 -0
- data/test/source/_posts/2009-05-18-tag.textile +6 -0
- data/test/source/_posts/2009-05-18-tags.textile +9 -0
- data/test/source/_posts/2009-06-22-empty-yaml.textile +3 -0
- data/test/source/_posts/2009-06-22-no-yaml.textile +1 -0
- data/test/source/_posts/2010-01-08-triple-dash.markdown +5 -0
- data/test/source/_posts/2010-01-09-date-override.textile +7 -0
- data/test/source/_posts/2010-01-09-time-override.textile +7 -0
- data/test/source/_posts/2010-01-09-timezone-override.textile +7 -0
- data/test/source/_posts/2010-01-16-override-data.textile +4 -0
- data/test/source/_posts/2011-04-12-md-extension.md +7 -0
- data/test/source/_posts/2011-04-12-text-extension.text +0 -0
- data/test/source/_posts/2013-01-02-post-excerpt.markdown +14 -0
- data/test/source/_posts/2013-01-12-nil-layout.textile +6 -0
- data/test/source/_posts/2013-01-12-no-layout.textile +5 -0
- data/test/source/_posts/2013-03-19-not-a-post.markdown/.gitkeep +0 -0
- data/test/source/_posts/2013-04-11-custom-excerpt.markdown +10 -0
- data/test/source/_posts/2013-05-10-number-category.textile +7 -0
- data/test/source/_posts/2013-07-22-post-excerpt-with-layout.markdown +23 -0
- data/test/source/_posts/2013-08-01-mkdn-extension.mkdn +0 -0
- data/test/source/_posts/2014-01-06-permalink-traversal.md +5 -0
- data/test/source/_posts/es/2008-11-21-nested.textile +8 -0
- data/test/source/about.html +6 -0
- data/test/source/category/_posts/2008-9-23-categories.textile +6 -0
- data/test/source/contacts/bar.html +5 -0
- data/test/source/contacts/index.html +5 -0
- data/test/source/contacts.html +5 -0
- data/test/source/css/screen.css +76 -0
- data/test/source/deal.with.dots.html +7 -0
- data/test/source/exploit.md +5 -0
- data/test/source/foo/_posts/bar/2008-12-12-topical-post.textile +8 -0
- data/test/source/index.html +22 -0
- data/test/source/products.yml +4 -0
- data/test/source/sitemap.xml +32 -0
- data/test/source/symlink-test/_data +1 -0
- data/test/source/symlink-test/symlinked-dir +1 -0
- data/test/source/symlink-test/symlinked-file +1 -0
- data/test/source/win/_posts/2009-05-24-yaml-linebreak.markdown +7 -0
- data/test/source/z_category/_posts/2008-9-23-categories.textile +6 -0
- data/test/suite.rb +11 -0
- data/test/test_command.rb +39 -0
- data/test/test_configuration.rb +181 -0
- data/test/test_convertible.rb +51 -0
- data/test/test_core_ext.rb +88 -0
- data/test/test_entry_filter.rb +74 -0
- data/test/test_excerpt.rb +78 -0
- data/test/test_filters.rb +113 -0
- data/test/test_generated_site.rb +83 -0
- data/test/test_kramdown.rb +62 -0
- data/test/test_new_command.rb +104 -0
- data/test/test_page.rb +212 -0
- data/test/test_pager.rb +116 -0
- data/test/test_post.rb +592 -0
- data/test/test_rdiscount.rb +22 -0
- data/test/test_redcarpet.rb +61 -0
- data/test/test_redcloth.rb +86 -0
- data/test/test_related_posts.rb +47 -0
- data/test/test_site.rb +333 -0
- data/test/test_tags.rb +490 -0
- data/test/test_url.rb +28 -0
- data/tigefa.gemspec +306 -0
- metadata +575 -45
- data/README.md +0 -4
@@ -0,0 +1,37 @@
|
|
1
|
+
module Tigefa
|
2
|
+
module Converters
|
3
|
+
class Markdown
|
4
|
+
class RDiscountParser
|
5
|
+
def initialize(config)
|
6
|
+
require 'rdiscount'
|
7
|
+
@config = config
|
8
|
+
@rdiscount_extensions = @config['rdiscount']['extensions'].map { |e| e.to_sym }
|
9
|
+
rescue LoadError
|
10
|
+
STDERR.puts 'You are missing a library required for Markdown. Please run:'
|
11
|
+
STDERR.puts ' $ [sudo] gem install rdiscount'
|
12
|
+
raise FatalException.new("Missing dependency: rdiscount")
|
13
|
+
end
|
14
|
+
|
15
|
+
def convert(content)
|
16
|
+
rd = RDiscount.new(content, *@rdiscount_extensions)
|
17
|
+
html = rd.to_html
|
18
|
+
if @config['rdiscount']['toc_token']
|
19
|
+
html = replace_generated_toc(rd, html, @config['rdiscount']['toc_token'])
|
20
|
+
end
|
21
|
+
html
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
def replace_generated_toc(rd, html, toc_token)
|
26
|
+
if rd.generate_toc && html.include?(toc_token)
|
27
|
+
utf8_toc = rd.toc_content
|
28
|
+
utf8_toc.force_encoding('utf-8') if utf8_toc.respond_to?(:force_encoding)
|
29
|
+
html.gsub(toc_token, utf8_toc)
|
30
|
+
else
|
31
|
+
html
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module Tigefa
|
2
|
+
module Converters
|
3
|
+
class Markdown
|
4
|
+
class RedcarpetParser
|
5
|
+
|
6
|
+
module CommonMethods
|
7
|
+
def add_code_tags(code, lang)
|
8
|
+
code = code.sub(/<pre>/, "<pre><code class=\"#{lang} language-#{lang}\" data-lang=\"#{lang}\">")
|
9
|
+
code = code.sub(/<\/pre>/,"</code></pre>")
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
module WithPygments
|
14
|
+
include CommonMethods
|
15
|
+
def block_code(code, lang)
|
16
|
+
require 'pygments'
|
17
|
+
lang = lang && lang.split.first || "text"
|
18
|
+
output = add_code_tags(
|
19
|
+
Pygments.highlight(code, :lexer => lang, :options => { :encoding => 'utf-8' }),
|
20
|
+
lang
|
21
|
+
)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
module WithoutPygments
|
26
|
+
require 'cgi'
|
27
|
+
|
28
|
+
include CommonMethods
|
29
|
+
|
30
|
+
def code_wrap(code)
|
31
|
+
"<div class=\"highlight\"><pre>#{CGI::escapeHTML(code)}</pre></div>"
|
32
|
+
end
|
33
|
+
|
34
|
+
def block_code(code, lang)
|
35
|
+
lang = lang && lang.split.first || "text"
|
36
|
+
output = add_code_tags(code_wrap(code), lang)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def initialize(config)
|
41
|
+
require 'redcarpet'
|
42
|
+
@config = config
|
43
|
+
@redcarpet_extensions = {}
|
44
|
+
@config['redcarpet']['extensions'].each { |e| @redcarpet_extensions[e.to_sym] = true }
|
45
|
+
|
46
|
+
@renderer ||= if @config['pygments']
|
47
|
+
Class.new(Redcarpet::Render::HTML) do
|
48
|
+
include WithPygments
|
49
|
+
end
|
50
|
+
else
|
51
|
+
Class.new(Redcarpet::Render::HTML) do
|
52
|
+
include WithoutPygments
|
53
|
+
end
|
54
|
+
end
|
55
|
+
rescue LoadError
|
56
|
+
STDERR.puts 'You are missing a library required for Markdown. Please run:'
|
57
|
+
STDERR.puts ' $ [sudo] gem install redcarpet'
|
58
|
+
raise FatalException.new("Missing dependency: redcarpet")
|
59
|
+
end
|
60
|
+
|
61
|
+
def convert(content)
|
62
|
+
@redcarpet_extensions[:fenced_code_blocks] = !@redcarpet_extensions[:no_fenced_code_blocks]
|
63
|
+
@renderer.send :include, Redcarpet::Render::SmartyPants if @redcarpet_extensions[:smart]
|
64
|
+
markdown = Redcarpet::Markdown.new(@renderer.new(@redcarpet_extensions), @redcarpet_extensions)
|
65
|
+
markdown.render(content)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Tigefa
|
2
|
+
module Converters
|
3
|
+
class Markdown < Converter
|
4
|
+
safe true
|
5
|
+
|
6
|
+
pygments_prefix "\n"
|
7
|
+
pygments_suffix "\n"
|
8
|
+
|
9
|
+
def setup
|
10
|
+
return if @setup
|
11
|
+
@parser = case @config['markdown']
|
12
|
+
when 'redcarpet'
|
13
|
+
RedcarpetParser.new @config
|
14
|
+
when 'kramdown'
|
15
|
+
KramdownParser.new @config
|
16
|
+
when 'rdiscount'
|
17
|
+
RDiscountParser.new @config
|
18
|
+
when 'maruku'
|
19
|
+
MarukuParser.new @config
|
20
|
+
else
|
21
|
+
STDERR.puts "Invalid Markdown processor: #{@config['markdown']}"
|
22
|
+
STDERR.puts " Valid options are [ maruku | rdiscount | kramdown | redcarpet ]"
|
23
|
+
raise FatalException.new("Invalid Markdown process: #{@config['markdown']}")
|
24
|
+
end
|
25
|
+
@setup = true
|
26
|
+
end
|
27
|
+
|
28
|
+
def matches(ext)
|
29
|
+
rgx = '^\.(' + @config['markdown_ext'].gsub(',','|') +')$'
|
30
|
+
ext =~ Regexp.new(rgx, Regexp::IGNORECASE)
|
31
|
+
end
|
32
|
+
|
33
|
+
def output_ext(ext)
|
34
|
+
".html"
|
35
|
+
end
|
36
|
+
|
37
|
+
def convert(content)
|
38
|
+
setup
|
39
|
+
@parser.convert(content)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Tigefa
|
2
|
+
module Converters
|
3
|
+
class Textile < Converter
|
4
|
+
safe true
|
5
|
+
|
6
|
+
pygments_prefix '<notextile>'
|
7
|
+
pygments_suffix '</notextile>'
|
8
|
+
|
9
|
+
def setup
|
10
|
+
return if @setup
|
11
|
+
require 'redcloth'
|
12
|
+
@setup = true
|
13
|
+
rescue LoadError
|
14
|
+
STDERR.puts 'You are missing a library required for Textile. Please run:'
|
15
|
+
STDERR.puts ' $ [sudo] gem install RedCloth'
|
16
|
+
raise FatalException.new("Missing dependency: RedCloth")
|
17
|
+
end
|
18
|
+
|
19
|
+
def matches(ext)
|
20
|
+
rgx = '(' + @config['textile_ext'].gsub(',','|') +')'
|
21
|
+
ext =~ Regexp.new(rgx, Regexp::IGNORECASE)
|
22
|
+
end
|
23
|
+
|
24
|
+
def output_ext(ext)
|
25
|
+
".html"
|
26
|
+
end
|
27
|
+
|
28
|
+
def convert(content)
|
29
|
+
setup
|
30
|
+
|
31
|
+
# Shortcut if config doesn't contain RedCloth section
|
32
|
+
return RedCloth.new(content).to_html if @config['redcloth'].nil?
|
33
|
+
|
34
|
+
# List of attributes defined on RedCloth
|
35
|
+
# (from http://redcloth.rubyforge.org/classes/RedCloth/TextileDoc.html)
|
36
|
+
attrs = ['filter_classes', 'filter_html', 'filter_ids', 'filter_styles',
|
37
|
+
'hard_breaks', 'lite_mode', 'no_span_caps', 'sanitize_html']
|
38
|
+
|
39
|
+
r = RedCloth.new(content)
|
40
|
+
|
41
|
+
# Set attributes in r if they are NOT nil in the config
|
42
|
+
attrs.each do |attr|
|
43
|
+
r.instance_variable_set("@#{attr}".to_sym, @config['redcloth'][attr]) unless @config['redcloth'][attr].nil?
|
44
|
+
end
|
45
|
+
|
46
|
+
r.to_html
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,174 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'set'
|
4
|
+
|
5
|
+
# Convertible provides methods for converting a pagelike item
|
6
|
+
# from a certain type of markup into actual content
|
7
|
+
#
|
8
|
+
# Requires
|
9
|
+
# self.site -> Tigefa::Site
|
10
|
+
# self.content
|
11
|
+
# self.content=
|
12
|
+
# self.data=
|
13
|
+
# self.ext=
|
14
|
+
# self.output=
|
15
|
+
# self.name
|
16
|
+
module Tigefa
|
17
|
+
module Convertible
|
18
|
+
# Returns the contents as a String.
|
19
|
+
def to_s
|
20
|
+
self.content || ''
|
21
|
+
end
|
22
|
+
|
23
|
+
# Returns merged optin hash for File.read of self.site (if exists)
|
24
|
+
# and a given param
|
25
|
+
def merged_file_read_opts(opts)
|
26
|
+
(self.site ? self.site.file_read_opts : {}).merge(opts)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Read the YAML frontmatter.
|
30
|
+
#
|
31
|
+
# base - The String path to the dir containing the file.
|
32
|
+
# name - The String filename of the file.
|
33
|
+
# opts - optional parameter to File.read, default at site configs
|
34
|
+
#
|
35
|
+
# Returns nothing.
|
36
|
+
def read_yaml(base, name, opts = {})
|
37
|
+
begin
|
38
|
+
self.content = File.read_with_options(File.join(base, name),
|
39
|
+
merged_file_read_opts(opts))
|
40
|
+
if self.content =~ /\A(---\s*\n.*?\n?)^(---\s*$\n?)/m
|
41
|
+
self.content = $POSTMATCH
|
42
|
+
self.data = YAML.safe_load($1)
|
43
|
+
end
|
44
|
+
rescue SyntaxError => e
|
45
|
+
puts "YAML Exception reading #{File.join(base, name)}: #{e.message}"
|
46
|
+
rescue Exception => e
|
47
|
+
puts "Error reading file #{File.join(base, name)}: #{e.message}"
|
48
|
+
end
|
49
|
+
|
50
|
+
self.data ||= {}
|
51
|
+
end
|
52
|
+
|
53
|
+
# Transform the contents based on the content type.
|
54
|
+
#
|
55
|
+
# Returns nothing.
|
56
|
+
def transform
|
57
|
+
self.content = converter.convert(self.content)
|
58
|
+
rescue => e
|
59
|
+
Tigefa.logger.error "Conversion error:", "There was an error converting" +
|
60
|
+
" '#{self.path}'."
|
61
|
+
raise e
|
62
|
+
end
|
63
|
+
|
64
|
+
# Determine the extension depending on content_type.
|
65
|
+
#
|
66
|
+
# Returns the String extension for the output file.
|
67
|
+
# e.g. ".html" for an HTML output file.
|
68
|
+
def output_ext
|
69
|
+
converter.output_ext(self.ext)
|
70
|
+
end
|
71
|
+
|
72
|
+
# Determine which converter to use based on this convertible's
|
73
|
+
# extension.
|
74
|
+
#
|
75
|
+
# Returns the Converter instance.
|
76
|
+
def converter
|
77
|
+
@converter ||= self.site.converters.find { |c| c.matches(self.ext) }
|
78
|
+
end
|
79
|
+
|
80
|
+
# Render Liquid in the content
|
81
|
+
#
|
82
|
+
# content - the raw Liquid content to render
|
83
|
+
# payload - the payload for Liquid
|
84
|
+
# info - the info for Liquid
|
85
|
+
#
|
86
|
+
# Returns the converted content
|
87
|
+
def render_liquid(content, payload, info, path = nil)
|
88
|
+
Liquid::Template.parse(content).render!(payload, info)
|
89
|
+
rescue Tags::IncludeTagError => e
|
90
|
+
Tigefa.logger.error "Liquid Exception:", "#{e.message} in #{e.path}, included in #{path || self.path}"
|
91
|
+
raise e
|
92
|
+
rescue Exception => e
|
93
|
+
Tigefa.logger.error "Liquid Exception:", "#{e.message} in #{path || self.path}"
|
94
|
+
raise e
|
95
|
+
end
|
96
|
+
|
97
|
+
# Convert this Convertible's data to a Hash suitable for use by Liquid.
|
98
|
+
#
|
99
|
+
# Returns the Hash representation of this Convertible.
|
100
|
+
def to_liquid(attrs = nil)
|
101
|
+
further_data = Hash[(attrs || self.class::ATTRIBUTES_FOR_LIQUID).map { |attribute|
|
102
|
+
[attribute, send(attribute)]
|
103
|
+
}]
|
104
|
+
data.deep_merge(further_data)
|
105
|
+
end
|
106
|
+
|
107
|
+
# Recursively render layouts
|
108
|
+
#
|
109
|
+
# layouts - a list of the layouts
|
110
|
+
# payload - the payload for Liquid
|
111
|
+
# info - the info for Liquid
|
112
|
+
#
|
113
|
+
# Returns nothing
|
114
|
+
def render_all_layouts(layouts, payload, info)
|
115
|
+
# recursively render layouts
|
116
|
+
layout = layouts[self.data["layout"]]
|
117
|
+
used = Set.new([layout])
|
118
|
+
|
119
|
+
while layout
|
120
|
+
payload = payload.deep_merge({"content" => self.output, "page" => layout.data})
|
121
|
+
|
122
|
+
self.output = self.render_liquid(layout.content,
|
123
|
+
payload,
|
124
|
+
info,
|
125
|
+
File.join(self.site.config['layouts'], layout.name))
|
126
|
+
|
127
|
+
if layout = layouts[layout.data["layout"]]
|
128
|
+
if used.include?(layout)
|
129
|
+
layout = nil # avoid recursive chain
|
130
|
+
else
|
131
|
+
used << layout
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
# Add any necessary layouts to this convertible document.
|
138
|
+
#
|
139
|
+
# payload - The site payload Hash.
|
140
|
+
# layouts - A Hash of {"name" => "layout"}.
|
141
|
+
#
|
142
|
+
# Returns nothing.
|
143
|
+
def do_layout(payload, layouts)
|
144
|
+
info = { :filters => [Tigefa::Filters], :registers => { :site => self.site, :page => payload['page'] } }
|
145
|
+
|
146
|
+
# render and transform content (this becomes the final content of the object)
|
147
|
+
payload["pygments_prefix"] = converter.pygments_prefix
|
148
|
+
payload["pygments_suffix"] = converter.pygments_suffix
|
149
|
+
|
150
|
+
self.content = self.render_liquid(self.content,
|
151
|
+
payload,
|
152
|
+
info)
|
153
|
+
self.transform
|
154
|
+
|
155
|
+
# output keeps track of what will finally be written
|
156
|
+
self.output = self.content
|
157
|
+
|
158
|
+
self.render_all_layouts(layouts, payload, info)
|
159
|
+
end
|
160
|
+
|
161
|
+
# Write the generated page file to the destination directory.
|
162
|
+
#
|
163
|
+
# dest - The String path to the destination dir.
|
164
|
+
#
|
165
|
+
# Returns nothing.
|
166
|
+
def write(dest)
|
167
|
+
path = destination(dest)
|
168
|
+
FileUtils.mkdir_p(File.dirname(path))
|
169
|
+
File.open(path, 'wb') do |f|
|
170
|
+
f.write(self.output)
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
class Hash
|
2
|
+
# Merges self with another hash, recursively.
|
3
|
+
#
|
4
|
+
# This code was lovingly stolen from some random gem:
|
5
|
+
# http://gemjack.com/gems/tartan-0.1.1/classes/Hash.html
|
6
|
+
#
|
7
|
+
# Thanks to whoever made it.
|
8
|
+
def deep_merge(hash)
|
9
|
+
target = dup
|
10
|
+
|
11
|
+
hash.keys.each do |key|
|
12
|
+
if hash[key].is_a? Hash and self[key].is_a? Hash
|
13
|
+
target[key] = target[key].deep_merge(hash[key])
|
14
|
+
next
|
15
|
+
end
|
16
|
+
|
17
|
+
target[key] = hash[key]
|
18
|
+
end
|
19
|
+
|
20
|
+
target
|
21
|
+
end
|
22
|
+
|
23
|
+
# Read array from the supplied hash favouring the singular key
|
24
|
+
# and then the plural key, and handling any nil entries.
|
25
|
+
# +hash+ the hash to read from
|
26
|
+
# +singular_key+ the singular key
|
27
|
+
# +plural_key+ the plural key
|
28
|
+
#
|
29
|
+
# Returns an array
|
30
|
+
def pluralized_array(singular_key, plural_key)
|
31
|
+
hash = self
|
32
|
+
if hash.has_key?(singular_key)
|
33
|
+
array = [hash[singular_key]] if hash[singular_key]
|
34
|
+
elsif hash.has_key?(plural_key)
|
35
|
+
case hash[plural_key]
|
36
|
+
when String
|
37
|
+
array = hash[plural_key].split
|
38
|
+
when Array
|
39
|
+
array = hash[plural_key].compact
|
40
|
+
end
|
41
|
+
end
|
42
|
+
array || []
|
43
|
+
end
|
44
|
+
|
45
|
+
def symbolize_keys!
|
46
|
+
keys.each do |key|
|
47
|
+
self[(key.to_sym rescue key) || key] = delete(key)
|
48
|
+
end
|
49
|
+
self
|
50
|
+
end
|
51
|
+
|
52
|
+
def symbolize_keys
|
53
|
+
dup.symbolize_keys!
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# Thanks, ActiveSupport!
|
58
|
+
class Date
|
59
|
+
# Converts datetime to an appropriate format for use in XML
|
60
|
+
def xmlschema
|
61
|
+
strftime("%Y-%m-%dT%H:%M:%S%Z")
|
62
|
+
end if RUBY_VERSION < '1.9'
|
63
|
+
end
|
64
|
+
|
65
|
+
module Enumerable
|
66
|
+
# Returns true if path matches against any glob pattern.
|
67
|
+
# Look for more detail about glob pattern in method File::fnmatch.
|
68
|
+
def glob_include?(e)
|
69
|
+
any? { |exp| File.fnmatch?(exp, e) }
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
# Ruby 1.8's File.read don't support option.
|
74
|
+
# read_with_options ignore optional parameter for 1.8,
|
75
|
+
# and act as alias for 1.9 or later.
|
76
|
+
class File
|
77
|
+
if RUBY_VERSION < '1.9'
|
78
|
+
def self.read_with_options(path, opts = {})
|
79
|
+
self.read(path)
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.realpath(filename)
|
83
|
+
Pathname.new(filename).realpath.to_s
|
84
|
+
end
|
85
|
+
else
|
86
|
+
def self.read_with_options(path, opts = {})
|
87
|
+
self.read(path, opts)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Tigefa
|
2
|
+
class Deprecator
|
3
|
+
def self.process(args)
|
4
|
+
no_subcommand(args)
|
5
|
+
arg_is_present? args, "--server", "The --server command has been replaced by the \
|
6
|
+
'serve' subcommand."
|
7
|
+
arg_is_present? args, "--no-server", "To build Tigefa without launching a server, \
|
8
|
+
use the 'build' subcommand."
|
9
|
+
arg_is_present? args, "--auto", "The switch '--auto' has been replaced with '--watch'."
|
10
|
+
arg_is_present? args, "--no-auto", "To disable auto-replication, simply leave off \
|
11
|
+
the '--watch' switch."
|
12
|
+
arg_is_present? args, "--pygments", "The 'pygments' setting can only be set in \
|
13
|
+
your config files."
|
14
|
+
arg_is_present? args, "--paginate", "The 'paginate' setting can only be set in your \
|
15
|
+
config files."
|
16
|
+
arg_is_present? args, "--url", "The 'url' setting can only be set in your config files."
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.no_subcommand(args)
|
20
|
+
if args.size > 0 && args.first =~ /^--/ && !%w[--help --version].include?(args.first)
|
21
|
+
Tigefa.logger.error "Deprecation:", "Tigefa now uses subcommands instead of just \
|
22
|
+
switches. Run `jekyll help' to find out more."
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.arg_is_present?(args, deprecated_argument, message)
|
27
|
+
if args.include?(deprecated_argument)
|
28
|
+
deprecation_message(message)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.deprecation_message(message)
|
33
|
+
Tigefa.logger.error "Deprecation:", message
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/tigefa/draft.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
module Tigefa
|
2
|
+
|
3
|
+
class Draft < Post
|
4
|
+
|
5
|
+
# Valid post name regex (no date)
|
6
|
+
MATCHER = /^(.*)(\.[^.]+)$/
|
7
|
+
|
8
|
+
# Draft name validator. Draft filenames must be like:
|
9
|
+
# my-awesome-post.textile
|
10
|
+
#
|
11
|
+
# Returns true if valid, false if not.
|
12
|
+
def self.valid?(name)
|
13
|
+
name =~ MATCHER
|
14
|
+
end
|
15
|
+
|
16
|
+
# Get the full path to the directory containing the draft files
|
17
|
+
def containing_dir(source, dir)
|
18
|
+
File.join(source, dir, '_drafts')
|
19
|
+
end
|
20
|
+
|
21
|
+
# Extract information from the post filename.
|
22
|
+
#
|
23
|
+
# name - The String filename of the post file.
|
24
|
+
#
|
25
|
+
# Returns nothing.
|
26
|
+
def process(name)
|
27
|
+
m, slug, ext = *name.match(MATCHER)
|
28
|
+
self.date = File.mtime(File.join(@base, name))
|
29
|
+
self.slug = slug
|
30
|
+
self.ext = ext
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
class EntryFilter
|
2
|
+
attr_reader :site
|
3
|
+
def initialize(site)
|
4
|
+
@site = site
|
5
|
+
end
|
6
|
+
|
7
|
+
def filter(entries)
|
8
|
+
entries.reject do |e|
|
9
|
+
unless included?(e)
|
10
|
+
special?(e) || backup?(e) || excluded?(e) || symlink?(e)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def included?(entry)
|
16
|
+
site.include.glob_include?(entry)
|
17
|
+
end
|
18
|
+
|
19
|
+
def special?(entry)
|
20
|
+
['.', '_', '#'].include?(entry[0..0])
|
21
|
+
end
|
22
|
+
|
23
|
+
def backup?(entry)
|
24
|
+
entry[-1..-1] == '~'
|
25
|
+
end
|
26
|
+
|
27
|
+
def excluded?(entry)
|
28
|
+
site.exclude.glob_include?(entry)
|
29
|
+
end
|
30
|
+
|
31
|
+
def symlink?(entry)
|
32
|
+
File.symlink?(entry) && site.safe
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
module Tigefa
|
2
|
+
class Excerpt
|
3
|
+
include Convertible
|
4
|
+
|
5
|
+
attr_accessor :post
|
6
|
+
attr_accessor :content, :output, :ext
|
7
|
+
|
8
|
+
# Initialize this Post instance.
|
9
|
+
#
|
10
|
+
# site - The Site.
|
11
|
+
# base - The String path to the dir containing the post file.
|
12
|
+
# name - The String filename of the post file.
|
13
|
+
#
|
14
|
+
# Returns the new Post.
|
15
|
+
def initialize(post)
|
16
|
+
self.post = post
|
17
|
+
self.content = extract_excerpt(post.content)
|
18
|
+
end
|
19
|
+
|
20
|
+
%w[site name ext].each do |meth|
|
21
|
+
define_method(meth) do
|
22
|
+
post.send(meth)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_liquid
|
27
|
+
post.to_liquid(Post::EXCERPT_ATTRIBUTES_FOR_LIQUID)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Fetch YAML front-matter data from related post, without layout key
|
31
|
+
#
|
32
|
+
# Returns Hash of post data
|
33
|
+
def data
|
34
|
+
@data ||= post.data.dup
|
35
|
+
@data.delete("layout")
|
36
|
+
@data
|
37
|
+
end
|
38
|
+
|
39
|
+
# 'Path' of the excerpt.
|
40
|
+
#
|
41
|
+
# Returns the path for the post this excerpt belongs to with #excerpt appended
|
42
|
+
def path
|
43
|
+
File.join(post.path, "#excerpt")
|
44
|
+
end
|
45
|
+
|
46
|
+
# Check if excerpt includes a string
|
47
|
+
#
|
48
|
+
# Returns true if the string passed in
|
49
|
+
def include?(something)
|
50
|
+
(self.output && self.output.include?(something)) || self.content.include?(something)
|
51
|
+
end
|
52
|
+
|
53
|
+
# The UID for this post (useful in feeds).
|
54
|
+
# e.g. /2008/11/05/my-awesome-post
|
55
|
+
#
|
56
|
+
# Returns the String UID.
|
57
|
+
def id
|
58
|
+
File.join(post.dir, post.slug, "#excerpt")
|
59
|
+
end
|
60
|
+
|
61
|
+
def to_s
|
62
|
+
self.output || self.content
|
63
|
+
end
|
64
|
+
|
65
|
+
# Returns the shorthand String identifier of this Post.
|
66
|
+
def inspect
|
67
|
+
"<Excerpt: #{self.id}>"
|
68
|
+
end
|
69
|
+
|
70
|
+
protected
|
71
|
+
|
72
|
+
# Internal: Extract excerpt from the content
|
73
|
+
#
|
74
|
+
# By default excerpt is your first paragraph of a post: everything before
|
75
|
+
# the first two new lines:
|
76
|
+
#
|
77
|
+
# ---
|
78
|
+
# title: Example
|
79
|
+
# ---
|
80
|
+
#
|
81
|
+
# First paragraph with [link][1].
|
82
|
+
#
|
83
|
+
# Second paragraph.
|
84
|
+
#
|
85
|
+
# [1]: http://example.com/
|
86
|
+
#
|
87
|
+
# This is fairly good option for Markdown and Textile files. But might cause
|
88
|
+
# problems for HTML posts (which is quite unusual for Jekyll). If default
|
89
|
+
# excerpt delimiter is not good for you, you might want to set your own via
|
90
|
+
# configuration option `excerpt_separator`. For example, following is a good
|
91
|
+
# alternative for HTML posts:
|
92
|
+
#
|
93
|
+
# # file: _config.yml
|
94
|
+
# excerpt_separator: "<!-- more -->"
|
95
|
+
#
|
96
|
+
# Notice that all markdown-style link references will be appended to the
|
97
|
+
# excerpt. So the example post above will have this excerpt source:
|
98
|
+
#
|
99
|
+
# First paragraph with [link][1].
|
100
|
+
#
|
101
|
+
# [1]: http://example.com/
|
102
|
+
#
|
103
|
+
# Excerpts are rendered same time as content is rendered.
|
104
|
+
#
|
105
|
+
# Returns excerpt String
|
106
|
+
def extract_excerpt(post_content)
|
107
|
+
separator = site.config['excerpt_separator']
|
108
|
+
head, _, tail = post_content.partition(separator)
|
109
|
+
|
110
|
+
"" << head << "\n\n" << tail.scan(/^\[[^\]]+\]:.+$/).join("\n")
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|