Module: Olelo::ApplicationHelper

Includes:
BlockHelper, FlashHelper, HttpHelper, PageHelper, Templates
Included in:
Application
Defined in:
lib/olelo/helper.rb

Instance Method Summary collapse

Methods included from Templates

enable_caching, with_caching

Methods included from HttpHelper

#cache_control

Methods included from Util

#check, #decode64, #deep_copy, #encode64, #escape, #escape_html, #escape_javascript, included, #md5, #no_cache?, #sha256, #titlecase, #truncate, #unescape, #unescape_backslash, #unescape_html, #valid_xml_chars?

Methods included from PageHelper

#breadcrumbs, #build_path, #date, #format_diff, #include_page, #pagination, #render_page

Methods included from FlashHelper

#flash, #flash_messages

Methods included from BlockHelper

#blocks, #define_block, #include_block, #render_block, #wrap_block

Instance Method Details

#action?(action) ⇒ Boolean

Returns:

  • (Boolean)


295
296
297
298
299
300
301
# File 'lib/olelo/helper.rb', line 295

def action?(action)
  if params[:action]
    params[:action].split('-', 2).first == action.to_s
  else
    unescape(request.path_info).starts_with?("/#{action}")
  end
end

#build_static_path(path) ⇒ Object



319
320
321
322
# File 'lib/olelo/helper.rb', line 319

def build_static_path(path)
  file = File.join(Config['app_path'], 'static', path)
  build_path "static-#{File.mtime(file).to_i}/#{path}"
end


303
304
305
306
307
308
309
# File 'lib/olelo/helper.rb', line 303

def footer(content = nil, &block)
  if block_given? || content
    define_block(:footer, content, &block)
  else
    render_block(:footer)
  end
end

#headObject



324
325
326
327
328
329
330
331
332
333
334
335
# File 'lib/olelo/helper.rb', line 324

def head
  @@head_links ||= %{<link rel="shortcut icon" href="#{escape_html build_static_path('favicon.png')}" type="image/png"/>
<link rel="stylesheet" href="#{escape_html build_static_path("themes/#{Config['theme']}/style.css")}" type="text/css"/>
<script src="#{escape_html build_static_path("script.js")}" type="text/javascript"></script>}
  # Add base path to root page to fix links in history browsing and for wikis with base_path
  base_path = if request.path_info =~ %r{^/version/[^/]+$} ||
                  (request.path_info == '/' && Config['base_path'] != '/')
    url = request.base_url << [Config['base_path'], '/', request.path_info, '/'].join.gsub(%r{/+}, '/')
    %{<base href="#{escape_html url}"/>}
  end
  [base_path, @@head_links, *invoke_hook(:head)].join.html_safe
end


341
342
343
344
345
# File 'lib/olelo/helper.rb', line 341

def menu(name)
  menu = Menu.new(name)
  invoke_hook :menu, menu
  menu.to_html
end

#render(name, options = {}) ⇒ Object



349
350
351
352
353
354
355
# File 'lib/olelo/helper.rb', line 349

def render(name, options = {})
  layout = options.delete(:layout) != false && !params[:no_layout]
  output = Symbol === name ? render_partial(name, options) : name
  output = render_partial(:layout, options) { output } if layout
  invoke_hook :render, name, output, layout
  output
end

#render_partialObject



347
# File 'lib/olelo/helper.rb', line 347

alias render_partial render

#sessionObject



337
338
339
# File 'lib/olelo/helper.rb', line 337

def session
  env['rack.session'] ||= {}
end

#tabs(*actions) ⇒ Object



288
289
290
291
292
293
# File 'lib/olelo/helper.rb', line 288

def tabs(*actions)
  tabs = actions.map do |action|
    %{<li id="tabhead-#{action}"#{action?(action) ? ' class="selected"' : ''}><a href="#tab-#{action}">#{escape_html action.t}</a></li>}
  end
  %{<ul class="tabs">#{tabs.join}</ul>}.html_safe
end

#title(content = nil, &block) ⇒ Object



311
312
313
314
315
316
317
# File 'lib/olelo/helper.rb', line 311

def title(content = nil, &block)
  if block_given? || content
    define_block(:title, content, &block)
  else
    render_block(:title)
  end
end