lib/stack/generator.rb in stack-0.0.2 vs lib/stack/generator.rb in stack-0.0.3
- old
+ new
@@ -1,16 +1,67 @@
module Stack
class Generator
+ attr_accessor :layouts
+ attr_accessor :pages
+
def initialize
- puts "Source -> #{Stack::runner.configuration.source}"
-
# read layouts
- # read "objects"
# read pages
# write pages
+
+ process!
end
- def layouts
+ def process!
+ read_layouts
+ read_pages
+ end
+
+ def read_layouts
+ @layouts = read_pages_from_directory("_layouts", Stack::Templates::Layout)
+ end
+
+ def read_pages
+ @pages = read_pages_from_directory(Stack::runner.configuration.source, Stack::Templates::Page)
+ end
+
+ def transform!
+ puts @layouts
+ puts @pages
+ self.pages.each do |name, page|
+ puts "Page -> #{name} #{page}"
+ page.write!
+ end
+ end
+
+ def to_hash
+ {
+
+ }
+ end
+
+ private
+ def read_pages_from_directory(folder, transformable_klass)
+ pages = { }
+
+ begin
+ path = (folder == Stack::runner.configuration.source) ? folder : File.join(Stack::runner.configuration.source, folder)
+ entries = Dir.entries(path)
+
+ files = entries.reject { |e| File.directory?(File.join(path, e)) }
+ files = files.reject { |e| e[0..0]=~/\.|_/ or e[-1..-1]=="~" }
+ files = files.select { |e| Stack::EXTENSIONS.include?(File.extname(e)) }
+
+ files.each do |f|
+ trans = transformable_klass.new(File.join(path, f), self)
+ pages[f.split(".").first] = trans
+ end
+ rescue Errno::ENOENT => e
+ # Ignore
+ puts e.to_str
+ end
+
+ return pages
end
end
end
\ No newline at end of file