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:
Saverio Trioni
2013-10-27 22:25:48 +01:00
parent 81ba88891b
commit 38aaa59ef9
4 changed files with 21 additions and 6 deletions

View File

@ -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?

View File

@ -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

View 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

View File

@ -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]