Sha256: bf55a17fbc55d198feebb040b7fc57087b225a98ba94f0c286290e8c61255212

Contents?: true

Size: 1.3 KB

Versions: 12

Compression:

Stored size: 1.3 KB

Contents

require 'awestruct/handlers/base_handler'

module Awestruct
  module Handlers
    class FileHandler < BaseHandler

      attr_accessor :path

      def initialize(site, path)
        super( site )
        case ( path )
          when Pathname
            @path = path
          else
            @path = Pathname.new( path.to_s )
        end
        @relative_source_path = nil
      end

      def output_filename
        File.basename( @path )
      end

      def relative_source_path
        return @relative_source_path unless @relative_source_path.nil?
        begin
          @relative_source_path = "/#{Pathname.new path.relative_path_from( site.dir )}"
        rescue Exception=>e
          nil
        end
        @relative_source_path
      end

      def stale?
        return true if ( @content.nil? || ( File.mtime( @path ) > @mtime ) )
        false
      end

      def input_mtime(page)
        path.mtime
      end

      def raw_content
        load_content
      end

      def rendered_content(context, with_layouts=true)
        raw_content
      end
      
      def read_content
        File.open(@path, 'r') {|is| is.read }
      end

      private 

      def load_content
        ( @content = read_content ) if stale?
        @mtime = File.mtime( @path )
        @content
      end

    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
awestruct-0.6.7 lib/awestruct/handlers/file_handler.rb
awestruct-0.6.6 lib/awestruct/handlers/file_handler.rb
awestruct-0.6.5 lib/awestruct/handlers/file_handler.rb
awestruct-0.6.4 lib/awestruct/handlers/file_handler.rb
awestruct-0.6.3 lib/awestruct/handlers/file_handler.rb
awestruct-0.6.2 lib/awestruct/handlers/file_handler.rb
awestruct-0.6.1 lib/awestruct/handlers/file_handler.rb
awestruct-0.6.0 lib/awestruct/handlers/file_handler.rb
awestruct-0.6.0.RC1 lib/awestruct/handlers/file_handler.rb
awestruct-0.6.0.alpha4 lib/awestruct/handlers/file_handler.rb
awestruct-0.6.0.alpha3 lib/awestruct/handlers/file_handler.rb
awestruct-0.6.0.alpha1 lib/awestruct/handlers/file_handler.rb