Sha256: 16d4666eb134988cab4495045c0d2d48824b4940f29d32cd4206375b5af8bc50

Contents?: true

Size: 1.16 KB

Versions: 7

Compression:

Stored size: 1.16 KB

Contents

require 'ostruct'

module Awestruct
  class Site < OpenStruct

    attr_reader :dir
    attr_reader :output_dir
    attr_reader :tmp_dir

    attr_reader   :layouts
    attr_accessor :pages

    def initialize(config)
      super({})

      @dir = config.input_dir
      @output_dir = config.output_dir
      @tmp_dir = config.tmp_dir

      FileUtils.mkdir_p( @output_dir )
      FileUtils.mkdir_p( @tmp_dir )

      @pages   = []
      @layouts = {}
    end

    def has_page?(path)
      ! pages.find{|e| e.source_path == path}.nil?
    end

    def output_path(path, ext=nil)
      path = File.join( @output_dir, path[ @dir.size..-1] )
      unless ( ext.nil? )
        path = File.join( File.dirname( path ), File.basename( path, ext ) )
      end
      path 
    end

    def url_path(path, ext=nil)
      url_path = output_path( path, ext )[ @output_dir.size .. -1 ]
    end

    def apply_plugins
      Dir[ File.join( @dir, '_plugins', '*.rb' ) ].each do |rb_path|
        site_root = @dir
        output_root = @output_dir
        begin
          eval File.read( rb_path )
        rescue => e
          puts e
          puts e.backtrace
        end
      end
    end

  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
awestruct-0.2.18 lib/awestruct/site.rb
awestruct-0.2.17 lib/awestruct/site.rb
awestruct-0.2.15 lib/awestruct/site.rb
awestruct-0.2.14 lib/awestruct/site.rb
awestruct-0.2.13 lib/awestruct/site.rb
awestruct-0.2.12 lib/awestruct/site.rb
awestruct-0.2.11 lib/awestruct/site.rb