Class: Intranet::Pandoc::Responder

Inherits:
AbstractResponder
  • Object
show all
Includes:
Core::HamlWrapper
Defined in:
lib/intranet/pandoc/responder.rb

Overview

The responder for the Pandoc module of the Intranet.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logger, title, rootdir, template = nil, in_menu = true) ⇒ Responder

Initializes a new Pandoc responder instance.

Parameters:

  • title (String)

    The title of the module instance.

  • rootdir (String)

    The root directory of the module instance.

  • in_menu (Boolean) (defaults to: true)

    Whether the module instance should be displayed in the main navigation menu or not.



38
39
40
41
42
43
44
# File 'lib/intranet/pandoc/responder.rb', line 38

def initialize(logger, title, rootdir, template = nil, in_menu = true)
  @logger   = logger
  @title    = title
  @rootdir  = rootdir
  @template = template
  @in_menu  = in_menu
end

Instance Attribute Details

#titleString (readonly)

The title of the module instance, as displayed on the web page.

Returns:

  • (String)

    The title of the module instance.



73
74
75
# File 'lib/intranet/pandoc/responder.rb', line 73

def title
  @title
end

Class Method Details

.module_homepageString

The homepage of the module.

Returns:

  • (String)

    The homepage URL of the module.



29
30
31
# File 'lib/intranet/pandoc/responder.rb', line 29

def self.module_homepage
  HOMEPAGE_URL
end

.module_nameString

Returns the name of the module.

Returns:

  • (String)

    The name of the module.



17
18
19
# File 'lib/intranet/pandoc/responder.rb', line 17

def self.module_name
  NAME
end

.module_versionString

The version of the module, according to semantic versionning.

Returns:

  • (String)

    The version of the module.



23
24
25
# File 'lib/intranet/pandoc/responder.rb', line 23

def self.module_version
  VERSION
end

Instance Method Details

#generate_page(path, query) ⇒ Integer, String

Generates the HTML content associated to the given path and query.

Parameters:

  • path (String)

    The requested URI, relative to that module root URI.

  • query (Hash<String,String>)

    The URI variable/value pairs, if any.

Returns:

  • (Integer, String, String)

    The HTTP return code, the MIME type and the answer body.



63
64
65
66
67
68
69
# File 'lib/intranet/pandoc/responder.rb', line 63

def generate_page(path, query)
  case path
  when %r{^/.+\.html$} then serve_page(path.gsub(%r{^/(.+)\.html$}, '\\1'))
  when %r{^/.+\.(jpg|png|svg)$} then serve_media(path.gsub(%r{^/(.+)$}, '\\1'))
  else super(path, query)
  end
end

#in_menu?Boolean

Specifies if the responder instance should be displayed in the main navigation menu or not.

Returns:

  • (Boolean)

    True if the responder instance should be added to the main navigation menu, False otherwise.



49
50
51
# File 'lib/intranet/pandoc/responder.rb', line 49

def in_menu?
  @in_menu
end

#resources_dirString

Specifies the absolute path to the resources directory for that module.

Returns:

  • (String)

    The absolute path to the resources directory for the module.



55
56
57
# File 'lib/intranet/pandoc/responder.rb', line 55

def resources_dir
  File.absolute_path(File.join('..', 'resources'), __dir__)
end