Module: Loudmouth::Controllers::Helpers

Extended by:
ActiveSupport::Concern
Includes:
ActionView::Helpers::SanitizeHelper
Defined in:
lib/extensions/helper.rb

Instance Method Summary collapse

Instance Method Details

#break_big_words(text, *args) ⇒ Object



45
46
47
48
49
50
51
52
53
54
# File 'lib/extensions/helper.rb', line 45

def break_big_words(text, *args)
   options = args.extract_options!
   unless args.blank?
     options[:max_word_length] = args[0] || 75
   end
   options.reverse_merge!(:max_word_length => 75)
   text = text.split(" ").collect do |word|
     word.length > options[:max_word_length] ? word.gsub(/(.{1,#{options[:max_word_length]}})/, "\\1 ") : word
   end * " "
end

#has_comments?(topic) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
32
33
34
35
36
37
38
39
# File 'lib/extensions/helper.rb', line 29

def has_comments?(topic)
  unless Loudmouth.treasure_map.has_key?(topic.class.name.underscore.to_sym)
    raise "loudmouth not setup for #{topic.class.name.underscore.downcase.to_sym}"
  end
  if topic.comments
    if topic.comments.count > 0
      return true
    end
  end
  return false
end

#render_comment_form_for(topic, user) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/extensions/helper.rb', line 11

def render_comment_form_for(topic, user)
  unless Loudmouth.treasure_map.has_key?(topic.class.name.underscore.to_sym)
    raise "loudmouth not setup for #{topic.class.name.underscore.downcase.to_sym}"
  end

  render :partial => 'loudmouth/comments/comment_form',
          :locals => { :topic => topic, :user => user, :content => Loudmouth.new_comment_content }
end

#render_comments_for(topic) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/extensions/helper.rb', line 20

def render_comments_for(topic)
  unless Loudmouth.treasure_map.has_key?(topic.class.name.underscore.to_sym)
    raise "loudmouth not setup for #{topic.class.name.underscore.downcase.to_sym}"
  end
  
  render :partial => 'loudmouth/comments/comment', :collection => topic.comments, 
            :locals => { :topic => topic }
end

#topic_comment_path(topic) ⇒ Object



41
42
43
# File 'lib/extensions/helper.rb', line 41

def topic_comment_path(topic)
  send("#{topic.class.name.underscore}_comments_path", topic)
end