Sha256: 6b6c18b1f61dc1da79fff5c4dedccf7ece841d6b0de05e53ae01975f7e4865d0

Contents?: true

Size: 1.47 KB

Versions: 3

Compression:

Stored size: 1.47 KB

Contents

module Gumdrop

  class Generator
    attr_reader :filename, :base_path, :params, :pages
    
    def initialize(content, opts={})
      @content= content
      if @content.is_a? Proc
        @filename= ""
        @base_path= ""
      else
        @filename= content.filename || ""
        @base_path= content.slug || ""
      end
      @params= HashObject.new
      @pages= []
    end
    
    def execute
      if @content.is_a? Proc
        run_dsl_from_proc @content
      else
        run_dsl_from_source IO.readlines(@content.path).join('')
      end
    end
    
    def data
      Gumdrop.data
    end
    
    def set(var_name, value)
      params[var_name]= value
    end
    
    def page(name, opts={}, &block)
      name= name[1..-1] if name.starts_with?('/')
      opts= params.reverse_merge(opts)
      filepath= if @base_path.empty?
        "/#{name}"
      else
        "/#{@base_path}/#{name}"
      end
      content= GeneratedContent.new(filepath, opts)
      content.template = if Gumdrop.layouts.has_key?( opts[:template] )
        Gumdrop.layouts[ opts[:template] ]
      else
        Gumdrop.layouts[ "#{opts[:template]}.template" ]
      end.template
      
      Gumdrop.site[content.uri]= content
    end
    
    def run_dsl_from_source(source)
      # puts source
      instance_eval source
    end

    def run_dsl_from_proc(proc)
      # puts source
      instance_eval &proc
    end
    
  end
  
  class GeneratedContent < Content
    # Nothing special, per se...
  end
  
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
gumdrop-0.2.16 lib/gumdrop/generator.rb
gumdrop-0.2.15 lib/gumdrop/generator.rb
gumdrop-0.2.14 lib/gumdrop/generator.rb