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, #dependencies, #execute_shell, #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



41
42
43
# File 'lib/awestruct/handlers/file_handler.rb', line 41

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



45
46
47
48
# File 'lib/awestruct/handlers/file_handler.rb', line 45

def raw_content
  read
  @content
end

#relative_source_pathObject



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

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

#rendered_content(context, with_layouts = true) ⇒ Object



50
51
52
# File 'lib/awestruct/handlers/file_handler.rb', line 50

def rendered_content(context, with_layouts=true)
  raw_content
end

#stale?Boolean

Returns:

  • (Boolean)


36
37
38
39
# File 'lib/awestruct/handlers/file_handler.rb', line 36

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