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 `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[: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 pattern_type: #{@config[: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[:pattern_type] == 'glob'
end
end
end
@@ -75,7 +75,7 @@ def build_mapping
end
def use_globs?
@config[:pattern_syntax] == 'glob'
@config[:pattern_type] == 'glob'
end
end
end
@@ -16,10 +16,10 @@ def self.from(obj)
end
def initialize(string, params = {})
@style = params.fetch(:style, :stripped)
@style = params.fetch(:style, :legacy)

This comment has been minimized.

@bobthecow

bobthecow May 18, 2015

Member

should this variable be renamed as well?

@bobthecow

bobthecow May 18, 2015

Member

should this variable be renamed as well?

This comment has been minimized.

@ddfreyne

ddfreyne May 18, 2015

Member

Good catch.

@ddfreyne

ddfreyne May 18, 2015

Member

Good catch.

case @style
when :stripped
when :legacy
@string = "/#{string}/".gsub(/^\/+|\/+$/, '/').freeze
when :full
if string !~ /\A\//
@@ -77,7 +77,7 @@ def prefix(string)
# @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
@@ -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',
pattern_type: 'glob',
}
# Creates a site object for the site specified by the given
@@ -23,7 +23,7 @@ def array_to_yaml(array)
# 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
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,7 +87,7 @@ 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'
if config[:identifier_type] == 'full'
return Nanoc::Identifier.new(filename, style: :full)
end
@@ -61,7 +61,7 @@ def filename_for(base_filename, ext)
# See {Nanoc::DataSources::Filesystem#identifier_for_filename}.
def identifier_for_filename(filename)
if config[:identifier_style] == 'full'
if config[:identifier_type] == 'full'
return Nanoc::Identifier.new(filename, style: :full)
end
@@ -2,7 +2,7 @@
describe Nanoc::Identifier do
describe '#initialize' do
context 'stripped style' do
context 'legacy style' do
it 'does not convert already clean paths' do
expect(described_class.new('/foo/bar/').to_s).to eql('/foo/bar/')
end
@@ -59,7 +59,7 @@
subject { identifier.inspect }
it { should == '<Nanoc::Identifier style=stripped "/foo/bar/">' }
it { should == '<Nanoc::Identifier style=legacy "/foo/bar/">' }
end
describe '#== and #eql?' do
@@ -197,7 +197,7 @@
describe '#with_ext' do
subject { identifier.with_ext(ext) }
context 'stripped style' do
context 'legacy style' do
let(:identifier) { described_class.new('/foo/') }
let(:ext) { 'html' }
@@ -266,7 +266,7 @@
describe '#without_ext' do
subject { identifier.without_ext }
context 'stripped style' do
context 'legacy style' do
let(:identifier) { described_class.new('/foo/') }
it 'raises an error' do
@@ -5,7 +5,7 @@
let(:view) { described_class.new(wrapped) }
let(:config) do
{ pattern_syntax: 'glob' }
{ pattern_type: 'glob' }
end
describe '#unwrap' do
@@ -86,7 +86,7 @@
let(:arg) { '/home.*' }
context 'globs not enabled' do
let(:config) { { pattern_syntax: nil } }
let(:config) { { pattern_type: 'legacy' } }
it 'returns nil' do
expect(subject).to be_nil
@@ -6,7 +6,7 @@
it_behaves_like 'a mutable identifiable collection'
let(:config) do
{ pattern_syntax: 'glob' }
{ pattern_type: 'glob' }
end
describe '#create' do
@@ -6,7 +6,7 @@
it_behaves_like 'a mutable identifiable collection'
let(:config) do
{ pattern_syntax: 'glob' }
{ pattern_type: 'glob' }
end
describe '#create' do
@@ -177,11 +177,11 @@ def test_passthrough_priority
def test_passthrough_with_full_identifiers
with_site do
File.open('nanoc.yaml', 'w') do |io|
io << 'pattern_syntax: null' << "\n"
io << 'pattern_type: legacy' << "\n"
io << 'data_sources:' << "\n"
io << ' -' << "\n"
io << ' type: filesystem_unified' << "\n"
io << ' identifier_style: full' << "\n"
io << ' identifier_type: full' << "\n"
end
# Create rules
@@ -267,15 +267,17 @@ def test_ignore_priority
end
end
def test_create_pattern_with_string
def test_create_pattern_with_string_with_no_config
compiler_dsl = Nanoc::Int::CompilerDSL.new(nil, {})
pattern = compiler_dsl.create_pattern('/foo/*')
assert pattern.match?('/foo/a/a/a/a')
err = assert_raises(Nanoc::Int::Errors::GenericTrivial) do
compiler_dsl.create_pattern('/foo/*')
end
assert_equal 'Invalid pattern_type: ', err.message
end
def test_create_pattern_with_string_with_glob_pattern_syntax
compiler_dsl = Nanoc::Int::CompilerDSL.new(nil, { pattern_syntax: 'glob' })
def test_create_pattern_with_string_with_glob_pattern_type
compiler_dsl = Nanoc::Int::CompilerDSL.new(nil, { pattern_type: 'glob' })
pattern = compiler_dsl.create_pattern('/foo/*')
assert pattern.match?('/foo/aaaa')
@@ -284,19 +286,19 @@ def test_create_pattern_with_string_with_glob_pattern_syntax
end
def test_create_pattern_with_regex
compiler_dsl = Nanoc::Int::CompilerDSL.new(nil, {})
compiler_dsl = Nanoc::Int::CompilerDSL.new(nil, { pattern_type: 'glob' })
pattern = compiler_dsl.create_pattern(%r<\A/foo/a*/>)
assert pattern.match?('/foo/aaaa/')
end
def test_create_pattern_with_string_with_unknown_pattern_syntax
compiler_dsl = Nanoc::Int::CompilerDSL.new(nil, { pattern_syntax: 'donkey' })
def test_create_pattern_with_string_with_unknown_pattern_type
compiler_dsl = Nanoc::Int::CompilerDSL.new(nil, { pattern_type: 'donkey' })
err = assert_raises(Nanoc::Int::Errors::GenericTrivial) do
compiler_dsl.create_pattern('/foo/*')
end
assert_equal 'Invalid pattern_syntax: donkey', err.message
assert_equal 'Invalid pattern_type: donkey', err.message
end
def test_identifier_to_regex_without_wildcards
@@ -27,7 +27,7 @@ def test_enumerable
end
def test_brackets_with_glob
@items = Nanoc::Int::IdentifiableCollection.new({ pattern_syntax: 'glob' })
@items = Nanoc::Int::IdentifiableCollection.new({ pattern_type: 'glob' })
@items << @one
@items << @two
@@ -283,11 +283,11 @@ def test_outdated_if_config_outdated
FileUtils.cd('foo') do
File.open('nanoc.yaml', 'w') do |io|
io << 'awesome: true' << "\n"
io << 'pattern_syntax: null' << "\n"
io << 'pattern_type: legacy' << "\n"
io << 'data_sources:' << "\n"
io << ' -' << "\n"
io << ' type: filesystem_unified' << "\n"
io << ' identifier_style: stripped' << "\n"
io << ' identifier_type: legacy' << "\n"
end
end
View
@@ -185,7 +185,7 @@ def test_setup_child_parent_links
FileUtils.mkdir_p('content/parent')
FileUtils.mkdir_p('content/parent/bar')
data = File.read('nanoc.yaml').sub('identifier_style: full', 'identifier_style: stripped')
data = File.read('nanoc.yaml').sub('identifier_type: full', 'identifier_type: legacy')
File.open('nanoc.yaml', 'w') { |io| io << data }
File.open('content/parent.md', 'w') { |io| io << 'asdf' }
@@ -50,7 +50,7 @@ def test_auto_prune
end
File.open('nanoc.yaml', 'w') do |io|
io.write "pattern_syntax: null\n"
io.write "pattern_type: legacy\n"
io.write "prune:\n"
io.write " auto_prune: false\n"
end
@@ -64,7 +64,7 @@ def test_auto_prune
assert File.file?('output/stray.html')
File.open('nanoc.yaml', 'w') do |io|
io.write "pattern_syntax: null\n"
io.write "pattern_type: legacy\n"
io.write "prune:\n"
io.write " auto_prune: true\n"
end
@@ -100,7 +100,7 @@ def test_auto_prune_with_exclude
Dir.mkdir('output/excluded_dir')
File.open('nanoc.yaml', 'w') do |io|
io.write "pattern_syntax: null\n"
io.write "pattern_type: legacy\n"
io.write "prune:\n"
io.write " auto_prune: false\n"
end
@@ -114,7 +114,7 @@ def test_auto_prune_with_exclude
assert File.file?('output/stray.html')
File.open('nanoc.yaml', 'w') do |io|
io.write "pattern_syntax: null\n"
io.write "pattern_type: legacy\n"
io.write "prune:\n"
io.write " auto_prune: true\n"
io.write " exclude: [ 'excluded_dir' ]\n"
@@ -72,11 +72,11 @@ def test_default_encoding
# Try with encoding = specific
File.open('nanoc.yaml', 'w') do |io|
io.write("pattern_syntax: glob\n")
io.write("pattern_type: glob\n")
io.write("data_sources:\n")
io.write(" -\n")
io.write(" type: filesystem_unified\n")
io.write(" identifier_style: full\n")
io.write(" identifier_type: full\n")
end
site = Nanoc::Int::Site.new('.')
site.compile
@@ -4,7 +4,7 @@ class Nanoc::CLI::Commands::PruneTest < Nanoc::TestCase
def test_run_without_yes
with_site do |_site|
# Set output dir
File.open('nanoc.yaml', 'w') { |io| io.write "output_dir: output2\npattern_syntax: null\n" }
File.open('nanoc.yaml', 'w') { |io| io.write "output_dir: output2\npattern_type: legacy\n" }
FileUtils.mkdir_p('output2')
# Create source files
@@ -28,11 +28,11 @@ def test_run_with_yes
# Set output dir
File.open('nanoc.yaml', 'w') do |io|
io << 'output_dir: output2' << "\n"
io << 'pattern_syntax: null' << "\n"
io << 'pattern_type: legacy' << "\n"
io << 'data_sources:' << "\n"
io << ' -' << "\n"
io << ' type: filesystem_unified' << "\n"
io << ' identifier_style: stripped' << "\n"
io << ' identifier_type: legacy' << "\n"
end
FileUtils.mkdir_p('output2')
@@ -53,7 +53,7 @@ def test_run_with_yes
def test_run_with_dry_run
with_site do |_site|
# Set output dir
File.open('nanoc.yaml', 'w') { |io| io.write "pattern_syntax: null\noutput_dir: output2" }
File.open('nanoc.yaml', 'w') { |io| io.write "pattern_type: legacy\noutput_dir: output2" }
FileUtils.mkdir_p('output2')
# Create source files
@@ -76,11 +76,11 @@ def test_run_with_exclude
File.open('nanoc.yaml', 'w') do |io|
io << 'prune:' << "\n"
io << ' exclude: [ "good-dir", "good-file.html" ]' << "\n"
io << 'pattern_syntax: null' << "\n"
io << 'pattern_type: legacy' << "\n"
io << 'data_sources:' << "\n"
io << ' -' << "\n"
io << ' type: filesystem_unified' << "\n"
io << ' identifier_style: stripped' << "\n"
io << ' identifier_type: legacy' << "\n"
end
FileUtils.mkdir_p('output')
@@ -98,7 +98,7 @@ def test_all_split_files_in_with_multiple_dirs
def test_all_split_files_in_with_same_extensions
# Create data source
config = { identifier_style: 'full' }
config = { identifier_type: 'full' }
data_source = Nanoc::DataSources::FilesystemUnified.new(nil, nil, nil, config)
# Write sample files
Oops, something went wrong.
ProTip! Use n and p to navigate between commits in a pull request.