Module: ApplicationHelper

Includes:
Admin::RegionsHelper, LocalTime, Radiant::LegacyRoutes
Defined in:
app/helpers/application_helper.rb

Instance Method Summary collapse

Methods included from LocalTime

#adjust_time

Instance Method Details

#adminObject



144
145
146
# File 'app/helpers/application_helper.rb', line 144

def admin
  Radiant::AdminUI.instance
end

#admin?Boolean

Returns:

  • (Boolean)


85
86
87
# File 'app/helpers/application_helper.rb', line 85

def admin?
  current_user and current_user.admin?
end

#clean(url) ⇒ Object



72
73
74
75
# File 'app/helpers/application_helper.rb', line 72

def clean(url)
  uri = URI.parse(url)
  uri.path.gsub(%r{/+}, '/').gsub(%r{/$}, '')
end

#configObject



6
7
8
# File 'app/helpers/application_helper.rb', line 6

def config
  Radiant::Config
end

#current_url?(options) ⇒ Boolean

Returns:

  • (Boolean)


62
63
64
65
66
67
68
69
70
# File 'app/helpers/application_helper.rb', line 62

def current_url?(options)
  url = case options
  when Hash
    url_for options
  else
    options.to_s
  end
  request.request_uri =~ Regexp.new('^' + Regexp.quote(clean(url)))
end

#default_page_titleObject



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

def default_page_title
  title + ' - ' + subtitle
end

#developer?Boolean

Returns:

  • (Boolean)


89
90
91
# File 'app/helpers/application_helper.rb', line 89

def developer?
  current_user and (current_user.developer? or current_user.admin?)
end

#filter_options_for_select(selected = nil) ⇒ Object



148
149
150
# File 'app/helpers/application_helper.rb', line 148

def filter_options_for_select(selected=nil)
  options_for_select([['<none>', '']] + TextFilter.descendants.map { |s| s.filter_name }.sort, selected)
end

#focus(field_name) ⇒ Object



93
94
95
# File 'app/helpers/application_helper.rb', line 93

def focus(field_name)
  javascript_tag "Field.activate('#{field_name}');"
end

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



136
137
138
# File 'app/helpers/application_helper.rb', line 136

def image(name, options = {})
  image_tag(append_image_extension("admin/#{name}"), options)
end

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



140
141
142
# File 'app/helpers/application_helper.rb', line 140

def image_submit(name, options = {})
  image_submit_tag(append_image_extension("admin/#{name}"), options)
end


50
51
52
53
54
55
56
# File 'app/helpers/application_helper.rb', line 50

def links_for_navigation
  tabs = admin.tabs
  links = tabs.map do |tab|
    nav_link_to(tab.name, File.join(ActionController::Base.relative_url_root || '', tab.url)) if tab.shown_for?(current_user)
  end.compact
  links.join(separator)
end

#logged_in?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'app/helpers/application_helper.rb', line 22

def logged_in?
  !current_user.nil?
end

#meta_errors?Boolean

Returns:

  • (Boolean)


128
129
130
# File 'app/helpers/application_helper.rb', line 128

def meta_errors?
  false
end

#meta_visible(symbol) ⇒ Object



118
119
120
121
122
123
124
125
126
# File 'app/helpers/application_helper.rb', line 118

def meta_visible(symbol)
  v = case symbol
  when :meta_more
    not meta_errors?
  when :meta, :meta_less
    meta_errors?
  end
  v ? {} : {:style => "display:none"}
end


77
78
79
80
81
82
83
# File 'app/helpers/application_helper.rb', line 77

def nav_link_to(name, options)
  if current_url?(options)
    %{<strong>#{ link_to name, options }</strong>}
  else
    link_to name, options
  end
end

#pluralize(count, singular, plural = nil) ⇒ Object

Redefine pluralize() so that it doesn’t put the count at the beginning of the string.



40
41
42
43
44
45
46
47
48
# File 'app/helpers/application_helper.rb', line 40

def pluralize(count, singular, plural = nil)
  if count == 1
    singular
  elsif plural
    plural
  else
    ActiveSupport::Inflector.pluralize(singular)
  end
end

#save_model_and_continue_editing_button(model) ⇒ Object



34
35
36
# File 'app/helpers/application_helper.rb', line 34

def save_model_and_continue_editing_button(model)
  submit_tag 'Save and Continue Editing', :name => 'continue', :class => 'button'
end

#save_model_button(model, options = {}) ⇒ Object



26
27
28
29
30
31
32
# File 'app/helpers/application_helper.rb', line 26

def save_model_button(model, options = {})
  options[:label] ||= model.new_record? ?
    "Create #{model.class.name}" : "Save Changes"
  options[:class] ||= "button"

  submit_tag options.delete(:label), options
end

#separatorObject



58
59
60
# File 'app/helpers/application_helper.rb', line 58

def separator
  %{ <span class="separator"> | </span> }
end

#subtitleObject



18
19
20
# File 'app/helpers/application_helper.rb', line 18

def subtitle
  config['admin.subtitle'] || 'Publishing for Small Teams'
end

#timestamp(time) ⇒ Object



114
115
116
# File 'app/helpers/application_helper.rb', line 114

def timestamp(time)
  time.strftime("%I:%M <small>%p</small> on %B %d, %Y")
end

#titleObject



14
15
16
# File 'app/helpers/application_helper.rb', line 14

def title
  config['admin.title'] || 'Radiant CMS'
end

#toggle_javascript_for(id) ⇒ Object



132
133
134
# File 'app/helpers/application_helper.rb', line 132

def toggle_javascript_for(id)
  "Element.toggle('#{id}'); Element.toggle('more-#{id}'); Element.toggle('less-#{id}'); return false;"
end

#updated_stamp(model) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'app/helpers/application_helper.rb', line 97

def updated_stamp(model)
  unless model.new_record?
    updated_by = (model.updated_by || model.created_by)
     = updated_by ? updated_by. : nil
    time = (model.updated_at || model.created_at)
    if  or time
      html = %{<p style="clear: left"><small>Last updated } 
      html << %{by #{login} } if 
      html << %{at #{ timestamp(time) }} if time
      html << %{</small></p>}
      html
    end
  else
    %{<p class="clear">&nbsp;</p>}
  end
end