blog_helper 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +16 -7
- data/Rakefile +1 -1
- data/lib/blog_helper.rb +19 -3
- data/lib/serious_blog_helper.rb +1 -0
- metadata +4 -4
data/README.md
CHANGED
@@ -33,14 +33,12 @@ For example, to use seo friendly titles, your layout.rhtml should be looking lik
|
|
33
33
|
<% require 'blog_helper'
|
34
34
|
page_title = BlogHelper::seo_friendly_title(@path, title, 'yourSitesTitle.com')
|
35
35
|
%>
|
36
|
-
.
|
37
|
-
.
|
38
|
-
.
|
39
36
|
<title><%= page_title %></title>
|
40
37
|
<link rel="alternate" type="application/atom+xml" title="<%= page_title %> - feed" href="/index.xml" />
|
41
38
|
.
|
42
39
|
.
|
43
40
|
.
|
41
|
+
|
44
42
|
### Tags
|
45
43
|
Adding the tagging feature requires the _toto_prerelease_ as mentioned above, since we need the http request to apply our little hack.
|
46
44
|
|
@@ -76,9 +74,7 @@ And again: piece of caked ;-). Now all we need to add is a page that displays ar
|
|
76
74
|
|
77
75
|
Create a page called `tagged.rhtml` in your `templates/pages` directory that looks like this:
|
78
76
|
|
79
|
-
|
80
|
-
# search given tags...
|
81
|
-
%>
|
77
|
+
|
82
78
|
<%
|
83
79
|
require 'blog_helper'
|
84
80
|
desired_tag = BlogHelper::desired_tag(env["QUERY_STRING"])
|
@@ -106,7 +102,20 @@ To use a bit.ly shortened URL, just call the followin function inside a .rhtml f
|
|
106
102
|
|
107
103
|
### disqus comment counter
|
108
104
|
|
109
|
-
|
105
|
+
Basically just adds the necessary java script to enable the disqus comment counter. For best performance, place it near the end of the page:
|
106
|
+
|
107
|
+
<%= BlogHelper::disqus_comment_count_js(@config[:disqus]) %>
|
108
|
+
</body>
|
109
|
+
|
110
|
+
</html>
|
111
|
+
|
112
|
+
Mind the usage of `@config[:disqus]`, this enables configuration via `config.ru`.
|
113
|
+
|
114
|
+
To access the comment count, use `#disqus_thread` at the end of the permalink to the post & it will be replaced with the disqus comment count:
|
115
|
+
|
116
|
+
<a href="<%= article.path %>#disqus_thread"> </a>
|
117
|
+
|
118
|
+
Will result in the number of comments of the article the permalink posts to.
|
110
119
|
|
111
120
|
### serious custom yaml field reader
|
112
121
|
|
data/Rakefile
CHANGED
@@ -12,7 +12,7 @@ require 'rake/testtask'
|
|
12
12
|
|
13
13
|
spec = Gem::Specification.new do |s|
|
14
14
|
s.name = 'blog_helper'
|
15
|
-
s.version = '0.0.
|
15
|
+
s.version = '0.0.10'
|
16
16
|
s.has_rdoc = true
|
17
17
|
s.extra_rdoc_files = ['README.md', 'LICENSE']
|
18
18
|
s.summary = 'Some handy helpers for serious, toto and the likes...'
|
data/lib/blog_helper.rb
CHANGED
@@ -2,10 +2,13 @@ require 'cgi'
|
|
2
2
|
require 'net/http'
|
3
3
|
require 'uri'
|
4
4
|
|
5
|
-
|
5
|
+
#
|
6
6
|
# Some useful feature for serious, toto and the likes. Basically, any ruby based blog or site.
|
7
|
+
#
|
7
8
|
module BlogHelper
|
9
|
+
#
|
8
10
|
# create a list of links to tagged articles, default link_format: <code>%&<a href="/tagged?tag=#{tag}" alt="articles concerning #{tag}" >#{tag}</a> &</code>
|
11
|
+
#
|
9
12
|
def BlogHelper.tag_link_list(csv_string)
|
10
13
|
# read csv-string into array
|
11
14
|
tag_list = csv_to_array(csv_string)
|
@@ -16,13 +19,17 @@ module BlogHelper
|
|
16
19
|
end
|
17
20
|
tag_string
|
18
21
|
end
|
22
|
+
#
|
19
23
|
# processes a csv-string into an array
|
24
|
+
#
|
20
25
|
def BlogHelper.csv_to_array(csv_string)
|
21
26
|
#split & handle forgotten spaces after the separator. then flatten the multidemnsional array:
|
22
27
|
csv_string.split(', ').map{ |e| e.split(',')}.flatten if csv_string
|
23
28
|
end
|
29
|
+
#
|
24
30
|
# pass the path (@path for a toto blog) & the desired SEO ending, e.g. the name of your blog.
|
25
31
|
# example for toto: <code>seo_friendly_title(@path, title, "mysite.com") will produce 'subpage | mysite.com' as seo friendly page title.</code>
|
32
|
+
#
|
26
33
|
def BlogHelper.seo_friendly_title(path, title, seo_ending)
|
27
34
|
#TODO use custom title separator...
|
28
35
|
if path == 'index'
|
@@ -34,6 +41,7 @@ module BlogHelper
|
|
34
41
|
end
|
35
42
|
page_title
|
36
43
|
end
|
44
|
+
#
|
37
45
|
#Generates javascript to include to the bottom of your index page.
|
38
46
|
#Appending '#disqus_thread' to the end of permalinks will replace the text of these links with the comment count.
|
39
47
|
#
|
@@ -54,13 +62,21 @@ module BlogHelper
|
|
54
62
|
|
55
63
|
& if disqus_shortname
|
56
64
|
end
|
65
|
+
#
|
57
66
|
# Retrieve bit.ly shortened url
|
67
|
+
#
|
58
68
|
def BlogHelper.short_url_bitly(url, login, api_key)
|
59
69
|
if api_key != "" && login != ""
|
60
70
|
rest_call=%{http://api.bit.ly/v3/shorten?login=#{login}&apikey=#{api_key}&longUrl=#{url}&format=txt}
|
61
|
-
|
71
|
+
begin
|
72
|
+
Net::HTTP::get(URI.parse(rest_call)) # handle http errors (esp. timeouts!)
|
73
|
+
rescue URI::InvalidURIError
|
74
|
+
raise URI::InvalidURIError
|
75
|
+
rescue
|
76
|
+
url#in the case of a web service or HTTP error, we'll just ignore it & return the long url
|
77
|
+
end
|
62
78
|
else
|
63
|
-
url #fallback: return url
|
79
|
+
url #fallback: return long url if no proper login has been provided. TODO: check if a call w/o login is possible
|
64
80
|
end
|
65
81
|
end
|
66
82
|
#desired articles matching a corresponding tag
|
data/lib/serious_blog_helper.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# extension to BlogHelper with special methods for serious
|
2
2
|
require 'blog_helper'
|
3
3
|
module SeriousBlogHelper
|
4
|
+
#extract tags from article
|
4
5
|
def SeriousBlogHelper.tags_from_article(article=nil)
|
5
6
|
tags_marker = %&tags"=>&
|
6
7
|
if article && article.inspect.index(tags_marker)
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blog_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 11
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 10
|
10
|
+
version: 0.0.10
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- "Sven Kr\xC3\xA4uter"
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-07-
|
18
|
+
date: 2010-07-21 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|