Module: Georgia::UiHelper

Defined in:
app/helpers/georgia/ui_helper.rb

Instance Method Summary collapse

Instance Method Details

#asset_icon_tag(extension) ⇒ Object

FIXME: Turn into a Hash



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/helpers/georgia/ui_helper.rb', line 15

def asset_icon_tag extension
  icon_name = case extension.downcase
    when 'avi' then 'file-movie-o'
    when 'css' then 'file-text-o'
    when 'csv' then 'file-excel-o'
    when 'doc' then 'file-word-o'
    when 'docx' then 'file-word-o'
    when 'eps' then 'file-powerpoint-o'
    when 'gif' then 'file-image-o'
    when 'gz' then 'file-archive-o'
    when 'html' then 'file-code-o'
    when 'jpeg' then 'file-image-o'
    when 'jpg' then 'file-image'
    when 'mp3' then 'file-audio-o'
    when 'ods' then 'file-excel-o'
    when 'odt' then 'file-word-o'
    when 'pdf' then 'file-pdf-o'
    when 'png' then 'file-image-o'
    when 'ppt' then 'file-powerpoint-o'
    when 'pptx' then 'file-powerpoint-o'
    when 'rar' then 'file-archive-o'
    when 'tar' then 'file-archive-o'
    when 'txt' then 'file-text-o'
    when 'wav' then 'file-audio-o'
    when 'xls' then 'file-excel-o'
    when 'zip' then 'file-archive-o'
    else
      'file'
    end
  icon_tag(icon_name)
end

#avatar_url(email = '', options = {}) ⇒ Object



4
5
6
7
8
# File 'app/helpers/georgia/ui_helper.rb', line 4

def avatar_url(email='', options={})
  gravatar_id = Digest::MD5.hexdigest(email.downcase) if email
  size = options.fetch(:size, '32')
  "//gravatar.com/avatar/#{gravatar_id}.png?s=#{size}&d=mm"
end

#button_to_editObject



74
75
76
77
# File 'app/helpers/georgia/ui_helper.rb', line 74

def button_to_edit
  return unless policy(@page).update?
  link_to "#{icon_tag('pencil')} Edit".html_safe, [:edit, @page], class: 'btn btn-info'
end

#button_to_settingsObject



69
70
71
72
# File 'app/helpers/georgia/ui_helper.rb', line 69

def button_to_settings
  return unless policy(@page).settings?
  link_to "#{icon_tag('cogs')} Settings".html_safe, [:settings, @page], class: 'btn btn-info'
end

#caret_tagObject



10
11
12
# File 'app/helpers/georgia/ui_helper.rb', line 10

def caret_tag
   :span, nil, class: 'caret'
end


100
101
102
103
104
105
106
107
108
109
110
111
# File 'app/helpers/georgia/ui_helper.rb', line 100

def link_to_available_locales
  return unless I18n.available_locales.length > 1
  links = I18n.available_locales.map do |locale|
    (:li, link_to(t("georgia.#{locale}"), params.merge(locale: locale) ))
  end
  (:p, class: 'hint') do
    (:div, class: 'dropdown') do
      link_to("Change language <span class='caret'></span>".html_safe, '#', class: 'btn btn-warning', data: {toggle: 'dropdown'}, role: :button) +
      (:ul, links.join('').html_safe, class: 'dropdown-menu', role: 'menu')
    end
  end
end


47
48
49
# File 'app/helpers/georgia/ui_helper.rb', line 47

def link_to_back url=:back
  link_to icon_tag('level-up fa-rotate-270'), url, class: 'btn btn-back'
end

Link to close modal box



57
58
59
# File 'app/helpers/georgia/ui_helper.rb', line 57

def link_to_close
   :button, icon_tag('times'), class: 'close', data: {dismiss: 'modal'}, aria: {hidden: true}, type: 'button'
end


51
52
53
54
# File 'app/helpers/georgia/ui_helper.rb', line 51

def link_to_delete url, options={}
  text = options.delete(:text) { "#{icon_tag('trash-o')} Delete".html_safe }
  link_to text, url, options.reverse_merge(data: {confirm: 'Are you sure?'}, method: :delete, class: 'btn btn-danger')
end

#page_actions_tag(page, revision = nil, options = {}) ⇒ Object



79
80
81
82
# File 'app/helpers/georgia/ui_helper.rb', line 79

def page_actions_tag page, revision=nil, options={}
  revision ||= page.current_revision
  Georgia::PageActionsPresenter.new(self, page, revision, options)
end

#page_url_minus_slugObject



84
85
86
# File 'app/helpers/georgia/ui_helper.rb', line 84

def page_url_minus_slug
  @page_full_url ||= (Georgia.url + @page.url).gsub(@page.slug, '')
end

#picture_tag(picture, options = {}) ⇒ Object



92
93
94
95
96
97
98
# File 'app/helpers/georgia/ui_helper.rb', line 92

def picture_tag picture, options={}
  return unless picture and picture.url.present?
  format = options.fetch(:format, :tiny)
  link_to picture.url_content, class: 'media-link bg-transparent', rel: 'shadowbox[gallery]' do
    image_tag(picture.url(format), title: picture.data_file_name, class: 'media-image')
  end
end

#revision_status_message(page, revision, options = {}) ⇒ Object



88
89
90
# File 'app/helpers/georgia/ui_helper.rb', line 88

def revision_status_message page, revision, options={}
  Georgia::RevisionStatusMessage.new(self, page, revision, options)
end

#tooltip_tag(icon, tooltip, options = {}) ⇒ Object



61
62
63
# File 'app/helpers/georgia/ui_helper.rb', line 61

def tooltip_tag icon, tooltip, options={}
  (:span, icon, options.reverse_merge(title: tooltip, class: 'js-tooltip', data: {placement: 'right'}))
end

#welcomed?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'app/helpers/georgia/ui_helper.rb', line 65

def welcomed?
  session[:welcomed] || !(session[:welcomed] = true)
end