lib/nanoc/base/source_data/site.rb in nanoc-3.7.4 vs lib/nanoc/base/source_data/site.rb in nanoc-3.7.5

- old
+ new

@@ -1,9 +1,8 @@ # encoding: utf-8 module Nanoc - # The in-memory representation of a nanoc site. It holds references to the # following site data: # # * {#items} — the list of items ({Nanoc::Item}) # * {#layouts} — the list of layouts ({Nanoc::Layout}) @@ -15,32 +14,31 @@ # # The physical representation of a {Nanoc::Site} is usually a directory # that contains a configuration file, site data, a rakefile, a rules file, # etc. The way site data is stored depends on the data source. class Site - # The default configuration for a data source. A data source's # configuration overrides these options. DEFAULT_DATA_SOURCE_CONFIG = { - :type => 'filesystem_unified', - :items_root => '/', - :layouts_root => '/', - :config => {} + type: 'filesystem_unified', + items_root: '/', + layouts_root: '/', + config: {} } # The default configuration for a site. A site's configuration overrides # these options: when a {Nanoc::Site} is created with a configuration # that lacks some options, the default value will be taken from # `DEFAULT_CONFIG`. DEFAULT_CONFIG = { - :text_extensions => %w( css erb haml htm html js less markdown md php rb sass scss txt xhtml xml coffee hb handlebars mustache ms slim ).sort, - :lib_dirs => %w( lib ), - :output_dir => 'output', - :data_sources => [{}], - :index_filenames => ['index.html'], - :enable_output_diff => false, - :prune => { :auto_prune => false, :exclude => ['.git', '.hg', '.svn', 'CVS'] } + text_extensions: %w( css erb haml htm html js less markdown md php rb sass scss txt xhtml xml coffee hb handlebars mustache ms slim ).sort, + lib_dirs: %w( lib ), + output_dir: 'output', + data_sources: [{}], + index_filenames: ['index.html'], + enable_output_diff: false, + prune: { auto_prune: false, exclude: ['.git', '.hg', '.svn', 'CVS'] } } # Creates a site object for the site specified by the given # `dir_or_config_hash` argument. # @@ -83,11 +81,11 @@ # Get data source class data_source_class = Nanoc::DataSource.named(data_source_hash[:type]) raise Nanoc::Errors::UnknownDataSource.new(data_source_hash[:type]) if data_source_class.nil? # Warn about deprecated data sources - # TODO [in nanoc 4.0] remove me + # TODO: [in nanoc 4.0] remove me case data_source_hash[:type] when 'filesystem' warn "Warning: the 'filesystem' data source has been renamed to 'filesystem_verbose'. Using 'filesystem' will work in nanoc 3.1.x, but it will likely not work anymore in a future release of nanoc. Please update your data source configuration and replace 'filesystem' with 'filesystem_verbose'." when 'filesystem_combined', 'filesystem_compact' warn "Warning: the 'filesystem_combined' and 'filesystem_compact' data source has been merged into the new 'filesystem_unified' data source. Using 'filesystem_combined' and 'filesystem_compact' will work in nanoc 3.1.x, but it will likely not work anymore in a future release of nanoc. Please update your data source configuration and replace 'filesystem_combined' and 'filesystem_compact with 'filesystem_unified'." @@ -215,13 +213,13 @@ # Prevents all further modifications to itself, its items, its layouts etc. # # @return [void] def freeze config.freeze_recursively - items.each { |i| i.freeze } - layouts.each { |l| l.freeze } - code_snippets.each { |cs| cs.freeze } + items.each(&:freeze) + layouts.each(&:freeze) + code_snippets.each(&:freeze) end # @deprecated It is no longer necessary to explicitly load site data. It # is safe to remove all {#load_data} calls. def load_data(_force = false) @@ -249,11 +247,11 @@ # Ensure unique ensure_identifier_uniqueness(@items, 'item') ensure_identifier_uniqueness(@layouts, 'layout') # Load compiler too - # FIXME this should not be necessary + # FIXME: this should not be necessary compiler.load @loaded = true rescue => e unload @@ -299,15 +297,15 @@ private # Executes the given block, making sure that the datasources are # available for the duration of the block - def with_datasources(&block) - data_sources.each { |ds| ds.use } + def with_datasources(&_block) + data_sources.each(&:use) yield ensure - data_sources.each { |ds| ds.unuse } + data_sources.each(&:unuse) end # Loads this site’s code and executes it. def load_code_snippets @code_snippets_loaded ||= false @@ -325,11 +323,11 @@ end @code_snippets.concat(code_snippets) end # Execute code snippets - @code_snippets.each { |cs| cs.load } + @code_snippets.each(&:load) end # Loads this site’s items, sets up item child-parent relationships and # builds each item's list of item representations. def load_items @@ -429,7 +427,6 @@ # Convert to proper configuration @config = Nanoc::Configuration.new(@config) end end - end