Module: HashtagsHelper

Defined in:
lib/generators/simple_hashtag/templates/views/hashtags_helper.rb

Instance Method Summary collapse

Instance Method Details

#linkify_hashtags(hashtaggable_content) ⇒ Object



2
3
4
5
6
7
8
# File 'lib/generators/simple_hashtag/templates/views/hashtags_helper.rb', line 2

def linkify_hashtags(hashtaggable_content)
  regex = SimpleHashtag::Hashtag::HASHTAG_REGEX
  hashtagged_content = hashtaggable_content.to_s.gsub(regex) do
    link_to($&, hashtag_path($2), {class: :hashtag})
  end
  hashtagged_content.html_safe
end

#render_hashtaggable(hashtaggable) ⇒ Object



10
11
12
13
14
15
# File 'lib/generators/simple_hashtag/templates/views/hashtags_helper.rb', line 10

def render_hashtaggable(hashtaggable)
  klass        = hashtaggable.class.to_s.underscore
  view_dirname = klass.pluralize
  partial      = klass
  render "#{view_dirname}/#{partial}", {klass.to_sym => hashtaggable}
end