nanoc 4.5.2 → 4.5.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +7 -7
  3. data/NEWS.md +7 -0
  4. data/lib/nanoc/base/entities/item_rep.rb +0 -46
  5. data/lib/nanoc/base/repos.rb +1 -0
  6. data/lib/nanoc/base/repos/snapshot_repo.rb +60 -0
  7. data/lib/nanoc/base/services/compiler.rb +30 -17
  8. data/lib/nanoc/base/services/executor.rb +17 -8
  9. data/lib/nanoc/base/services/item_rep_writer.rb +3 -3
  10. data/lib/nanoc/base/views/item_rep_collection_view.rb +1 -1
  11. data/lib/nanoc/base/views/item_rep_view.rb +2 -2
  12. data/lib/nanoc/base/views/post_compile_item_rep_view.rb +9 -7
  13. data/lib/nanoc/base/views/view_context.rb +3 -1
  14. data/lib/nanoc/cli/commands/compile.rb +3 -3
  15. data/lib/nanoc/cli/commands/shell.rb +1 -0
  16. data/lib/nanoc/extra/parallel_collection.rb +1 -1
  17. data/lib/nanoc/helpers/capturing.rb +9 -5
  18. data/lib/nanoc/rule_dsl/action_provider.rb +2 -0
  19. data/lib/nanoc/rule_dsl/rule_memory_calculator.rb +4 -1
  20. data/lib/nanoc/spec.rb +17 -18
  21. data/lib/nanoc/version.rb +1 -1
  22. data/spec/nanoc/base/compiler_spec.rb +9 -8
  23. data/spec/nanoc/base/entities/item_rep_spec.rb +0 -222
  24. data/spec/nanoc/base/filter_spec.rb +1 -0
  25. data/spec/nanoc/base/item_rep_writer_spec.rb +9 -4
  26. data/spec/nanoc/base/repos/snapshot_repo_spec.rb +314 -0
  27. data/spec/nanoc/base/services/compiler/phases/cache_spec.rb +107 -0
  28. data/spec/nanoc/base/services/executor_spec.rb +230 -44
  29. data/spec/nanoc/base/views/document_view_spec.rb +1 -0
  30. data/spec/nanoc/base/views/item_rep_view_spec.rb +18 -5
  31. data/spec/nanoc/base/views/item_view_spec.rb +18 -7
  32. data/spec/nanoc/base/views/mutable_document_view_spec.rb +6 -5
  33. data/spec/nanoc/base/views/post_compile_item_rep_view_spec.rb +8 -3
  34. data/spec/nanoc/cli/commands/compile/file_action_printer_spec.rb +3 -3
  35. data/spec/nanoc/helpers/capturing_spec.rb +8 -5
  36. data/spec/nanoc/regressions/gh_1064_spec.rb +18 -0
  37. data/spec/nanoc/rule_dsl/rule_context_spec.rb +2 -1
  38. data/spec/nanoc/rule_dsl/rule_memory_calculator_spec.rb +15 -3
  39. data/spec/spec_helper.rb +43 -0
  40. data/test/cli/commands/test_compile.rb +1 -1
  41. data/test/filters/test_xsl.rb +1 -0
  42. data/test/helpers/test_capturing.rb +9 -2
  43. data/test/helpers/test_xml_sitemap.rb +1 -1
  44. metadata +6 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 64b516baea97186cbb7ad99448ae7c02e9ce9ab2
4
- data.tar.gz: 0ff4539f5c80a3c1f75838b7cb60014d3ab13a0a
3
+ metadata.gz: 313d3c808d70b4205249d9c65a62bacb56ed63d6
4
+ data.tar.gz: d583fb40f3264a55ba3bc283a4db921d65c488f4
5
5
  SHA512:
6
- metadata.gz: 75b0aa1a6e74954ae178edbb234d46090310344ec13f00fde190cc0ab6822c136662a57c46f418fb68310a30ab194491ad42c3283a5e3f488913e7ccfa473c80
7
- data.tar.gz: 242c70e3aa96b2730ce5614ee2d7a371cce65a8df888d40e8fc45b15f7deb73742643a5e509cdae79b6fd7a4ff8e3b6985fe2128b67d1e9087f784908d8ed65c
6
+ metadata.gz: e521ca2081dd8fe9377ab40e09d31b603f08cc6100ec875fee3cd0f629d982a8d142f94877f0f7335998737ad860bb8bb62ad16f26edf3c5b10a798325e15021
7
+ data.tar.gz: f64f51bfa27c7e6db9ef29a3266e5bc6a52797dfdc69e442fbedee9665afcc8a2216fea8b647f7513490745afc42a2babeeeaf8d9e5d69ad79f69217d142ce4b
data/Gemfile.lock CHANGED
@@ -1,6 +1,6 @@
1
1
  GIT
2
2
  remote: git://github.com/bbatsov/rubocop.git
3
- revision: c8d652dfa521526ff91cbf769e0d3551d50e1f3e
3
+ revision: d2652328e819cc8317e69b883449e71b83dcdffc
4
4
  specs:
5
5
  rubocop (0.46.0)
6
6
  parser (>= 2.3.3.1, < 3.0)
@@ -48,7 +48,7 @@ GEM
48
48
  thor (>= 0.14.0)
49
49
  ast (2.3.0)
50
50
  bluecloth (2.2.0)
51
- builder (3.2.2)
51
+ builder (3.2.3)
52
52
  chunky_png (1.3.8)
53
53
  coderay (1.1.1)
54
54
  coffee-script (2.4.1)
@@ -87,7 +87,7 @@ GEM
87
87
  erubis (2.7.0)
88
88
  excon (0.54.0)
89
89
  execjs (2.7.0)
90
- ffi (1.9.14)
90
+ ffi (1.9.17)
91
91
  fission (0.5.0)
92
92
  CFPropertyList (~> 2.2)
93
93
  fog (1.38.0)
@@ -242,7 +242,7 @@ GEM
242
242
  hashdiff (0.3.2)
243
243
  inflecto (0.0.2)
244
244
  ipaddress (0.8.3)
245
- json (2.0.2)
245
+ json (2.0.3)
246
246
  kramdown (1.13.2)
247
247
  less (2.6.0)
248
248
  commonjs (~> 0.2.7)
@@ -257,7 +257,7 @@ GEM
257
257
  rake (>= 0.9.2.2)
258
258
  markaby (0.8.0)
259
259
  builder
260
- maruku (0.7.2)
260
+ maruku (0.7.3)
261
261
  metaclass (0.0.4)
262
262
  method_source (0.8.2)
263
263
  mime-types (3.1)
@@ -344,7 +344,7 @@ GEM
344
344
  rubypants
345
345
  uglifier (3.0.4)
346
346
  execjs (>= 0.3.0, < 3)
347
- unicode-display_width (1.1.2)
347
+ unicode-display_width (1.1.3)
348
348
  vcr (3.0.3)
349
349
  w3c_validators (1.3.1)
350
350
  json (~> 2.0)
@@ -354,7 +354,7 @@ GEM
354
354
  crack (>= 0.3.2)
355
355
  hashdiff
356
356
  xml-simple (1.1.5)
357
- yard (0.9.7)
357
+ yard (0.9.8)
358
358
  yard-contracts (0.1.5)
359
359
  contracts (~> 0.7)
360
360
  yard (~> 0.8)
data/NEWS.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Nanoc news
2
2
 
3
+ ## 4.5.3 (2017-01-15)
4
+
5
+ Fixes:
6
+
7
+ * Fixed “Fixnum is deprecated” message (#1061, #1062)
8
+ * Fixed `:pre` snapshot not being created for items that are not laid out (#1064, #1065)
9
+
3
10
  ## 4.5.2 (2017-01-11)
4
11
 
5
12
  Fixes:
@@ -3,9 +3,6 @@ module Nanoc::Int
3
3
  class ItemRep
4
4
  include Nanoc::Int::ContractsSupport
5
5
 
6
- # @return [Hash<Symbol,Nanoc::Int::Content>]
7
- attr_accessor :snapshot_contents
8
-
9
6
  # @return [Boolean]
10
7
  attr_accessor :compiled
11
8
  alias compiled? compiled
@@ -42,54 +39,11 @@ module Nanoc::Int
42
39
  @raw_paths = {}
43
40
  @paths = {}
44
41
  @snapshot_defs = []
45
- @snapshot_contents = { last: @item.content }
46
42
 
47
43
  # Reset flags
48
44
  @compiled = false
49
45
  end
50
46
 
51
- contract C::None => C::Bool
52
- def binary?
53
- @snapshot_contents[:last].binary?
54
- end
55
-
56
- contract C::KeywordArgs[snapshot: C::Optional[C::Maybe[Symbol]]] => String
57
- # Returns the compiled content from a given snapshot.
58
- #
59
- # @param [Symbol] snapshot The name of the snapshot from which to
60
- # fetch the compiled content. By default, the returned compiled content
61
- # will be the content compiled right before the first layout call (if
62
- # any).
63
- #
64
- # @return [String] The compiled content at the given snapshot (or the
65
- # default snapshot if no snapshot is specified)
66
- def compiled_content(snapshot: nil)
67
- # Get name of last pre-layout snapshot
68
- snapshot_name = snapshot || (@snapshot_contents[:pre] ? :pre : :last)
69
-
70
- # Check existance of snapshot
71
- snapshot_def = snapshot_defs.reverse.find { |sd| sd.name == snapshot_name }
72
- unless snapshot_def
73
- raise Nanoc::Int::Errors::NoSuchSnapshot.new(self, snapshot_name)
74
- end
75
-
76
- # Verify snapshot is usable
77
- stopped_moving = snapshot_name != :last || compiled?
78
- is_usable_snapshot = @snapshot_contents[snapshot_name] && stopped_moving
79
- unless is_usable_snapshot
80
- Fiber.yield(Nanoc::Int::Errors::UnmetDependency.new(self))
81
- return compiled_content(snapshot: snapshot)
82
- end
83
-
84
- # Verify snapshot is not binary
85
- snapshot_content = @snapshot_contents[snapshot_name]
86
- if snapshot_content.binary?
87
- raise Nanoc::Int::Errors::CannotGetCompiledContentOfBinaryItem.new(self)
88
- end
89
-
90
- snapshot_content.string
91
- end
92
-
93
47
  contract C::KeywordArgs[snapshot: C::Optional[Symbol]] => C::Maybe[String]
94
48
  # Returns the item rep’s raw path. It includes the path to the output
95
49
  # directory and the full filename.
@@ -9,3 +9,4 @@ require_relative 'repos/item_rep_repo'
9
9
  require_relative 'repos/outdatedness_store'
10
10
  require_relative 'repos/rule_memory_store'
11
11
  require_relative 'repos/site_loader'
12
+ require_relative 'repos/snapshot_repo'
@@ -0,0 +1,60 @@
1
+ module Nanoc::Int
2
+ # @api private
3
+ class SnapshotRepo
4
+ include Nanoc::Int::ContractsSupport
5
+
6
+ def initialize
7
+ @contents = {}
8
+ end
9
+
10
+ contract Nanoc::Int::ItemRep, Symbol => C::Maybe[Nanoc::Int::Content]
11
+ def get(rep, snapshot_name)
12
+ @contents[rep] ||= {}
13
+ @contents[rep][snapshot_name]
14
+ end
15
+
16
+ contract Nanoc::Int::ItemRep, Symbol, Nanoc::Int::Content => C::Any
17
+ def set(rep, snapshot_name, contents)
18
+ @contents[rep] ||= {}
19
+ @contents[rep][snapshot_name] = contents
20
+ end
21
+
22
+ contract Nanoc::Int::ItemRep => C::HashOf[Symbol => Nanoc::Int::Content]
23
+ def get_all(rep)
24
+ @contents[rep] || {}
25
+ end
26
+
27
+ contract Nanoc::Int::ItemRep, C::HashOf[Symbol => Nanoc::Int::Content] => C::Any
28
+ def set_all(rep, contents_per_snapshot)
29
+ @contents[rep] = contents_per_snapshot
30
+ end
31
+
32
+ contract C::KeywordArgs[rep: Nanoc::Int::ItemRep, snapshot: C::Optional[C::Maybe[Symbol]]] => String
33
+ def compiled_content(rep:, snapshot: nil)
34
+ # Get name of last pre-layout snapshot
35
+ snapshot_name = snapshot || (get(rep, :pre) ? :pre : :last)
36
+
37
+ # Check existance of snapshot
38
+ snapshot_def = rep.snapshot_defs.reverse.find { |sd| sd.name == snapshot_name }
39
+ unless snapshot_def
40
+ raise Nanoc::Int::Errors::NoSuchSnapshot.new(rep, snapshot_name)
41
+ end
42
+
43
+ # Verify snapshot is usable
44
+ stopped_moving = snapshot_name != :last || rep.compiled?
45
+ is_usable_snapshot = get(rep, snapshot_name) && stopped_moving
46
+ unless is_usable_snapshot
47
+ Fiber.yield(Nanoc::Int::Errors::UnmetDependency.new(rep))
48
+ return compiled_content(rep: rep, snapshot: snapshot)
49
+ end
50
+
51
+ # Verify snapshot is not binary
52
+ snapshot_content = get(rep, snapshot_name)
53
+ if snapshot_content.binary?
54
+ raise Nanoc::Int::Errors::CannotGetCompiledContentOfBinaryItem.new(rep)
55
+ end
56
+
57
+ snapshot_content.string
58
+ end
59
+ end
60
+ end
@@ -20,11 +20,16 @@ module Nanoc::Int
20
20
  class Compiler
21
21
  # Provides common functionality for accesing “context” of an item that is being compiled.
22
22
  class CompilationContext
23
- def initialize(action_provider:, reps:, site:, compiled_content_cache:)
23
+ attr_reader :site
24
+ attr_reader :compiled_content_cache
25
+ attr_reader :snapshot_repo
26
+
27
+ def initialize(action_provider:, reps:, site:, compiled_content_cache:, snapshot_repo:)
24
28
  @action_provider = action_provider
25
29
  @reps = reps
26
30
  @site = site
27
31
  @compiled_content_cache = compiled_content_cache
32
+ @snapshot_repo = snapshot_repo
28
33
  end
29
34
 
30
35
  def filter_name_and_args_for_layout(layout)
@@ -41,15 +46,17 @@ module Nanoc::Int
41
46
  items: @site.items,
42
47
  dependency_tracker: dependency_tracker,
43
48
  compilation_context: self,
49
+ snapshot_repo: @snapshot_repo,
44
50
  )
45
51
  end
46
52
 
47
53
  def assigns_for(rep, dependency_tracker)
54
+ last_content = @snapshot_repo.get(rep, :last)
48
55
  content_or_filename_assigns =
49
- if rep.binary?
50
- { filename: rep.snapshot_contents[:last].filename }
56
+ if last_content.binary?
57
+ { filename: last_content.filename }
51
58
  else
52
- { content: rep.snapshot_contents[:last].string }
59
+ { content: last_content.string }
53
60
  end
54
61
 
55
62
  view_context = create_view_context(dependency_tracker)
@@ -63,14 +70,6 @@ module Nanoc::Int
63
70
  config: Nanoc::ConfigView.new(@site.config, view_context),
64
71
  )
65
72
  end
66
-
67
- def site
68
- @site
69
- end
70
-
71
- def compiled_content_cache
72
- @compiled_content_cache
73
- end
74
73
  end
75
74
 
76
75
  # All phases for the compilation of a single item rep. Phases will be repeated for every rep.
@@ -93,6 +92,8 @@ module Nanoc::Int
93
92
 
94
93
  executor = Nanoc::Int::Executor.new(rep, @compilation_context, dependency_tracker)
95
94
 
95
+ @compilation_context.snapshot_repo.set(rep, :last, rep.item.content)
96
+
96
97
  @action_provider.memory_for(rep).each do |action|
97
98
  case action
98
99
  when Nanoc::Int::ProcessingActions::Filter
@@ -115,8 +116,9 @@ module Nanoc::Int
115
116
  class Cache
116
117
  include Nanoc::Int::ContractsSupport
117
118
 
118
- def initialize(compiled_content_cache:, wrapped:)
119
+ def initialize(compiled_content_cache:, snapshot_repo:, wrapped:)
119
120
  @compiled_content_cache = compiled_content_cache
121
+ @snapshot_repo = snapshot_repo
120
122
  @wrapped = wrapped
121
123
  end
122
124
 
@@ -124,13 +126,14 @@ module Nanoc::Int
124
126
  def run(rep, is_outdated:)
125
127
  if can_reuse_content_for_rep?(rep, is_outdated: is_outdated)
126
128
  Nanoc::Int::NotificationCenter.post(:cached_content_used, rep)
127
- rep.snapshot_contents = @compiled_content_cache[rep]
129
+
130
+ @snapshot_repo.set_all(rep, @compiled_content_cache[rep])
128
131
  else
129
132
  @wrapped.run(rep, is_outdated: is_outdated)
130
133
  end
131
134
 
132
135
  rep.compiled = true
133
- @compiled_content_cache[rep] = rep.snapshot_contents
136
+ @compiled_content_cache[rep] = @snapshot_repo.get_all(rep)
134
137
  end
135
138
 
136
139
  contract Nanoc::Int::ItemRep, C::KeywordArgs[is_outdated: C::Bool] => C::Bool
@@ -187,7 +190,8 @@ module Nanoc::Int
187
190
  class Write
188
191
  include Nanoc::Int::ContractsSupport
189
192
 
190
- def initialize(wrapped:)
193
+ def initialize(snapshot_repo:, wrapped:)
194
+ @snapshot_repo = snapshot_repo
191
195
  @wrapped = wrapped
192
196
  end
193
197
 
@@ -196,7 +200,7 @@ module Nanoc::Int
196
200
  @wrapped.run(rep, is_outdated: is_outdated)
197
201
 
198
202
  rep.snapshot_defs.each do |sdef|
199
- ItemRepWriter.new.write(rep, sdef.name)
203
+ ItemRepWriter.new.write(rep, @snapshot_repo, sdef.name)
200
204
  end
201
205
  end
202
206
  end
@@ -321,6 +325,7 @@ module Nanoc::Int
321
325
 
322
326
  cache_phase = Phases::Cache.new(
323
327
  compiled_content_cache: @compiled_content_cache,
328
+ snapshot_repo: @compilation_context.snapshot_repo,
324
329
  wrapped: recalculate_phase,
325
330
  )
326
331
 
@@ -329,6 +334,7 @@ module Nanoc::Int
329
334
  )
330
335
 
331
336
  write_phase = Phases::Write.new(
337
+ snapshot_repo: @compilation_context.snapshot_repo,
332
338
  wrapped: resume_phase,
333
339
  )
334
340
 
@@ -372,6 +378,9 @@ module Nanoc::Int
372
378
  # @api private
373
379
  attr_reader :outdatedness_store
374
380
 
381
+ # @api private
382
+ attr_reader :snapshot_repo
383
+
375
384
  def initialize(site, compiled_content_cache:, checksum_store:, rule_memory_store:, action_provider:, dependency_store:, outdatedness_checker:, reps:, outdatedness_store:)
376
385
  @site = site
377
386
 
@@ -383,6 +392,9 @@ module Nanoc::Int
383
392
  @reps = reps
384
393
  @action_provider = action_provider
385
394
  @outdatedness_store = outdatedness_store
395
+
396
+ # TODO: inject
397
+ @snapshot_repo = Nanoc::Int::SnapshotRepo.new
386
398
  end
387
399
 
388
400
  def run_all
@@ -443,6 +455,7 @@ module Nanoc::Int
443
455
  reps: @reps,
444
456
  site: @site,
445
457
  compiled_content_cache: compiled_content_cache,
458
+ snapshot_repo: snapshot_repo,
446
459
  )
447
460
  end
448
461
 
@@ -20,17 +20,20 @@ module Nanoc
20
20
  Nanoc::Int::NotificationCenter.post(:filtering_started, @rep, filter_name)
21
21
 
22
22
  # Run filter
23
- last = @rep.snapshot_contents[:last]
24
- source = @rep.binary? ? last.filename : last.string
23
+ last = @compilation_context.snapshot_repo.get(@rep, :last)
24
+ source = last.binary? ? last.filename : last.string
25
25
  filter_args.freeze
26
26
  result = filter.setup_and_run(source, filter_args)
27
- @rep.snapshot_contents[:last] =
27
+ last =
28
28
  if filter.class.to_binary?
29
29
  Nanoc::Int::BinaryContent.new(filter.output_filename).tap(&:freeze)
30
30
  else
31
31
  Nanoc::Int::TextualContent.new(result).tap(&:freeze)
32
32
  end
33
33
 
34
+ # Store
35
+ @compilation_context.snapshot_repo.set(@rep, :last, last)
36
+
34
37
  # Check whether file was written
35
38
  if filter.class.to_binary? && !File.file?(filter.output_filename)
36
39
  raise OutputNotWrittenError.new(filter_name, filter.output_filename)
@@ -50,7 +53,8 @@ module Nanoc
50
53
  filter_args.freeze
51
54
 
52
55
  # Check whether item can be laid out
53
- raise Nanoc::Int::Errors::CannotLayoutBinaryItem.new(@rep) if @rep.binary?
56
+ last = @compilation_context.snapshot_repo.get(@rep, :last)
57
+ raise Nanoc::Int::Errors::CannotLayoutBinaryItem.new(@rep) if last.binary?
54
58
 
55
59
  # Create filter
56
60
  klass = Nanoc::Filter.named(filter_name)
@@ -69,14 +73,18 @@ module Nanoc
69
73
  content = layout.content
70
74
  arg = content.binary? ? content.filename : content.string
71
75
  res = filter.setup_and_run(arg, filter_args)
72
- @rep.snapshot_contents[:last] = Nanoc::Int::TextualContent.new(res).tap(&:freeze)
76
+
77
+ # Store
78
+ last = Nanoc::Int::TextualContent.new(res).tap(&:freeze)
79
+ @compilation_context.snapshot_repo.set(@rep, :last, last)
73
80
  ensure
74
81
  Nanoc::Int::NotificationCenter.post(:filtering_ended, @rep, filter_name)
75
82
  end
76
83
  end
77
84
 
78
85
  def snapshot(snapshot_name)
79
- @rep.snapshot_contents[snapshot_name] = @rep.snapshot_contents[:last]
86
+ last = @compilation_context.snapshot_repo.get(@rep, :last)
87
+ @compilation_context.snapshot_repo.set(@rep, snapshot_name, last)
80
88
  end
81
89
 
82
90
  def assigns_for(rep)
@@ -105,9 +113,10 @@ module Nanoc
105
113
  klass = Nanoc::Filter.named(filter_name)
106
114
  raise Nanoc::Int::Errors::UnknownFilter.new(filter_name) if klass.nil?
107
115
 
108
- if klass.from_binary? && !rep.binary?
116
+ last = @compilation_context.snapshot_repo.get(@rep, :last)
117
+ if klass.from_binary? && !last.binary?
109
118
  raise Nanoc::Int::Errors::CannotUseBinaryFilter.new(rep, klass)
110
- elsif !klass.from_binary? && rep.binary?
119
+ elsif !klass.from_binary? && last.binary?
111
120
  raise Nanoc::Int::Errors::CannotUseTextualFilter.new(rep, klass)
112
121
  end
113
122
 
@@ -3,7 +3,7 @@ module Nanoc::Int
3
3
  class ItemRepWriter
4
4
  TMP_TEXT_ITEMS_DIR = 'text_items'.freeze
5
5
 
6
- def write(item_rep, snapshot_name)
6
+ def write(item_rep, snapshot_repo, snapshot_name)
7
7
  raw_path = item_rep.raw_path(snapshot: snapshot_name)
8
8
  return unless raw_path
9
9
 
@@ -18,7 +18,7 @@ module Nanoc::Int
18
18
  :will_write_rep, item_rep, raw_path
19
19
  )
20
20
 
21
- content = item_rep.snapshot_contents[snapshot_name]
21
+ content = snapshot_repo.get(item_rep, snapshot_name)
22
22
  if content.binary?
23
23
  temp_path = content.filename
24
24
  else
@@ -36,7 +36,7 @@ module Nanoc::Int
36
36
 
37
37
  # Notify
38
38
  Nanoc::Int::NotificationCenter.post(
39
- :rep_written, item_rep, raw_path, is_created, is_modified
39
+ :rep_written, item_rep, content.binary?, raw_path, is_created, is_modified
40
40
  )
41
41
  end
42
42