lib/nanoc/base/compilation/compiler.rb in nanoc-3.7.4 vs lib/nanoc/base/compilation/compiler.rb in nanoc-3.7.5

- old
+ new

@@ -1,9 +1,8 @@ # encoding: utf-8 module Nanoc - # Responsible for compiling a site’s item representations. # # The compilation process makes use of notifications (see # {Nanoc::NotificationCenter}) to track dependencies between items, # layouts, etc. The following notifications are used: @@ -37,11 +36,10 @@ # representation or when it is used as a partial) # # * `processing_ended` — indicates that the compiler has finished processing # the specified object. class Compiler - extend Nanoc::Memoization # @group Accessors # @return [Nanoc::Site] The site this compiler belongs to @@ -123,11 +121,11 @@ site.setup_child_parent_links build_reps route_reps # Load auxiliary stores - stores.each { |s| s.load } + stores.each(&:load) @loaded = true rescue => e unload raise e @@ -142,11 +140,11 @@ # @return [void] def unload return if @unloading @unloading = true - stores.each { |s| s.unload } + stores.each(&:unload) @stack = [] items.each { |item| item.reps.clear } site.teardown_child_parent_links @@ -173,11 +171,11 @@ objects.each do |obj| checksum_store[obj] = obj.checksum end # Store - stores.each { |s| s.store } + stores.each(&:store) end # Returns the dependency tracker for this site, creating it first if it # does not yet exist. # @@ -218,11 +216,11 @@ # Find matching rules matching_rules = rules_collection.item_compilation_rules_for(item) raise Nanoc::Errors::NoMatchingCompilationRuleFound.new(item) if matching_rules.empty? # Create reps - rep_names = matching_rules.map { |r| r.rep_name }.uniq + rep_names = matching_rules.map(&:rep_name).uniq rep_names.each do |rep_name| item.reps << ItemRep.new(item, rep_name) end end end @@ -236,11 +234,11 @@ rules = rules_collection.routing_rules_for(rep) raise Nanoc::Errors::NoMatchingRoutingRuleFound.new(rep) if rules[:last].nil? rules.each_pair do |snapshot, rule| # Get basic path by applying matching rule - basic_path = rule.apply_to(rep, :compiler => self) + basic_path = rule.apply_to(rep, compiler: self) next if basic_path.nil? if basic_path !~ %r{^/} raise "The path returned for the #{rep.inspect} item representation, “#{basic_path}”, does not start with a slash. Please ensure that all routing rules return a path that starts with a slash." end @@ -268,32 +266,32 @@ # operation # # @api private def assigns_for(rep) if rep.binary? - content_or_filename_assigns = { :filename => rep.temporary_filenames[:last] } + content_or_filename_assigns = { filename: rep.temporary_filenames[:last] } else - content_or_filename_assigns = { :content => rep.content[:last] } + content_or_filename_assigns = { content: rep.content[:last] } end content_or_filename_assigns.merge({ - :item => rep.item, - :rep => rep, - :item_rep => rep, - :items => site.items, - :layouts => site.layouts, - :config => site.config, - :site => site + item: rep.item, + rep: rep, + item_rep: rep, + items: site.items, + layouts: site.layouts, + config: site.config, + site: site }) end # @return [Nanoc::OutdatednessChecker] The outdatedness checker def outdatedness_checker Nanoc::OutdatednessChecker.new( - :site => @site, - :checksum_store => checksum_store, - :dependency_tracker => dependency_tracker) + site: @site, + checksum_store: checksum_store, + dependency_tracker: dependency_tracker) end memoize :outdatedness_checker private @@ -303,11 +301,11 @@ end memoize :items # @return [Array<Nanoc::ItemRep>] The site’s item representations def reps - items.map { |i| i.reps }.flatten + items.map(&:reps).flatten end memoize :reps # @return [Array<Nanoc::Layout>] The site’s layouts def layouts @@ -381,12 +379,12 @@ Nanoc::NotificationCenter.post(:cached_content_used, rep) rep.content = compiled_content_cache[rep] else # Recalculate content rep.snapshot(:raw) - rep.snapshot(:pre, :final => false) - rules_collection.compilation_rule_for(rep).apply_to(rep, :compiler => self) + rep.snapshot(:pre, final: false) + rules_collection.compilation_rule_for(rep).apply_to(rep, compiler: self) rep.snapshot(:post) if rep.has_snapshot?(:post) rep.snapshot(:last) end rep.compiled = true @@ -417,14 +415,14 @@ end # Returns a preprocessor context, creating one if none exists yet. def preprocessor_context Nanoc::Context.new({ - :site => @site, - :config => @site.config, - :items => @site.items, - :layouts => @site.layouts + site: @site, + config: @site.config, + items: @site.items, + layouts: @site.layouts }) end memoize :preprocessor_context # @return [CompiledContentCache] The compiled content cache @@ -433,23 +431,23 @@ end memoize :compiled_content_cache # @return [ChecksumStore] The checksum store def checksum_store - Nanoc::ChecksumStore.new(:site => @site) + Nanoc::ChecksumStore.new(site: @site) end memoize :checksum_store # @return [RuleMemoryStore] The rule memory store def rule_memory_store - Nanoc::RuleMemoryStore.new(:site => @site) + Nanoc::RuleMemoryStore.new(site: @site) end memoize :rule_memory_store # @return [RuleMemoryCalculator] The rule memory calculator def rule_memory_calculator - Nanoc::RuleMemoryCalculator.new(:rules_collection => rules_collection) + Nanoc::RuleMemoryCalculator.new(rules_collection: rules_collection) end memoize :rule_memory_calculator # Returns all stores that can load/store data that can be used for # compilation. @@ -459,9 +457,7 @@ compiled_content_cache, dependency_tracker, rule_memory_store ] end - end - end