pluto 0.8.10 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Manifest.txt +0 -1
- data/Rakefile +2 -2
- data/config/pluto.index.yml +4 -0
- data/lib/pluto.rb +0 -1
- data/lib/pluto/fetcher.rb +14 -4
- data/lib/pluto/formatter.rb +2 -1
- data/lib/pluto/models/feed.rb +17 -13
- data/lib/pluto/models/item.rb +4 -9
- data/lib/pluto/schema.rb +1 -0
- data/lib/pluto/version.rb +1 -1
- data/test/test_helpers.rb +1 -61
- metadata +22 -23
- data/lib/pluto/template_helpers.rb +0 -173
data/Manifest.txt
CHANGED
data/Rakefile
CHANGED
@@ -21,9 +21,9 @@ Hoe.spec 'pluto' do
|
|
21
21
|
['pakman', '>= 0.5'],
|
22
22
|
['fetcher', '>= 0.4.1'], # use min. 0.4.1 - added cache/conditional GET support
|
23
23
|
['logutils', '>= 0.6'],
|
24
|
-
['feedutils', '>= 0.
|
24
|
+
['feedutils', '>= 0.4.0'], # use min. 0.4.0 - added rss 2.0 - content:encoded; added fix for rss.item.guid missing; no more auto-summary in atom
|
25
25
|
['props', '>= 1.0.2'], # use min. 1.0.2 - added ini support
|
26
|
-
['textutils', '>= 0.
|
26
|
+
['textutils', '>= 0.7'], # use min. 0.7; moved hy/date helpers to gem; future: add some filters (for include/exclude)
|
27
27
|
['gli', '>= 2.5.6']
|
28
28
|
## ['activerecord', '~> 3.2'], # NB: soft dependency, will include activesupport,etc.
|
29
29
|
]
|
data/config/pluto.index.yml
CHANGED
@@ -12,6 +12,10 @@ top: https://raw.github.com/feedreader/pluto.top/master/top.txt
|
|
12
12
|
|
13
13
|
news: https://raw.github.com/feedreader/pluto.news/master/news.txt
|
14
14
|
|
15
|
+
feeds: https://raw.github.com/feedreader/pluto.feeds/master/feeds.txt
|
16
|
+
|
17
|
+
classic: https://raw.github.com/feedreader/pluto.classic/master/classic.txt
|
18
|
+
|
15
19
|
|
16
20
|
####
|
17
21
|
# all:
|
data/lib/pluto.rb
CHANGED
@@ -50,7 +50,6 @@ require 'pluto/refresher'
|
|
50
50
|
require 'pluto/subscriber'
|
51
51
|
require 'pluto/updater'
|
52
52
|
require 'pluto/lister'
|
53
|
-
require 'pluto/template_helpers'
|
54
53
|
require 'pluto/formatter'
|
55
54
|
|
56
55
|
require 'pluto/cli/opts' ## fix: make sure fetcher/updater etc. do not depend on cli/opts
|
data/lib/pluto/fetcher.rb
CHANGED
@@ -18,7 +18,8 @@ class Fetcher
|
|
18
18
|
|
19
19
|
## if debug?
|
20
20
|
puts "http status #{response.code} #{response.message}"
|
21
|
-
|
21
|
+
|
22
|
+
puts "http header - server: #{response.header['server']} - #{response.header['server'].class.name}"
|
22
23
|
puts "http header - etag: #{response.header['etag']} - #{response.header['etag'].class.name}"
|
23
24
|
puts "http header - last-modified: #{response.header['last-modified']} - #{response.header['last-modified'].class.name}"
|
24
25
|
## end
|
@@ -66,9 +67,6 @@ class Fetcher
|
|
66
67
|
|
67
68
|
puts "Before parsing feed >#{feed_key}<..."
|
68
69
|
|
69
|
-
### move to feedutils
|
70
|
-
### logger.debug "using stdlib RSS::VERSION #{RSS::VERSION}"
|
71
|
-
|
72
70
|
## fix/todo: check for feed.nil? -> error parsing!!!
|
73
71
|
# or throw exception
|
74
72
|
feed = FeedUtils::Parser.parse( feed_xml )
|
@@ -93,6 +91,15 @@ class Fetcher
|
|
93
91
|
'last-modified' => feed_rec.http_last_modified
|
94
92
|
}
|
95
93
|
|
94
|
+
### fix bug in fetcher - do NOT use request_uri use uri.to
|
95
|
+
## - add request_uri entry to (e.g. w/o host etc.)
|
96
|
+
## - remove code here once fixed in fetcher
|
97
|
+
@worker.cache[ URI.parse( feed_url ).request_uri ] = {
|
98
|
+
'etag' => feed_rec.http_etag,
|
99
|
+
'last-modified' => feed_rec.http_last_modified
|
100
|
+
}
|
101
|
+
|
102
|
+
|
96
103
|
response = @worker.get( feed_url )
|
97
104
|
@worker.use_cache = false # fix/todo: restore old use_cache setting instead of false
|
98
105
|
|
@@ -110,6 +117,7 @@ class Fetcher
|
|
110
117
|
|
111
118
|
feed_attribs = {
|
112
119
|
http_code: response.code.to_i,
|
120
|
+
http_server: response.header[ 'server' ],
|
113
121
|
http_etag: nil,
|
114
122
|
http_last_modified: nil,
|
115
123
|
body: nil,
|
@@ -155,6 +163,7 @@ class Fetcher
|
|
155
163
|
|
156
164
|
feed_attribs = {
|
157
165
|
http_code: response.code.to_i,
|
166
|
+
http_server: response.header[ 'server' ],
|
158
167
|
http_etag: response.header[ 'etag' ],
|
159
168
|
http_last_modified: response.header[ 'last-modified' ], ## note: last_modified header gets stored as plain text (not datetime)
|
160
169
|
body: feed_xml,
|
@@ -163,6 +172,7 @@ class Fetcher
|
|
163
172
|
}
|
164
173
|
|
165
174
|
## if debug?
|
175
|
+
puts "http header - server: #{response.header['server']} - #{response.header['server'].class.name}"
|
166
176
|
puts "http header - etag: #{response.header['etag']} - #{response.header['etag'].class.name}"
|
167
177
|
puts "http header - last-modified: #{response.header['last-modified']} - #{response.header['last-modified'].class.name}"
|
168
178
|
## end
|
data/lib/pluto/formatter.rb
CHANGED
@@ -7,7 +7,8 @@ class Formatter
|
|
7
7
|
include Models
|
8
8
|
include ManifestHelper
|
9
9
|
|
10
|
-
include
|
10
|
+
include TextUtils::DateHelper # e.g. lets us use time_ago_in_words
|
11
|
+
include TextUtils::HypertextHelper # e.g. lets us use link_to, strip_tags, sanitize, textify, etc.
|
11
12
|
|
12
13
|
def initialize( opts, config )
|
13
14
|
@opts = opts
|
data/lib/pluto/models/feed.rb
CHANGED
@@ -27,13 +27,6 @@ class Feed < ActiveRecord::Base
|
|
27
27
|
def link() url; end # alias for url
|
28
28
|
def feed() feed_url; end # alias for feed_url
|
29
29
|
|
30
|
-
def last_published_at() last_published; end # legay attrib reader - depreciated - remove!!
|
31
|
-
def fetched_at() fetched; end # legay attrib reader - depreciated - remove!!
|
32
|
-
def published_at() published; end # legay attrib reader - depreciated - remove!!
|
33
|
-
def touched_at() touched; end # legay attrib reader - depreciated - remove!!
|
34
|
-
def built_at() built; end # legay attrib reader - depreciated - remove!!
|
35
|
-
|
36
|
-
|
37
30
|
def url?() read_attribute(:url).present?; end
|
38
31
|
def title?() read_attribute(:title).present?; end
|
39
32
|
def title2?() read_attribute(:title2).present?; end
|
@@ -87,18 +80,29 @@ class Feed < ActiveRecord::Base
|
|
87
80
|
|
88
81
|
|
89
82
|
def update_from_struct!( data )
|
83
|
+
|
84
|
+
## todo: move to FeedUtils::Feed ??? why? why not??
|
85
|
+
if data.generator
|
86
|
+
generator_full = ''
|
87
|
+
generator_full << data.generator
|
88
|
+
generator_full << " @version=#{data.generator_version}" if data.generator_version
|
89
|
+
generator_full << " @uri=#{data.generator_uri}" if data.generator_uri
|
90
|
+
else
|
91
|
+
generator_full = nil
|
92
|
+
end
|
93
|
+
|
90
94
|
feed_attribs = {
|
91
95
|
format: data.format,
|
92
|
-
published: data.published
|
93
|
-
touched: data.updated
|
94
|
-
built: data.built
|
95
|
-
summary: data.summary
|
96
|
+
published: data.published,
|
97
|
+
touched: data.updated,
|
98
|
+
built: data.built,
|
99
|
+
summary: data.summary,
|
96
100
|
### todo/fix: add/use
|
97
101
|
# auto_title: ???,
|
98
102
|
# auto_url: ???,
|
99
103
|
# auto_feed_url: ???,
|
100
|
-
auto_title2: data.title2
|
101
|
-
generator:
|
104
|
+
auto_title2: data.title2,
|
105
|
+
generator: generator_full
|
102
106
|
}
|
103
107
|
|
104
108
|
if debug?
|
data/lib/pluto/models/item.rb
CHANGED
@@ -14,11 +14,6 @@ class Item < ActiveRecord::Base
|
|
14
14
|
def description() summary; end # alias for summary -- also add descr shortcut??
|
15
15
|
def link() url; end # alias for url
|
16
16
|
|
17
|
-
def fetched_at() fetched; end # legay attrib reader - depreciated - remove!!
|
18
|
-
def published_at() published; end # legay attrib reader - depreciated - remove!!
|
19
|
-
def touched_at() touched; end # legay attrib reader - depreciated - remove!!
|
20
|
-
|
21
|
-
|
22
17
|
def self.latest
|
23
18
|
# note: order by first non-null datetime field
|
24
19
|
# coalesce - supported by sqlite (yes), postgres (yes)
|
@@ -52,10 +47,10 @@ class Item < ActiveRecord::Base
|
|
52
47
|
guid: data.guid, # todo: only add for new records???
|
53
48
|
title: data.title,
|
54
49
|
url: data.url,
|
55
|
-
summary: data.summary
|
56
|
-
content: data.content
|
57
|
-
published: data.published
|
58
|
-
touched: data.updated
|
50
|
+
summary: data.summary,
|
51
|
+
content: data.content,
|
52
|
+
published: data.published,
|
53
|
+
touched: data.updated,
|
59
54
|
feed_id: feed_rec.id, # add feed_id fk_ref
|
60
55
|
fetched: feed_rec.fetched
|
61
56
|
}
|
data/lib/pluto/schema.rb
CHANGED
@@ -61,6 +61,7 @@ class CreateDb < ActiveRecord::Migration
|
|
61
61
|
t.string :http_etag # last http header etag
|
62
62
|
## note: save last-modified header as text (not datetime) - pass through as is
|
63
63
|
t.string :http_last_modified # last http header last-modified - note: save header as plain text!!! pass along in next request as-is
|
64
|
+
t.string :http_server # last http server header if present
|
64
65
|
|
65
66
|
t.string :md5 # md5 hash of body
|
66
67
|
t.text :body # last http response body (complete feed!)
|
data/lib/pluto/version.rb
CHANGED
data/test/test_helpers.rb
CHANGED
@@ -10,66 +10,6 @@ require 'helper'
|
|
10
10
|
|
11
11
|
class TestHelper < MiniTest::Unit::TestCase
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
def test_textify
|
16
|
-
hyin =<<EOS
|
17
|
-
<p><img style="float:left; margin-right:4px" src="http://photos1.meetupstatic.com/photos/event/7/c/b/2/event_244651922.jpeg" alt="photo" class="photo" />vienna.rb</p>
|
18
|
-
<p>
|
19
|
-
<p>The cool guys from <a href="http://platogo.com/">Platogo</a> will sponsor (y)our drinks. Which is awesome.</p>
|
20
|
-
<p><strong>Talks</strong>*</p>
|
21
|
-
<p>Jakob Sommerhuber - sponsor talk</p>
|
22
|
-
<p>Martin Schürrer - Erlang/OTP in production for highly-available, scalable systems</p>
|
23
|
-
<p>Markus Prinz - How to improve your code</p>
|
24
|
-
<p>Gerald Bauer - working with Sinatra</p>
|
25
|
-
<p>Kathrin Folkendt - 'Chapter one' (lightning talk on getting started with Rails, and building her first web app)</p>
|
26
|
-
<p><em>*preliminary program</em></p>
|
27
|
-
</p>
|
28
|
-
<p>Vienna - Austria</p>
|
29
|
-
<p>Friday, October 11 at 6:00 PM</p>
|
30
|
-
<p>Attending: 21</p>
|
31
|
-
<p>Details: http://www.meetup.com/vienna-rb/events/130346182/</p>
|
32
|
-
EOS
|
33
|
-
|
34
|
-
hystep1 = <<EOS
|
35
|
-
‹p›♦vienna.rb‹/p›
|
36
|
-
‹p›
|
37
|
-
‹p›The cool guys from Platogo will sponsor (y)our drinks. Which is awesome.‹/p›
|
38
|
-
‹p›Talks*‹/p›
|
39
|
-
‹p›Jakob Sommerhuber - sponsor talk‹/p›
|
40
|
-
‹p›Martin Schürrer - Erlang/OTP in production for highly-available, scalable systems‹/p›
|
41
|
-
‹p›Markus Prinz - How to improve your code‹/p›
|
42
|
-
‹p›Gerald Bauer - working with Sinatra‹/p›
|
43
|
-
‹p›Kathrin Folkendt - 'Chapter one' (lightning talk on getting started with Rails, and building her first web app)‹/p›
|
44
|
-
‹p›*preliminary program‹/p›
|
45
|
-
‹/p›
|
46
|
-
‹p›Vienna - Austria‹/p›
|
47
|
-
‹p›Friday, October 11 at 6:00 PM‹/p›
|
48
|
-
‹p›Attending: 21‹/p›
|
49
|
-
‹p›Details: www.meetup.com/vienna-rb/events/130346182/‹/p›
|
50
|
-
EOS
|
51
|
-
|
52
|
-
hyout = <<EOS
|
53
|
-
<p>♦vienna.rb</p>
|
54
|
-
<p>
|
55
|
-
<p>The cool guys from Platogo will sponsor (y)our drinks. Which is awesome.</p>
|
56
|
-
<p>Talks*</p>
|
57
|
-
<p>Jakob Sommerhuber - sponsor talk</p>
|
58
|
-
<p>Martin Schürrer - Erlang/OTP in production for highly-available, scalable systems</p>
|
59
|
-
<p>Markus Prinz - How to improve your code</p>
|
60
|
-
<p>Gerald Bauer - working with Sinatra</p>
|
61
|
-
<p>Kathrin Folkendt - 'Chapter one' (lightning talk on getting started with Rails, and building her first web app)</p>
|
62
|
-
<p>*preliminary program</p>
|
63
|
-
</p>
|
64
|
-
<p>Vienna - Austria</p>
|
65
|
-
<p>Friday, October 11 at 6:00 PM</p>
|
66
|
-
<p>Attending: 21</p>
|
67
|
-
<p>Details: www.meetup.com/vienna-rb/events/130346182/</p>
|
68
|
-
EOS
|
69
|
-
|
70
|
-
assert_equal( hyout, textify( hyin ) )
|
71
|
-
|
72
|
-
assert_equal( hystep1, textify( hyin, skip_restore: true ) )
|
73
|
-
end
|
13
|
+
## add some tests; to be done
|
74
14
|
|
75
15
|
end # class TestHelper
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pluto
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-10-
|
12
|
+
date: 2013-10-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: pakman
|
16
|
-
requirement: &
|
16
|
+
requirement: &85034260 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0.5'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *85034260
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: fetcher
|
27
|
-
requirement: &
|
27
|
+
requirement: &85034020 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 0.4.1
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *85034020
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: logutils
|
38
|
-
requirement: &
|
38
|
+
requirement: &85033740 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,21 +43,21 @@ dependencies:
|
|
43
43
|
version: '0.6'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *85033740
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: feedutils
|
49
|
-
requirement: &
|
49
|
+
requirement: &85033490 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.
|
54
|
+
version: 0.4.0
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *85033490
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: props
|
60
|
-
requirement: &
|
60
|
+
requirement: &85033170 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,21 +65,21 @@ dependencies:
|
|
65
65
|
version: 1.0.2
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *85033170
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: textutils
|
71
|
-
requirement: &
|
71
|
+
requirement: &85032890 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
75
75
|
- !ruby/object:Gem::Version
|
76
|
-
version: 0.
|
76
|
+
version: '0.7'
|
77
77
|
type: :runtime
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *85032890
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: gli
|
82
|
-
requirement: &
|
82
|
+
requirement: &85032620 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: 2.5.6
|
88
88
|
type: :runtime
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *85032620
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: rdoc
|
93
|
-
requirement: &
|
93
|
+
requirement: &85032330 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ~>
|
@@ -98,10 +98,10 @@ dependencies:
|
|
98
98
|
version: '3.10'
|
99
99
|
type: :development
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *85032330
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: hoe
|
104
|
-
requirement: &
|
104
|
+
requirement: &85032040 !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
107
|
- - ~>
|
@@ -109,7 +109,7 @@ dependencies:
|
|
109
109
|
version: '3.3'
|
110
110
|
type: :development
|
111
111
|
prerelease: false
|
112
|
-
version_requirements: *
|
112
|
+
version_requirements: *85032040
|
113
113
|
description: pluto - Another Planet Generator (Lets You Build Web Pages from Published
|
114
114
|
Web Feeds)
|
115
115
|
email: feedreader@googlegroups.com
|
@@ -144,7 +144,6 @@ files:
|
|
144
144
|
- lib/pluto/refresher.rb
|
145
145
|
- lib/pluto/schema.rb
|
146
146
|
- lib/pluto/subscriber.rb
|
147
|
-
- lib/pluto/template_helpers.rb
|
148
147
|
- lib/pluto/updater.rb
|
149
148
|
- lib/pluto/version.rb
|
150
149
|
- test/helper.rb
|
@@ -1,173 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
module Pluto
|
4
|
-
|
5
|
-
|
6
|
-
module TemplateHelper
|
7
|
-
|
8
|
-
def strip_tags( ht )
|
9
|
-
### tobe done
|
10
|
-
## strip markup tags; return plain text
|
11
|
-
ht.gsub( /<[^>]+>/, '' )
|
12
|
-
end
|
13
|
-
|
14
|
-
|
15
|
-
def whitelist( ht, tags, opts={} )
|
16
|
-
|
17
|
-
# note: assumes properly escaped <> in ht/hypertext
|
18
|
-
|
19
|
-
###############################################
|
20
|
-
# step one - save whitelisted tags use ‹tag›
|
21
|
-
tags.each do |tag|
|
22
|
-
# note: we strip all attribues
|
23
|
-
# note: match all tags case insensitive e.g. allow a,A or br,BR,bR etc.
|
24
|
-
# downcase all tags
|
25
|
-
|
26
|
-
# convert xml-style empty tags to simple html emtpty tags
|
27
|
-
# e.g. <br/> or <br /> becomses <br>
|
28
|
-
ht = ht.gsub( /<(#{tag})\s*\/>/i ) { |_| "‹#{$1.downcase}›" } # eg. <br /> or <br/> becomes ‹br›
|
29
|
-
|
30
|
-
# make sure we won't swall <br> for <b> for example, thus use \s+ before [^>]
|
31
|
-
ht = ht.gsub( /<(#{tag})(\s+[^>]*)?>/i ) { |_| "‹#{$1.downcase}›" } # opening tag <p>
|
32
|
-
ht = ht.gsub( /<\/(#{tag})\s*>/i ) { |_| "‹/#{$1.downcase}›" } # closing tag e.g. </p>
|
33
|
-
end
|
34
|
-
|
35
|
-
############################
|
36
|
-
# step two - clean tags
|
37
|
-
|
38
|
-
# strip images - special treatment for debugging
|
39
|
-
ht = ht.gsub( /<img[^>]*>/i, '♦' ) # for debugging use black diamond e.g. ♦
|
40
|
-
ht = ht.gsub( /<\/img>/i, '' ) # should not exists
|
41
|
-
|
42
|
-
# strip all remaining tags
|
43
|
-
ht = ht.gsub( /<[^>]+>/, '' )
|
44
|
-
|
45
|
-
pp ht # fix: debugging indo - remove
|
46
|
-
|
47
|
-
############################################
|
48
|
-
# step three - restore whitelisted tags
|
49
|
-
|
50
|
-
return ht if opts[:skip_restore].present? # skip step 3 for debugging
|
51
|
-
|
52
|
-
tags.each do |tag|
|
53
|
-
# ht = ht.gsub( /‹(#{tag})›/, "<\1>" ) # opening tag e.g. <p>
|
54
|
-
# ht = ht.gsub( /‹\/(#{tag})›/, "<\/\1>" ) # closing tag e.g. </p>
|
55
|
-
ht = ht.gsub( /‹(#{tag})›/ ) { |_| "<#{$1}>" }
|
56
|
-
ht = ht.gsub( /‹\/(#{tag})›/ ) { |_| "<\/#{$1}>" } # closing tag e.g. </p>
|
57
|
-
end
|
58
|
-
|
59
|
-
ht
|
60
|
-
end # method whitelist
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
## move into own helper module???
|
66
|
-
## - any helper already for easy reuse
|
67
|
-
##
|
68
|
-
# rails style asset tag helpers and friends
|
69
|
-
|
70
|
-
def stylesheet_link_tag( href )
|
71
|
-
href = "#{href}.css" unless href.ends_with?( '.css' ) # auto-add .css if not present
|
72
|
-
"<link rel='stylesheet' type='text/css' href='#{href}'>"
|
73
|
-
end
|
74
|
-
|
75
|
-
def image_tag( src, opts={} )
|
76
|
-
attributes = ""
|
77
|
-
opts.each do |key,value|
|
78
|
-
attributes << "#{key}='#{value}' "
|
79
|
-
end
|
80
|
-
"<img src='#{src}' #{attributes}>"
|
81
|
-
end
|
82
|
-
|
83
|
-
def link_to( text, href, opts={} )
|
84
|
-
attributes = ""
|
85
|
-
opts.each do |key,value|
|
86
|
-
attributes << "#{key}='#{value}' "
|
87
|
-
end
|
88
|
-
"<a href='#{href}' #{attributes}>#{text}</a>"
|
89
|
-
end
|
90
|
-
|
91
|
-
|
92
|
-
## change to simple_hypertext or
|
93
|
-
# hypertext_simple or
|
94
|
-
# sanitize ???
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
def textify( ht, opts={} ) # ht -> hypertext
|
99
|
-
## turn into text
|
100
|
-
# todo: add options for
|
101
|
-
# keep links, images, lists (?too), code, codeblocks
|
102
|
-
|
103
|
-
ht = whitelist( ht, [:br, :p, :ul, :ol, :li, :pre, :code, :blockquote, :q, :cite], opts )
|
104
|
-
|
105
|
-
# strip bold
|
106
|
-
# ht = ht.gsub( /<b[^>]*>/, '**' ) # fix: will also swallow bxxx tags - add b space
|
107
|
-
# ht = ht.gsub( /<\/b>/, '**' )
|
108
|
-
|
109
|
-
# strip em
|
110
|
-
# ht = ht.gsub( /<em[^>]*>/, '__' )
|
111
|
-
# ht = ht.gsub( /<\/em>/, '__' )
|
112
|
-
|
113
|
-
# clean (prettify) literal urls (strip protocoll)
|
114
|
-
ht = ht.gsub( /(http|https):\/\//, '' )
|
115
|
-
|
116
|
-
# ht = ht.gsub( / /, ' ' )
|
117
|
-
|
118
|
-
# # try to cleanup whitespaces
|
119
|
-
# # -- keep no more than two spaces
|
120
|
-
# ht = ht.gsub( /[ \t]{3,}/, ' ' )
|
121
|
-
# # -- keep no more than two new lines
|
122
|
-
# ht = ht.gsub( /\n{2,}/m, "\n\n" )
|
123
|
-
# # -- remove all trailing spaces
|
124
|
-
# ht = ht.gsub( /[ \t\n]+$/m, '' )
|
125
|
-
# # -- remove all leading spaces
|
126
|
-
# ht = ht.gsub( /^[ \t\n]+/m, '' )
|
127
|
-
|
128
|
-
ht
|
129
|
-
end
|
130
|
-
|
131
|
-
|
132
|
-
####
|
133
|
-
# fix: move to DateHelper ??
|
134
|
-
|
135
|
-
|
136
|
-
def time_ago_in_words( from_time )
|
137
|
-
from_time = from_time.to_time
|
138
|
-
to_time = Time.now
|
139
|
-
|
140
|
-
### todo: will not handle future dates??
|
141
|
-
## what todo do??
|
142
|
-
## use -1..-50000000000 ?? "future"
|
143
|
-
|
144
|
-
## from_time, to_time = to_time, from_time if from_time > to_time
|
145
|
-
|
146
|
-
distance_in_minutes = ((to_time - from_time)/60.0).round
|
147
|
-
|
148
|
-
case distance_in_minutes
|
149
|
-
when 0..1 then "just now"
|
150
|
-
when 2...45 then "%d minutes ago" % distance_in_minutes
|
151
|
-
when 45...90 then "an hour ago" ## use one instead of 1 ?? why? why not?
|
152
|
-
# 90 mins up to 24 hours
|
153
|
-
when 90...1440 then "%d hours ago" % (distance_in_minutes.to_f / 60.0).round
|
154
|
-
# 24 hours up to 42 hours
|
155
|
-
when 1440...2520 then "a day ago" ## use one day ago - why? why not?
|
156
|
-
# 42 hours up to 30 days
|
157
|
-
when 2520...43200 then "%d days ago" % (distance_in_minutes.to_f / 1440.0).round
|
158
|
-
# 30 days up to 60 days
|
159
|
-
# fix: use pluralize for months - fix: change when - use just for a month ago
|
160
|
-
when 43200...86400 then "%d months ago" % (distance_in_minutes.to_f / 43200.0).round
|
161
|
-
# 60 days up to 365 days
|
162
|
-
when 86400...525600 then "%d months ago" % (distance_in_minutes.to_f / 43200.0).round
|
163
|
-
## fix - add number of years ago
|
164
|
-
else "over a year ago" #todo: use over a year ago???
|
165
|
-
# fix: split into two - use
|
166
|
-
# 1) a year ago
|
167
|
-
# 2) (x) years ago
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
|
-
|
172
|
-
end # module TemplateHelper
|
173
|
-
end # module Pluto
|