From 6eeda9f938077f1a48284fa96deb7d0bb13a392b Mon Sep 17 00:00:00 2001 From: Daniel Bogan Date: Fri, 19 Jan 2024 22:05:33 +0000 Subject: [PATCH] Add the scanners --- lib/dimples/scanner/pages.rb | 12 ++++++++++++ lib/dimples/scanner/posts.rb | 13 +++++++++++++ lib/dimples/scanner/templates.rb | 16 ++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 lib/dimples/scanner/pages.rb create mode 100644 lib/dimples/scanner/posts.rb create mode 100644 lib/dimples/scanner/templates.rb diff --git a/lib/dimples/scanner/pages.rb b/lib/dimples/scanner/pages.rb new file mode 100644 index 0000000..536819a --- /dev/null +++ b/lib/dimples/scanner/pages.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +module Dimples + module Scanner + # A helper class for scanning a directory of page files. + class Pages + def self.scan(source_path) + Dir[File.join(source_path, '**', '*.*')].map { |path| Dimples::Page.new(path: path) } + end + end + end +end diff --git a/lib/dimples/scanner/posts.rb b/lib/dimples/scanner/posts.rb new file mode 100644 index 0000000..d14ac66 --- /dev/null +++ b/lib/dimples/scanner/posts.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module Dimples + module Scanner + # A helper class for scanning a directory of post files. + class Posts + def self.scan(source_path) + posts = Dir[File.join(source_path, '**', '*.*')].map { |path| Dimples::Post.new(path: path) } + posts.sort_by!(&:date).reverse! + end + end + end +end diff --git a/lib/dimples/scanner/templates.rb b/lib/dimples/scanner/templates.rb new file mode 100644 index 0000000..6ac69ad --- /dev/null +++ b/lib/dimples/scanner/templates.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +module Dimples + module Scanner + # A helper class for scanning a directory of template files. + class Templates + def self.scan(source_path) + {}.tap do |templates| + Dir[File.join(source_path, '**', '*.*')].each do |path| + templates[File.basename(path, '.erb')] = Dimples::Template.new(path: path) + end + end + end + end + end +end