Sha256: 206f06aa2f34dd1dd9b2adb279aa02b6068797184fc6e0d79074a33ec983f61c

Contents?: true

Size: 1.52 KB

Versions: 1

Compression:

Stored size: 1.52 KB

Contents

module Stack
  class Generator
    attr_accessor :layouts
    attr_accessor :pages
    
    def initialize
      # read layouts
      # read pages
      # write pages
      
      process!
    end
    
    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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
stack-0.0.3 lib/stack/generator.rb