Module: Locomotive::Plugin::RackAppHelpers

Included in:
Locomotive::Plugin
Defined in:
lib/locomotive/plugin/rack_app_helpers.rb

Overview

This module adds helpers for handling the Rack app supplied by the rack_app method.

Defined Under Namespace

Modules: ClassMethods, HelperMethods

Instance Method Summary collapse

Instance Method Details

#mounted_rack_appObject

Delegates to ClassMethods#mounted_rack_app.

Returns:

  • the rack app with the helper methods



92
93
94
# File 'lib/locomotive/plugin/rack_app_helpers.rb', line 92

def mounted_rack_app
  self.class.mounted_rack_app
end

#mountpointObject

The mountpoint of the Rack app.

Returns:

  • the mountpoint



52
53
54
# File 'lib/locomotive/plugin/rack_app_helpers.rb', line 52

def mountpoint
  @mountpoint ||= '/'
end

#mountpoint=(mountpoint) ⇒ Object

Set the mountpoint of the Rack app.

Parameters:

  • mountpoint (String)

    the new mountpoint



59
60
61
# File 'lib/locomotive/plugin/rack_app_helpers.rb', line 59

def mountpoint=(mountpoint)
  @mountpoint = mountpoint
end

#rack_app_full_path(path) ⇒ Object

Generate the full absolute path within the plugin’s rack app for the given path based on the mountpoint.

Parameters:

  • path (String)

    the path relative to the mountpoint of the rack app

Returns:

  • the absolute path



69
70
71
72
73
74
# File 'lib/locomotive/plugin/rack_app_helpers.rb', line 69

def rack_app_full_path(path)
  [
    base_uri_object.path.sub(%r{/+$}, ''),
    path.sub(%r{^/+}, '')
  ].join('/')
end

#rack_app_full_url(path) ⇒ Object

Generate the full URL for the given path based on the mountpoint of this plugin’s rack app.

Parameters:

  • path (String)

    the path relative to the mountpoint of the rack app

Returns:

  • the URL



82
83
84
85
86
87
# File 'lib/locomotive/plugin/rack_app_helpers.rb', line 82

def rack_app_full_url(path)
  [
    base_uri_object.to_s.sub(%r{/+$}, ''),
    path.sub(%r{^/+}, '')
  ].join('/')
end