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



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

def admin
  Radiant::AdminUI.instance
end

#admin?Boolean

Returns:

  • (Boolean)


91
92
93
# File 'app/helpers/application_helper.rb', line 91

def admin?
  current_user and current_user.admin?
end

#body_classesObject



156
157
158
# File 'app/helpers/application_helper.rb', line 156

def body_classes
  @body_classes ||= []
end

#clean(url) ⇒ Object



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

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_item?(item) ⇒ Boolean

Returns:

  • (Boolean)


54
55
56
57
58
59
60
61
# File 'app/helpers/application_helper.rb', line 54

def current_item?(item)
  if item.tab.many? {|i| current_url?(i.relative_url) }
    # Accept only stricter URL matches if more than one matches
    current_page?(item.url)
  else
    current_url?(item.relative_url)
  end
end

#current_tab?(tab) ⇒ Boolean

Returns:

  • (Boolean)


63
64
65
66
# File 'app/helpers/application_helper.rb', line 63

def current_tab?(tab)
  @current_tab ||= tab if tab.any? {|item| current_url?(item.relative_url) }
  @current_tab == tab
end

#current_url?(options) ⇒ Boolean

Returns:

  • (Boolean)


68
69
70
71
72
73
74
75
76
# File 'app/helpers/application_helper.rb', line 68

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

#designer?Boolean

Returns:

  • (Boolean)


95
96
97
# File 'app/helpers/application_helper.rb', line 95

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

#filter_options_for_select(selected = nil) ⇒ Object



152
153
154
# File 'app/helpers/application_helper.rb', line 152

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



99
100
101
# File 'app/helpers/application_helper.rb', line 99

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

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



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

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

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



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

def image_submit(name, options = {})
  image_submit_tag(append_image_extension("admin/#{name}"), options)
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)


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

def meta_errors?
  false
end

#meta_visible(symbol) ⇒ Object



122
123
124
125
126
127
128
129
130
# File 'app/helpers/application_helper.rb', line 122

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


83
84
85
86
87
88
89
# File 'app/helpers/application_helper.rb', line 83

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


160
161
162
# File 'app/helpers/application_helper.rb', line 160

def nav_tabs
  admin.nav
end

#onsubmit_status(model) ⇒ Object



26
27
28
# File 'app/helpers/application_helper.rb', line 26

def onsubmit_status(model)
  model.new_record? ? "Creating #{model.class.name.downcase}&#8230;" : "Saving changes&#8230;"
end

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

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



44
45
46
47
48
49
50
51
52
# File 'app/helpers/application_helper.rb', line 44

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



38
39
40
# File 'app/helpers/application_helper.rb', line 38

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

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



30
31
32
33
34
35
36
# File 'app/helpers/application_helper.rb', line 30

def save_model_button(model, options = {})
  options[:label] ||= model.new_record? ?
    "Create #{model.class.name}" : "Save Changes"
  options[:class] ||= "button"
  options[:accesskey] ||= 'S'
  submit_tag options.delete(:label), options
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



118
119
120
# File 'app/helpers/application_helper.rb', line 118

def timestamp(time)
  time.strftime("%I:%M %p on %B %e, %Y").sub("AM", 'am').sub("PM", 'pm')
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



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

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

#updated_stamp(model) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'app/helpers/application_helper.rb', line 103

def updated_stamp(model)
  unless model.new_record?
    updated_by = (model.updated_by || model.created_by)
    name = updated_by ? updated_by.name : nil
    time = (model.updated_at || model.created_at)
    if name or time
      html = %{<p class="updated_line">Last updated } 
      html << %{by <strong>#{name}</strong> } if name
      html << %{at #{timestamp(time)}} if time
      html << %{</p>}
      html
    end
  end
end