Class: Awestruct::Handlers::RedirectHandler

Inherits:
BaseHandler
  • Object
show all
Defined in:
lib/awestruct/handlers/redirect_handler.rb

Constant Summary collapse

CHAIN =
Awestruct::HandlerChain.new( /\.redirect$/,
  Awestruct::Handlers::FileHandler,
  Awestruct::Handlers::FrontMatterHandler,
  Awestruct::Handlers::InterpolationHandler,
  Awestruct::Handlers::RedirectHandler
)

Instance Attribute Summary

Attributes inherited from BaseHandler

#delegate, #site

Instance Method Summary collapse

Methods inherited from BaseHandler

#content_line_offset, #dependencies, #execute_shell, #front_matter, #inherit_front_matter, #input_mtime, #output_path, #path, #raw_content, #relative_source_path, #stale?, #to_chain

Constructor Details

#initialize(site, delegate) ⇒ RedirectHandler

Returns a new instance of RedirectHandler.



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

def initialize(site, delegate)
  super( site, delegate )
end

Instance Method Details

#content_syntaxObject



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

def content_syntax
  :text
end

#output_extensionObject



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

def output_extension
  '.html'
end

#output_filenameObject



27
28
29
# File 'lib/awestruct/handlers/redirect_handler.rb', line 27

def output_filename
  simple_name + output_extension
end

#rendered_content(context, with_layouts = false) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/awestruct/handlers/redirect_handler.rb', line 39

def rendered_content(context, with_layouts=false)
  url = delegate.rendered_content( context, with_layouts ).strip
  # should we auto-qualify the URL?
  # they can use #{site.base_url}/path currently
  #if url.start_with? '/'
  #  url = File.join(@site.base_url, url)
  #end
  %{<!DOCTYPE html><html><head><meta http-equiv="refresh" content="0;url=#{url}"></head></html>}
end

#simple_nameObject



23
24
25
# File 'lib/awestruct/handlers/redirect_handler.rb', line 23

def simple_name
  File.basename( relative_source_path || path, '.redirect' ) 
end