Browse Source

Truncate post body in results

master
Dylan Baker 2 months ago
parent
commit
7db28d294b
4 changed files with 13 additions and 1 deletions
  1. 2
    0
      Gemfile
  2. 5
    0
      Gemfile.lock
  3. 5
    0
      web/server.rb
  4. 1
    1
      web/views/results.erb

+ 2
- 0
Gemfile View File

@@ -13,3 +13,5 @@ gem 'rspec', '~> 3.9'
13 13
 gem 'sassc', '~> 2.2'
14 14
 gem 'sequel', '~> 5.30'
15 15
 gem 'sinatra', '~> 2.0'
16
+
17
+gem "truncato", "~> 0.7.11"

+ 5
- 0
Gemfile.lock View File

@@ -4,6 +4,7 @@ GEM
4 4
     diff-lcs (1.3)
5 5
     dotenv (2.7.5)
6 6
     ffi (1.12.2)
7
+    htmlentities (4.3.4)
7 8
     httparty (0.18.0)
8 9
       mime-types (~> 3.0)
9 10
       multi_xml (>= 0.5.2)
@@ -44,6 +45,9 @@ GEM
44 45
       rack-protection (= 2.0.8.1)
45 46
       tilt (~> 2.0)
46 47
     tilt (2.0.10)
48
+    truncato (0.7.11)
49
+      htmlentities (~> 4.3.1)
50
+      nokogiri (>= 1.7.0, <= 2.0)
47 51
 
48 52
 PLATFORMS
49 53
   ruby
@@ -59,6 +63,7 @@ DEPENDENCIES
59 63
   sassc (~> 2.2)
60 64
   sequel (~> 5.30)
61 65
   sinatra (~> 2.0)
66
+  truncato (~> 0.7.11)
62 67
 
63 68
 BUNDLED WITH
64 69
    2.1.4

+ 5
- 0
web/server.rb View File

@@ -1,6 +1,7 @@
1 1
 require 'dotenv/load'
2 2
 require 'sequel'
3 3
 require 'sinatra'
4
+require 'truncato'
4 5
 
5 6
 require_relative '../db/connect'
6 7
 require_relative '../lib/auth'
@@ -122,6 +123,10 @@ class VLVSearch < Sinatra::Base
122 123
     def external_link(url, text)
123 124
       "<a href=\"#{url}\" target=\"_blank\">#{text}</a>"
124 125
     end
126
+
127
+    def truncate(s)
128
+      Truncato.truncate(s, max_length: 500)
129
+    end
125 130
   end
126 131
 
127 132
   run! if __FILE__ == $0

+ 1
- 1
web/views/results.erb View File

@@ -41,7 +41,7 @@
41 41
               <%= result[:creator] %> posted this at <%= result[:created_at] %>
42 42
             </p>
43 43
             <p class="result__body">
44
-              <%= result[:body] %>
44
+              <%= truncate(result[:body]) %>
45 45
             </p>
46 46
           <% end %>
47 47
         </div>

Loading…
Cancel
Save