lib/nanoc/data_sources/filesystem.rb in nanoc-3.7.3 vs lib/nanoc/data_sources/filesystem.rb in nanoc-3.7.4
- old
+ new
@@ -32,11 +32,11 @@
end
# See {Nanoc::DataSource#setup}.
def setup
# Create directories
- [ content_dir_name, layouts_dir_name ].each do |dir|
+ [content_dir_name, layouts_dir_name].each do |dir|
FileUtils.mkdir_p(dir)
vcs.add(dir)
end
end
@@ -58,16 +58,16 @@
# See {Nanoc::DataSource#create_layout}.
def create_layout(content, attributes, identifier, params = {})
create_object(layouts_dir_name, content, attributes, identifier, params)
end
- protected
+ protected
# Creates a new object (item or layout) on disk in dir_name according to
# the given identifier. The file will have its attributes taken from the
# attributes hash argument and its content from the content argument.
- def create_object(dir_name, content, attributes, identifier, params = {})
+ def create_object(_dir_name, _content, _attributes, _identifier, _params = {})
raise NotImplementedError.new(
"#{self.class} does not implement ##{name}"
)
end
@@ -87,11 +87,11 @@
# Get filenames
meta_filename = filename_for(base_filename, meta_ext)
content_filename = filename_for(base_filename, content_ext)
# Read content and metadata
- is_binary = !!(content_filename && !@site.config[:text_extensions].include?(File.extname(content_filename)[1..-1]))
+ is_binary = content_filename && !@site.config[:text_extensions].include?(File.extname(content_filename)[1..-1])
if is_binary && klass == Nanoc::Item
meta = (meta_filename && YAML.load_file(meta_filename)) || {}
content_or_filename = content_filename
elsif is_binary && klass == Nanoc::Layout
raise "The layout file '#{content_filename}' is a binary file, but layouts can only be textual"
@@ -151,24 +151,24 @@
# 'content/foo' => [ 'yaml', 'html' ],
# 'content/bar' => [ 'yaml', nil ],
# 'content/qux' => [ nil, 'html' ]
# }
def all_split_files_in(dir_name)
- grouped_filenames = all_files_in(dir_name).
- reject { |fn| fn =~ /(~|\.orig|\.rej|\.bak)$/ }.
- group_by { |fn| basename_of(fn) }
+ grouped_filenames = all_files_in(dir_name)
+ .reject { |fn| fn =~ /(~|\.orig|\.rej|\.bak)$/ }
+ .group_by { |fn| basename_of(fn) }
grouped_filenames.each_pair do |key, filenames|
# Divide
meta_filenames = filenames.select { |fn| ext_of(fn) == '.yaml' }
content_filenames = filenames.select { |fn| ext_of(fn) != '.yaml' }
# Check number of files per type
- if ![ 0, 1 ].include?(meta_filenames.size)
+ unless [0, 1].include?(meta_filenames.size)
raise "Found #{meta_filenames.size} meta files for #{key}; expected 0 or 1"
end
- if ![ 0, 1 ].include?(content_filenames.size)
+ unless [0, 1].include?(content_filenames.size)
raise "Found #{content_filenames.size} content files for #{key}; expected 0 or 1"
end
# Reorder elements and convert to extnames
filenames[0] = meta_filenames[0] ? 'yaml' : nil
@@ -191,19 +191,19 @@
# period and an extension (which is what the
# {Nanoc::DataSources::FilesystemCompact} data source does), but other
# data sources may prefer to implement this differently (for example,
# {Nanoc::DataSources::FilesystemVerbose} doubles the last part of the
# basename before concatenating it with a period and the extension).
- def filename_for(base_filename, ext)
+ def filename_for(_base_filename, _ext)
raise NotImplementedError.new(
"#{self.class} does not implement #filename_for"
)
end
# Returns the identifier that corresponds with the given filename, which
# can be the content filename or the meta filename.
- def identifier_for_filename(filename)
+ def identifier_for_filename(_filename)
raise NotImplementedError.new(
"#{self.class} does not implement #identifier_for_filename"
)
end
@@ -233,29 +233,29 @@
end
# Parses the file named `filename` and returns an array with its first
# element a hash with the file's metadata, and with its second element the
# file content itself.
- def parse(content_filename, meta_filename, kind)
+ def parse(content_filename, meta_filename, _kind)
# Read content and metadata from separate files
if meta_filename
content = content_filename ? read(content_filename) : ''
meta_raw = read(meta_filename)
begin
meta = YAML.load(meta_raw) || {}
rescue Exception => e
raise "Could not parse YAML for #{meta_filename}: #{e.message}"
end
- return [ meta, content ]
+ return [meta, content]
end
# Read data
data = read(content_filename)
# Check presence of metadata section
if data !~ /\A-{3,5}\s*$/
- return [ {}, data ]
+ return [{}, data]
end
# Split data
pieces = data.split(/^(-{5}|-{3})[ \t]*\r?\n?/, 3)
if pieces.size < 4
@@ -271,11 +271,11 @@
raise "Could not parse YAML for #{content_filename}: #{e.message}"
end
content = pieces[4]
# Done
- [ meta, content ]
+ [meta, content]
end
# Reads the content of the file with the given name and returns a string
# in UTF-8 encoding. The original encoding of the string is derived from
# the default external encoding, but this can be overridden by the
@@ -301,10 +301,10 @@
data.encode!('UTF-8')
rescue
raise_encoding_error(filename, original_encoding)
end
- if !data.valid_encoding?
+ unless data.valid_encoding?
raise_encoding_error(filename, original_encoding)
end
end
# Remove UTF-8 BOM (ugly)