Module: Jetpack::Helper

Defined in:
lib/jetpack/helper.rb

Instance Method Summary collapse

Instance Method Details

#flash_messagesObject

Outputs a standard flash message.



25
26
27
28
29
30
31
32
# File 'lib/jetpack/helper.rb', line 25

def flash_messages
	str = ""
	flash.each do |type, msg|
		type == :alert ? persist = true : persist = false
		str +=  :div, msg, :class => ['alert-message', type], :data => { :persist => persist }
	end
	str.html_safe
end

Creates a nav link, ie. one that links to nothing (“#”) if it is the current page and in that case the link has the class “current”



18
19
20
21
22
# File 'lib/jetpack/helper.rb', line 18

def nav_link_to(text, path)
	link_to_unless_current text, path do
		link_to text, '#', :class => 'current'
	end
end

#title(page_title) ⇒ Object

Creates a smart title helper, appending [DEV] when you’re in dev mode.



35
36
37
38
# File 'lib/jetpack/helper.rb', line 35

def title(page_title)
	mode = "[DEV] " unless ::Rails.env.production?
	content_for(:title) { mode.to_s + page_title + " | " }
end

#view_nameObject

Creates a view name for CSS namespacing.



6
7
8
# File 'lib/jetpack/helper.rb', line 6

def view_name
	[controller.controller_name,controller.action_name,params[:id]].compact.join(' ')
end

#viewing?(string) ⇒ Boolean

Checks whether the user is looking at a particular view. Helpful for cases like a unique home page design element: - if viewing? ‘home’

Returns:

  • (Boolean)


12
13
14
# File 'lib/jetpack/helper.rb', line 12

def viewing?(string)
	view_name.include?(string)
end