jekyll 3.0.0.pre.beta6 → 3.0.0.pre.beta7

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.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 451685a00389d54c63e5c8f309de1741500e57ad
4
- data.tar.gz: 59f07f3ecf913afa131cc89039240fd9e5cb44f5
3
+ metadata.gz: db35d240087be44c4ec3b9995db45be24d86729f
4
+ data.tar.gz: 80b2adb83105584c92a2ac9b26eb395209fb3a50
5
5
  SHA512:
6
- metadata.gz: 83ab065105a64bfb0c2f276c4d27ac6b8ba616679b8eac02fed08176943d02b2ca0b23149ab926163e229d52f0c36fdf5fd019fae7429a034390e323b5cde2b8
7
- data.tar.gz: 1a235a69b2757fa129fe14afca242306512cc210390e11030f0339ca0463e45d1f19f7fe70a82fdbdee7fe6a71c66c50124f3740405c202692c3e498b399f45b
6
+ metadata.gz: 84435f02d83627163c2abc3eb4e59f97fdcbd2c22e636da93b219cf77834198e7d62dd53859e16508b82e1e5b0b5cdb59cb15055bcc18c0ed7b26f22ffa0aec5
7
+ data.tar.gz: 25215ce3c27a0fc3fb630ca19356a0d220de31185fe15297041cf5acde25660d34ad5f40858d41b0d595b5c9631a821c8d0450c43d42c6fb3428c372b9315929
data/bin/jekyll CHANGED
@@ -24,6 +24,7 @@ Mercenary.program(:jekyll) do |p|
24
24
  p.option 'safe', '--safe', 'Safe mode (defaults to false)'
25
25
  p.option 'plugins', '-p', '--plugins PLUGINS_DIR1[,PLUGINS_DIR2[,...]]', Array, 'Plugins directory (defaults to ./_plugins)'
26
26
  p.option 'layouts', '--layouts DIR', String, 'Layouts directory (defaults to ./_layouts)'
27
+ p.option 'profile', '--profile', 'Generate a Liquid rendering profile'
27
28
 
28
29
  Jekyll::Command.subclasses.each { |c| c.init_with_program(p) }
29
30
 
@@ -66,6 +66,7 @@ module Jekyll
66
66
  autoload :Regenerator, 'jekyll/regenerator'
67
67
  autoload :RelatedPosts, 'jekyll/related_posts'
68
68
  autoload :Renderer, 'jekyll/renderer'
69
+ autoload :LiquidRenderer, 'jekyll/liquid_renderer'
69
70
  autoload :Site, 'jekyll/site'
70
71
  autoload :StaticFile, 'jekyll/static_file'
71
72
  autoload :Stevenson, 'jekyll/stevenson'
@@ -29,7 +29,7 @@ module Jekyll
29
29
  include CommonMethods
30
30
 
31
31
  def code_wrap(code)
32
- "<div class=\"highlight\"><pre>#{CGI::escapeHTML(code)}</pre></div>"
32
+ "<figure class=\"highlight\"><pre>#{CGI::escapeHTML(code)}</pre></figure>"
33
33
  end
34
34
 
35
35
  def block_code(code, lang)
@@ -108,8 +108,8 @@ module Jekyll
108
108
  # info - the info for Liquid
109
109
  #
110
110
  # Returns the converted content
111
- def render_liquid(content, payload, info, path = nil)
112
- Liquid::Template.parse(content).render!(payload, info)
111
+ def render_liquid(content, payload, info, path)
112
+ site.liquid_renderer.file(path).parse(content).render(payload, info)
113
113
  rescue Tags::IncludeTagError => e
114
114
  Jekyll.logger.error "Liquid Exception:", "#{e.message} in #{e.path}, included in #{path || self.path}"
115
115
  raise e
@@ -243,7 +243,7 @@ module Jekyll
243
243
  payload["highlighter_prefix"] = converters.first.highlighter_prefix
244
244
  payload["highlighter_suffix"] = converters.first.highlighter_suffix
245
245
 
246
- self.content = render_liquid(content, payload, info) if render_with_liquid?
246
+ self.content = render_liquid(content, payload, info, path) if render_with_liquid?
247
247
  self.content = transform
248
248
 
249
249
  # output keeps track of what will finally be written
@@ -173,7 +173,7 @@ module Jekyll
173
173
  if path.nil? || path.empty?
174
174
  ""
175
175
  else
176
- path.gsub(/\A\//, '').gsub(/([^\/])\z/, '\1/')
176
+ path.gsub(/\A\//, '').gsub(/([^\/])\z/, '\1')
177
177
  end
178
178
  end
179
179
  end
@@ -0,0 +1,39 @@
1
+ require 'jekyll/liquid_renderer/file'
2
+ require 'jekyll/liquid_renderer/table'
3
+
4
+ module Jekyll
5
+ class LiquidRenderer
6
+ def initialize(site)
7
+ @site = site
8
+ reset
9
+ end
10
+
11
+ def reset
12
+ @stats = {}
13
+ end
14
+
15
+ def file(filename)
16
+ filename = @site.in_source_dir(filename).sub(/\A#{Regexp.escape(@site.source)}\//, '')
17
+
18
+ LiquidRenderer::File.new(self, filename).tap do |file|
19
+ @stats[filename] ||= {}
20
+ @stats[filename][:count] ||= 0
21
+ @stats[filename][:count] += 1
22
+ end
23
+ end
24
+
25
+ def increment_bytes(filename, bytes)
26
+ @stats[filename][:bytes] ||= 0
27
+ @stats[filename][:bytes] += bytes
28
+ end
29
+
30
+ def increment_time(filename, time)
31
+ @stats[filename][:time] ||= 0.0
32
+ @stats[filename][:time] += time
33
+ end
34
+
35
+ def stats_table(n = 50)
36
+ LiquidRenderer::Table.new(@stats).to_s(n)
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,50 @@
1
+ module Jekyll
2
+ class LiquidRenderer
3
+ class File
4
+ def initialize(renderer, filename)
5
+ @renderer = renderer
6
+ @filename = filename
7
+ end
8
+
9
+ def parse(content)
10
+ measure_time do
11
+ @template = Liquid::Template.parse(content)
12
+ end
13
+
14
+ self
15
+ end
16
+
17
+ def render(*args)
18
+ measure_time do
19
+ measure_bytes do
20
+ @template.render(*args)
21
+ end
22
+ end
23
+ end
24
+
25
+ def render!(*args)
26
+ measure_time do
27
+ measure_bytes do
28
+ @template.render!(*args)
29
+ end
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ def measure_bytes
36
+ str = yield
37
+ ensure
38
+ @renderer.increment_bytes(@filename, str.bytesize)
39
+ end
40
+
41
+ def measure_time
42
+ before = Time.now
43
+ yield
44
+ ensure
45
+ after = Time.now
46
+ @renderer.increment_time(@filename, after - before)
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,94 @@
1
+ module Jekyll
2
+ class LiquidRenderer::Table
3
+ def initialize(stats)
4
+ @stats = stats
5
+ end
6
+
7
+ def to_s(n = 50)
8
+ data = data_for_table(n)
9
+ widths = table_widths(data)
10
+ generate_table(data, widths)
11
+ end
12
+
13
+ private
14
+
15
+ def generate_table(data, widths)
16
+ str = "\n"
17
+
18
+ table_head = data.shift
19
+ str << generate_row(table_head, widths)
20
+ str << generate_table_head_border(table_head, widths)
21
+
22
+ data.each do |row_data|
23
+ str << generate_row(row_data, widths)
24
+ end
25
+
26
+ str << "\n"
27
+ str
28
+ end
29
+
30
+ def generate_table_head_border(row_data, widths)
31
+ str = ""
32
+
33
+ row_data.each_index do |cell_index|
34
+ str << '-' * widths[cell_index]
35
+ str << '-+-' unless cell_index == row_data.length-1
36
+ end
37
+
38
+ str << "\n"
39
+ str
40
+ end
41
+
42
+ def generate_row(row_data, widths)
43
+ str = ''
44
+
45
+ row_data.each_with_index do |cell_data, cell_index|
46
+ if cell_index == 0
47
+ str << cell_data.ljust(widths[cell_index], ' ')
48
+ else
49
+ str << cell_data.rjust(widths[cell_index], ' ')
50
+ end
51
+
52
+ str << ' | ' unless cell_index == row_data.length-1
53
+ end
54
+
55
+ str << "\n"
56
+ str
57
+ end
58
+
59
+ def table_widths(data)
60
+ widths = []
61
+
62
+ data.each do |row|
63
+ row.each_with_index do |cell, index|
64
+ widths[index] = [ cell.length, widths[index] ].compact.max
65
+ end
66
+ end
67
+
68
+ widths
69
+ end
70
+
71
+ def data_for_table(n)
72
+ sorted = @stats.sort_by{ |filename, file_stats| -file_stats[:time] }
73
+ sorted = sorted.slice(0, n)
74
+
75
+ table = [[ 'Filename', 'Count', 'Bytes', 'Time' ]]
76
+
77
+ sorted.each do |filename, file_stats|
78
+ row = []
79
+ row << filename
80
+ row << file_stats[:count].to_s
81
+ row << format_bytes(file_stats[:bytes])
82
+ row << "%.3f" % file_stats[:time]
83
+ table << row
84
+ end
85
+
86
+ table
87
+ end
88
+
89
+ def format_bytes(bytes)
90
+ bytes /= 1024.0
91
+ "%.2fK" % bytes
92
+ end
93
+ end
94
+ end
@@ -49,7 +49,7 @@ module Jekyll
49
49
  output = document.content
50
50
 
51
51
  if document.render_with_liquid?
52
- output = render_liquid(output, payload, info)
52
+ output = render_liquid(output, payload, info, document.path)
53
53
  end
54
54
 
55
55
  output = convert(output)
@@ -92,7 +92,7 @@ module Jekyll
92
92
  #
93
93
  # Returns the content, rendered by Liquid.
94
94
  def render_liquid(content, payload, info, path = nil)
95
- Liquid::Template.parse(content).render!(payload, info)
95
+ site.liquid_renderer.file(path).parse(content).render!(payload, info)
96
96
  rescue Tags::IncludeTagError => e
97
97
  Jekyll.logger.error "Liquid Exception:", "#{e.message} in #{e.path}, included in #{path || document.relative_path}"
98
98
  raise e
@@ -11,7 +11,7 @@ module Jekyll
11
11
  :gems, :plugin_manager
12
12
 
13
13
  attr_accessor :converters, :generators, :reader
14
- attr_reader :regenerator
14
+ attr_reader :regenerator, :liquid_renderer
15
15
 
16
16
  # Public: Initialize a new Site.
17
17
  #
@@ -33,6 +33,8 @@ module Jekyll
33
33
  # Initialize incremental regenerator
34
34
  @regenerator = Regenerator.new(self)
35
35
 
36
+ @liquid_renderer = LiquidRenderer.new(self)
37
+
36
38
  self.plugin_manager = Jekyll::PluginManager.new(self)
37
39
  self.plugins = plugin_manager.plugins_path
38
40
 
@@ -57,6 +59,13 @@ module Jekyll
57
59
  render
58
60
  cleanup
59
61
  write
62
+ print_stats
63
+ end
64
+
65
+ def print_stats
66
+ if @config['profile']
67
+ puts @liquid_renderer.stats_table
68
+ end
60
69
  end
61
70
 
62
71
  # Reset Site details.
@@ -70,7 +79,8 @@ module Jekyll
70
79
  self.static_files = []
71
80
  self.data = {}
72
81
  @collections = nil
73
- @regenerator.clear_cache()
82
+ @regenerator.clear_cache
83
+ @liquid_renderer.reset
74
84
 
75
85
  if limit_posts < 0
76
86
  raise ArgumentError, "limit_posts must be a non-negative number"
@@ -319,7 +329,6 @@ module Jekyll
319
329
  end.to_a
320
330
  end
321
331
 
322
-
323
332
  def each_site_file
324
333
  %w(posts pages static_files docs_to_write).each do |type|
325
334
  send(type).each do |item|
@@ -113,7 +113,7 @@ eos
113
113
  "class=\"language-#{@lang.to_s.gsub('+', '-')}\"",
114
114
  "data-lang=\"#{@lang.to_s}\""
115
115
  ].join(" ")
116
- "<div class=\"highlight\"><pre><code #{code_attributes}>#{code.chomp}</code></pre></div>"
116
+ "<figure class=\"highlight\"><pre><code #{code_attributes}>#{code.chomp}</code></pre></figure>"
117
117
  end
118
118
 
119
119
  end
@@ -95,7 +95,7 @@ eos
95
95
  # Render the variable if required
96
96
  def render_variable(context)
97
97
  if @file.match(VARIABLE_SYNTAX)
98
- partial = Liquid::Template.parse(@file)
98
+ partial = context.registers[:site].liquid_renderer.file("(variable)").parse(@file)
99
99
  partial.render!(context)
100
100
  end
101
101
  end
@@ -123,7 +123,7 @@ eos
123
123
  end
124
124
 
125
125
  begin
126
- partial = Liquid::Template.parse(read_file(path, context))
126
+ partial = site.liquid_renderer.file(path).parse(read_file(path, context))
127
127
 
128
128
  context.stack do
129
129
  context['include'] = parse_params(context) if @params
@@ -1,3 +1,3 @@
1
1
  module Jekyll
2
- VERSION = '3.0.0.pre.beta6'
2
+ VERSION = '3.0.0.pre.beta7'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0.pre.beta6
4
+ version: 3.0.0.pre.beta7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Preston-Werner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-04 00:00:00.000000000 Z
11
+ date: 2015-06-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: liquid
@@ -165,6 +165,9 @@ files:
165
165
  - lib/jekyll/hooks.rb
166
166
  - lib/jekyll/layout.rb
167
167
  - lib/jekyll/liquid_extensions.rb
168
+ - lib/jekyll/liquid_renderer.rb
169
+ - lib/jekyll/liquid_renderer/file.rb
170
+ - lib/jekyll/liquid_renderer/table.rb
168
171
  - lib/jekyll/log_adapter.rb
169
172
  - lib/jekyll/mime.types
170
173
  - lib/jekyll/page.rb