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
18
# 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
  @relative_source_path = nil
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



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

def output_filename
  File.basename( @path )
end

#raw_contentObject



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

def raw_content
  load_content
end

#read_contentObject



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

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

#relative_source_pathObject



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

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

#rendered_content(context, with_layouts = true) ⇒ Object



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

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