lib/plate/site.rb in plate-0.6.3 vs lib/plate/site.rb in plate-0.7.0.pre

- old
+ new

@@ -7,10 +7,13 @@ include Callbacks attr_accessor :assets, :build_destination, :cache_location, :destination, :layouts, :logger, :metadata, :options, :pages, :posts, :source + # An array of all view partials available in this site. + attr_accessor :partials + def initialize(source, destination, options = {}) # Setup source and destination for the site files self.source = source self.destination = destination @@ -51,10 +54,11 @@ self.assets = [] self.layouts = [] self.pages = [] self.posts = PostCollection.new + self.partials = [] @metadata = {} end # The default blog post category @@ -209,63 +213,74 @@ @url ||= self.options[:base_url].to_s.gsub(/(.*?)\/?$/, '\1') end protected # Load all layouts from layouts/ - def load_layouts!(log = true) + def load_layouts!(verbose = true) @layouts = [] Dir.glob(File.join(source, "layouts/**/*")).each do |file| # If this 'file' is a directory, just skip it. We only care about files. unless File.directory?(file) @layouts << Layout.new(self, file) end end - log("#{@layouts.size} layouts loaded") if log + log("#{@layouts.size} layouts loaded") if verbose @layouts end - def load_pages!(log = true) + def load_pages!(verbose = true) @assets = [] @pages = [] + @partials = [] # Load all pages, static pages and assets from content/ Dir.glob(File.join(source, "content/**/*")).each do |file| + # Detect if this is a partial or not + partial = File.basename(file).start_with?('_') + # If this 'file' is a directory, just skip it. We only care about files. unless File.directory?(file) # Check for assets that need to be compiled. Currently only looks to see if the file # ends in .coffee, .scss or .sass. # # Assets that start with _ are assumed to be partials and are not loaded. if asset_engine_extensions.include?(File.extname(file)) - unless File.basename(file).start_with?('_') + unless partial @assets << Asset.new(self, file) end else - # Check for YAML meta header. If it starts with ---, then process it as a page - intro = File.open(file) { |f| f.read(3) } - - # If file contents start with ---, then it is something we should process as a page. - if intro == "---" - @pages << Page.new(self, file) + if partial + @partials << Partial.new(self, file) else - @pages << StaticPage.new(self, file) + # Check for YAML meta header. If it starts with ---, then process it as a page + intro = File.open(file) { |f| f.read(3) } + + # If file contents start with ---, then it is something we should process as a page. + if intro == "---" + @pages << Page.new(self, file) + else + @pages << StaticPage.new(self, file) + end end end end end - log("#{@assets.size} assets loaded") if log - log("#{@pages.size} pages and other files loaded") if log + if verbose + log("#{@assets.size} assets loaded") + log("#{@pages.size} pages and other files loaded") + log("#{@partials.size} partials loaded") + end @pages end # Load blog posts from posts/ - def load_posts!(log = true) + def load_posts!(verbose = true) @posts = PostCollection.new Dir.glob(File.join(source, "posts/**/*")).each do |file| # If this 'file' is a directory, just skip it. We only care about files. unless File.directory?(file) @@ -279,10 +294,10 @@ end end @posts.sort! - log("#{@posts.size} posts loaded") if log + log("#{@posts.size} posts loaded") if verbose @posts end end end \ No newline at end of file