lib/nanoc3/base/compilation/compiler.rb in nanoc3-3.2.0a2 vs lib/nanoc3/base/compilation/compiler.rb in nanoc3-3.2.0a3

- old
+ new

@@ -38,10 +38,12 @@ # # * `processing_ended` — indicates that the compiler has finished processing # the specified object. class Compiler + # @group Accessors + # @return [Nanoc3::Site] The site this compiler belongs to attr_reader :site # The compilation stack. When the compiler begins compiling a rep or a # layout, it will be placed on the stack; when it is done compiling the @@ -66,10 +68,12 @@ # @return [Proc] The code block that will be executed after all data is # loaded but before the site is compiled attr_accessor :preprocessor + # @group Public instance methods + # Creates a new compiler fo the given site # # @param [Nanoc3::Site] site The site this compiler belongs to def initialize(site) @site = site @@ -94,37 +98,44 @@ # Create output directory if necessary FileUtils.mkdir_p(@site.config[:output_dir]) # Compile reps load + @site.freeze dependency_tracker.start compile_reps(reps) dependency_tracker.stop store ensure # Cleanup FileUtils.rm_rf(Nanoc3::Filter::TMP_BINARY_ITEMS_DIR) end + # @group Private instance methods + # Load the helper data that is used for compiling the site. # # @api private # # @return [void] def load return if @loaded @loaded = true - stores.each { |s| s.load } + # Load site if necessary + @site.load # Preprocess load_rules preprocess site.setup_child_parent_links build_reps route_reps + # Load auxiliary stores + stores.each { |s| s.load } + # Determine which reps need to be recompiled dependency_tracker.propagate_outdatedness forget_dependencies_if_outdated(items) end @@ -258,13 +269,23 @@ # @api private def preprocess preprocessor_context.instance_eval(&preprocessor) if preprocessor end - # FIXME get rid of this + # Returns all objects managed by the site (items, layouts, code snippets, + # site configuration and the rules). # # @api private + def objects + # FIXME remove reference to rules + site.items + site.layouts + site.code_snippets + [ site.config, self.rules_with_reference ] + end + + # Returns the rules along with an unique reference (`:rules`) so that the + # outdatedness checker can use them. + # + # @api private def rules_with_reference rules = @rules @rules_pseudo ||= begin pseudo = Object.new pseudo.instance_eval { @data = rules } @@ -304,10 +325,13 @@ rules.each_pair do |snapshot, rule| # Get basic path by applying matching rule basic_path = rule.apply_to(rep, :compiler => self) next if basic_path.nil? + if basic_path !~ %r{^/} + raise RuntimeError, "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.".make_compatible_with_env + end # Get raw path by prepending output directory rep.raw_paths[snapshot] = @site.config[:output_dir] + basic_path # Get normal path by stripping index filename @@ -326,12 +350,14 @@ # @param [Nanoc3::ItemRep] rep The item representation for which the # assigns should be fetched # # @return [Hash] The assigns that should be used in the next filter/layout # operation + # + # @api private def assigns_for(rep) if rep.binary? - content_or_filename_assigns = { :filename => rep.filenames[:last] } + content_or_filename_assigns = { :filename => rep.temporary_filenames[:last] } else content_or_filename_assigns = { :content => rep.content[:last] } end content_or_filename_assigns.merge({