nanoc 4.0.0b3 → 4.0.0b4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -0
  3. data/Gemfile.lock +4 -2
  4. data/NEWS.md +10 -0
  5. data/TODO.md +15 -0
  6. data/lib/nanoc/base.rb +4 -27
  7. data/lib/nanoc/base/checksummer.rb +69 -19
  8. data/lib/nanoc/base/compilation/compiler.rb +14 -12
  9. data/lib/nanoc/base/compilation/compiler_dsl.rb +2 -0
  10. data/lib/nanoc/base/compilation/filter.rb +4 -2
  11. data/lib/nanoc/base/compilation/outdatedness_checker.rb +7 -7
  12. data/lib/nanoc/base/compilation/rule.rb +5 -6
  13. data/lib/nanoc/base/compilation/rule_context.rb +16 -34
  14. data/lib/nanoc/base/compilation/rule_memory_calculator.rb +3 -3
  15. data/lib/nanoc/base/compilation/rules_collection.rb +4 -10
  16. data/lib/nanoc/base/context.rb +2 -0
  17. data/lib/nanoc/base/core_ext/array.rb +0 -10
  18. data/lib/nanoc/base/core_ext/hash.rb +0 -10
  19. data/lib/nanoc/base/core_ext/pathname.rb +0 -9
  20. data/lib/nanoc/base/core_ext/string.rb +0 -10
  21. data/lib/nanoc/base/entities.rb +5 -0
  22. data/lib/nanoc/base/entities/content.rb +86 -0
  23. data/lib/nanoc/base/entities/document.rb +56 -0
  24. data/lib/nanoc/base/{source_data → entities}/identifier.rb +12 -1
  25. data/lib/nanoc/base/entities/layout.rb +8 -0
  26. data/lib/nanoc/base/{pattern.rb → entities/pattern.rb} +0 -0
  27. data/lib/nanoc/base/errors.rb +2 -1
  28. data/lib/nanoc/base/result_data/item_rep.rb +13 -278
  29. data/lib/nanoc/base/services.rb +5 -0
  30. data/lib/nanoc/base/services/executor.rb +141 -0
  31. data/lib/nanoc/base/services/item_rep_writer.rb +40 -0
  32. data/lib/nanoc/base/{notification_center.rb → services/notification_center.rb} +0 -0
  33. data/lib/nanoc/base/services/recording_executor.rb +41 -0
  34. data/lib/nanoc/base/{temp_filename_factory.rb → services/temp_filename_factory.rb} +0 -0
  35. data/lib/nanoc/base/source_data/code_snippet.rb +0 -6
  36. data/lib/nanoc/base/source_data/data_source.rb +4 -3
  37. data/lib/nanoc/base/source_data/item.rb +23 -213
  38. data/lib/nanoc/base/source_data/site.rb +0 -1
  39. data/lib/nanoc/base/views.rb +18 -0
  40. data/lib/nanoc/base/views/config.rb +1 -1
  41. data/lib/nanoc/base/views/item.rb +8 -73
  42. data/lib/nanoc/base/views/item_rep.rb +9 -0
  43. data/lib/nanoc/base/views/item_rep_collection.rb +17 -0
  44. data/lib/nanoc/base/views/layout.rb +1 -40
  45. data/lib/nanoc/base/views/mixins/document.rb +76 -0
  46. data/lib/nanoc/base/views/mixins/mutable_document.rb +22 -0
  47. data/lib/nanoc/base/views/mutable_identifiable_collection.rb +1 -1
  48. data/lib/nanoc/base/views/mutable_item.rb +1 -18
  49. data/lib/nanoc/base/views/mutable_item_collection.rb +6 -2
  50. data/lib/nanoc/base/views/mutable_layout.rb +1 -8
  51. data/lib/nanoc/cli/commands/compile.rb +1 -2
  52. data/lib/nanoc/cli/commands/create-site.rb +5 -5
  53. data/lib/nanoc/cli/commands/show-data.rb +11 -1
  54. data/lib/nanoc/data_sources/filesystem.rb +17 -10
  55. data/lib/nanoc/helpers/capturing.rb +1 -2
  56. data/lib/nanoc/helpers/filtering.rb +13 -1
  57. data/lib/nanoc/helpers/rendering.rb +4 -2
  58. data/lib/nanoc/version.rb +1 -1
  59. data/test/base/core_ext/array_spec.rb +0 -7
  60. data/test/base/core_ext/hash_spec.rb +0 -13
  61. data/test/base/core_ext/pathname_spec.rb +0 -33
  62. data/test/base/core_ext/string_spec.rb +0 -10
  63. data/test/base/test_compiler_dsl.rb +3 -3
  64. data/test/base/test_data_source.rb +2 -2
  65. data/test/base/test_item.rb +5 -129
  66. data/test/base/test_item_rep.rb +26 -558
  67. data/test/base/test_layout.rb +2 -26
  68. data/test/base/test_rule.rb +3 -3
  69. data/test/base/test_rule_context.rb +34 -15
  70. data/test/data_sources/test_filesystem.rb +2 -2
  71. data/test/data_sources/test_filesystem_unified.rb +39 -33
  72. data/test/extra/checking/checks/test_html.rb +0 -1
  73. data/test/extra/checking/checks/test_mixed_content.rb +3 -3
  74. data/test/extra/deployers/test_fog.rb +24 -24
  75. data/test/filters/test_less.rb +4 -4
  76. data/test/filters/test_sass.rb +10 -5
  77. data/test/filters/test_xsl.rb +6 -0
  78. data/test/helpers/test_capturing.rb +0 -1
  79. data/test/helpers/test_filtering.rb +5 -19
  80. data/test/helpers/test_tagging.rb +6 -6
  81. metadata +18 -11
  82. data/lib/nanoc/base/compilation/item_rep_proxy.rb +0 -109
  83. data/lib/nanoc/base/compilation/item_rep_recorder_proxy.rb +0 -97
  84. data/lib/nanoc/base/source_data/layout.rb +0 -111
  85. data/test/base/checksummer_spec.rb +0 -256
  86. data/test/base/test_item_rep_recorder_proxy.rb +0 -17
@@ -1,111 +0,0 @@
1
- module Nanoc::Int
2
- # Represents a layout in a nanoc site. It has content, attributes, an
3
- # identifier and a modification time (to speed up compilation).
4
- #
5
- # @api private
6
- class Layout
7
- extend Nanoc::Int::Memoization
8
-
9
- # @return [String] The raw content of this layout
10
- attr_reader :raw_content
11
-
12
- # @return [Hash] This layout's attributes
13
- attr_reader :attributes
14
-
15
- # @return [Nanoc::Identifier] This layout's identifier
16
- attr_accessor :identifier
17
-
18
- # Creates a new layout.
19
- #
20
- # @param [String] raw_content The raw content of this layout.
21
- #
22
- # @param [Hash] attributes A hash containing this layout's attributes.
23
- #
24
- # @param [String] identifier This layout's identifier.
25
- #
26
- # @param [Hash] params Extra parameters. Unused.
27
- def initialize(raw_content, attributes, identifier, params = {})
28
- @raw_content = raw_content
29
- @attributes = attributes.__nanoc_symbolize_keys_recursively
30
- @identifier = Nanoc::Identifier.from(identifier)
31
- end
32
-
33
- # Requests the attribute with the given key.
34
- #
35
- # @param [Symbol] key The name of the attribute to fetch.
36
- #
37
- # @return [Object] The value of the requested attribute.
38
- def [](key)
39
- @attributes[key]
40
- end
41
-
42
- def []=(key, value)
43
- @attributes[key] = value
44
- end
45
-
46
- # Returns the type of this object. Will always return `:layout`, because
47
- # this is a layout. For items, this method returns `:item`.
48
- #
49
- # @api private
50
- #
51
- # @return [Symbol] :layout
52
- def type
53
- :layout
54
- end
55
-
56
- # Prevents all further modifications to the layout.
57
- #
58
- # @return [void]
59
- def freeze
60
- attributes.__nanoc_freeze_recursively
61
- identifier.freeze
62
- raw_content.freeze
63
- end
64
-
65
- # Returns an object that can be used for uniquely identifying objects.
66
- #
67
- # @api private
68
- #
69
- # @return [Object] An unique reference to this object
70
- def reference
71
- [type, identifier]
72
- end
73
-
74
- def inspect
75
- "<#{self.class} identifier=\"#{identifier}\">"
76
- end
77
-
78
- # @return [String] The checksum for this object. If its contents change,
79
- # the checksum will change as well.
80
- def __nanoc_checksum
81
- Nanoc::Int::Checksummer.calc(self)
82
- end
83
- memoize :__nanoc_checksum
84
-
85
- def hash
86
- self.class.hash ^ identifier.hash
87
- end
88
-
89
- def eql?(other)
90
- self.class == other.class && identifier == other.identifier
91
- end
92
-
93
- def ==(other)
94
- self.eql?(other)
95
- end
96
-
97
- def marshal_dump
98
- [
99
- @raw_content,
100
- @attributes,
101
- @identifier
102
- ]
103
- end
104
-
105
- def marshal_load(source)
106
- @raw_content,
107
- @attributes,
108
- @identifier = *source
109
- end
110
- end
111
- end
@@ -1,256 +0,0 @@
1
- require 'tempfile'
2
-
3
- describe Nanoc::Int::Checksummer do
4
- subject { Nanoc::Int::Checksummer }
5
-
6
- CHECKSUM_REGEX = /\A[0-9a-zA-Z\/+]+=*\Z/
7
-
8
- describe 'for String' do
9
- it 'should checksum strings' do
10
- subject.calc('foo').must_equal('+5k/BWvkYc6T1qhGaSyf3861CyE=')
11
- end
12
- end
13
-
14
- describe 'for Array' do
15
- it 'should checksum arrays' do
16
- subject.calc([1, 'a', :a]).must_equal 'YtWOEFUAMQritkY38KXHFZM/n2E='
17
- end
18
-
19
- it 'should take order into account when checksumming arrays' do
20
- subject.calc([:a, 'a', 1]).wont_equal(subject.calc([1, 'a', :a]))
21
- end
22
-
23
- it 'should checksum non-serializable arrays' do
24
- subject.calc([-> {}]).must_match(CHECKSUM_REGEX)
25
- end
26
-
27
- it 'should checksum recursive arrays' do
28
- array = [:a]
29
- array << array
30
- subject.calc(array).must_equal('mR3c98xA5ecazxx+M3h0Ss4/J20=')
31
- end
32
- end
33
-
34
- describe 'for Hash' do
35
- it 'should checksum hashes' do
36
- subject.calc({ a: 1, b: 2 }).must_equal 'qY8fW6gWK7F1XQ9MLrx3Gru/RTY='
37
- end
38
-
39
- it 'should take order into account when checksumming hashes' do
40
- subject.calc({ a: 1, b: 2 }).wont_equal(subject.calc({ b: 2, a: 1 }))
41
- end
42
-
43
- it 'should checksum non-serializable hashes' do
44
- subject.calc({ a: -> {} }).must_match(CHECKSUM_REGEX)
45
- end
46
-
47
- it 'should checksum recursive hash keys' do
48
- hash = {}
49
- hash[hash] = 123
50
- subject.calc(hash).must_equal('mKucWMhRtR/FHWNqR/EErF4qgTk=')
51
- end
52
-
53
- it 'should checksum recursive hash values' do
54
- hash = {}
55
- hash[123] = hash
56
- subject.calc(hash).must_equal('PBiDX0nWnV+DAYB+w+xM0Kf21ZM=')
57
- end
58
- end
59
-
60
- describe 'for Pathname' do
61
- let(:file) { Tempfile.new('foo') }
62
- let(:filename) { file.path }
63
- let(:pathname) { Pathname.new(filename) }
64
- let(:atime) { 1_234_567_890 }
65
- let(:mtime) { 1_234_567_890 }
66
- let(:data) { 'stuffs' }
67
- let(:normal_checksum) { 'THy7Y28oroov/KvPxT6wcMnXr/s=' }
68
-
69
- before do
70
- file.write(data)
71
- file.close
72
- File.utime(atime, mtime, filename)
73
- end
74
-
75
- after do
76
- file.unlink
77
- end
78
-
79
- describe 'does not exist' do
80
- let(:non_existing_filename) { 'askldjfklaslasdfkjsajdf' }
81
- let(:pathname) { Pathname.new(filename) }
82
-
83
- it 'should still checksum' do
84
- subject.calc(pathname).must_equal(normal_checksum)
85
- end
86
- end
87
-
88
- it 'should get the mtime right' do
89
- stat = File.stat(filename)
90
- stat.mtime.to_i.must_equal(mtime)
91
- end
92
-
93
- it 'should get the file size right' do
94
- stat = File.stat(filename)
95
- stat.size.must_equal(6)
96
- end
97
-
98
- it 'should checksum binary content' do
99
- subject.calc(pathname).must_equal(normal_checksum)
100
- end
101
-
102
- describe 'if the mtime changes' do
103
- let(:mtime) { 1_333_333_333 }
104
-
105
- it 'should have a different checksum' do
106
- subject.calc(pathname).must_match(CHECKSUM_REGEX)
107
- subject.calc(pathname).wont_equal(normal_checksum)
108
- end
109
- end
110
-
111
- describe 'if the content changes, but not the file size' do
112
- let(:data) { 'STUFF!' }
113
-
114
- it 'should have the same checksum' do
115
- subject.calc(pathname).must_equal(normal_checksum)
116
- end
117
- end
118
-
119
- describe 'if the file size changes' do
120
- let(:data) { 'stuff and stuff and stuff!!!' }
121
-
122
- it 'should have a different checksum' do
123
- subject.calc(pathname).must_match(CHECKSUM_REGEX)
124
- subject.calc(pathname).wont_equal(normal_checksum)
125
- end
126
- end
127
- end
128
-
129
- it 'should not have the same checksum for same content but different class'
130
-
131
- describe 'for Nanoc::Int::RulesCollection' do
132
- let(:data) { 'STUFF!' }
133
- let(:normal_checksum) { 'Y6mX13i8ZEd4a11xRPc2yNQSRDs=' }
134
-
135
- let(:rules_collection) do
136
- coll = Nanoc::Int::RulesCollection.new(nil)
137
- coll.data = data
138
- coll
139
- end
140
-
141
- it 'should calculate' do
142
- subject.calc(rules_collection).must_equal(normal_checksum)
143
- end
144
-
145
- describe 'if the content changes' do
146
- let(:data) { 'Other stuff!' }
147
-
148
- it 'should have a different checksum' do
149
- subject.calc(rules_collection).must_match(CHECKSUM_REGEX)
150
- subject.calc(rules_collection).wont_equal(normal_checksum)
151
- end
152
- end
153
- end
154
-
155
- describe 'for Nanoc::Int::CodeSnippet' do
156
- let(:data) { 'asdf' }
157
- let(:filename) { File.expand_path('bob.txt') }
158
- let(:code_snippet) { Nanoc::Int::CodeSnippet.new(data, filename) }
159
- let(:normal_checksum) { 's6oZ1xLVekKDVhYrXsJuHChFjek=' }
160
-
161
- it 'should checksum the data' do
162
- subject.calc(code_snippet).must_equal(normal_checksum)
163
- end
164
-
165
- describe 'if the filename changes' do
166
- let(:filename) { File.expand_path('george.txt') }
167
-
168
- it 'should have the same checksum' do
169
- subject.calc(code_snippet).must_equal(normal_checksum)
170
- end
171
- end
172
-
173
- describe 'if the content changes' do
174
- let(:data) { 'Other stuff!' }
175
-
176
- it 'should have a different checksum' do
177
- subject.calc(code_snippet).must_match(CHECKSUM_REGEX)
178
- subject.calc(code_snippet).wont_equal(normal_checksum)
179
- end
180
- end
181
- end
182
-
183
- describe 'for Nanoc::Int::Configuration' do
184
- let(:wrapped) { { a: 1, b: 2 } }
185
- let(:configuration) { Nanoc::Int::Configuration.new(wrapped) }
186
- let(:normal_checksum) { 'xwbPeftLbSXYx0OJbKCqrPHctPU=' }
187
-
188
- it 'should checksum the hash' do
189
- subject.calc(configuration).must_equal(normal_checksum)
190
- end
191
-
192
- describe 'if the content changes' do
193
- let(:wrapped) { { a: 666, b: 2 } }
194
-
195
- it 'should have a different checksum' do
196
- subject.calc(configuration).must_match(CHECKSUM_REGEX)
197
- subject.calc(configuration).wont_equal(normal_checksum)
198
- end
199
- end
200
- end
201
-
202
- describe 'for Nanoc::Int::Item' do
203
- let(:content) { 'asdf' }
204
- let(:filename) { File.expand_path('bob.txt') }
205
- let(:attributes) { { a: 1, b: 2 } }
206
- let(:identifier) { '/foo/' }
207
- let(:item) { Nanoc::Int::Item.new(content, attributes, identifier) }
208
- let(:normal_checksum) { '6VtlVLx1JE69erzfDczZW7HSWeY=' }
209
-
210
- it 'should checksum item' do
211
- subject.calc(item).must_equal(normal_checksum)
212
- end
213
-
214
- describe 'with recursive attributes' do
215
- it 'should checksum' do
216
- item.attributes[:a] = item
217
- subject.calc(item).must_match(CHECKSUM_REGEX)
218
- subject.calc(item).wont_equal(normal_checksum)
219
- end
220
- end
221
-
222
- describe 'with changed attributes' do
223
- let(:attributes) { { x: 4, y: 5 } }
224
-
225
- it 'should have a different checksum' do
226
- subject.calc(item).must_match(CHECKSUM_REGEX)
227
- subject.calc(item).wont_equal(normal_checksum)
228
- end
229
- end
230
-
231
- describe 'with changed content' do
232
- let(:content) { 'something drastically different' }
233
-
234
- it 'should have a different checksum' do
235
- subject.calc(item).must_match(CHECKSUM_REGEX)
236
- subject.calc(item).wont_equal(normal_checksum)
237
- end
238
- end
239
- end
240
-
241
- describe 'for other marshal-able classes' do
242
- let(:obj) { :foobar }
243
-
244
- it 'should checksum' do
245
- subject.calc(obj).must_match(CHECKSUM_REGEX)
246
- end
247
- end
248
-
249
- describe 'for other non-marshal-able classes' do
250
- let(:obj) { proc {} }
251
-
252
- it 'should checksum' do
253
- subject.calc(obj).must_match(CHECKSUM_REGEX)
254
- end
255
- end
256
- end
@@ -1,17 +0,0 @@
1
- class Nanoc::Int::ItemRepRecorderProxyTest < Nanoc::TestCase
2
- def test_double_names
3
- proxy = Nanoc::Int::ItemRepRecorderProxy.new(mock)
4
-
5
- proxy.snapshot(:foo, stuff: :giraffe)
6
- assert_raises(Nanoc::Int::Errors::CannotCreateMultipleSnapshotsWithSameName) do
7
- proxy.snapshot(:foo, stuff: :donkey)
8
- end
9
- end
10
-
11
- def test_double_params
12
- proxy = Nanoc::Int::ItemRepRecorderProxy.new(mock)
13
-
14
- proxy.snapshot(:foo)
15
- proxy.snapshot(:bar)
16
- end
17
- end