Class: Rack::UsersAndHashtags
- Inherits:
-
Object
- Object
- Rack::UsersAndHashtags
- Includes:
- Utils
- Defined in:
- lib/rack/users-and-hashtags.rb,
lib/rack/users-and-hashtags/version.rb
Constant Summary collapse
- VERSION =
"0.0.5"
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options) ⇒ UsersAndHashtags
constructor
A new instance of UsersAndHashtags.
Constructor Details
#initialize(app, options) ⇒ UsersAndHashtags
Returns a new instance of UsersAndHashtags.
7 8 9 10 |
# File 'lib/rack/users-and-hashtags.rb', line 7 def initialize(app, ) @app = app @options = end |
Instance Method Details
#call(env) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rack/users-and-hashtags.rb', line 12 def call(env) status, headers, body = @app.call(env) if body.class == ActionDispatch::Response headers = HeaderHash.new(headers) nbody = "" body.each do |b| doc = Nokogiri::HTML(b.to_s) doc.css(@options[:matcher]).each do |d| d.inner_html = d.inner_html.gsub(/(\W)@([\w-]+)?/, '\1<a href="' + "#{@options[:user_url]}" + '\2">@\2</a>') d.inner_html = d.inner_html.gsub(/(\W)#([\w-]+)?/, '\1<a href="' + "#{@options[:hashtag_url]}" + '\2">#\2</a>') end nbody = doc.to_s end body = [nbody] headers['Content-Length'] &&= bytesize(nbody).to_s end [status, headers, body] end |