jroes-jekyll 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/History.txt +127 -0
  2. data/README.textile +41 -0
  3. data/Rakefile +91 -0
  4. data/VERSION.yml +4 -0
  5. data/bin/jekyll +150 -0
  6. data/lib/jekyll/albino.rb +122 -0
  7. data/lib/jekyll/converters/csv.rb +26 -0
  8. data/lib/jekyll/converters/mephisto.rb +79 -0
  9. data/lib/jekyll/converters/mt.rb +59 -0
  10. data/lib/jekyll/converters/textpattern.rb +50 -0
  11. data/lib/jekyll/converters/typo.rb +49 -0
  12. data/lib/jekyll/converters/wordpress.rb +54 -0
  13. data/lib/jekyll/convertible.rb +82 -0
  14. data/lib/jekyll/core_ext.rb +22 -0
  15. data/lib/jekyll/filters.rb +47 -0
  16. data/lib/jekyll/layout.rb +36 -0
  17. data/lib/jekyll/page.rb +70 -0
  18. data/lib/jekyll/pager.rb +45 -0
  19. data/lib/jekyll/post.rb +247 -0
  20. data/lib/jekyll/site.rb +266 -0
  21. data/lib/jekyll/tags/highlight.rb +56 -0
  22. data/lib/jekyll/tags/include.rb +31 -0
  23. data/lib/jekyll.rb +84 -0
  24. data/test/helper.rb +27 -0
  25. data/test/source/_includes/sig.markdown +3 -0
  26. data/test/source/_layouts/default.html +27 -0
  27. data/test/source/_layouts/simple.html +1 -0
  28. data/test/source/_posts/2008-02-02-not-published.textile +8 -0
  29. data/test/source/_posts/2008-02-02-published.textile +8 -0
  30. data/test/source/_posts/2008-10-18-foo-bar.textile +8 -0
  31. data/test/source/_posts/2008-11-21-complex.textile +8 -0
  32. data/test/source/_posts/2008-12-03-permalinked-post.textile +9 -0
  33. data/test/source/_posts/2008-12-13-include.markdown +8 -0
  34. data/test/source/_posts/2009-01-27-array-categories.textile +10 -0
  35. data/test/source/_posts/2009-01-27-categories.textile +7 -0
  36. data/test/source/_posts/2009-01-27-category.textile +7 -0
  37. data/test/source/_posts/2009-03-12-hash-#1.markdown +6 -0
  38. data/test/source/category/_posts/2008-9-23-categories.textile +6 -0
  39. data/test/source/css/screen.css +76 -0
  40. data/test/source/foo/_posts/bar/2008-12-12-topical-post.textile +8 -0
  41. data/test/source/index.html +22 -0
  42. data/test/source/z_category/_posts/2008-9-23-categories.textile +6 -0
  43. data/test/suite.rb +9 -0
  44. data/test/test_filters.rb +49 -0
  45. data/test/test_post.rb +279 -0
  46. data/test/test_site.rb +69 -0
  47. data/test/test_tags.rb +116 -0
  48. metadata +163 -0
data/History.txt ADDED
@@ -0,0 +1,127 @@
1
+ == 0.5.1
2
+ * Major Enhancements
3
+ * Next/previous posts in site payload [github.com/pantulis, github.com/tomo]
4
+ * Permalink templating system
5
+ * Moved most of the README out to the GitHub wiki
6
+ * Exclude option in configuration so specified files won't be brought over with generated site [github.com/duritong]
7
+ * Bug Fixes
8
+ * Making sure config.yaml references are all gone, using only config.yml
9
+ * Fixed syntax highlighting breaking for UTF-8 code [github.com/henrik]
10
+ * Worked around RDiscount bug that prevents Markdown from getting parsed after highlight [github.com/henrik]
11
+ * CGI escaped post titles [github.com/Chrononaut]
12
+
13
+ == 0.5.0 / 2009-04-07
14
+ * Minor Enhancements
15
+ * Ability to set post categories via YAML [github.com/qrush]
16
+ * Ability to set prevent a post from publishing via YAML [github.com/qrush]
17
+ * Add textilize filter [github.com/willcodeforfoo]
18
+ * Add 'pretty' permalink style for wordpress-like urls [github.com/dysinger]
19
+ * Made it possible to enter categories from YAML as an array [github.com/Chrononaut]
20
+ * Ignore Emacs autosave files [github.com/Chrononaut]
21
+ * Bug Fixes
22
+ * Use block syntax of popen4 to ensure that subprocesses are properly disposed [github.com/jqr]
23
+ * Close open4 streams to prevent zombies [github.com/rtomayko]
24
+ * Only query required fields from the WP Database [github.com/ariejan]
25
+ * Prevent _posts from being copied to the destination directory [github.com/bdimcheff]
26
+ * Refactors
27
+ * Factored the filtering code into a method [github.com/Chrononaut]
28
+ * Fix tests and convert to Shoulda [github.com/qrush, github.com/technicalpickles]
29
+ * Add Cucumber acceptance test suite [github.com/qrush, github.com/technicalpickles]
30
+
31
+ == 0.4.1
32
+ * Minor Enhancements
33
+ * Changed date format on wordpress converter (zeropadding) [github.com/dysinger]
34
+ * Bug Fixes
35
+ * Add jekyll binary as executable to gemspec [github.com/dysinger]
36
+
37
+ == 0.4.0 / 2009-02-03
38
+ * Major Enhancements
39
+ * Switch to Jeweler for packaging tasks
40
+ * Minor Enhancements
41
+ * Type importer [github.com/codeslinger]
42
+ * site.topics accessor [github.com/baz]
43
+ * Add array_to_sentence_string filter [github.com/mchung]
44
+ * Add a converter for textpattern [github.com/PerfectlyNormal]
45
+ * Add a working Mephisto / MySQL converter [github.com/ivey]
46
+ * Allowing .htaccess files to be copied over into the generated site [github.com/briandoll]
47
+ * Add option to not put file date in permalink URL [github.com/mreid]
48
+ * Add line number capabilities to highlight blocks [github.com/jcon]
49
+ * Bug Fixes
50
+ * Fix permalink behavior [github.com/cavalle]
51
+ * Fixed an issue with pygments, markdown, and newlines [github.com/zpinter]
52
+ * Ampersands need to be escaped [github.com/pufuwozu, github.com/ap]
53
+ * Test and fix the site.categories hash [github.com/zzot]
54
+ * Fix site payload available to files [github.com/matrix9180]
55
+
56
+ == 0.3.0 / 2008-12-24
57
+ * Major Enhancements
58
+ * Added --server option to start a simple WEBrick server on destination directory [github.com/johnreilly and github.com/mchung]
59
+ * Minor Enhancements
60
+ * Added post categories based on directories containing _posts [github.com/mreid]
61
+ * Added post topics based on directories underneath _posts
62
+ * Added new date filter that shows the full month name [github.com/mreid]
63
+ * Merge Post's YAML front matter into its to_liquid payload [github.com/remi]
64
+ * Restrict includes to regular files underneath _includes
65
+ * Bug Fixes
66
+ * Change YAML delimiter matcher so as to not chew up 2nd level markdown headers [github.com/mreid]
67
+ * Fix bug that meant page data (such as the date) was not available in templates [github.com/mreid]
68
+ * Properly reject directories in _layouts
69
+
70
+ == 0.2.1 / 2008-12-15
71
+ * Major Changes
72
+ * Use Maruku (pure Ruby) for Markdown by default [github.com/mreid]
73
+ * Allow use of RDiscount with --rdiscount flag
74
+ * Minor Enhancements
75
+ * Don't load directory_watcher unless it's needed [github.com/pjhyett]
76
+
77
+ == 0.2.0 / 2008-12-14
78
+ * Major Changes
79
+ * related_posts is now found in site.related_posts
80
+
81
+ == 0.1.6 / 2008-12-13
82
+ * Major Features
83
+ * Include files in _includes with {% include x.textile %}
84
+
85
+ == 0.1.5 / 2008-12-12
86
+ * Major Features
87
+ * Code highlighting with Pygments if --pygments is specified
88
+ * Disable true LSI by default, enable with --lsi
89
+ * Minor Enhancements
90
+ * Output informative message if RDiscount is not available [github.com/JackDanger]
91
+ * Bug Fixes
92
+ * Prevent Jekyll from picking up the output directory as a source [github.com/JackDanger]
93
+ * Skip related_posts when there is only one post [github.com/JackDanger]
94
+
95
+ == 0.1.4 / 2008-12-08
96
+ * Bug Fixes
97
+ * DATA does not work properly with rubygems
98
+
99
+ == 0.1.3 / 2008-12-06
100
+ * Major Features
101
+ * Markdown support [github.com/vanpelt]
102
+ * Mephisto and CSV converters [github.com/vanpelt]
103
+ * Code hilighting [github.com/vanpelt]
104
+ * Autobuild
105
+ * Bug Fixes
106
+ * Accept both \r\n and \n in YAML header [github.com/vanpelt]
107
+
108
+ == 0.1.2 / 2008-11-22
109
+ * Major Features
110
+ * Add a real "related posts" implementation using Classifier
111
+ * Command Line Changes
112
+ * Allow cli to be called with 0, 1, or 2 args intuiting dir paths
113
+ if they are omitted
114
+
115
+ == 0.1.1 / 2008-11-22
116
+ * Minor Additions
117
+ * Posts now support introspectional data e.g. {{ page.url }}
118
+
119
+ == 0.1.0 / 2008-11-05
120
+ * First release
121
+ * Converts posts written in Textile
122
+ * Converts regular site pages
123
+ * Simple copy of binary files
124
+
125
+ == 0.0.0 / 2008-10-19
126
+ * Birthday!
127
+
data/README.textile ADDED
@@ -0,0 +1,41 @@
1
+ h1. Jekyll
2
+
3
+ By Tom Preston-Werner, Nick Quaranto, and many awesome contributors!
4
+
5
+ Jekyll is a simple, blog aware, static site generator. It takes a template directory (representing the raw form of a website), runs it through Textile or Markdown and Liquid converters, and spits out a complete, static website suitable for serving with Apache or your favorite web server. This is also the engine behind "GitHub Pages":http://pages.github.com, which you can use to host your project's page or blog right here from GitHub.
6
+
7
+ h2. Getting Started
8
+
9
+ * "Install":http://wiki.github.com/mojombo/jekyll/install the gem
10
+ * Read up about its "Usage":http://wiki.github.com/mojombo/jekyll/usage and "Configuration":http://wiki.github.com/mojombo/jekyll/configuration
11
+ * Take a gander at some existing "Sites":http://wiki.github.com/mojombo/jekyll/sites
12
+ * Fork and "Contribute":http://wiki.github.com/mojombo/jekyll/contribute your own modifications
13
+
14
+ h2. Diving In
15
+
16
+ * "Migrate":http://wiki.github.com/mojombo/jekyll/blog-migrations from your previous system
17
+ * Learn how the "YAML Front Matter":http://wiki.github.com/mojombo/jekyll/yaml-front-matter works
18
+ * Put information on your site with "Template Data":http://wiki.github.com/mojombo/jekyll/template-data
19
+ * Customize the "Permalinks":http://wiki.github.com/mojombo/jekyll/permalinks your posts are generated with
20
+ * Use the built-in "Liquid Extensions":http://wiki.github.com/mojombo/jekyll/liquid-extensions to make your life easier
21
+
22
+ h2. Dependencies
23
+
24
+ * RedCloth 4.1.0: Textile support. This version obeys @<notextile>@ tags. The latest version will still work, but tests will fail.
25
+ * Liquid: Templating system
26
+ * Classifier: Generating related posts
27
+ * Maruku: Default markdown engine
28
+ * Directory Watcher: Auto-regeneration of sites
29
+ * Open4: Talking to pygments for syntax highlighting
30
+
31
+ h2. License
32
+
33
+ (The MIT License)
34
+
35
+ Copyright (c) 2008 Tom Preston-Werner
36
+
37
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
38
+
39
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
40
+
41
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,91 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ begin
6
+ gem 'jeweler', '>= 0.11.0'
7
+ require 'jeweler'
8
+ Jeweler::Tasks.new do |s|
9
+ s.name = "jekyll"
10
+ s.summary = %Q{Jekyll is a simple, blog aware, static site generator.}
11
+ s.email = "tom@mojombo.com"
12
+ s.homepage = "http://github.com/mojombo/jekyll"
13
+ s.description = "Jekyll is a simple, blog aware, static site generator."
14
+ s.authors = ["Tom Preston-Werner"]
15
+ s.rubyforge_project = "jekyll"
16
+ s.files.exclude 'test/dest'
17
+ s.test_files.exclude 'test/dest'
18
+ s.add_dependency('RedCloth', '= 4.1.0')
19
+ s.add_dependency('liquid', '>= 1.9.0')
20
+ s.add_dependency('classifier', '>= 1.3.1')
21
+ s.add_dependency('maruku', '>= 0.5.9')
22
+ s.add_dependency('directory_watcher', '>= 1.1.1')
23
+ s.add_dependency('open4', '>= 0.9.6')
24
+ end
25
+ rescue LoadError
26
+ puts "Jeweler not available. Install it with: sudo gem install jeweler --version '>= 0.11.0'"
27
+ exit(1)
28
+ end
29
+
30
+ Rake::TestTask.new do |t|
31
+ t.libs << 'lib'
32
+ t.pattern = 'test/**/test_*.rb'
33
+ t.verbose = false
34
+ end
35
+
36
+ Rake::RDocTask.new do |rdoc|
37
+ rdoc.rdoc_dir = 'rdoc'
38
+ rdoc.title = 'jekyll'
39
+ rdoc.options << '--line-numbers' << '--inline-source'
40
+ rdoc.rdoc_files.include('README*')
41
+ rdoc.rdoc_files.include('lib/**/*.rb')
42
+ end
43
+
44
+ begin
45
+ require 'rcov/rcovtask'
46
+ Rcov::RcovTask.new do |t|
47
+ t.libs << 'test'
48
+ t.test_files = FileList['test/**/test_*.rb']
49
+ t.verbose = true
50
+ end
51
+ rescue LoadError
52
+ end
53
+
54
+ task :default => [:test, :features]
55
+
56
+ # console
57
+
58
+ desc "Open an irb session preloaded with this library"
59
+ task :console do
60
+ sh "irb -rubygems -I lib -r jekyll.rb"
61
+ end
62
+
63
+ # converters
64
+
65
+ namespace :convert do
66
+ desc "Migrate from mephisto in the current directory"
67
+ task :mephisto do
68
+ sh %q(ruby -r './lib/jekyll/converters/mephisto' -e 'Jekyll::Mephisto.postgres(:database => "#{ENV["DB"]}")')
69
+ end
70
+ desc "Migrate from Movable Type in the current directory"
71
+ task :mt do
72
+ sh %q(ruby -r './lib/jekyll/converters/mt' -e 'Jekyll::MT.process("#{ENV["DB"]}", "#{ENV["USER"]}", "#{ENV["PASS"]}")')
73
+ end
74
+ desc "Migrate from Typo in the current directory"
75
+ task :typo do
76
+ sh %q(ruby -r './lib/jekyll/converters/typo' -e 'Jekyll::Typo.process("#{ENV["DB"]}", "#{ENV["USER"]}", "#{ENV["PASS"]}")')
77
+ end
78
+ end
79
+
80
+ begin
81
+ require 'cucumber/rake/task'
82
+
83
+ Cucumber::Rake::Task.new(:features) do |t|
84
+ t.cucumber_opts = "--format progress"
85
+ end
86
+ rescue LoadError
87
+ desc 'Cucumber rake task not available'
88
+ task :features do
89
+ abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin'
90
+ end
91
+ end
data/VERSION.yml ADDED
@@ -0,0 +1,4 @@
1
+ ---
2
+ :major: 0
3
+ :minor: 5
4
+ :patch: 1
data/bin/jekyll ADDED
@@ -0,0 +1,150 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
4
+
5
+ help = <<HELP
6
+ Jekyll is a blog-aware, static site generator.
7
+
8
+ Basic Command Line Usage:
9
+ jekyll # . -> ./_site
10
+ jekyll <path to write generated site> # . -> <path>
11
+ jekyll <path to source> <path to write generated site> # <path> -> <path>
12
+
13
+ Configuration is read from '<source>/_config.yml' but can be overriden
14
+ using the following options:
15
+
16
+ HELP
17
+
18
+ require 'optparse'
19
+ require 'jekyll'
20
+
21
+ exec = {}
22
+ options = {}
23
+ opts = OptionParser.new do |opts|
24
+ opts.banner = help
25
+
26
+ opts.on("--auto", "Auto-regenerate") do
27
+ options['auto'] = true
28
+ end
29
+
30
+ opts.on("--no-auto", "No auto-regenerate") do
31
+ options['auto'] = false
32
+ end
33
+
34
+ opts.on("--server [PORT]", "Start web server (default port 4000)") do |port|
35
+ options['server'] = true
36
+ options['server_port'] = port unless port.nil?
37
+ end
38
+
39
+ opts.on("--lsi", "Use LSI for better related posts") do
40
+ options['lsi'] = true
41
+ end
42
+
43
+ opts.on("--pygments", "Use pygments to highlight code") do
44
+ options['pygments'] = true
45
+ end
46
+
47
+ opts.on("--rdiscount", "Use rdiscount gem for Markdown") do
48
+ options['markdown'] = 'rdiscount'
49
+ end
50
+
51
+ opts.on("--permalink [TYPE]", "Use 'date' (default) for YYYY/MM/DD") do |style|
52
+ options['permalink'] = style unless style.nil?
53
+ end
54
+
55
+ opts.on("--paginate [POSTS_PER_PAGE]", "Paginate a blog's posts") do |per_page|
56
+ begin
57
+ options['paginate'] = per_page.to_i
58
+ raise ArgumentError if options['paginate'] == 0
59
+ rescue
60
+ puts 'you must specify a number of posts by page bigger than 0'
61
+ exit 0
62
+ end
63
+ end
64
+
65
+ opts.on("--version", "Display current version") do
66
+ puts "Jekyll " + Jekyll.version
67
+ exit 0
68
+ end
69
+ end
70
+
71
+ # Read command line options into `options` hash
72
+ opts.parse!
73
+
74
+ # Get source and destintation from command line
75
+ case ARGV.size
76
+ when 0
77
+ when 1
78
+ options['destination'] = ARGV[0]
79
+ when 2
80
+ options['source'] = ARGV[0]
81
+ options['destination'] = ARGV[1]
82
+ else
83
+ puts "Invalid options. Run `jekyll --help` for assistance."
84
+ exit(1)
85
+ end
86
+
87
+ options = Jekyll.configuration(options)
88
+
89
+ # Get source and destination directories (possibly set by config file)
90
+ source = options['source']
91
+ destination = options['destination']
92
+
93
+ # Files to watch
94
+ def globs(source)
95
+ Dir.chdir(source) do
96
+ dirs = Dir['*'].select { |x| File.directory?(x) }
97
+ dirs -= ['_site']
98
+ dirs = dirs.map { |x| "#{x}/**/*" }
99
+ dirs += ['*']
100
+ end
101
+ end
102
+
103
+ # Create the Site
104
+ site = Jekyll::Site.new(options)
105
+
106
+ # Run the directory watcher for auto-generation, if required
107
+ if options['auto']
108
+ require 'directory_watcher'
109
+
110
+ puts "Auto-regenerating enabled: #{source} -> #{destination}"
111
+
112
+ dw = DirectoryWatcher.new(source)
113
+ dw.interval = 1
114
+ dw.glob = globs(source)
115
+
116
+ dw.add_observer do |*args|
117
+ t = Time.now.strftime("%Y-%m-%d %H:%M:%S")
118
+ puts "[#{t}] regeneration: #{args.size} files changed"
119
+ site.process
120
+ end
121
+
122
+ dw.start
123
+
124
+ unless options['server']
125
+ loop { sleep 1000 }
126
+ end
127
+ else
128
+ puts "Building site: #{source} -> #{destination}"
129
+ site.process
130
+ puts "Successfully generated site: #{source} -> #{destination}"
131
+ end
132
+
133
+ # Run the server on the specified port, if required
134
+ if options['server']
135
+ require 'webrick'
136
+ include WEBrick
137
+
138
+ FileUtils.mkdir_p(destination)
139
+
140
+ s = HTTPServer.new(
141
+ :Port => options['server_port'],
142
+ :DocumentRoot => destination
143
+ )
144
+ t = Thread.new {
145
+ s.start
146
+ }
147
+
148
+ trap("INT") { s.shutdown }
149
+ t.join()
150
+ end
@@ -0,0 +1,122 @@
1
+ ##
2
+ # Wrapper for the Pygments command line tool, pygmentize.
3
+ #
4
+ # Pygments: http://pygments.org/
5
+ #
6
+ # Assumes pygmentize is in the path. If not, set its location
7
+ # with Albino.bin = '/path/to/pygmentize'
8
+ #
9
+ # Use like so:
10
+ #
11
+ # @syntaxer = Albino.new('/some/file.rb', :ruby)
12
+ # puts @syntaxer.colorize
13
+ #
14
+ # This'll print out an HTMLized, Ruby-highlighted version
15
+ # of '/some/file.rb'.
16
+ #
17
+ # To use another formatter, pass it as the third argument:
18
+ #
19
+ # @syntaxer = Albino.new('/some/file.rb', :ruby, :bbcode)
20
+ # puts @syntaxer.colorize
21
+ #
22
+ # You can also use the #colorize class method:
23
+ #
24
+ # puts Albino.colorize('/some/file.rb', :ruby)
25
+ #
26
+ # Another also: you get a #to_s, for somewhat nicer use in Rails views.
27
+ #
28
+ # ... helper file ...
29
+ # def highlight(text)
30
+ # Albino.new(text, :ruby)
31
+ # end
32
+ #
33
+ # ... view file ...
34
+ # <%= highlight text %>
35
+ #
36
+ # The default lexer is 'text'. You need to specify a lexer yourself;
37
+ # because we are using STDIN there is no auto-detect.
38
+ #
39
+ # To see all lexers and formatters available, run `pygmentize -L`.
40
+ #
41
+ # Chris Wanstrath // chris@ozmm.org
42
+ # GitHub // http://github.com
43
+ #
44
+ require 'open4'
45
+
46
+ class Albino
47
+ @@bin = Rails.development? ? 'pygmentize' : '/usr/bin/pygmentize' rescue 'pygmentize'
48
+
49
+ def self.bin=(path)
50
+ @@bin = path
51
+ end
52
+
53
+ def self.colorize(*args)
54
+ new(*args).colorize
55
+ end
56
+
57
+ def initialize(target, lexer = :text, format = :html)
58
+ @target = File.exists?(target) ? File.read(target) : target rescue target
59
+ @options = { :l => lexer, :f => format, :O => 'encoding=utf-8' }
60
+ end
61
+
62
+ def execute(command)
63
+ output = ''
64
+ Open4.popen4(command) do |pid, stdin, stdout, stderr|
65
+ stdin.puts @target
66
+ stdin.close
67
+ output = stdout.read.strip
68
+ [stdout, stderr].each { |io| io.close }
69
+ end
70
+ output
71
+ end
72
+
73
+ def colorize(options = {})
74
+ html = execute(@@bin + convert_options(options))
75
+ # Work around an RDiscount bug: http://gist.github.com/97682
76
+ html.to_s.sub(%r{</pre></div>\Z}, "</pre>\n</div>")
77
+ end
78
+ alias_method :to_s, :colorize
79
+
80
+ def convert_options(options = {})
81
+ @options.merge(options).inject('') do |string, (flag, value)|
82
+ string + " -#{flag} #{value}"
83
+ end
84
+ end
85
+ end
86
+
87
+ if $0 == __FILE__
88
+ require 'rubygems'
89
+ require 'test/spec'
90
+ require 'mocha'
91
+ begin require 'redgreen'; rescue LoadError; end
92
+
93
+ context "Albino" do
94
+ setup do
95
+ @syntaxer = Albino.new(__FILE__, :ruby)
96
+ end
97
+
98
+ specify "defaults to text" do
99
+ syntaxer = Albino.new(__FILE__)
100
+ syntaxer.expects(:execute).with('pygmentize -f html -l text').returns(true)
101
+ syntaxer.colorize
102
+ end
103
+
104
+ specify "accepts options" do
105
+ @syntaxer.expects(:execute).with('pygmentize -f html -l ruby').returns(true)
106
+ @syntaxer.colorize
107
+ end
108
+
109
+ specify "works with strings" do
110
+ syntaxer = Albino.new('class New; end', :ruby)
111
+ assert_match %r(highlight), syntaxer.colorize
112
+ end
113
+
114
+ specify "aliases to_s" do
115
+ assert_equal @syntaxer.colorize, @syntaxer.to_s
116
+ end
117
+
118
+ specify "class method colorize" do
119
+ assert_equal @syntaxer.colorize, Albino.colorize(__FILE__, :ruby)
120
+ end
121
+ end
122
+ 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
@@ -0,0 +1,79 @@
1
+ # Quickly hacked together my Michael Ivey
2
+ # Based on mt.rb by Nick Gerakines, open source and publically
3
+ # available under the MIT license. Use this module at your own risk.
4
+
5
+ require 'rubygems'
6
+ require 'sequel'
7
+ require 'fastercsv'
8
+ require 'fileutils'
9
+ require File.join(File.dirname(__FILE__),"csv.rb")
10
+
11
+ # NOTE: This converter requires Sequel and the MySQL gems.
12
+ # The MySQL gem can be difficult to install on OS X. Once you have MySQL
13
+ # installed, running the following commands should work:
14
+ # $ sudo gem install sequel
15
+ # $ sudo gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
16
+
17
+ module Jekyll
18
+ module Mephisto
19
+ #Accepts a hash with database config variables, exports mephisto posts into a csv
20
+ #export PGPASSWORD if you must
21
+ def self.postgres(c)
22
+ sql = <<-SQL
23
+ BEGIN;
24
+ CREATE TEMP TABLE jekyll AS
25
+ SELECT title, permalink, body, published_at, filter FROM contents
26
+ WHERE user_id = 1 AND type = 'Article' ORDER BY published_at;
27
+ COPY jekyll TO STDOUT WITH CSV HEADER;
28
+ ROLLBACK;
29
+ SQL
30
+ command = %Q(psql -h #{c[:host] || "localhost"} -c "#{sql.strip}" #{c[:database]} #{c[:username]} -o #{c[:filename] || "posts.csv"})
31
+ puts command
32
+ `#{command}`
33
+ CSV.process
34
+ end
35
+
36
+ # This query will pull blog posts from all entries across all blogs. If
37
+ # you've got unpublished, deleted or otherwise hidden posts please sift
38
+ # through the created posts to make sure nothing is accidently published.
39
+
40
+ QUERY = "SELECT id, permalink, body, published_at, title FROM contents WHERE user_id = 1 AND type = 'Article' AND published_at IS NOT NULL ORDER BY published_at"
41
+
42
+ def self.process(dbname, user, pass, host = 'localhost')
43
+ db = Sequel.mysql(dbname, :user => user, :password => pass, :host => host)
44
+
45
+ FileUtils.mkdir_p "_posts"
46
+
47
+ db[QUERY].each do |post|
48
+ title = post[:title]
49
+ slug = post[:permalink]
50
+ date = post[:published_at]
51
+ content = post[:body]
52
+ # more_content = ''
53
+
54
+ # Be sure to include the body and extended body.
55
+ # if more_content != nil
56
+ # content = content + " \n" + more_content
57
+ # end
58
+
59
+ # Ideally, this script would determine the post format (markdown, html
60
+ # , etc) and create files with proper extensions. At this point it
61
+ # just assumes that markdown will be acceptable.
62
+ name = [date.year, date.month, date.day, slug].join('-') + ".markdown"
63
+
64
+ data = {
65
+ 'layout' => 'post',
66
+ 'title' => title.to_s,
67
+ 'mt_id' => post[:entry_id],
68
+ }.delete_if { |k,v| v.nil? || v == ''}.to_yaml
69
+
70
+ File.open("_posts/#{name}", "w") do |f|
71
+ f.puts data
72
+ f.puts "---"
73
+ f.puts content
74
+ end
75
+ end
76
+
77
+ end
78
+ end
79
+ end