New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename identifier_style and pattern_syntax #593

Merged
merged 5 commits into from May 19, 2015
View
@@ -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:
@@ -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
@@ -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
@@ -75,7 +75,7 @@ def build_mapping
end
def use_globs?
@config[:pattern_syntax] == 'glob'
@config[:string_pattern_type] == 'glob'
end
end
end
@@ -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\//
@@ -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
@@ -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]
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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:
@@ -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
@@ -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(\.[^\/]+)?$/
@@ -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$/, '')
@@ -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
@@ -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
@@ -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
@@ -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) }
@@ -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' }
@@ -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' }
@@ -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' }
@@ -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
@@ -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')
@@ -5,7 +5,7 @@
let(:view) { described_class.new(wrapped) }
let(:config) do
{ pattern_syntax: 'glob' }
{ string_pattern_type: 'glob' }
end
describe '#unwrap' do
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
Oops, something went wrong.
ProTip! Use n and p to navigate between commits in a pull request.