Glyph helper. Use as <%= glyph('icon') %>
Uses glyphicons library. One may add also custom icon association in the GLYPHS constant. If a class is passed to the helper, it is underscored before being searched in the GLYPHS.
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
class ApplicationController < ActionController::Base
|
||||
protect_from_forgery
|
||||
helper :glyph
|
||||
|
||||
# before_filter :intercept_html_requests
|
||||
helper_method :current_user, :current_organization, :admin?, :superadmin?
|
||||
|
||||
@ -3,10 +3,7 @@ module ApplicationHelper
|
||||
# froom http://railscasts.com/episodes/244-gravatar?language=en&view=asciicast
|
||||
def avatar_url(user, size=32)
|
||||
gravatar_id = Digest::MD5::hexdigest(user.email).downcase
|
||||
gravatar_options = Hash[
|
||||
s: size,
|
||||
d: 'identicon'
|
||||
]
|
||||
gravatar_options = Hash[s: size, d: 'identicon']
|
||||
"http://gravatar.com/avatar/#{gravatar_id}.png?#{Rack::Utils.build_query(gravatar_options)}"
|
||||
end
|
||||
|
||||
|
||||
17
app/helpers/glyph_helper.rb
Normal file
17
app/helpers/glyph_helper.rb
Normal file
@ -0,0 +1,17 @@
|
||||
module GlyphHelper
|
||||
|
||||
GLYPHS = Hash[
|
||||
"offer" => "hand-up",
|
||||
"inquiry" => "belt",
|
||||
"user" => "user",
|
||||
"tag" => "tag",
|
||||
"category" => "folder-open",
|
||||
"organization" => "tower"
|
||||
]
|
||||
|
||||
def glyph(kind)
|
||||
kind = kind.to_s.underscore
|
||||
content_tag :span, "", class: "glyphicon glyphicon-#{GLYPHS.fetch kind, kind}"
|
||||
end
|
||||
|
||||
end
|
||||
@ -3,11 +3,11 @@
|
||||
= Offer.model_name.human(count: :many)
|
||||
- if @category.present?
|
||||
%small
|
||||
%span.glyphicon.glyphicon-folder-open
|
||||
= glyph(Category)
|
||||
= @category.name
|
||||
- if params[:q].present?
|
||||
%small
|
||||
%span.glyphicon.glyphicon-search
|
||||
= glyph(:search)
|
||||
= params[:q]
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user