Class: OodAppkit::Urls::Editor

Inherits:
OodAppkit::Url show all
Defined in:
lib/ood_appkit/urls/editor.rb

Overview

A class used to handle URLs for the system file Editor app.

Instance Attribute Summary

Attributes inherited from OodAppkit::Url

#title

Instance Method Summary collapse

Methods inherited from OodAppkit::Url

#url

Constructor Details

#initialize(edit_url: '/edit', template: '{/url*}{/fs}{+path}', **kwargs) ⇒ Editor

Returns a new instance of Editor.

Parameters:

  • edit_url (#to_s) (defaults to: '/edit')

    the URL used to request the file editor api

  • title (#to_s)

    the title of the URL

  • base_url (#to_s)

    the base URL used to access this app

  • template (#to_s) (defaults to: '{/url*}{/fs}{+path}')

    the template used to generate URLs for this app



7
8
9
10
# File 'lib/ood_appkit/urls/editor.rb', line 7

def initialize(edit_url: '/edit', template: '{/url*}{/fs}{+path}', **kwargs)
  super(template: template, **kwargs)
  @edit_url = parse_url_segments(edit_url.to_s)
end

Instance Method Details

#edit(opts = {}) ⇒ Addressable::URI

URL to access this app’s file editor API for a given absolute file path

Parameters:

  • opts (#to_h) (defaults to: {})

    the available options for this method

Options Hash (opts):

  • :path (#to_s, nil) — default: ""

    The absolute path to the file on the filesystem

  • :fs (#to_s, nil) — default: ""

    The filesystem for the path

Returns:

  • (Addressable::URI)

    absolute url to access path in file editor api



19
20
21
22
23
24
25
# File 'lib/ood_appkit/urls/editor.rb', line 19

def edit(opts = {})
  opts = opts.to_h.compact.symbolize_keys

  path = opts.fetch(:path, "").to_s
  fs = opts.fetch(:fs, "fs").to_s
  @template.expand url: @base_url + @edit_url, fs: fs, path: path
end