Skip to content

Commit

Permalink
Avoid setting backend_name to empty string
Browse files Browse the repository at this point in the history
When backend_name is empty string, then some code highlighters doesn't
work. Yeah, it's weird...
  • Loading branch information
jirutka committed Dec 29, 2014
1 parent a514272 commit bf5f077
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 4 additions & 3 deletions lib/asciidoctor/doctest/asciidoc_renderer.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'active_support/core_ext/array/wrap'
require 'active_support/core_ext/object/blank'
require 'asciidoctor'
require 'asciidoctor/converter/template'

Expand All @@ -12,7 +13,7 @@ class AsciidocRenderer
attr_reader :backend_name, :converter, :template_dirs

##
# @param backend_name [#to_s] the name of the tested backend.
# @param backend_name [#to_s, nil] the name of the tested backend.
#
# @param converter [Class, Asciidoctor::Converter::Base, nil]
# the backend's converter class (or its instance). If not
Expand All @@ -33,10 +34,10 @@ class AsciidocRenderer
# @raise [ArgumentError] if some path from the +template_dirs+ doesn't
# exist or is not a directory.
#
def initialize(backend_name: '', converter: nil, template_dirs: [],
def initialize(backend_name: nil, converter: nil, template_dirs: [],
templates_fallback: false)

@backend_name = backend_name.freeze
@backend_name = backend_name.to_s.freeze.presence
@converter = converter
@converter ||= NoFallbackTemplateConverter unless template_dirs.empty? || templates_fallback

Expand Down
7 changes: 6 additions & 1 deletion spec/asciidoc_renderer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,17 @@

context 'with defaults' do
subject { described_class.new }
it { is_expected.to have_attributes backend_name: '', converter: nil, template_dirs: nil }
it { is_expected.to have_attributes backend_name: nil, converter: nil, template_dirs: nil }
end

context 'with backend_name' do
subject { described_class.new(backend_name: 'html5') }
it { is_expected.to have_attributes backend_name: 'html5' }

context 'empty string' do
subject { described_class.new(backend_name: '') }
it { is_expected.to have_attributes backend_name: nil }
end
end

context 'with template_dirs' do
Expand Down

0 comments on commit bf5f077

Please sign in to comment.