jekyll 3.0.0.pre.beta3 → 3.0.0.pre.beta4

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: b3bfbcb3305b1d99e27d4f8e0b4498a9bd26162e
4
- data.tar.gz: bce86abbe4ecf82618bb8ab2cfd46c94a82c83e1
3
+ metadata.gz: 8b671ad21c396f69a1ce1e75bfa41ae9f7ab299f
4
+ data.tar.gz: 65895690b84df23c794c12dc1d3f1c4d6e61ba15
5
5
  SHA512:
6
- metadata.gz: a35034599b1cf1be9b4194b058a244b070bb7deaac9525068239cfd307f4c4aaa64e7534002b0d517cdf69cbf8855eddea5b8501d91d1b9fd319feec9dc2d423
7
- data.tar.gz: 0ea6b82be241eb5bbdcf1124e178c510b7450e1c86b27367b8351358236ee51c4b63a4eb9aee2bc62a16094bbdbdc3dc8812f04c1c1936a4750e4e6fa090b1bf
6
+ metadata.gz: 017c26c08ee3989732900b36af6464ed884d5c6a19f083c42bfbfce8cc345910934ea3695f02b2198fe91da9d813562c91da2d93d25d851f549773fa7f1e4840
7
+ data.tar.gz: 3298b7ff1db4e4e271d3f0ed1e48e95e32c05c8908cdfbfd58d42086f6275f72962fe97f9063b03bb2e296705aefaa0a88d2bc1aa342640ed68260460d5ec052
@@ -48,6 +48,7 @@ module Jekyll
48
48
  autoload :External, 'jekyll/external'
49
49
  autoload :Filters, 'jekyll/filters'
50
50
  autoload :FrontmatterDefaults, 'jekyll/frontmatter_defaults'
51
+ autoload :Hooks, 'jekyll/hooks'
51
52
  autoload :Layout, 'jekyll/layout'
52
53
  autoload :CollectionReader, 'jekyll/readers/collection_reader'
53
54
  autoload :DataReader, 'jekyll/readers/data_reader'
@@ -236,6 +236,7 @@ module Jekyll
236
236
  #
237
237
  # Returns nothing.
238
238
  def do_layout(payload, layouts)
239
+ Jekyll::Hooks.trigger self, :pre_render, payload
239
240
  info = { :filters => [Jekyll::Filters], :registers => { :site => site, :page => payload['page'] } }
240
241
 
241
242
  # render and transform content (this becomes the final content of the object)
@@ -249,6 +250,7 @@ module Jekyll
249
250
  self.output = content
250
251
 
251
252
  render_all_layouts(layouts, payload, info) if place_in_layout?
253
+ Jekyll::Hooks.trigger self, :post_render
252
254
  end
253
255
 
254
256
  # Write the generated page file to the destination directory.
@@ -262,6 +264,7 @@ module Jekyll
262
264
  File.open(path, 'wb') do |f|
263
265
  f.write(output)
264
266
  end
267
+ Jekyll::Hooks.trigger self, :post_write
265
268
  end
266
269
 
267
270
  # Accessor for data properties by Liquid.
@@ -4,8 +4,7 @@ module Jekyll
4
4
  class Document
5
5
  include Comparable
6
6
 
7
- attr_reader :path, :site, :extname, :output_ext
8
- attr_accessor :content, :collection, :output
7
+ attr_reader :path, :site, :extname, :output_ext, :content, :output, :collection
9
8
 
10
9
  YAML_FRONT_MATTER_REGEXP = /\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)/m
11
10
 
@@ -24,6 +23,16 @@ module Jekyll
24
23
  @has_yaml_header = nil
25
24
  end
26
25
 
26
+ def output=(output)
27
+ @to_liquid = nil
28
+ @output = output
29
+ end
30
+
31
+ def content=(content)
32
+ @to_liquid = nil
33
+ @content = content
34
+ end
35
+
27
36
  # Fetch the Document's data.
28
37
  #
29
38
  # Returns a Hash containing the data. An empty hash is returned if
@@ -180,6 +189,8 @@ module Jekyll
180
189
  File.open(path, 'wb') do |f|
181
190
  f.write(output)
182
191
  end
192
+
193
+ Jekyll::Hooks.trigger self, :post_write
183
194
  end
184
195
 
185
196
  # Returns merged option hash for File.read of self.site (if exists)
@@ -205,6 +216,8 @@ module Jekyll
205
216
  #
206
217
  # Returns nothing.
207
218
  def read(opts = {})
219
+ @to_liquid = nil
220
+
208
221
  if yaml_file?
209
222
  @data = SafeYAML.load_file(path)
210
223
  else
@@ -213,9 +226,9 @@ module Jekyll
213
226
  unless defaults.empty?
214
227
  @data = defaults
215
228
  end
216
- @content = File.read(path, merged_file_read_opts(opts))
229
+ self.content = File.read(path, merged_file_read_opts(opts))
217
230
  if content =~ YAML_FRONT_MATTER_REGEXP
218
- @content = $POSTMATCH
231
+ self.content = $POSTMATCH
219
232
  data_file = SafeYAML.load($1)
220
233
  unless data_file.nil?
221
234
  @data = Utils.deep_merge_hashes(defaults, data_file)
@@ -233,7 +246,7 @@ module Jekyll
233
246
  #
234
247
  # Returns a Hash representing this Document's data.
235
248
  def to_liquid
236
- if data.is_a?(Hash)
249
+ @to_liquid ||= if data.is_a?(Hash)
237
250
  Utils.deep_merge_hashes data, {
238
251
  "output" => output,
239
252
  "content" => content,
@@ -279,6 +292,5 @@ module Jekyll
279
292
  def write?
280
293
  collection && collection.write?
281
294
  end
282
-
283
295
  end
284
296
  end
@@ -0,0 +1,107 @@
1
+ module Jekyll
2
+ module Hooks
3
+ # Helps look up hooks from the registry by owner's class
4
+ OWNER_MAP = {
5
+ Jekyll::Site => :site,
6
+ Jekyll::Page => :page,
7
+ Jekyll::Post => :post,
8
+ Jekyll::Document => :document,
9
+ }.freeze
10
+
11
+ DEFAULT_PRIORITY = 20
12
+
13
+ # compatibility layer for octopress-hooks users
14
+ PRIORITY_MAP = {
15
+ low: 10,
16
+ normal: 20,
17
+ high: 30,
18
+ }.freeze
19
+
20
+ # initial empty hooks
21
+ @registry = {
22
+ :site => {
23
+ after_reset: [],
24
+ post_read: [],
25
+ pre_render: [],
26
+ post_write: [],
27
+ },
28
+ :page => {
29
+ post_init: [],
30
+ pre_render: [],
31
+ post_render: [],
32
+ post_write: [],
33
+ },
34
+ :post => {
35
+ post_init: [],
36
+ pre_render: [],
37
+ post_render: [],
38
+ post_write: [],
39
+ },
40
+ :document => {
41
+ pre_render: [],
42
+ post_render: [],
43
+ post_write: [],
44
+ },
45
+ }
46
+
47
+ # map of all hooks and their priorities
48
+ @hook_priority = {}
49
+
50
+ NotAvailable = Class.new(RuntimeError)
51
+ Uncallable = Class.new(RuntimeError)
52
+
53
+ # register hook(s) to be called later, public API
54
+ def self.register(owners, event, priority: DEFAULT_PRIORITY, &block)
55
+ Array(owners).each do |owner|
56
+ register_one(owner, event, priority_value(priority), &block)
57
+ end
58
+ end
59
+
60
+ # Ensure the priority is a Fixnum
61
+ def self.priority_value(priority)
62
+ return priority if priority.is_a?(Fixnum)
63
+ PRIORITY_MAP[priority] || DEFAULT_PRIORITY
64
+ end
65
+
66
+ # register a single hook to be called later, internal API
67
+ def self.register_one(owner, event, priority, &block)
68
+ unless @registry[owner]
69
+ raise NotAvailable, "Hooks are only available for the following " <<
70
+ "classes: #{@registry.keys.inspect}"
71
+ end
72
+
73
+ unless @registry[owner][event]
74
+ raise NotAvailable, "Invalid hook. #{owner} supports only the " <<
75
+ "following hooks #{@registry[owner].keys.inspect}"
76
+ end
77
+
78
+ unless block.respond_to? :call
79
+ raise Uncallable, "Hooks must respond to :call"
80
+ end
81
+
82
+ insert_hook owner, event, priority, &block
83
+ end
84
+
85
+ def self.insert_hook(owner, event, priority, &block)
86
+ @hook_priority[block] = "#{priority}.#{@hook_priority.size}".to_f
87
+ @registry[owner][event] << block
88
+ end
89
+
90
+ # interface for Jekyll core components to trigger hooks
91
+ def self.trigger(instance, event, *args)
92
+ owner_symbol = OWNER_MAP[instance.class]
93
+
94
+ # proceed only if there are hooks to call
95
+ return unless @registry[owner_symbol]
96
+ return unless @registry[owner_symbol][event]
97
+
98
+ # hooks to call for this owner and event
99
+ hooks = @registry[owner_symbol][event]
100
+
101
+ # sort and call hooks according to priority and load order
102
+ hooks.sort_by { |h| @hook_priority[h] }.each do |hook|
103
+ hook.call(instance, *args)
104
+ end
105
+ end
106
+ end
107
+ end
@@ -35,6 +35,8 @@ module Jekyll
35
35
  data.default_proc = proc do |hash, key|
36
36
  site.frontmatter_defaults.find(File.join(dir, name), type, key)
37
37
  end
38
+
39
+ Jekyll::Hooks.trigger self, :post_init
38
40
  end
39
41
 
40
42
  # The generated directory into which the page will be placed
@@ -68,6 +68,8 @@ module Jekyll
68
68
 
69
69
  populate_categories
70
70
  populate_tags
71
+
72
+ Jekyll::Hooks.trigger self, :post_init
71
73
  end
72
74
 
73
75
  def published?
@@ -35,6 +35,8 @@ module Jekyll
35
35
  "page" => document.to_liquid
36
36
  }, site_payload || site.site_payload)
37
37
 
38
+ Jekyll::Hooks.trigger document, :pre_render, payload
39
+
38
40
  info = {
39
41
  filters: [Jekyll::Filters],
40
42
  registers: { :site => site, :page => payload['page'] }
@@ -75,6 +75,8 @@ module Jekyll
75
75
  if limit_posts < 0
76
76
  raise ArgumentError, "limit_posts must be a non-negative number"
77
77
  end
78
+
79
+ Jekyll::Hooks.trigger self, :after_reset
78
80
  end
79
81
 
80
82
  # Load necessary libraries, plugins, converters, and generators.
@@ -132,6 +134,7 @@ module Jekyll
132
134
  def read
133
135
  reader.read
134
136
  limit_posts!
137
+ Jekyll::Hooks.trigger self, :post_read
135
138
  end
136
139
 
137
140
  # Run each of the Generators.
@@ -150,15 +153,18 @@ module Jekyll
150
153
  relative_permalinks_are_deprecated
151
154
 
152
155
  payload = site_payload
156
+
157
+ Jekyll::Hooks.trigger self, :pre_render, payload
158
+
153
159
  collections.each do |label, collection|
154
160
  collection.docs.each do |document|
155
161
  if regenerator.regenerate?(document)
156
162
  document.output = Jekyll::Renderer.new(self, document, payload).run
163
+ Jekyll::Hooks.trigger document, :post_render
157
164
  end
158
165
  end
159
166
  end
160
167
 
161
- payload = site_payload
162
168
  [posts, pages].flatten.each do |page_or_post|
163
169
  if regenerator.regenerate?(page_or_post)
164
170
  page_or_post.render(layouts, payload)
@@ -183,6 +189,7 @@ module Jekyll
183
189
  item.write(dest) if regenerator.regenerate?(item)
184
190
  }
185
191
  regenerator.write_metadata
192
+ Jekyll::Hooks.trigger self, :post_write
186
193
  end
187
194
 
188
195
  # Construct a Hash of Posts indexed by the specified Post attribute.
@@ -1,3 +1,3 @@
1
1
  module Jekyll
2
- VERSION = '3.0.0.pre.beta3'
2
+ VERSION = '3.0.0.pre.beta4'
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.beta3
4
+ version: 3.0.0.pre.beta4
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-05-07 00:00:00.000000000 Z
11
+ date: 2015-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: liquid
@@ -162,6 +162,7 @@ files:
162
162
  - lib/jekyll/filters.rb
163
163
  - lib/jekyll/frontmatter_defaults.rb
164
164
  - lib/jekyll/generator.rb
165
+ - lib/jekyll/hooks.rb
165
166
  - lib/jekyll/layout.rb
166
167
  - lib/jekyll/liquid_extensions.rb
167
168
  - lib/jekyll/log_adapter.rb
@@ -228,7 +229,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
228
229
  version: 1.3.1
229
230
  requirements: []
230
231
  rubyforge_project:
231
- rubygems_version: 2.2.2
232
+ rubygems_version: 2.2.3
232
233
  signing_key:
233
234
  specification_version: 2
234
235
  summary: A simple, blog aware, static site generator.