Sha256: 2737a726f23e0bac2fad60490f62ee6eba7ad45e46f9fe8edffd7d578b819e85

Contents?: true

Size: 1.25 KB

Versions: 20

Compression:

Stored size: 1.25 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
      end

      def output_filename
        File.basename( @path )
      end

      def relative_source_path
        begin
          p = path.relative_path_from( site.dir ) 
          if !! ( %r(^\.\.) =~ p.to_s )
            return nil 
          end
          r = File.join( '', p )
          return r
        rescue Exception=>e
          nil
        end
      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

20 entries across 20 versions & 1 rubygems

Version Path
awestruct-0.5.7.RC2 lib/awestruct/handlers/file_handler.rb
awestruct-0.5.7.RC1 lib/awestruct/handlers/file_handler.rb
awestruct-0.5.6 lib/awestruct/handlers/file_handler.rb
awestruct-0.5.6.beta9 lib/awestruct/handlers/file_handler.rb
awestruct-0.5.6.beta8 lib/awestruct/handlers/file_handler.rb
awestruct-0.5.6.beta7 lib/awestruct/handlers/file_handler.rb
awestruct-0.5.6.beta6 lib/awestruct/handlers/file_handler.rb
awestruct-0.5.6.beta5 lib/awestruct/handlers/file_handler.rb
awestruct-0.5.6.beta4 lib/awestruct/handlers/file_handler.rb
awestruct-0.5.6.beta3 lib/awestruct/handlers/file_handler.rb
awestruct-0.5.6.beta2 lib/awestruct/handlers/file_handler.rb
awestruct-0.5.6.beta lib/awestruct/handlers/file_handler.rb
awestruct-0.5.5 lib/awestruct/handlers/file_handler.rb
awestruct-0.5.4.2 lib/awestruct/handlers/file_handler.rb
awestruct-0.5.4.1 lib/awestruct/handlers/file_handler.rb
awestruct-0.5.4 lib/awestruct/handlers/file_handler.rb
awestruct-0.5.4.rc3 lib/awestruct/handlers/file_handler.rb
awestruct-0.5.4.rc2 lib/awestruct/handlers/file_handler.rb
awestruct-0.5.4.rc lib/awestruct/handlers/file_handler.rb
awestruct-0.5.4.beta1 lib/awestruct/handlers/file_handler.rb