diaspora/lib/diaspora/markdownify/email.rb
Jonne Haß ac147cc9f4 Refactor config/ directory
* Get rid of early pathname requirement
* Use require_relative where approciate
* Drop unused files
* Imported new application.rb, environment.rb and environments/* from fresh Rails app
* Cleaned up boot.rb
* Load config in boot.rb
* Deduplicate environments/integration*.rb
* Move username blacklist into defaults.yml
* Ruby 1.9 Hash syntax everywhere
* Reorganize lib/diaspora/markdownify to match conventions
* Get rid of full path requires where possible
* Add dummy content to production section diaspora.yml.example to prevent warning
* Drop sqlite? method
* Move postgres? method into ConfigurationMethods
* Drop token authentication from User
2013-05-19 18:54:54 +02:00

27 lines
764 B
Ruby

module Diaspora
module Markdownify
class Email < Redcarpet::Render::HTML
include Rails.application.routes.url_helpers
TAG_REGEX = /(?:^|\s)#([#{ActsAsTaggableOn::Tag.tag_text_regexp}]+)/u
def preprocess(text)
process_tags(text)
end
private
def tags(text)
text.scan(TAG_REGEX).map { |match| match[0] }
end
def process_tags(text)
return text unless text.match(TAG_REGEX)
tags(text).each do |tag|
text.gsub!(/##{tag}/) do |tag|
opts = {:name => ActsAsTaggableOn::Tag.normalize(tag)}.merge(Rails.application.config.action_mailer.default_url_options)
"[#{tag}](#{tag_url(opts)})"
end
end
text
end
end
end
end