Skip to content

Commit 027af71

Browse files
committed
merged changes from master branch
2 parents a99640e + 75a6584 commit 027af71

File tree

22 files changed

+166
-48
lines changed

22 files changed

+166
-48
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
script: "bundle exec rake skip=Nanoc3::Filters::LessTest"
1+
rvm: 1.9.3

NEWS.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ Extensions:
1616
* Added Albino to supported syntax colorizers [Dan Callahan]
1717
* Allowed syntax colorizer to colorize outside `pre` elements [Kevin Lynagh]
1818

19+
## 3.2.3 (2011-10-31)
20+
21+
* Made syntax colorizer only strip trailing blank lines instead of all blanks
22+
* Improved Ruby 1.9.x compatibility
23+
* Made default rakefile require rubygems if necessary
24+
* Made filename/content argument of `Nanoc3::Item#initialize` mandatory
25+
1926
## 3.2.2 (2011-09-04)
2027

2128
* Fixed command usage printing

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ may be interested in the development dependencies:
7373

7474
* Ben Armston
7575
* Colin Barrett
76+
* Bil Bas
7677
* Dmitry Bilunov
7778
* Devon Luke Buchanan
7879
* Stefan Bühler
@@ -102,6 +103,7 @@ may be interested in the development dependencies:
102103
* Eric Sunshine
103104
* Dennis Sutch
104105
* Matthias Vallentin
106+
* Ruben Verborgh
105107
* Toon Willems
106108

107109
## Contact

lib/nanoc/base/compilation/compiler.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,7 @@ def layouts
315315
#
316316
# @return [void]
317317
def compile_reps(reps)
318-
outdated_reps = Set.new(reps.select { |rep| outdatedness_checker.outdated?(rep) })
319-
content_dependency_graph = Nanoc::DirectedGraph.new(outdated_reps)
318+
content_dependency_graph = Nanoc::DirectedGraph.new(reps)
320319

321320
# Listen to processing start/stop
322321
Nanoc::NotificationCenter.on(:processing_started, self) { |obj| @stack.push(obj) }

lib/nanoc/base/directed_graph.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module Nanoc
88
# @example Creating and using a directed graph
99
#
1010
# # Create a graph with three vertices
11-
# graph = DirectedGraph.new(%w( a b c d ))
11+
# graph = Nanoc::DirectedGraph.new(%w( a b c d ))
1212
#
1313
# # Add edges
1414
# graph.add_edge('a', 'b')

lib/nanoc/base/result_data/item_rep.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ def compiled_content(params={})
240240
Nanoc::NotificationCenter.post(:visit_ended, self.item)
241241

242242
# Require compilation
243-
raise Nanoc::Errors::UnmetDependency.new(self) if !compiled? && !params[:force]
243+
raise Nanoc::Errors::UnmetDependency.new(self) if !compiled?
244244

245245
# Get name of last pre-layout snapshot
246246
snapshot_name = params[:snapshot]

lib/nanoc/base/source_data/item.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ def initialize(raw_content_or_raw_filename, attributes, identifier, params=nil)
7070
params = { :mtime => params } if params.is_a?(Time)
7171
params[:binary] = false unless params.has_key?(:binary)
7272

73+
if raw_content_or_raw_filename.nil?
74+
raise "attempted to create an item with no content/filename (identifier #{identifier})"
75+
end
76+
7377
# Get type and raw content or raw filename
7478
@is_binary = params[:binary]
7579
if @is_binary

lib/nanoc/cli/commands/compile.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def generate_diff_for(rep, snapshot)
153153

154154
# Get old and new content
155155
old_content = File.read(rep.raw_path(:snapshot => snapshot))
156-
new_content = rep.compiled_content(:snapshot => snapshot, :force => true)
156+
new_content = rep.compiled_content(:snapshot => snapshot)
157157

158158
# Check whether there’s a different
159159
return if old_content == new_content

lib/nanoc/cli/commands/watch.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ class Notifier
9292
# A list of commandline tool names that can be used to send notifications
9393
TOOLS = %w( growlnotify notify-send )
9494

95+
# The tool to use for discovering binaries' locations
96+
FIND_BINARY_COMMAND = RUBY_PLATFORM =~ /mingw|mswin/ ? "where" : "which"
97+
9598
# Send a notification. If no notifier is found, no notification will be
9699
# created.
97100
#
@@ -104,7 +107,7 @@ def notify(message)
104107
private
105108

106109
def tool
107-
@tool ||= TOOLS.find { |t| !`which #{t}`.empty? }
110+
@tool ||= TOOLS.find { |t| !`#{FIND_BINARY_COMMAND} #{t}`.empty? }
108111
end
109112

110113
def growlnotify(message)

lib/nanoc/cli/error_handler.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,9 @@ def resolution_for(error)
169169
case error
170170
when LoadError
171171
# Get gem name
172-
matches = error.message.match(/no such file to load -- ([^\s]+)/)
173-
return nil if matches.size == 0
174-
lib_name = matches[1]
175-
gem_name = GEM_NAMES[$1]
172+
matches = error.message.match(/(no such file to load|cannot load such file) -- ([^\s]+)/)
173+
return nil if matches.nil?
174+
gem_name = GEM_NAMES[matches[2]]
176175

177176
# Build message
178177
if gem_name

lib/nanoc/data_sources/filesystem.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,9 @@ def read(filename)
283283
raise_encoding_error(filename, original_encoding) if !data.valid_encoding?
284284
end
285285

286+
# Remove UTF-8 BOM (ugly)
287+
data.gsub!("\xEF\xBB\xBF", '')
288+
286289
data
287290
end
288291

lib/nanoc/filters/colorize_syntax.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,9 @@ def run(content, params={})
119119
next if language.nil?
120120

121121
# Highlight
122-
highlighted_code = highlight(element.inner_text.strip, language, params)
123-
element.inner_html = highlighted_code.strip
122+
raw = strip(element.inner_text)
123+
highlighted_code = highlight(raw, language, params)
124+
element.inner_html = strip(highlighted_code)
124125

125126
# Add class
126127
unless has_class
@@ -139,6 +140,11 @@ def run(content, params={})
139140

140141
KNOWN_COLORIZERS = [ :albino, :coderay, :dummy, :pygmentize, :simon_highlight ]
141142

143+
# Removes the first blank lines and any whitespace at the end.
144+
def strip(s)
145+
s.lines.drop_while { |line| line.strip.empty? }.join.rstrip
146+
end
147+
142148
def highlight(code, language, params={})
143149
colorizer = @colorizers[language.to_sym]
144150
if KNOWN_COLORIZERS.include?(colorizer)

lib/nanoc/helpers/rendering.rb

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,33 @@ module Rendering
77

88
include Nanoc::Helpers::Capturing
99

10-
# Returns a string containing the rendered given layout. The given layout
11-
# will first be run through the matching layout rule.
10+
# Renders the given layout. The given layout will be run through the first
11+
# matching layout rule.
1212
#
13-
# The assigns (`@item`, `@config`, …) will not be available in the
14-
# partial, but it is possible to pass custom assigns to the method. These
15-
# assigns will be made available as instance variables inside the partial.
13+
# When this method is invoked _without_ a block, the return value will be
14+
# the rendered layout (a string) and `_erbout` will not be modified.
1615
#
17-
# The method can also take a block. In this case, the content of the block
18-
# will be captured (using the {Nanoc::Helpers::Capturing} helper) and
19-
# this content will be made available with `yield`. In other words, a
20-
# `yield` inside the partial will output the content of the block passed
21-
# to the method.
16+
# When this method is invoked _with_ a block, an empty string will be
17+
# returned and the rendered content will be appended to `_erbout`. In this
18+
# case, the content of the block will be captured (using the
19+
# {Nanoc::Helpers::Capturing} helper) and this content will be made
20+
# available with `yield`. In other words, a `yield` inside the partial
21+
# will output the content of the block passed to the method.
22+
#
23+
# (For the curious: the reason why {#render} with a block has this
24+
# behaviour of returning an empty string and modifying `_erbout` is
25+
# because ERB does not support combining the `<%= ... %>` form with a
26+
# method call that takes a block.)
27+
#
28+
# The assigns (`@item`, `@config`, …) will be available in the partial. It
29+
# is also possible to pass custom assigns to the method; these assigns
30+
# will be made available as instance variables inside the partial.
2231
#
2332
# @param [String] identifier The identifier of the layout that should be
2433
# rendered
2534
#
26-
# @param [Hash] other_assigns A hash containing assigns that will be made
27-
# available as instance variables in the partial
35+
# @param [Hash] other_assigns A hash containing extra assigns that will be
36+
# made available as instance variables in the partial
2837
#
2938
# @example Rendering a head and a foot partial around some text
3039
#
@@ -52,10 +61,22 @@ module Rendering
5261
# I'm boxy! Luvz!
5362
# <% end %>
5463
#
64+
# # Result
65+
# <div class="box">
66+
# I'm boxy! Luvz!
67+
# </div>
68+
#
5569
# @raise [Nanoc::Errors::UnknownLayout] if the given layout does not
5670
# exist
5771
#
58-
# @return [String] The rendered partial
72+
# @raise [Nanoc::Errors::CannotDetermineFilter] if there is no layout
73+
# rule for the given layout
74+
#
75+
# @raise [Nanoc::Errors::UnknownFilter] if the layout rule for the given
76+
# layout specifies an unknown filter
77+
#
78+
# @return [String, nil] The rendered partial, or nil if this method was
79+
# invoked with a block
5980
def render(identifier, other_assigns={}, &block)
6081
# Find layout
6182
layout = @site.layouts.find { |l| l.identifier == identifier.cleaned_identifier }

test/base/test_compiler.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,4 +298,19 @@ def compiler.route_reps
298298
end
299299
end
300300

301+
def test_compile_should_recompile_all_reps
302+
Nanoc3::CLI.run %w( create_site bar )
303+
304+
FileUtils.cd('bar') do
305+
Nanoc3::CLI.run %w( compile )
306+
307+
site = Nanoc3::Site.new('.')
308+
site.compile
309+
310+
# At this point, even the already compiled items in the previous pass
311+
# should have their compiled content assigned, so this should work:
312+
site.items[0].reps[0].compiled_content
313+
end
314+
end
315+
301316
end

test/base/test_directed_graph.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,4 +280,9 @@ def test_roots_after_removing_edge
280280
assert_equal Set.new([ 1, 2, 3 ]), graph.roots
281281
end
282282

283+
def test_example
284+
YARD.parse('../lib/nanoc/base/directed_graph.rb')
285+
assert_examples_correct 'Nanoc::DirectedGraph'
286+
end
287+
283288
end

test/base/test_item.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def test_frozen_identifier
2525
item.identifier.chop!
2626
rescue => error
2727
raised = true
28-
assert_equal "can't modify frozen string", error.message
28+
assert_match /^can't modify frozen [Ss]tring$/, error.message
2929
end
3030
assert raised, 'Should have raised when trying to modify a frozen string'
3131
end

test/base/test_layout.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def test_frozen_identifier
2222
layout.identifier.chop!
2323
rescue => error
2424
raised = true
25-
assert_equal "can't modify frozen string", error.message
25+
assert_match /^can't modify frozen [Ss]tring$/, error.message
2626
end
2727
assert raised, 'Should have raised when trying to modify a frozen string'
2828
end

test/data_sources/test_filesystem.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,22 @@ def test_parse_embedded_empty_meta
365365
assert_equal('blah blah', result[1])
366366
end
367367

368+
def test_parse_utf8_bom
369+
File.open('test.html', 'w') do |io|
370+
io.write [ 0xEF, 0xBB, 0xBF ].map { |i| i.chr }.join
371+
io.write "-----\n"
372+
io.write "utf8bomawareness: high\n"
373+
io.write "-----\n"
374+
io.write "content goes here\n"
375+
end
376+
377+
data_source = Nanoc::DataSources::FilesystemCombined.new(nil, nil, nil, nil)
378+
379+
result = data_source.instance_eval { parse('test.html', nil, 'foobar') }
380+
assert_equal({ 'utf8bomawareness' => 'high' }, result[0])
381+
assert_equal('content goes here', result[1])
382+
end
383+
368384
def test_parse_embedded_no_meta
369385
content = "blah\n" \
370386
"blah blah blah\n" \

test/data_sources/test_filesystem_unified.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ def test_create_object_not_at_root
2727
assert File.file?('foobar/asdf.html')
2828

2929
# Check file content
30-
expected = "--- \nfoo: bar\n---\n\ncontent here"
31-
assert_equal expected, File.read('foobar/asdf.html')
30+
expected = /^--- ?\nfoo: bar\n---\n\ncontent here$/
31+
assert_match expected, File.read('foobar/asdf.html')
3232
end
3333

3434
def test_create_object_at_root
@@ -43,8 +43,8 @@ def test_create_object_at_root
4343
assert File.file?('foobar/index.html')
4444

4545
# Check file content
46-
expected = "--- \nfoo: bar\n---\n\ncontent here"
47-
assert_equal expected, File.read('foobar/index.html')
46+
expected = /^--- ?\nfoo: bar\n---\n\ncontent here$/
47+
assert_match expected, File.read('foobar/index.html')
4848
end
4949

5050
def test_load_objects

test/filters/test_colorize_syntax.rb

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ def test_not_outside_pre
287287
def test_outside_pre
288288
if_have 'coderay', 'nokogiri' do
289289
# Create filter
290-
filter = ::Nanoc3::Filters::ColorizeSyntax.new
290+
filter = ::Nanoc::Filters::ColorizeSyntax.new
291291

292292
# Get input and expected output
293293
input = '<code class="language-ruby"># comment</code>'
@@ -299,4 +299,34 @@ def test_outside_pre
299299
end
300300
end
301301

302+
def test_strip
303+
if_have 'coderay', 'nokogiri' do
304+
# Create filter
305+
filter = ::Nanoc::Filters::ColorizeSyntax.new
306+
307+
# Simple test
308+
assert_equal " bar", filter.send(:strip, "\n bar")
309+
310+
# Get input and expected output
311+
input = <<EOS
312+
before
313+
<pre><code class="language-ruby">
314+
def foo
315+
end
316+
</code></pre>
317+
after
318+
EOS
319+
expected_output = <<EOS
320+
before
321+
<pre><code class="language-ruby"> <span class=\"keyword\">def</span> <span class=\"function\">foo</span>
322+
<span class=\"keyword\">end</span></code></pre>
323+
after
324+
EOS
325+
326+
# Run filter
327+
actual_output = filter.run(input)
328+
assert_equal(expected_output, actual_output)
329+
end
330+
end
331+
302332
end

test/filters/test_rdoc.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def test_filter
1111

1212
# Run filter
1313
result = filter.run("= Foo")
14-
assert_match(%r{<h1>Foo</h1>\Z}, result)
14+
assert_match(%r{<h1( id="label-Foo")?>Foo</h1>\Z}, result)
1515
end
1616
end
1717

0 commit comments

Comments
 (0)