Class: Awestruct::Handlers::FileHandler

Inherits:
BaseHandler show all
Defined in:
lib/awestruct/handlers/file_handler.rb

Instance Attribute Summary collapse

Attributes inherited from BaseHandler

#delegate, #site

Instance Method Summary collapse

Methods inherited from BaseHandler

#content_line_offset, #content_syntax, #front_matter, #inherit_front_matter, #output_extension, #output_path, #simple_name, #to_chain

Constructor Details

#initialize(site, path) ⇒ FileHandler

Returns a new instance of FileHandler.



9
10
11
12
13
14
15
16
17
# File 'lib/awestruct/handlers/file_handler.rb', line 9

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

Instance Attribute Details

#pathObject

Returns the value of attribute path.



7
8
9
# File 'lib/awestruct/handlers/file_handler.rb', line 7

def path
  @path
end

Instance Method Details

#input_mtime(page) ⇒ Object



39
40
41
# File 'lib/awestruct/handlers/file_handler.rb', line 39

def input_mtime(page)
  path.mtime
end

#output_filenameObject



19
20
21
# File 'lib/awestruct/handlers/file_handler.rb', line 19

def output_filename
  File.basename( @path )
end

#raw_contentObject



43
44
45
46
# File 'lib/awestruct/handlers/file_handler.rb', line 43

def raw_content
  read
  @content
end

#relative_source_pathObject



23
24
25
26
27
28
29
30
31
32
# File 'lib/awestruct/handlers/file_handler.rb', line 23

def relative_source_path
  begin
    p = path.relative_path_from( site.dir ) 
    return nil if !! ( %r(^\.\.) =~ p )
    r = File.join( '', p )
    return r
  rescue Exception=>e
    nil
  end
end

#rendered_content(context, with_layouts = true) ⇒ Object



48
49
50
# File 'lib/awestruct/handlers/file_handler.rb', line 48

def rendered_content(context, with_layouts=true)
  raw_content
end

#stale?Boolean

Returns:

  • (Boolean)


34
35
36
37
# File 'lib/awestruct/handlers/file_handler.rb', line 34

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