jekyll 1.0.0.beta4 → 1.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of jekyll might be problematic. Click here for more details.

@@ -8,5 +8,20 @@ module Jekyll
8
8
  dirs += ['*']
9
9
  end
10
10
  end
11
+
12
+ # Static: Run Site#process and catch errors
13
+ #
14
+ # site - the Jekyll::Site object
15
+ #
16
+ # Returns nothing
17
+ def self.process_site(site)
18
+ site.process
19
+ rescue Jekyll::FatalException => e
20
+ puts
21
+ Jekyll::Logger.error "ERROR:", "YOUR SITE COULD NOT BE BUILT:"
22
+ Jekyll::Logger.error "", "------------------------------------"
23
+ Jekyll::Logger.error "", e.message
24
+ exit(1)
25
+ end
11
26
  end
12
27
  end
@@ -17,18 +17,10 @@ module Jekyll
17
17
  def self.build(site, options)
18
18
  source = options['source']
19
19
  destination = options['destination']
20
- puts " Source: #{source}"
21
- puts " Destination: #{destination}"
22
- print " Generating... "
23
- begin
24
- site.process
25
- rescue Jekyll::FatalException => e
26
- puts
27
- puts "ERROR: YOUR SITE COULD NOT BE BUILT:"
28
- puts "------------------------------------"
29
- puts e.message
30
- exit(1)
31
- end
20
+ Jekyll::Logger.info "Source:", source
21
+ Jekyll::Logger.info "Destination:", destination
22
+ print Jekyll::Logger.formatted_topic "Generating..."
23
+ self.process_site(site)
32
24
  puts "done."
33
25
  end
34
26
 
@@ -44,23 +36,15 @@ module Jekyll
44
36
  source = options['source']
45
37
  destination = options['destination']
46
38
 
47
- puts " Auto-regeneration: enabled"
39
+ Jekyll::Logger.info "Auto-regeneration:", "enabled"
48
40
 
49
41
  dw = DirectoryWatcher.new(source, :glob => self.globs(source, destination), :pre_load => true)
50
42
  dw.interval = 1
51
43
 
52
44
  dw.add_observer do |*args|
53
45
  t = Time.now.strftime("%Y-%m-%d %H:%M:%S")
54
- print " Regenerating: #{args.size} files at #{t} "
55
- begin
56
- site.process
57
- rescue Jekyll::FatalException => e
58
- puts
59
- puts "ERROR: YOUR SITE COULD NOT BE BUILT:"
60
- puts "------------------------------------"
61
- puts e.message
62
- exit(1)
63
- end
46
+ print Jekyll::Logger.formatted_topic("Regenerating:") + "#{args.size} files at #{t} "
47
+ self.process_site(site)
64
48
  puts "...done."
65
49
  end
66
50
 
@@ -0,0 +1,169 @@
1
+ module Jekyll
2
+ class Configuration < Hash
3
+
4
+ # Default options. Overriden by values in _config.yml.
5
+ # Strings rather than symbols are used for compatability with YAML.
6
+ DEFAULTS = {
7
+ 'source' => Dir.pwd,
8
+ 'destination' => File.join(Dir.pwd, '_site'),
9
+ 'plugins' => '_plugins',
10
+ 'layouts' => '_layouts',
11
+ 'keep_files' => ['.git','.svn'],
12
+
13
+ 'timezone' => nil, # use the local timezone
14
+
15
+ 'safe' => false,
16
+ 'show_drafts' => nil,
17
+ 'limit_posts' => nil,
18
+ 'lsi' => false,
19
+ 'future' => true, # remove and make true just default
20
+ 'pygments' => true, # remove and make true just default
21
+
22
+ 'markdown' => 'maruku',
23
+ 'permalink' => 'date',
24
+ 'baseurl' => '/',
25
+ 'include' => ['.htaccess'],
26
+ 'exclude' => [],
27
+ 'paginate_path' => 'page:num',
28
+
29
+ 'markdown_ext' => 'markdown,mkd,mkdn,md',
30
+ 'textile_ext' => 'textile',
31
+
32
+ 'port' => '4000',
33
+ 'host' => '0.0.0.0',
34
+
35
+ 'excerpt_separator' => "\n\n",
36
+
37
+ 'maruku' => {
38
+ 'use_tex' => false,
39
+ 'use_divs' => false,
40
+ 'png_engine' => 'blahtex',
41
+ 'png_dir' => 'images/latex',
42
+ 'png_url' => '/images/latex'
43
+ },
44
+
45
+ 'rdiscount' => {
46
+ 'extensions' => []
47
+ },
48
+
49
+ 'redcarpet' => {
50
+ 'extensions' => []
51
+ },
52
+
53
+ 'kramdown' => {
54
+ 'auto_ids' => true,
55
+ 'footnote_nr' => 1,
56
+ 'entity_output' => 'as_char',
57
+ 'toc_levels' => '1..6',
58
+ 'smart_quotes' => 'lsquo,rsquo,ldquo,rdquo',
59
+ 'use_coderay' => false,
60
+
61
+ 'coderay' => {
62
+ 'coderay_wrap' => 'div',
63
+ 'coderay_line_numbers' => 'inline',
64
+ 'coderay_line_number_start' => 1,
65
+ 'coderay_tab_width' => 4,
66
+ 'coderay_bold_every' => 10,
67
+ 'coderay_css' => 'style'
68
+ }
69
+ },
70
+
71
+ 'redcloth' => {
72
+ 'hard_breaks' => true
73
+ }
74
+ }
75
+
76
+ # Public: Turn all keys into string
77
+ #
78
+ # Return a copy of the hash where all its keys are strings
79
+ def stringify_keys
80
+ reduce({}) { |hsh,(k,v)| hsh.merge(k.to_s => v) }
81
+ end
82
+
83
+ # Public: Directory of the Jekyll source folder
84
+ #
85
+ # override - the command-line options hash
86
+ #
87
+ # Returns the path to the Jekyll source directory
88
+ def source(override)
89
+ override['source'] || self['source'] || DEFAULTS['source']
90
+ end
91
+
92
+ # Public: Generate list of configuration files from the override
93
+ #
94
+ # override - the command-line options hash
95
+ #
96
+ # Returns an Array of config files
97
+ def config_files(override)
98
+ # Get configuration from <source>/_config.yml or <source>/<config_file>
99
+ config_files = override.delete('config')
100
+ config_files = File.join(source(override), "_config.yml") if config_files.to_s.empty?
101
+ config_files = [config_files] unless config_files.is_a? Array
102
+ config_files
103
+ end
104
+
105
+ # Public: Read configuration and return merged Hash
106
+ #
107
+ # file - the path to the YAML file to be read in
108
+ #
109
+ # Returns this configuration, overridden by the values in the file
110
+ def read_config_file(file)
111
+ next_config = YAML.safe_load_file(file)
112
+ raise "Configuration file: (INVALID) #{file}".yellow if !next_config.is_a?(Hash)
113
+ Jekyll::Logger.info "Configuration file:", file
114
+ next_config
115
+ end
116
+
117
+ # Public: Read in a list of configuration files and merge with this hash
118
+ #
119
+ # files - the list of configuration file paths
120
+ #
121
+ # Returns the full configuration, with the defaults overridden by the values in the
122
+ # configuration files
123
+ def read_config_files(files)
124
+ configuration = clone
125
+
126
+ begin
127
+ files.each do |config_file|
128
+ new_config = read_config_file(config_file)
129
+ configuration = configuration.deep_merge(new_config)
130
+ end
131
+ rescue SystemCallError
132
+ # Errno:ENOENT = file not found
133
+ Jekyll::Logger.warn "Configuration file:", "none"
134
+ rescue => err
135
+ Jekyll::Logger.warn "WARNING:", "Error reading configuration. " +
136
+ "Using defaults (and options)."
137
+ $stderr.puts "#{err}"
138
+ end
139
+
140
+ configuration.backwards_compatibilize
141
+ end
142
+
143
+ # Public: Ensure the proper options are set in the configuration to allow for
144
+ # backwards-compatibility with Jekyll pre-1.0
145
+ #
146
+ # Returns the backwards-compatible configuration
147
+ def backwards_compatibilize
148
+ config = clone
149
+ # Provide backwards-compatibility
150
+ if config.has_key?('auto') || config.has_key?('watch')
151
+ Jekyll::Logger.warn "Deprecation:", "Auto-regeneration can no longer" +
152
+ " be set from your configuration file(s). Use the"+
153
+ " --watch/-w command-line option instead."
154
+ config.delete('auto')
155
+ config.delete('watch')
156
+ end
157
+
158
+ if config.has_key? 'server'
159
+ Jekyll::Logger.warn "Deprecation:", "The 'server' configuration option" +
160
+ " is no longer accepted. Use the 'jekyll serve'" +
161
+ " subcommand to serve your site with WEBrick."
162
+ config.delete('server')
163
+ end
164
+
165
+ config
166
+ end
167
+
168
+ end
169
+ end
@@ -8,87 +8,23 @@ module Jekyll
8
8
 
9
9
  def setup
10
10
  return if @setup
11
- case @config['markdown']
11
+ @parser = case @config['markdown']
12
12
  when 'redcarpet'
13
- begin
14
- require 'redcarpet'
15
-
16
- @renderer ||= Class.new(Redcarpet::Render::HTML) do
17
- def block_code(code, lang)
18
- lang = lang && lang.split.first || "text"
19
- output = add_code_tags(
20
- Pygments.highlight(code, :lexer => lang, :options => { :encoding => 'utf-8' }),
21
- lang
22
- )
23
- end
24
-
25
- def add_code_tags(code, lang)
26
- code = code.sub(/<pre>/,'<pre><code class="' + lang + '">')
27
- code = code.sub(/<\/pre>/,"</code></pre>")
28
- end
29
- end
30
-
31
- @redcarpet_extensions = {}
32
- @config['redcarpet']['extensions'].each { |e| @redcarpet_extensions[e.to_sym] = true }
33
- rescue LoadError
34
- STDERR.puts 'You are missing a library required for Markdown. Please run:'
35
- STDERR.puts ' $ [sudo] gem install redcarpet'
36
- raise FatalException.new("Missing dependency: redcarpet")
37
- end
13
+ RedcarpetParser.new @config
38
14
  when 'kramdown'
39
- begin
40
- require 'kramdown'
41
- rescue LoadError
42
- STDERR.puts 'You are missing a library required for Markdown. Please run:'
43
- STDERR.puts ' $ [sudo] gem install kramdown'
44
- raise FatalException.new("Missing dependency: kramdown")
45
- end
15
+ KramdownParser.new @config
46
16
  when 'rdiscount'
47
- begin
48
- require 'rdiscount'
49
- @rdiscount_extensions = @config['rdiscount']['extensions'].map { |e| e.to_sym }
50
- rescue LoadError
51
- STDERR.puts 'You are missing a library required for Markdown. Please run:'
52
- STDERR.puts ' $ [sudo] gem install rdiscount'
53
- raise FatalException.new("Missing dependency: rdiscount")
54
- end
17
+ RDiscountParser.new @config
55
18
  when 'maruku'
56
- begin
57
- require 'maruku'
58
-
59
- if @config['maruku']['use_divs']
60
- require 'maruku/ext/div'
61
- STDERR.puts 'Maruku: Using extended syntax for div elements.'
62
- end
63
-
64
- if @config['maruku']['use_tex']
65
- require 'maruku/ext/math'
66
- STDERR.puts "Maruku: Using LaTeX extension. Images in `#{@config['maruku']['png_dir']}`."
67
-
68
- # Switch off MathML output
69
- MaRuKu::Globals[:html_math_output_mathml] = false
70
- MaRuKu::Globals[:html_math_engine] = 'none'
71
-
72
- # Turn on math to PNG support with blahtex
73
- # Resulting PNGs stored in `images/latex`
74
- MaRuKu::Globals[:html_math_output_png] = true
75
- MaRuKu::Globals[:html_png_engine] = @config['maruku']['png_engine']
76
- MaRuKu::Globals[:html_png_dir] = @config['maruku']['png_dir']
77
- MaRuKu::Globals[:html_png_url] = @config['maruku']['png_url']
78
- end
79
- rescue LoadError
80
- STDERR.puts 'You are missing a library required for Markdown. Please run:'
81
- STDERR.puts ' $ [sudo] gem install maruku'
82
- raise FatalException.new("Missing dependency: maruku")
83
- end
19
+ MarukuParser.new @config
84
20
  else
85
21
  STDERR.puts "Invalid Markdown processor: #{@config['markdown']}"
86
- STDERR.puts " Valid options are [ maruku | rdiscount | kramdown ]"
22
+ STDERR.puts " Valid options are [ maruku | rdiscount | kramdown | redcarpet ]"
87
23
  raise FatalException.new("Invalid Markdown process: #{@config['markdown']}")
88
24
  end
89
25
  @setup = true
90
26
  end
91
-
27
+
92
28
  def matches(ext)
93
29
  rgx = '(' + @config['markdown_ext'].gsub(',','|') +')'
94
30
  ext =~ Regexp.new(rgx, Regexp::IGNORECASE)
@@ -100,49 +36,7 @@ module Jekyll
100
36
 
101
37
  def convert(content)
102
38
  setup
103
- case @config['markdown']
104
- when 'redcarpet'
105
- @redcarpet_extensions[:fenced_code_blocks] = !@redcarpet_extensions[:no_fenced_code_blocks]
106
- @renderer.send :include, Redcarpet::Render::SmartyPants if @redcarpet_extensions[:smart]
107
- markdown = Redcarpet::Markdown.new(@renderer.new(@redcarpet_extensions), @redcarpet_extensions)
108
- markdown.render(content)
109
- when 'kramdown'
110
- # Check for use of coderay
111
- if @config['kramdown']['use_coderay']
112
- Kramdown::Document.new(content, {
113
- :auto_ids => @config['kramdown']['auto_ids'],
114
- :footnote_nr => @config['kramdown']['footnote_nr'],
115
- :entity_output => @config['kramdown']['entity_output'],
116
- :toc_levels => @config['kramdown']['toc_levels'],
117
- :smart_quotes => @config['kramdown']['smart_quotes'],
118
-
119
- :coderay_wrap => @config['kramdown']['coderay']['coderay_wrap'],
120
- :coderay_line_numbers => @config['kramdown']['coderay']['coderay_line_numbers'],
121
- :coderay_line_number_start => @config['kramdown']['coderay']['coderay_line_number_start'],
122
- :coderay_tab_width => @config['kramdown']['coderay']['coderay_tab_width'],
123
- :coderay_bold_every => @config['kramdown']['coderay']['coderay_bold_every'],
124
- :coderay_css => @config['kramdown']['coderay']['coderay_css']
125
- }).to_html
126
- else
127
- # not using coderay
128
- Kramdown::Document.new(content, {
129
- :auto_ids => @config['kramdown']['auto_ids'],
130
- :footnote_nr => @config['kramdown']['footnote_nr'],
131
- :entity_output => @config['kramdown']['entity_output'],
132
- :toc_levels => @config['kramdown']['toc_levels'],
133
- :smart_quotes => @config['kramdown']['smart_quotes']
134
- }).to_html
135
- end
136
- when 'rdiscount'
137
- rd = RDiscount.new(content, *@rdiscount_extensions)
138
- html = rd.to_html
139
- if rd.generate_toc and html.include?(@config['rdiscount']['toc_token'])
140
- html.gsub!(@config['rdiscount']['toc_token'], rd.toc_content.force_encoding('utf-8'))
141
- end
142
- html
143
- when 'maruku'
144
- Maruku.new(content).to_html
145
- end
39
+ @parser.convert(content)
146
40
  end
147
41
  end
148
42
  end
@@ -0,0 +1,44 @@
1
+ module Jekyll
2
+ module Converters
3
+ class Markdown
4
+ class KramdownParser
5
+ def initialize(config)
6
+ require 'kramdown'
7
+ @config = config
8
+ rescue LoadError
9
+ STDERR.puts 'You are missing a library required for Markdown. Please run:'
10
+ STDERR.puts ' $ [sudo] gem install kramdown'
11
+ raise FatalException.new("Missing dependency: kramdown")
12
+ end
13
+
14
+ def convert(content)
15
+ # Check for use of coderay
16
+ kramdown_configs = if @config['kramdown']['use_coderay']
17
+ base_kramdown_configs.merge({
18
+ :coderay_wrap => @config['kramdown']['coderay']['coderay_wrap'],
19
+ :coderay_line_numbers => @config['kramdown']['coderay']['coderay_line_numbers'],
20
+ :coderay_line_number_start => @config['kramdown']['coderay']['coderay_line_number_start'],
21
+ :coderay_tab_width => @config['kramdown']['coderay']['coderay_tab_width'],
22
+ :coderay_bold_every => @config['kramdown']['coderay']['coderay_bold_every'],
23
+ :coderay_css => @config['kramdown']['coderay']['coderay_css']
24
+ })
25
+ else
26
+ # not using coderay
27
+ base_kramdown_configs
28
+ end
29
+ Kramdown::Document.new(content, kramdown_configs).to_html
30
+ end
31
+
32
+ def base_kramdown_configs
33
+ {
34
+ :auto_ids => @config['kramdown']['auto_ids'],
35
+ :footnote_nr => @config['kramdown']['footnote_nr'],
36
+ :entity_output => @config['kramdown']['entity_output'],
37
+ :toc_levels => @config['kramdown']['toc_levels'],
38
+ :smart_quotes => @config['kramdown']['smart_quotes']
39
+ }
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,47 @@
1
+ module Jekyll
2
+ module Converters
3
+ class Markdown
4
+ class MarukuParser
5
+ def initialize(config)
6
+ require 'maruku'
7
+ @config = config
8
+ if @config['maruku']['use_divs']
9
+ load_divs_library
10
+ end
11
+ if @config['maruku']['use_tex']
12
+ load_blahtext_library
13
+ end
14
+ rescue LoadError
15
+ STDERR.puts 'You are missing a library required for Markdown. Please run:'
16
+ STDERR.puts ' $ [sudo] gem install maruku'
17
+ raise FatalException.new("Missing dependency: maruku")
18
+ end
19
+
20
+ def load_divs_library
21
+ require 'maruku/ext/div'
22
+ STDERR.puts 'Maruku: Using extended syntax for div elements.'
23
+ end
24
+
25
+ def load_blahtext_library
26
+ require 'maruku/ext/math'
27
+ STDERR.puts "Maruku: Using LaTeX extension. Images in `#{@config['maruku']['png_dir']}`."
28
+
29
+ # Switch off MathML output
30
+ MaRuKu::Globals[:html_math_output_mathml] = false
31
+ MaRuKu::Globals[:html_math_engine] = 'none'
32
+
33
+ # Turn on math to PNG support with blahtex
34
+ # Resulting PNGs stored in `images/latex`
35
+ MaRuKu::Globals[:html_math_output_png] = true
36
+ MaRuKu::Globals[:html_png_engine] = @config['maruku']['png_engine']
37
+ MaRuKu::Globals[:html_png_dir] = @config['maruku']['png_dir']
38
+ MaRuKu::Globals[:html_png_url] = @config['maruku']['png_url']
39
+ end
40
+
41
+ def convert(content)
42
+ Maruku.new(content).to_html
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end