Class: Awestruct::Handlers::FileHandler

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

Direct Known Subclasses

VerbatimFileHandler

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



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

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



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

def raw_content
  load_content
end

#read_contentObject



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

def read_content
  File.open(@path, 'r') {|is| is.read }
end

#relative_source_pathObject



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

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

#rendered_content(context, with_layouts = true) ⇒ Object



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

def rendered_content(context, with_layouts=true)
  raw_content
end

#stale?Boolean

Returns:

  • (Boolean)


31
32
33
34
# File 'lib/awestruct/handlers/file_handler.rb', line 31

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