Skip to content

Commit

Permalink
Merge branch 'release-4.2.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdefreyne committed Jun 18, 2016
2 parents 1035294 + d85e3b7 commit 5945aa3
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 49 deletions.
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -5,6 +5,7 @@ gemspec
group :devel do
gem 'coveralls', require: false
gem 'guard-rake'
gem 'fuubar'
gem 'minitest', '~> 5.0'
gem 'mocha'
gem 'pry'
Expand Down
18 changes: 15 additions & 3 deletions lib/nanoc/base/memoization.rb
Expand Up @@ -15,6 +15,8 @@ def initialize(value)
end
end

NONE = Object.new

# Memoizes the method with the given name. The modified method will cache
# the results of the original method, so that calling a method twice with
# the same arguments will short-circuit and return the cached results
Expand Down Expand Up @@ -57,12 +59,22 @@ def memoize(method_name)
@__memoization_cache[method_name] ||= {}
method_cache = @__memoization_cache[method_name]

if method_cache.key?(args) && method_cache[args].weakref_alive?
method_cache[args].value
else
value = NONE
if method_cache.key?(args)
value =
begin
method_cache[args].value
rescue WeakRef::RefError
NONE
end
end

if value.equal?(NONE)
send(original_method_name, *args).tap do |r|
method_cache[args] = WeakRef.new(Wrapper.new(r))
end
else
value
end
end
end
Expand Down
6 changes: 5 additions & 1 deletion lib/nanoc/cli/command_runner.rb
Expand Up @@ -44,14 +44,18 @@ def in_site_dir?
# Asserts that the current working directory contains a site and loads the site into memory.
#
# @return [void]
def load_site
def load_site(preprocess: false)
print 'Loading site… '
$stdout.flush

if site.nil?
raise ::Nanoc::Int::Errors::GenericTrivial, 'The current working directory does not seem to be a Nanoc site.'
end

if preprocess
site.compiler.action_provider.preprocess(site)
end

puts 'done'
end

Expand Down
3 changes: 1 addition & 2 deletions lib/nanoc/cli/commands/check.rb
Expand Up @@ -12,8 +12,7 @@ module Nanoc::CLI::Commands
class Check < ::Nanoc::CLI::CommandRunner
def run
validate_options_and_arguments
load_site
site.compiler.action_provider.preprocess(site)
load_site(preprocess: true)

runner = Nanoc::Extra::Checking::Runner.new(site)

Expand Down
8 changes: 1 addition & 7 deletions lib/nanoc/cli/commands/deploy.rb
Expand Up @@ -13,7 +13,7 @@
module Nanoc::CLI::Commands
class Deploy < ::Nanoc::CLI::CommandRunner
def run
prepare
load_site(preprocess: true)

if options[:'list-deployers']
list_deployers
Expand All @@ -26,12 +26,6 @@ def run

private

def prepare
load_site
# FIXME: ugly to preprocess here
site.compiler.action_provider.preprocess(site)
end

def list_deployers
deployers = Nanoc::Int::PluginRegistry.instance.find_all(Nanoc::Extra::Deployer)
deployer_names = deployers.keys.sort_by(&:to_s)
Expand Down
4 changes: 1 addition & 3 deletions lib/nanoc/cli/commands/prune.rb
Expand Up @@ -15,9 +15,7 @@
module Nanoc::CLI::Commands
class Prune < ::Nanoc::CLI::CommandRunner
def run
load_site
# FIXME: ugly to preprocess here
site.compiler.action_provider.preprocess(site)
load_site(preprocess: true)
site.compiler.build_reps

if options.key?(:yes)
Expand Down
2 changes: 1 addition & 1 deletion lib/nanoc/cli/commands/show-data.rb
Expand Up @@ -9,7 +9,7 @@
module Nanoc::CLI::Commands
class ShowData < ::Nanoc::CLI::CommandRunner
def run
load_site
load_site(preprocess: true)

# Get data
items = site.items
Expand Down
15 changes: 15 additions & 0 deletions spec/nanoc/regressions/gh_867_spec.rb
@@ -0,0 +1,15 @@
describe 'GH-867', site: true, stdio: true do
before do
File.write('content/foo.md', 'stuff')

File.write('Rules', <<EOS)
preprocess do
items.delete_if { |_| true }
end
EOS
end

it 'preprocesses before running show-data' do
expect { Nanoc::CLI.run(%w( show-data )) }.not_to output(/foo/).to_stdout
end
end
2 changes: 1 addition & 1 deletion tasks/test.rake
Expand Up @@ -17,7 +17,7 @@ namespace :test do
end

RSpec::Core::RakeTask.new(:spec) do |t|
t.rspec_opts = '-r ./spec/spec_helper.rb --color'
t.rspec_opts = '-r ./spec/spec_helper.rb --format Fuubar --color'
t.verbose = false
end

Expand Down
29 changes: 1 addition & 28 deletions test/filters/test_colorize_syntax.rb
Expand Up @@ -406,7 +406,7 @@ def foo
EOS
expected_output = <<EOS
before
<pre><code class=\"language-ruby highlight\"> <span class=\"k\">def</span> <span class=\"nf\">foo</span>
<pre><code class=\"language-ruby\"> <span class=\"k\">def</span> <span class=\"nf\">foo</span>
<span class=\"k\">end</span></code></pre>
after
EOS
Expand All @@ -416,31 +416,4 @@ def foo
assert_equal(expected_output, actual_output)
end
end

def test_rouge_with_css_class
if_have 'rouge', 'nokogiri' do
# Create filter
filter = ::Nanoc::Filters::ColorizeSyntax.new

# Get input and expected output
input = <<EOS
before
<pre><code class="language-ruby">
def foo
end
</code></pre>
after
EOS
expected_output = <<EOS
before
<pre><code class=\"language-ruby my-class\"> <span class=\"k\">def</span> <span class=\"nf\">foo</span>
<span class=\"k\">end</span></code></pre>
after
EOS

# Run filter
actual_output = filter.setup_and_run(input, default_colorizer: :rouge, rouge: { css_class: 'my-class' })
assert_equal(expected_output, actual_output)
end
end
end
3 changes: 0 additions & 3 deletions test/helper.rb
@@ -1,9 +1,6 @@
require 'simplecov'
SimpleCov.start

require 'minitest/test'
require 'minitest/spec'
require 'minitest/mock'
require 'minitest/autorun'
require 'mocha/setup'
require 'vcr'
Expand Down

0 comments on commit 5945aa3

Please sign in to comment.