Module: Calagator::ApplicationHelper

Includes:
TimeRangeHelper
Defined in:
app/helpers/calagator/application_helper.rb

Constant Summary collapse

FLASH_TYPES =
[:success, :failure]

Instance Method Summary collapse

Methods included from TimeRangeHelper

#normalize_time

Instance Method Details

#cache_if(condition, name = {}, &block) ⇒ Object

Caches block in view only if the condition is true. skionrails.wordpress.com/2008/05/22/conditional-fragment-caching/



58
59
60
61
62
63
64
# File 'app/helpers/calagator/application_helper.rb', line 58

def cache_if(condition, name={}, &block)
  if condition
    cache(name, &block)
  else
    block.call
  end
end

#datestamp(item) ⇒ Object

returns html markup with source (if any), imported/created time, and - if modified - modified time



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

def datestamp(item)
  source = if item.source.nil?
    "added directly to #{Calagator.title}"
  else
    "imported from #{link_to truncate(item.source.name, length: 40), url_for(item.source)}"
  end
  created = " <br /><strong>#{normalize_time(item.created_at, format: :html)}</strong>"
  updated = if item.updated_at > item.created_at
    " and last updated <br /><strong>#{normalize_time(item.updated_at, format: :html)}</strong>"
  end
  raw "This item was #{source}#{created}#{updated}."
end

#datetime_format(time, format) ⇒ Object



32
33
34
35
# File 'app/helpers/calagator/application_helper.rb', line 32

def datetime_format(time,format)
  format = format.gsub(/(%[dHImU])/,'*\1')
  time.strftime(format).gsub(/\*0*/,'').html_safe
end

#format_description(string) ⇒ Object

Returns HTML string of an event or venue description for display in a view.



8
9
10
# File 'app/helpers/calagator/application_helper.rb', line 8

def format_description(string)
  sanitize(auto_link(upgrade_br(markdown(string))))
end

#markdown(text) ⇒ Object



12
13
14
# File 'app/helpers/calagator/application_helper.rb', line 12

def markdown(text)
  BlueCloth.new(text, :relaxed => true).to_html
end

#render_flashObject



23
24
25
26
27
28
29
30
# File 'app/helpers/calagator/application_helper.rb', line 23

def render_flash
  FLASH_TYPES.map{|type|
    next unless flash[type].present?
    (:div, :class => "flash #{type} flash_#{type}") do
      "#{type == :failure ? 'ERROR: ' : ''}#{flash[type]}".html_safe
    end
  }.compact.join.html_safe
end

#source_code_versionObject

Return a string describing the source code version being used



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

def source_code_version
  Calagator::VERSION
end


66
67
68
69
70
# File 'app/helpers/calagator/application_helper.rb', line 66

def subnav_class_for(controller_name, action_name)
  css_class = "#{controller.controller_name}_#{controller.action_name}_subnav"
  css_class += " active" if [controller.controller_name, controller.action_name] == [controller_name, action_name]
  css_class
end

#upgrade_br(content) ⇒ Object

Return a HTML string with the BR tags converted to XHTML compliant markup.



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

def upgrade_br(content)
  content.gsub('<br>','<br />')
end