Class: PublifyApp::Textfilter::Twitterfilter
- Inherits:
-
TextFilterPlugin::PostProcess
- Object
- TextFilterPlugin
- TextFilterPlugin::PostProcess
- PublifyApp::Textfilter::Twitterfilter
- Defined in:
- lib/publify_textfilter_twitterfilter.rb
Class Method Summary collapse
Methods inherited from TextFilterPlugin::PostProcess
Methods inherited from TextFilterPlugin
available_filter_types, available_filters, component_name, config_value, default_config, default_helper_module!, filter_map, filter_type, help_text, inherited, logger, macro_filters, reloadable?, sanitize, short_name
Methods included from PublifyPlugins
#plugin_description, #plugin_display_name, #plugin_public_action, #plugin_public_actions
Class Method Details
.filtertext(text) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/publify_textfilter_twitterfilter.rb', line 11 def self.filtertext(text) # First, autolink text = text.to_s URI.extract(text, %w(http https mailto gopher)) do |item| text = text.gsub(item, "<a href='#{item}'>#{item}</a>") end # hashtags text.split.grep(/^#\w+/) do |item| # strip_html because Ruby considers "#prouddad</p>" as a word item = item.strip_html search_item = URI.encode_www_form_component(item) uri = "https://twitter.com/search?q=#{search_item}&src=tren&mode=realtime" text = text.gsub(item, "<a href='#{uri}'>#{item}</a>") end # @mention text.to_s.split.grep(/@\w+/) do |item| item = item.strip_html uri = html_escape("https://twitter.com/#{item.delete("@")}") text = text.gsub(item, "<a href='#{uri}'>#{item}</a>") end text end |