blog_helper 0.0.8 → 0.0.9

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.
Files changed (4) hide show
  1. data/README.md +6 -19
  2. data/Rakefile +1 -1
  3. data/lib/blog_helper.rb +26 -1
  4. metadata +4 -4
data/README.md CHANGED
@@ -79,28 +79,14 @@ Create a page called `tagged.rhtml` in your `templates/pages` directory that loo
79
79
  <%#
80
80
  # search given tags...
81
81
  %>
82
-
83
82
  <%
84
- require 'cgi'
85
83
  require 'blog_helper'
86
-
87
- desired_tag = env["QUERY_STRING"]
88
- if desired_tag
89
- start = desired_tag.index("=")
90
- stop = desired_tag.index("&")
91
- stop = 0 unless stop
92
- desired_tag = desired_tag[start+1..stop-1]
93
- desired_tag = CGI::unescape(desired_tag)
94
- end
95
-
84
+ desired_tag = BlogHelper::desired_tag(env["QUERY_STRING"])
96
85
  %>
97
86
  <h1>Posts filed under '<%= desired_tag %>': </h1>
98
87
  <ul>
99
88
 
100
- <% @articles.select do |a|
101
- tags = BlogHelper::csv_to_array(a[:tags])
102
- tags.include?(desired_tag) if tags
103
- end.each do |article| %>
89
+ <% BlogHelper::desired_articles(@articles, desired_tag).each do |article| %>
104
90
  <li>
105
91
  <span class="descr"><a href="<%= article.path %>" alt="<%= article.title %>"><%= article.title %></a><br/></span>
106
92
  </li>
@@ -110,11 +96,12 @@ Create a page called `tagged.rhtml` in your `templates/pages` directory that loo
110
96
 
111
97
  Now, you did most likely implement a tag listing on your toto blog. Congrats!
112
98
 
113
- BTW: part of my to dos is encapsulating the tag parsing process so you won't have to fiddle around with too much ruby code here...
114
99
 
115
- ### shor url (via bit.ly)
100
+ ### short url (via bit.ly)
101
+
102
+ To use a bit.ly shortened URL, just call the followin function inside a .rhtml file:
116
103
 
117
- short_url = BlogHelper::short_url_bitly(<url>, <bit.ly login nam>, <bit.ly api key>)
104
+ <%= BlogHelper::short_url_bitly(<url>, <bit.ly login name>, <bit.ly api key>) %>
118
105
 
119
106
 
120
107
  ### disqus comment counter
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.8'
15
+ s.version = '0.0.9'
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
@@ -58,9 +58,34 @@ module BlogHelper
58
58
  def BlogHelper.short_url_bitly(url, login, api_key)
59
59
  if api_key != "" && login != ""
60
60
  rest_call=%{http://api.bit.ly/v3/shorten?login=#{login}&apikey=#{api_key}&longUrl=#{url}&format=txt}
61
- Net::HTTP::get(URI.parse(rest_call))
61
+ Net::HTTP::get(URI.parse(rest_call)) # handle http errors (esp. timeouts!)
62
62
  else
63
63
  url #fallback: return url to shorten - or nil if it isn't set
64
64
  end
65
65
  end
66
+ #desired articles matching a corresponding tag
67
+ def BlogHelper.desired_articles(articles, tag)
68
+ if(articles && tag)
69
+ articles.select do |a|
70
+ tags = BlogHelper::csv_to_array(a[:tags])
71
+ tags.include?(tag) if tags
72
+ end
73
+ end
74
+ end
75
+ # extract desired tag from <code>env["QUERY_STRING"]</code> or an equally formed expression, e.g. tag=desired_tag
76
+ def BlogHelper.desired_tag(query_string)
77
+ if query_string
78
+ start = query_string.index("tag=")
79
+ if start
80
+ start = start + 3
81
+ stop = query_string.index("&")
82
+ stop = 0 unless stop
83
+ desired_tag = query_string[start+1..stop-1]
84
+ desired_tag = CGI::unescape(desired_tag)
85
+ else
86
+ '' #fallback: return empty string to prevent nil errors
87
+ end
88
+ end
89
+ end
90
+
66
91
  end
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: 15
4
+ hash: 13
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 8
10
- version: 0.0.8
9
+ - 9
10
+ version: 0.0.9
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-16 00:00:00 +02:00
18
+ date: 2010-07-20 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies: []
21
21