Method: Olelo::PageHelper#build_path

Defined in:
lib/olelo/helper.rb

#build_path(page, options = {}) ⇒ Object



200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/olelo/helper.rb', line 200

def build_path(page, options = {})
  options = options.dup
  action = options.delete(:action)
  version = options.delete(:version)
  path = (page.try(:path) || page).to_s

  if action
    raise ArgumentError if version
    path = action.to_s/path
  else
    version ||= page if Page === page
    version = version.tree_version if Page === version
    path = 'version'/version/path if version && (options.delete(:force_version) || !version.head?)
  end

  unless options.empty?
    query = Rack::Utils.build_query(options)
    path += '?' + query unless query.empty?
  end
  '/' + (Config['base_path'] / path)
end