realityforge-jekyll 0.7.1-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. data/History.txt +255 -0
  2. data/LICENSE +21 -0
  3. data/README.textile +41 -0
  4. data/Rakefile +159 -0
  5. data/bin/jekyll +178 -0
  6. data/cucumber.yml +1 -0
  7. data/features/create_sites.feature +94 -0
  8. data/features/embed_filters.feature +60 -0
  9. data/features/markdown.feature +30 -0
  10. data/features/pagination.feature +27 -0
  11. data/features/permalinks.feature +65 -0
  12. data/features/post_data.feature +153 -0
  13. data/features/site_configuration.feature +103 -0
  14. data/features/site_data.feature +82 -0
  15. data/features/step_definitions/jekyll_steps.rb +145 -0
  16. data/features/support/env.rb +16 -0
  17. data/jekyll.gemspec +135 -0
  18. data/lib/jekyll.rb +109 -0
  19. data/lib/jekyll/albino.rb +120 -0
  20. data/lib/jekyll/converter.rb +50 -0
  21. data/lib/jekyll/converters/identity.rb +22 -0
  22. data/lib/jekyll/converters/markdown.rb +80 -0
  23. data/lib/jekyll/converters/textile.rb +33 -0
  24. data/lib/jekyll/convertible.rb +82 -0
  25. data/lib/jekyll/core_ext.rb +52 -0
  26. data/lib/jekyll/errors.rb +6 -0
  27. data/lib/jekyll/filters.rb +47 -0
  28. data/lib/jekyll/generator.rb +7 -0
  29. data/lib/jekyll/generators/pagination.rb +87 -0
  30. data/lib/jekyll/layout.rb +36 -0
  31. data/lib/jekyll/migrators/csv.rb +26 -0
  32. data/lib/jekyll/migrators/mephisto.rb +79 -0
  33. data/lib/jekyll/migrators/mt.rb +59 -0
  34. data/lib/jekyll/migrators/textpattern.rb +50 -0
  35. data/lib/jekyll/migrators/typo.rb +49 -0
  36. data/lib/jekyll/migrators/wordpress.rb +55 -0
  37. data/lib/jekyll/page.rb +133 -0
  38. data/lib/jekyll/plugin.rb +76 -0
  39. data/lib/jekyll/post.rb +242 -0
  40. data/lib/jekyll/site.rb +235 -0
  41. data/lib/jekyll/static_file.rb +76 -0
  42. data/lib/jekyll/tags/highlight.rb +73 -0
  43. data/lib/jekyll/tags/include.rb +31 -0
  44. data/test/helper.rb +33 -0
  45. data/test/source/_includes/sig.markdown +3 -0
  46. data/test/source/_layouts/default.html +27 -0
  47. data/test/source/_layouts/simple.html +1 -0
  48. data/test/source/_posts/2008-02-02-not-published.textile +8 -0
  49. data/test/source/_posts/2008-02-02-published.textile +8 -0
  50. data/test/source/_posts/2008-10-18-foo-bar.textile +8 -0
  51. data/test/source/_posts/2008-11-21-complex.textile +8 -0
  52. data/test/source/_posts/2008-12-03-permalinked-post.textile +9 -0
  53. data/test/source/_posts/2008-12-13-include.markdown +8 -0
  54. data/test/source/_posts/2009-01-27-array-categories.textile +10 -0
  55. data/test/source/_posts/2009-01-27-categories.textile +7 -0
  56. data/test/source/_posts/2009-01-27-category.textile +7 -0
  57. data/test/source/_posts/2009-01-27-empty-categories.textile +7 -0
  58. data/test/source/_posts/2009-01-27-empty-category.textile +7 -0
  59. data/test/source/_posts/2009-03-12-hash-#1.markdown +6 -0
  60. data/test/source/_posts/2009-05-18-empty-tag.textile +6 -0
  61. data/test/source/_posts/2009-05-18-empty-tags.textile +6 -0
  62. data/test/source/_posts/2009-05-18-tag.textile +6 -0
  63. data/test/source/_posts/2009-05-18-tags.textile +9 -0
  64. data/test/source/_posts/2009-06-22-empty-yaml.textile +3 -0
  65. data/test/source/_posts/2009-06-22-no-yaml.textile +1 -0
  66. data/test/source/_posts/2010-01-08-triple-dash.markdown +5 -0
  67. data/test/source/_posts/2010-01-09-date-override.textile +7 -0
  68. data/test/source/_posts/2010-01-09-time-override.textile +7 -0
  69. data/test/source/_posts/2010-01-09-timezone-override.textile +7 -0
  70. data/test/source/_posts/2010-01-16-override-data.textile +4 -0
  71. data/test/source/about.html +6 -0
  72. data/test/source/category/_posts/2008-9-23-categories.textile +6 -0
  73. data/test/source/contacts.html +5 -0
  74. data/test/source/css/screen.css +76 -0
  75. data/test/source/foo/_posts/bar/2008-12-12-topical-post.textile +8 -0
  76. data/test/source/index.html +22 -0
  77. data/test/source/sitemap.xml +32 -0
  78. data/test/source/win/_posts/2009-05-24-yaml-linebreak.markdown +7 -0
  79. data/test/source/z_category/_posts/2008-9-23-categories.textile +6 -0
  80. data/test/suite.rb +9 -0
  81. data/test/test_configuration.rb +29 -0
  82. data/test/test_core_ext.rb +66 -0
  83. data/test/test_filters.rb +49 -0
  84. data/test/test_generated_site.rb +44 -0
  85. data/test/test_page.rb +98 -0
  86. data/test/test_pager.rb +113 -0
  87. data/test/test_post.rb +396 -0
  88. data/test/test_rdiscount.rb +18 -0
  89. data/test/test_site.rb +153 -0
  90. data/test/test_tags.rb +116 -0
  91. metadata +282 -0
@@ -0,0 +1,80 @@
1
+ module Jekyll
2
+
3
+ class MarkdownConverter < Converter
4
+ safe true
5
+
6
+ pygments_prefix "\n"
7
+ pygments_suffix "\n"
8
+
9
+ def setup
10
+ return if @setup
11
+ # Set the Markdown interpreter (and Maruku self.config, if necessary)
12
+ case @config['markdown']
13
+ when 'rdiscount'
14
+ begin
15
+ require 'rdiscount'
16
+
17
+ # Load rdiscount extensions
18
+ @rdiscount_extensions = @config['rdiscount']['extensions'].map { |e| e.to_sym }
19
+ rescue LoadError
20
+ STDERR.puts 'You are missing a library required for Markdown. Please run:'
21
+ STDERR.puts ' $ [sudo] gem install rdiscount'
22
+ raise FatalException.new("Missing dependency: rdiscount")
23
+ end
24
+ when 'maruku'
25
+ begin
26
+ require 'maruku'
27
+
28
+ if @config['maruku']['use_divs']
29
+ require 'maruku/ext/div'
30
+ STDERR.puts 'Maruku: Using extended syntax for div elements.'
31
+ end
32
+
33
+ if @config['maruku']['use_tex']
34
+ require 'maruku/ext/math'
35
+ STDERR.puts "Maruku: Using LaTeX extension. Images in `#{@config['maruku']['png_dir']}`."
36
+
37
+ # Switch off MathML output
38
+ MaRuKu::Globals[:html_math_output_mathml] = false
39
+ MaRuKu::Globals[:html_math_engine] = 'none'
40
+
41
+ # Turn on math to PNG support with blahtex
42
+ # Resulting PNGs stored in `images/latex`
43
+ MaRuKu::Globals[:html_math_output_png] = true
44
+ MaRuKu::Globals[:html_png_engine] = @config['maruku']['png_engine']
45
+ MaRuKu::Globals[:html_png_dir] = @config['maruku']['png_dir']
46
+ MaRuKu::Globals[:html_png_url] = @config['maruku']['png_url']
47
+ end
48
+ rescue LoadError
49
+ STDERR.puts 'You are missing a library required for Markdown. Please run:'
50
+ STDERR.puts ' $ [sudo] gem install maruku'
51
+ raise FatalException.new("Missing dependency: maruku")
52
+ end
53
+ else
54
+ STDERR.puts "Invalid Markdown processor: #{@config['markdown']}"
55
+ STDERR.puts " Valid options are [ maruku | rdiscount ]"
56
+ raise FatalException.new("Invalid Markdown process: #{@config['markdown']}")
57
+ end
58
+ @setup = true
59
+ end
60
+
61
+ def matches(ext)
62
+ ext =~ /(markdown|mkdn?|md)/i
63
+ end
64
+
65
+ def output_ext(ext)
66
+ ".html"
67
+ end
68
+
69
+ def convert(content)
70
+ setup
71
+ case @config['markdown']
72
+ when 'rdiscount'
73
+ RDiscount.new(content, *@rdiscount_extensions).to_html
74
+ when 'maruku'
75
+ Maruku.new(content).to_html
76
+ end
77
+ end
78
+ end
79
+
80
+ end
@@ -0,0 +1,33 @@
1
+ module Jekyll
2
+
3
+ class TextileConverter < 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
+ ext =~ /textile/i
21
+ end
22
+
23
+ def output_ext(ext)
24
+ ".html"
25
+ end
26
+
27
+ def convert(content)
28
+ setup
29
+ RedCloth.new(content).to_html
30
+ end
31
+ end
32
+
33
+ end
@@ -0,0 +1,82 @@
1
+ # Convertible provides methods for converting a pagelike item
2
+ # from a certain type of markup into actual content
3
+ #
4
+ # Requires
5
+ # self.site -> Jekyll::Site
6
+ # self.content
7
+ # self.content=
8
+ # self.data=
9
+ # self.ext=
10
+ # self.output=
11
+ module Jekyll
12
+ module Convertible
13
+ # Return the contents as a string
14
+ def to_s
15
+ self.content || ''
16
+ end
17
+
18
+ # Read the YAML frontmatter
19
+ # +base+ is the String path to the dir containing the file
20
+ # +name+ is the String filename of the file
21
+ #
22
+ # Returns nothing
23
+ def read_yaml(base, name)
24
+ self.content = File.read(File.join(base, name))
25
+
26
+ if self.content =~ /^(---\s*\n.*?\n?)^(---\s*$\n?)/m
27
+ self.content = self.content[($1.size + $2.size)..-1]
28
+
29
+ self.data = YAML.load($1)
30
+ end
31
+
32
+ self.data ||= {}
33
+ end
34
+
35
+ # Transform the contents based on the content type.
36
+ #
37
+ # Returns nothing
38
+ def transform
39
+ self.content = converter.convert(self.content)
40
+ end
41
+
42
+ # Determine the extension depending on content_type
43
+ #
44
+ # Returns the extensions for the output file
45
+ def output_ext
46
+ converter.output_ext(self.ext)
47
+ end
48
+
49
+ # Determine which converter to use based on this convertible's
50
+ # extension
51
+ def converter
52
+ @converter ||= self.site.converters.find { |c| c.matches(self.ext) }
53
+ end
54
+
55
+ # Add any necessary layouts to this convertible document
56
+ # +layouts+ is a Hash of {"name" => "layout"}
57
+ # +site_payload+ is the site payload hash
58
+ #
59
+ # Returns nothing
60
+ def do_layout(payload, layouts)
61
+ info = { :filters => [Jekyll::Filters], :registers => { :site => self.site } }
62
+
63
+ # render and transform content (this becomes the final content of the object)
64
+ payload["pygments_prefix"] = converter.pygments_prefix
65
+ payload["pygments_suffix"] = converter.pygments_suffix
66
+ self.content = Liquid::Template.parse(self.content).render(payload, info)
67
+ self.transform
68
+
69
+ # output keeps track of what will finally be written
70
+ self.output = self.content
71
+
72
+ # recursively render layouts
73
+ layout = layouts[self.data["layout"]]
74
+ while layout
75
+ payload = payload.deep_merge({"content" => self.output, "page" => layout.data})
76
+ self.output = Liquid::Template.parse(layout.content).render(payload, info)
77
+
78
+ layout = layouts[layout.data["layout"]]
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,52 @@
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 singular 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
+ end
45
+
46
+ # Thanks, ActiveSupport!
47
+ class Date
48
+ # Converts datetime to an appropriate format for use in XML
49
+ def xmlschema
50
+ strftime("%Y-%m-%dT%H:%M:%S%Z")
51
+ end if RUBY_VERSION < '1.9'
52
+ end
@@ -0,0 +1,6 @@
1
+ module Jekyll
2
+
3
+ class FatalException < StandardError
4
+ end
5
+
6
+ end
@@ -0,0 +1,47 @@
1
+ module Jekyll
2
+
3
+ module Filters
4
+ def textilize(input)
5
+ TextileConverter.new.convert(input)
6
+ end
7
+
8
+ def date_to_string(date)
9
+ date.strftime("%d %b %Y")
10
+ end
11
+
12
+ def date_to_long_string(date)
13
+ date.strftime("%d %B %Y")
14
+ end
15
+
16
+ def date_to_xmlschema(date)
17
+ date.xmlschema
18
+ end
19
+
20
+ def xml_escape(input)
21
+ CGI.escapeHTML(input)
22
+ end
23
+
24
+ def cgi_escape(input)
25
+ CGI::escape(input)
26
+ end
27
+
28
+ def number_of_words(input)
29
+ input.split.length
30
+ end
31
+
32
+ def array_to_sentence_string(array)
33
+ connector = "and"
34
+ case array.length
35
+ when 0
36
+ ""
37
+ when 1
38
+ array[0].to_s
39
+ when 2
40
+ "#{array[0]} #{connector} #{array[1]}"
41
+ else
42
+ "#{array[0...-1].join(', ')}, #{connector} #{array[-1]}"
43
+ end
44
+ end
45
+
46
+ end
47
+ end
@@ -0,0 +1,7 @@
1
+ module Jekyll
2
+
3
+ class Generator < Plugin
4
+
5
+ end
6
+
7
+ end
@@ -0,0 +1,87 @@
1
+ module Jekyll
2
+
3
+ class Pagination < Generator
4
+ safe true
5
+
6
+ def generate(site)
7
+ site.pages.dup.each do |page|
8
+ paginate(site, page) if Pager.pagination_enabled?(site.config, page.name)
9
+ end
10
+ end
11
+
12
+ # Paginates the blog's posts. Renders the index.html file into paginated
13
+ # directories, ie: page2/index.html, page3/index.html, etc and adds more
14
+ # site-wide data.
15
+ # +page+ is the index.html Page that requires pagination
16
+ #
17
+ # {"paginator" => { "page" => <Number>,
18
+ # "per_page" => <Number>,
19
+ # "posts" => [<Post>],
20
+ # "total_posts" => <Number>,
21
+ # "total_pages" => <Number>,
22
+ # "previous_page" => <Number>,
23
+ # "next_page" => <Number> }}
24
+ def paginate(site, page)
25
+ all_posts = site.site_payload['site']['posts']
26
+ pages = Pager.calculate_pages(all_posts, site.config['paginate'].to_i)
27
+ (1..pages).each do |num_page|
28
+ pager = Pager.new(site.config, num_page, all_posts, pages)
29
+ if num_page > 1
30
+ newpage = Page.new(site, site.source, page.dir, page.name)
31
+ newpage.pager = pager
32
+ newpage.dir = File.join(page.dir, "page#{num_page}")
33
+ site.pages << newpage
34
+ else
35
+ page.pager = pager
36
+ end
37
+ end
38
+ end
39
+
40
+ end
41
+
42
+ class Pager
43
+ attr_reader :page, :per_page, :posts, :total_posts, :total_pages, :previous_page, :next_page
44
+
45
+ def self.calculate_pages(all_posts, per_page)
46
+ num_pages = all_posts.size / per_page.to_i
47
+ num_pages = num_pages + 1 if all_posts.size % per_page.to_i != 0
48
+ num_pages
49
+ end
50
+
51
+ def self.pagination_enabled?(config, file)
52
+ file == 'index.html' && !config['paginate'].nil?
53
+ end
54
+
55
+ def initialize(config, page, all_posts, num_pages = nil)
56
+ @page = page
57
+ @per_page = config['paginate'].to_i
58
+ @total_pages = num_pages || Pager.calculate_pages(all_posts, @per_page)
59
+
60
+ if @page > @total_pages
61
+ raise RuntimeError, "page number can't be greater than total pages: #{@page} > #{@total_pages}"
62
+ end
63
+
64
+ init = (@page - 1) * @per_page
65
+ offset = (init + @per_page - 1) >= all_posts.size ? all_posts.size : (init + @per_page - 1)
66
+
67
+ @total_posts = all_posts.size
68
+ @posts = all_posts[init..offset]
69
+ @previous_page = @page != 1 ? @page - 1 : nil
70
+ @next_page = @page != @total_pages ? @page + 1 : nil
71
+ end
72
+
73
+ def to_liquid
74
+ {
75
+ 'page' => page,
76
+ 'per_page' => per_page,
77
+ 'posts' => posts,
78
+ 'total_posts' => total_posts,
79
+ 'total_pages' => total_pages,
80
+ 'previous_page' => previous_page,
81
+ 'next_page' => next_page
82
+ }
83
+ end
84
+ end
85
+
86
+
87
+ end
@@ -0,0 +1,36 @@
1
+ module Jekyll
2
+
3
+ class Layout
4
+ include Convertible
5
+
6
+ attr_accessor :site
7
+ attr_accessor :ext
8
+ attr_accessor :data, :content
9
+
10
+ # Initialize a new Layout.
11
+ # +site+ is the Site
12
+ # +base+ is the String path to the <source>
13
+ # +name+ is the String filename of the post file
14
+ #
15
+ # Returns <Page>
16
+ def initialize(site, base, name)
17
+ @site = site
18
+ @base = base
19
+ @name = name
20
+
21
+ self.data = {}
22
+
23
+ self.process(name)
24
+ self.read_yaml(base, name)
25
+ end
26
+
27
+ # Extract information from the layout filename
28
+ # +name+ is the String filename of the layout file
29
+ #
30
+ # Returns nothing
31
+ def process(name)
32
+ self.ext = File.extname(name)
33
+ end
34
+ end
35
+
36
+ end
@@ -0,0 +1,26 @@
1
+ module Jekyll
2
+ module CSV
3
+ #Reads a csv with title, permalink, body, published_at, and filter.
4
+ #It creates a post file for each row in the csv
5
+ def self.process(file = "posts.csv")
6
+ FileUtils.mkdir_p "_posts"
7
+ posts = 0
8
+ FasterCSV.foreach(file) do |row|
9
+ next if row[0] == "title"
10
+ posts += 1
11
+ name = row[3].split(" ")[0]+"-"+row[1]+(row[4] =~ /markdown/ ? ".markdown" : ".textile")
12
+ File.open("_posts/#{name}", "w") do |f|
13
+ f.puts <<-HEADER
14
+ ---
15
+ layout: post
16
+ title: #{row[0]}
17
+ ---
18
+
19
+ HEADER
20
+ f.puts row[2]
21
+ end
22
+ end
23
+ "Created #{posts} posts!"
24
+ end
25
+ end
26
+ end