matflores-jekyll 0.4.3 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -13,7 +13,7 @@ require File.join(File.dirname(__FILE__),"csv.rb")
13
13
  # installed, running the following commands should work:
14
14
  # $ sudo gem install sequel
15
15
  # $ sudo gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
16
-
16
+
17
17
  module Jekyll
18
18
  module Mephisto
19
19
  #Accepts a hash with database config variables, exports mephisto posts into a csv
@@ -38,24 +38,24 @@ module Jekyll
38
38
  # through the created posts to make sure nothing is accidently published.
39
39
 
40
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
-
41
+
42
42
  def self.process(dbname, user, pass, host = 'localhost')
43
43
  db = Sequel.mysql(dbname, :user => user, :password => pass, :host => host)
44
-
44
+
45
45
  FileUtils.mkdir_p "_posts"
46
-
46
+
47
47
  db[QUERY].each do |post|
48
48
  title = post[:title]
49
49
  slug = post[:permalink]
50
50
  date = post[:published_at]
51
51
  content = post[:body]
52
52
  # more_content = ''
53
-
53
+
54
54
  # Be sure to include the body and extended body.
55
55
  # if more_content != nil
56
56
  # content = content + " \n" + more_content
57
57
  # end
58
-
58
+
59
59
  # Ideally, this script would determine the post format (markdown, html
60
60
  # , etc) and create files with proper extensions. At this point it
61
61
  # just assumes that markdown will be acceptable.
@@ -66,14 +66,14 @@ module Jekyll
66
66
  'title' => title.to_s,
67
67
  'mt_id' => post[:entry_id],
68
68
  }.delete_if { |k,v| v.nil? || v == ''}.to_yaml
69
-
69
+
70
70
  File.open("_posts/#{name}", "w") do |f|
71
71
  f.puts data
72
72
  f.puts "---"
73
73
  f.puts content
74
74
  end
75
75
  end
76
-
76
+
77
77
  end
78
78
  end
79
79
  end
@@ -11,31 +11,31 @@ require 'fileutils'
11
11
  # installed, running the following commands should work:
12
12
  # $ sudo gem install sequel
13
13
  # $ sudo gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
14
-
14
+
15
15
  module Jekyll
16
16
  module MT
17
17
  # This query will pull blog posts from all entries across all blogs. If
18
18
  # you've got unpublished, deleted or otherwise hidden posts please sift
19
19
  # through the created posts to make sure nothing is accidently published.
20
20
  QUERY = "SELECT entry_id, entry_basename, entry_text, entry_text_more, entry_created_on, entry_title FROM mt_entry"
21
-
21
+
22
22
  def self.process(dbname, user, pass, host = 'localhost')
23
23
  db = Sequel.mysql(dbname, :user => user, :password => pass, :host => host)
24
-
24
+
25
25
  FileUtils.mkdir_p "_posts"
26
-
26
+
27
27
  db[QUERY].each do |post|
28
28
  title = post[:entry_title]
29
29
  slug = post[:entry_basename]
30
30
  date = post[:entry_created_on]
31
31
  content = post[:entry_text]
32
32
  more_content = post[:entry_text_more]
33
-
33
+
34
34
  # Be sure to include the body and extended body.
35
35
  if more_content != nil
36
36
  content = content + " \n" + more_content
37
37
  end
38
-
38
+
39
39
  # Ideally, this script would determine the post format (markdown, html
40
40
  # , etc) and create files with proper extensions. At this point it
41
41
  # just assumes that markdown will be acceptable.
@@ -46,14 +46,14 @@ module Jekyll
46
46
  'title' => title.to_s,
47
47
  'mt_id' => post[:entry_id],
48
48
  }.delete_if { |k,v| v.nil? || v == ''}.to_yaml
49
-
49
+
50
50
  File.open("_posts/#{name}", "w") do |f|
51
51
  f.puts data
52
52
  f.puts "---"
53
53
  f.puts content
54
54
  end
55
55
  end
56
-
56
+
57
57
  end
58
58
  end
59
59
  end
@@ -18,20 +18,20 @@ module Jekyll
18
18
 
19
19
  def self.process(dbname, user, pass, host = 'localhost')
20
20
  db = Sequel.mysql(dbname, :user => user, :password => pass, :host => host)
21
-
21
+
22
22
  FileUtils.mkdir_p "_posts"
23
-
23
+
24
24
  db[QUERY].each do |post|
25
25
  # Get required fields and construct Jekyll compatible name
26
26
  title = post[:Title]
27
27
  slug = post[:url_title]
28
28
  date = post[:Posted]
29
29
  content = post[:Body]
30
-
30
+
31
31
  name = [date.strftime("%Y-%m-%d"), slug].join('-') + ".textile"
32
32
 
33
33
  # Get the relevant fields as a hash, delete empty fields and convert
34
- # to YAML for the header
34
+ # to YAML for the header
35
35
  data = {
36
36
  'layout' => 'post',
37
37
  'title' => title.to_s,
@@ -2,22 +2,22 @@
2
2
  require 'fileutils'
3
3
  require 'rubygems'
4
4
  require 'sequel'
5
-
5
+
6
6
  module Jekyll
7
7
  module Typo
8
- # this SQL *should* work for both MySQL and PostgreSQL, but I haven't
8
+ # this SQL *should* work for both MySQL and PostgreSQL, but I haven't
9
9
  # tested PostgreSQL yet (as of 2008-12-16)
10
10
  SQL = <<-EOS
11
11
  SELECT c.id id,
12
- c.title title,
13
- c.permalink slug,
12
+ c.title title,
13
+ c.permalink slug,
14
14
  c.body body,
15
- c.published_at date,
15
+ c.published_at date,
16
16
  c.state state,
17
17
  COALESCE(tf.name, 'html') filter
18
- FROM contents c
18
+ FROM contents c
19
19
  LEFT OUTER JOIN text_filters tf
20
- ON c.text_filter_id = tf.id
20
+ ON c.text_filter_id = tf.id
21
21
  EOS
22
22
 
23
23
  def self.process dbname, user, pass, host='localhost'
@@ -30,7 +30,7 @@ module Jekyll
30
30
  sprintf("%.02d", post[:date].month),
31
31
  sprintf("%.02d", post[:date].day),
32
32
  post[:slug].strip ].join('-')
33
- # Can have more than one text filter in this field, but we just want
33
+ # Can have more than one text filter in this field, but we just want
34
34
  # the first one for this
35
35
  name += '.' + post[:filter].split(' ')[0]
36
36
 
@@ -28,7 +28,6 @@ module Jekyll
28
28
  slug = post[:post_name]
29
29
  date = post[:post_date]
30
30
  content = post[:post_content]
31
-
32
31
  name = "%02d-%02d-%02d-%s.markdown" % [date.year, date.month, date.day,
33
32
  slug]
34
33
 
@@ -1,10 +1,15 @@
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
1
6
  module Jekyll
2
7
  module Convertible
3
8
  # Return the contents as a string
4
9
  def to_s
5
10
  self.content || ''
6
11
  end
7
-
12
+
8
13
  # Read the YAML frontmatter
9
14
  # +base+ is the String path to the dir containing the file
10
15
  # +name+ is the String filename of the file
@@ -12,58 +17,64 @@ module Jekyll
12
17
  # Returns nothing
13
18
  def read_yaml(base, name)
14
19
  self.content = File.read(File.join(base, name))
15
-
20
+
16
21
  if self.content =~ /^(---\s*\n.*?)\n---\s*\n/m
17
22
  self.content = self.content[($1.size + 5)..-1]
18
-
23
+
19
24
  self.data = YAML.load($1)
20
25
  end
21
26
  end
22
-
27
+
23
28
  # Transform the contents based on the file extension.
24
29
  #
25
30
  # Returns nothing
26
31
  def transform
27
- case Jekyll.content_type
28
- when :textile
32
+ case self.content_type
33
+ when 'textile'
29
34
  self.ext = ".html"
30
- self.content = RedCloth.new(self.content).to_html
31
- when :markdown
35
+ self.content = self.site.textile(self.content)
36
+ when 'markdown'
32
37
  self.ext = ".html"
33
- self.content = Jekyll.markdown_proc.call(self.content)
38
+ self.content = self.site.markdown(self.content)
34
39
  end
35
40
  end
36
-
37
- def determine_content_type
41
+
42
+ # Determine which formatting engine to use based on this convertible's
43
+ # extension
44
+ #
45
+ # Returns one of :textile, :markdown or :unknown
46
+ def content_type
38
47
  case self.ext[1..-1]
39
48
  when /textile/i
40
- return :textile
49
+ return 'textile'
41
50
  when /markdown/i, /mkdn/i, /md/i
42
- return :markdown
43
- end
44
- return :unknown
51
+ return 'markdown'
52
+ end
53
+ return 'unknown'
45
54
  end
46
-
55
+
47
56
  # Add any necessary layouts to this convertible document
48
57
  # +layouts+ is a Hash of {"name" => "layout"}
49
58
  # +site_payload+ is the site payload hash
50
59
  #
51
60
  # Returns nothing
52
61
  def do_layout(payload, layouts)
62
+ info = { :filters => [Jekyll::Filters], :registers => { :site => self.site } }
63
+
53
64
  # render and transform content (this becomes the final content of the object)
54
- Jekyll.content_type = self.determine_content_type
55
- self.content = Liquid::Template.parse(self.content).render(payload, [Jekyll::Filters])
65
+ payload["content_type"] = self.content_type
66
+ self.content = Liquid::Template.parse(self.content).render(payload, info)
56
67
  self.transform
57
-
68
+
58
69
  # output keeps track of what will finally be written
59
70
  self.output = self.content
60
-
71
+
61
72
  # recursively render layouts
62
73
  layout = layouts[self.data["layout"]]
63
74
  while layout
64
75
  payload = payload.deep_merge({"content" => self.output, "page" => layout.data})
65
- self.output = Liquid::Template.parse(layout.content).render(payload, [Jekyll::Filters])
66
-
76
+ self.output = Liquid::Template.parse(layout.content).render(payload, info)
77
+
67
78
  layout = layouts[layout.data["layout"]]
68
79
  end
69
80
  end
@@ -1,22 +1,22 @@
1
1
  class Hash
2
2
  # Merges self with another hash, recursively.
3
- #
3
+ #
4
4
  # This code was lovingly stolen from some random gem:
5
5
  # http://gemjack.com/gems/tartan-0.1.1/classes/Hash.html
6
- #
6
+ #
7
7
  # Thanks to whoever made it.
8
8
  def deep_merge(hash)
9
9
  target = dup
10
-
10
+
11
11
  hash.keys.each do |key|
12
12
  if hash[key].is_a? Hash and self[key].is_a? Hash
13
13
  target[key] = target[key].deep_merge(hash[key])
14
14
  next
15
15
  end
16
-
16
+
17
17
  target[key] = hash[key]
18
18
  end
19
-
19
+
20
20
  target
21
21
  end
22
22
  end
@@ -1,10 +1,10 @@
1
1
  module Jekyll
2
-
2
+
3
3
  module Filters
4
4
  def textilize(input)
5
5
  RedCloth.new(input).to_html
6
6
  end
7
-
7
+
8
8
  def date_to_string(date)
9
9
  date.strftime("%d %b %Y")
10
10
  end
@@ -12,19 +12,19 @@ module Jekyll
12
12
  def date_to_long_string(date)
13
13
  date.strftime("%d %B %Y")
14
14
  end
15
-
15
+
16
16
  def date_to_xmlschema(date)
17
17
  date.xmlschema
18
18
  end
19
-
19
+
20
20
  def xml_escape(input)
21
21
  input.gsub("&", "&amp;").gsub("<", "&lt;").gsub(">", "&gt;")
22
22
  end
23
-
23
+
24
24
  def number_of_words(input)
25
25
  input.split.length
26
26
  end
27
-
27
+
28
28
  def array_to_sentence_string(array)
29
29
  connector = "and"
30
30
  case array.length
data/lib/jekyll/layout.rb CHANGED
@@ -2,25 +2,28 @@ module Jekyll
2
2
 
3
3
  class Layout
4
4
  include Convertible
5
-
5
+
6
+ attr_accessor :site
6
7
  attr_accessor :ext
7
8
  attr_accessor :data, :content
8
-
9
+
9
10
  # Initialize a new Layout.
11
+ # +site+ is the Site
10
12
  # +base+ is the String path to the <source>
11
13
  # +name+ is the String filename of the post file
12
14
  #
13
15
  # Returns <Page>
14
- def initialize(base, name)
16
+ def initialize(site, base, name)
17
+ @site = site
15
18
  @base = base
16
19
  @name = name
17
-
20
+
18
21
  self.data = {}
19
-
22
+
20
23
  self.process(name)
21
24
  self.read_yaml(base, name)
22
25
  end
23
-
26
+
24
27
  # Extract information from the layout filename
25
28
  # +name+ is the String filename of the layout file
26
29
  #
data/lib/jekyll/page.rb CHANGED
@@ -2,28 +2,31 @@ module Jekyll
2
2
 
3
3
  class Page
4
4
  include Convertible
5
-
5
+
6
+ attr_accessor :site
6
7
  attr_accessor :ext
7
8
  attr_accessor :data, :content, :output
8
-
9
+
9
10
  # Initialize a new Page.
11
+ # +site+ is the Site
10
12
  # +base+ is the String path to the <source>
11
13
  # +dir+ is the String path between <source> and the file
12
14
  # +name+ is the String filename of the file
13
15
  #
14
16
  # Returns <Page>
15
- def initialize(base, dir, name)
17
+ def initialize(site, base, dir, name)
18
+ @site = site
16
19
  @base = base
17
20
  @dir = dir
18
21
  @name = name
19
-
22
+
20
23
  self.data = {}
21
-
24
+
22
25
  self.process(name)
23
26
  self.read_yaml(File.join(base, dir), name)
24
27
  #self.transform
25
28
  end
26
-
29
+
27
30
  # Extract information from the page filename
28
31
  # +name+ is the String filename of the page file
29
32
  #
@@ -31,7 +34,7 @@ module Jekyll
31
34
  def process(name)
32
35
  self.ext = File.extname(name)
33
36
  end
34
-
37
+
35
38
  # Add any necessary layouts to this post
36
39
  # +layouts+ is a Hash of {"name" => "layout"}
37
40
  # +site_payload+ is the site payload hash
@@ -41,19 +44,19 @@ module Jekyll
41
44
  payload = {"page" => self.data}.deep_merge(site_payload)
42
45
  do_layout(payload, layouts)
43
46
  end
44
-
47
+
45
48
  # Write the generated page file to the destination directory.
46
49
  # +dest+ is the String path to the destination dir
47
50
  #
48
51
  # Returns nothing
49
52
  def write(dest)
50
53
  FileUtils.mkdir_p(File.join(dest, @dir))
51
-
54
+
52
55
  name = @name
53
56
  if self.ext != ""
54
57
  name = @name.split(".")[0..-2].join('.') + self.ext
55
58
  end
56
-
59
+
57
60
  path = File.join(dest, @dir, name)
58
61
  File.open(path, 'w') do |f|
59
62
  f.write(self.output)