Skip to content

Commit

Permalink
Merge pull request #593 from nanoc/rename-identifier-and-pattern-options
Browse files Browse the repository at this point in the history
Rename identifier_style and pattern_syntax
  • Loading branch information
denisdefreyne committed May 19, 2015
2 parents 072b15b + 84bdb89 commit 2d4a54e
Show file tree
Hide file tree
Showing 25 changed files with 89 additions and 85 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Changes:

* Removed `ItemCollectionView#at`
* Removed support for calling `ItemCollectionView#[]` with an integer
* Renamed `identifier_style` to `identifier_type`, and made its values be `"full"` or `"legacy"`.
* Renamed `pattern_syntax` to `string_pattern_type`, and made its values be `"glob"` or `"legacy"`.

Enhancements:

Expand Down
6 changes: 3 additions & 3 deletions lib/nanoc/base/compilation/compiler_dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -260,14 +260,14 @@ def include_rules(name)

# @api private
def create_pattern(arg)
case @config[:pattern_syntax]
case @config[:string_pattern_type]
when 'glob'
Nanoc::Int::Pattern.from(arg)
when nil
when 'legacy'
Nanoc::Int::Pattern.from(identifier_to_regex(arg))
else
raise Nanoc::Int::Errors::GenericTrivial,
"Invalid pattern_syntax: #{@config[:pattern_syntax]}"
"Invalid string_pattern_type: #{@config[:string_pattern_type]}"
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/nanoc/base/compilation/item_rep_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def layout_with_identifier(layout_identifier)
end

def use_globs?
@compiler.site.config[:pattern_syntax] == 'glob'
@compiler.site.config[:string_pattern_type] == 'glob'
end
end
end
2 changes: 1 addition & 1 deletion lib/nanoc/base/identifiable_collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def build_mapping
end

def use_globs?
@config[:pattern_syntax] == 'glob'
@config[:string_pattern_type] == 'glob'
end
end
end
18 changes: 9 additions & 9 deletions lib/nanoc/base/source_data/identifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ def self.from(obj)
end

def initialize(string, params = {})
@style = params.fetch(:style, :stripped)
@type = params.fetch(:type, :legacy)

case @style
when :stripped
case @type
when :legacy
@string = "/#{string}/".gsub(/^\/+|\/+$/, '/').freeze
when :full
if string !~ /\A\//
Expand All @@ -29,7 +29,7 @@ def initialize(string, params = {})
@string = string.dup.freeze
else
raise Nanoc::Int::Errors::Generic,
"Invalid :style param for identifier: #{@style.inspect}"
"Invalid :type param for identifier: #{@type.inspect}"
end
end

Expand All @@ -50,10 +50,10 @@ def <=>(other)
to_s <=> other.to_s
end

# @return [Boolean] True if this is a full-style identifier (i.e. includes
# @return [Boolean] True if this is a full-type identifier (i.e. includes
# the extension), false otherwise
def full?
@style == :full
@type == :full
end

# @return [String]
Expand All @@ -72,12 +72,12 @@ def prefix(string)
raise Nanoc::Int::Errors::Generic,
"Invalid prefix (does not start with a slash): #{@string.inspect}"
end
Nanoc::Identifier.new(string.sub(/\/+\z/, '') + @string, style: @style)
Nanoc::Identifier.new(string.sub(/\/+\z/, '') + @string, type: @type)
end

# @return [String]
def with_ext(ext)
if @style == :stripped
unless full?
raise Nanoc::Int::Errors::Generic,
'Cannot use #with_ext on identifier that does not include the file extension'
end
Expand Down Expand Up @@ -117,7 +117,7 @@ def to_str
end

def inspect
"<Nanoc::Identifier style=#{@style} #{to_s.inspect}>"
"<Nanoc::Identifier type=#{@type} #{to_s.inspect}>"
end
end
end
4 changes: 2 additions & 2 deletions lib/nanoc/base/source_data/site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Site
items_root: '/',
layouts_root: '/',
config: {},
identifier_style: 'full',
identifier_type: 'full',
}

# The default configuration for a site. A site's configuration overrides
Expand All @@ -41,7 +41,7 @@ class Site
index_filenames: ['index.html'],
enable_output_diff: false,
prune: { auto_prune: false, exclude: ['.git', '.hg', '.svn', 'CVS'] },
pattern_syntax: 'glob',
string_pattern_type: 'glob',
}

# Creates a site object for the site specified by the given
Expand Down
8 changes: 4 additions & 4 deletions lib/nanoc/cli/commands/create-site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ def array_to_yaml(array)

DEFAULT_CONFIG = <<EOS unless defined? DEFAULT_CONFIG
# The syntax to use for patterns in the Rules file. Can be either `"glob"`
# (default) or `null`. The former will enable glob patterns, which behave like
# Ruby’s File.fnmatch. The latter will enable nanoc 3.x-style patterns.
pattern_syntax: glob
# (default) or `"legacy"`. The former will enable glob patterns, which behave
# like Ruby’s File.fnmatch. The latter will enable nanoc 3.x-style patterns.
string_pattern_type: glob
# A list of file extensions that nanoc will consider to be textual rather than
# binary. If an item with an extension not in this list is found, the file
Expand Down Expand Up @@ -89,7 +89,7 @@ def array_to_yaml(array)
# UTF-8 (which they should be!), change this.
encoding: utf-8
identifier_style: full
identifier_type: full
# Configuration for the “check” command, which run unit tests on the site.
checks:
Expand Down
2 changes: 1 addition & 1 deletion lib/nanoc/data_sources/filesystem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def all_split_files_in(dir_name)
unless [0, 1].include?(meta_filenames.size)
raise "Found #{meta_filenames.size} meta files for #{basename}; expected 0 or 1"
end
unless config[:identifier_style] == 'full'
unless config[:identifier_type] == 'full'
unless [0, 1].include?(content_filenames.size)
raise "Found #{content_filenames.size} content files for #{basename}; expected 0 or 1"
end
Expand Down
4 changes: 2 additions & 2 deletions lib/nanoc/data_sources/filesystem_unified.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ def filename_for(base_filename, ext)
# Returns the identifier derived from the given filename, first stripping
# the given directory name off the filename.
def identifier_for_filename(filename)
if config[:identifier_style] == 'full'
return Nanoc::Identifier.new(filename, style: :full)
if config[:identifier_type] == 'full'
return Nanoc::Identifier.new(filename, type: :full)
end

if filename =~ /(^|\/)index(\.[^\/]+)?$/
Expand Down
4 changes: 2 additions & 2 deletions lib/nanoc/data_sources/filesystem_verbose.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ def filename_for(base_filename, ext)

# See {Nanoc::DataSources::Filesystem#identifier_for_filename}.
def identifier_for_filename(filename)
if config[:identifier_style] == 'full'
return Nanoc::Identifier.new(filename, style: :full)
if config[:identifier_type] == 'full'
return Nanoc::Identifier.new(filename, type: :full)
end

filename.sub(/[^\/]+\.yaml$/, '')
Expand Down
26 changes: 13 additions & 13 deletions spec/nanoc/base/identifier_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

describe Nanoc::Identifier do
describe '#initialize' do
context 'stripped style' do
context 'legacy type' do
it 'does not convert already clean paths' do
expect(described_class.new('/foo/bar/').to_s).to eql('/foo/bar/')
end
Expand All @@ -24,21 +24,21 @@
end
end

context 'full style' do
context 'full type' do
it 'refuses string not starting with a slash' do
expect { described_class.new('foo', style: :full) }.to raise_error('Invalid identifier (does not start with a slash): "foo"')
expect { described_class.new('foo', type: :full) }.to raise_error('Invalid identifier (does not start with a slash): "foo"')
end

it 'has proper string representation' do
expect(described_class.new('/foo', style: :full).to_s).to eql('/foo')
expect(described_class.new('/foo', type: :full).to_s).to eql('/foo')
end
end
end

describe '#to_s' do
it 'returns immutable string' do
expect { described_class.new('foo/').to_s << 'lols' }.to raise_error
expect { described_class.new('/foo', style: :full).to_s << 'lols' }.to raise_error
expect { described_class.new('/foo', type: :full).to_s << 'lols' }.to raise_error
end
end

Expand All @@ -59,7 +59,7 @@

subject { identifier.inspect }

it { should == '<Nanoc::Identifier style=stripped "/foo/bar/">' }
it { should == '<Nanoc::Identifier type=legacy "/foo/bar/">' }
end

describe '#== and #eql?' do
Expand Down Expand Up @@ -155,7 +155,7 @@
end

describe '#prefix' do
let(:identifier) { described_class.new('/foo', style: :full) }
let(:identifier) { described_class.new('/foo', type: :full) }

subject { identifier.prefix(prefix) }

Expand Down Expand Up @@ -197,7 +197,7 @@
describe '#with_ext' do
subject { identifier.with_ext(ext) }

context 'stripped style' do
context 'legacy type' do
let(:identifier) { described_class.new('/foo/') }
let(:ext) { 'html' }

Expand All @@ -207,7 +207,7 @@
end

context 'identifier with no extension' do
let(:identifier) { described_class.new('/foo', style: :full) }
let(:identifier) { described_class.new('/foo', type: :full) }

context 'extension without dot given' do
let(:ext) { 'html' }
Expand Down Expand Up @@ -235,7 +235,7 @@
end

context 'identifier with extension' do
let(:identifier) { described_class.new('/foo.md', style: :full) }
let(:identifier) { described_class.new('/foo.md', type: :full) }

context 'extension without dot given' do
let(:ext) { 'html' }
Expand Down Expand Up @@ -266,7 +266,7 @@
describe '#without_ext' do
subject { identifier.without_ext }

context 'stripped style' do
context 'legacy type' do
let(:identifier) { described_class.new('/foo/') }

it 'raises an error' do
Expand All @@ -275,15 +275,15 @@
end

context 'identifier with no extension' do
let(:identifier) { described_class.new('/foo', style: :full) }
let(:identifier) { described_class.new('/foo', type: :full) }

it 'does nothing' do
expect(subject).to eql('/foo')
end
end

context 'identifier with extension' do
let(:identifier) { described_class.new('/foo.md', style: :full) }
let(:identifier) { described_class.new('/foo.md', type: :full) }

it 'removes the extension' do
expect(subject).to eql('/foo')
Expand Down
14 changes: 7 additions & 7 deletions spec/nanoc/base/views/identifiable_collection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
let(:view) { described_class.new(wrapped) }

let(:config) do
{ pattern_syntax: 'glob' }
{ string_pattern_type: 'glob' }
end

describe '#unwrap' do
Expand Down Expand Up @@ -52,11 +52,11 @@

describe '#[]' do
let(:page_object) do
double(:identifiable, identifier: Nanoc::Identifier.new('/page.erb', style: :full))
double(:identifiable, identifier: Nanoc::Identifier.new('/page.erb', type: :full))
end

let(:home_object) do
double(:identifiable, identifier: Nanoc::Identifier.new('/home.erb', style: :full))
double(:identifiable, identifier: Nanoc::Identifier.new('/home.erb', type: :full))
end

let(:wrapped) do
Expand Down Expand Up @@ -86,7 +86,7 @@
let(:arg) { '/home.*' }

context 'globs not enabled' do
let(:config) { { pattern_syntax: nil } }
let(:config) { { string_pattern_type: 'legacy' } }

it 'returns nil' do
expect(subject).to be_nil
Expand Down Expand Up @@ -114,9 +114,9 @@
describe '#find_all' do
let(:wrapped) do
Nanoc::Int::IdentifiableCollection.new(config).tap do |arr|
arr << double(:identifiable, identifier: Nanoc::Identifier.new('/about.css', style: :full))
arr << double(:identifiable, identifier: Nanoc::Identifier.new('/about.md', style: :full))
arr << double(:identifiable, identifier: Nanoc::Identifier.new('/style.css', style: :full))
arr << double(:identifiable, identifier: Nanoc::Identifier.new('/about.css', type: :full))
arr << double(:identifiable, identifier: Nanoc::Identifier.new('/about.md', type: :full))
arr << double(:identifiable, identifier: Nanoc::Identifier.new('/style.css', type: :full))
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/nanoc/base/views/mutable_item_collection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
it_behaves_like 'a mutable identifiable collection'

let(:config) do
{ pattern_syntax: 'glob' }
{ string_pattern_type: 'glob' }
end

describe '#create' do
Expand Down
2 changes: 1 addition & 1 deletion spec/nanoc/base/views/mutable_layout_collection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
it_behaves_like 'a mutable identifiable collection'

let(:config) do
{ pattern_syntax: 'glob' }
{ string_pattern_type: 'glob' }
end

describe '#create' do
Expand Down
Loading

0 comments on commit 2d4a54e

Please sign in to comment.