Permalink
Browse files

introduced rvm and moved to 1.9.2

  • Loading branch information...
1 parent aa46b16 commit 37e5c30f7fc49f0072c9bbf89c58919d1ae00d63 @5v3n committed Oct 20, 2010
Showing with 59 additions and 55 deletions.
  1. +1 −0 .rvmrc
  2. +2 −2 LICENSE
  3. +7 −7 Rakefile
  4. +10 −10 lib/{blog_helper.rb → karakuri.rb}
  5. +2 −2 lib/serious_blog_helper.rb
  6. +37 −34 test/{blog_helper_test.rb → karakuri_test.rb}
View
1 .rvmrc
@@ -0,0 +1 @@
+rvm 1.9.1@karakuri
View
4 LICENSE
@@ -1,6 +1,6 @@
-== BlogHelper
+== Karakuri
-Copyright (c) 2010 Sven Kräuter sven.kraeuter@gmx.net
+Copyright (c) 2010 Sven Kraeuter mail@5v3n.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
View
14 Rakefile
@@ -11,15 +11,15 @@ require 'rake/rdoctask'
require 'rake/testtask'
spec = Gem::Specification.new do |s|
- s.name = 'blog_helper'
- s.version = '0.0.10'
+ s.name = 'karakuri'
+ s.version = '0.1.0'
s.has_rdoc = true
s.extra_rdoc_files = ['README.md', 'LICENSE']
- s.summary = 'Some handy helpers for serious, toto and the likes...'
+ s.summary = 'Some handy helpers for toto and the likes...'
s.description = s.summary
- s.author = 'Sven Kräuter'
- s.email = 'sven.krauter@gmx.net'
- s.homepage = 'http://github.com/5v3n/blog_helper'
+ s.author = 'Sven Kraeuter'
+ s.email = 'mail@5v3n.com'
+ s.homepage = 'http://github.com/5v3n/karakuri'
# s.executables = ['your_executable_here']
s.files = %w(LICENSE README.md Rakefile) + Dir.glob("{bin,lib,spec}/**/*")
s.require_path = "lib"
@@ -36,7 +36,7 @@ Rake::RDocTask.new do |rdoc|
files =['README.md', 'LICENSE', 'lib/**/*.rb']
rdoc.rdoc_files.add(files)
rdoc.main = "README" # page to start on
- rdoc.title = "BlogHelper Docs"
+ rdoc.title = "Karakuri Docs"
rdoc.rdoc_dir = 'doc/rdoc' # rdoc output folder
rdoc.options << '--line-numbers'
end
View
20 lib/blog_helper.rb → lib/karakuri.rb
@@ -3,13 +3,13 @@
require 'uri'
#
-# Some useful feature for serious, toto and the likes. Basically, any ruby based blog or site.
+# Some useful feature for toto and the likes. Basically, any ruby based blog or site.
#
-module BlogHelper
+module Karakuri
#
# create a list of links to tagged articles, default link_format: <code>%&amp;&lt;a href=&quot;/tagged?tag=#{tag}&quot; alt=&quot;articles concerning #{tag}&quot; &gt;#{tag}&lt;/a&gt; &amp;</code>
#
- def BlogHelper.tag_link_list(csv_string)
+ def Karakuri.tag_link_list(csv_string)
# read csv-string into array
tag_list = csv_to_array(csv_string)
if tag_list
@@ -22,15 +22,15 @@ def BlogHelper.tag_link_list(csv_string)
#
# processes a csv-string into an array
#
- def BlogHelper.csv_to_array(csv_string)
+ def Karakuri.csv_to_array(csv_string)
#split & handle forgotten spaces after the separator. then flatten the multidemnsional array:
csv_string.split(', ').map{ |e| e.split(',')}.flatten if csv_string
end
#
# pass the path (@path for a toto blog) & the desired SEO ending, e.g. the name of your blog.
# example for toto: <code>seo_friendly_title(@path, title, "mysite.com") will produce 'subpage | mysite.com' as seo friendly page title.</code>
#
- def BlogHelper.seo_friendly_title(path, title, seo_ending)
+ def Karakuri.seo_friendly_title(path, title, seo_ending)
#TODO use custom title separator...
if path == 'index'
page_title = seo_ending
@@ -49,7 +49,7 @@ def BlogHelper.seo_friendly_title(path, title, seo_ending)
#
#(see http://disqus.com/comments/universal/ for details)
#
- def BlogHelper.disqus_comment_count_js(disqus_shortname)
+ def Karakuri.disqus_comment_count_js(disqus_shortname)
%&
<script type="text/javascript">
var disqus_shortname = '#{disqus_shortname}';
@@ -65,7 +65,7 @@ def BlogHelper.disqus_comment_count_js(disqus_shortname)
#
# Retrieve bit.ly shortened url
#
- def BlogHelper.short_url_bitly(url, login, api_key)
+ def Karakuri.short_url_bitly(url, login, api_key)
if api_key != "" && login != ""
rest_call=%{http://api.bit.ly/v3/shorten?login=#{login}&apikey=#{api_key}&longUrl=#{url}&format=txt}
begin
@@ -80,16 +80,16 @@ def BlogHelper.short_url_bitly(url, login, api_key)
end
end
#desired articles matching a corresponding tag
- def BlogHelper.desired_articles(articles, tag)
+ def Karakuri.desired_articles(articles, tag)
if(articles && tag)
articles.select do |a|
- tags = BlogHelper::csv_to_array(a[:tags])
+ tags = Karakuri::csv_to_array(a[:tags])
tags.include?(tag) if tags
end
end
end
# extract desired tag from <code>env["QUERY_STRING"]</code> or an equally formed expression, e.g. tag=desired_tag
- def BlogHelper.desired_tag(query_string)
+ def Karakuri.desired_tag(query_string)
if query_string
start = query_string.index("tag=")
if start
View
4 lib/serious_blog_helper.rb
@@ -1,5 +1,5 @@
-# extension to BlogHelper with special methods for serious
-require 'blog_helper'
+# extension to Karakuri with special methods for serious
+require 'karakuri'
module SeriousBlogHelper
#extract tags from article
def SeriousBlogHelper.tags_from_article(article=nil)
View
71 test/blog_helper_test.rb → test/karakuri_test.rb
@@ -4,7 +4,7 @@
$:.unshift File.join(File.dirname(__FILE__),'..','lib')
require 'test/unit'
-require 'blog_helper'
+require 'karakuri'
class BlogHelperTest < Test::Unit::TestCase
#TODO DRY! use methods for the repetitive parts of the test!
@@ -23,58 +23,61 @@ class BlogHelperTest < Test::Unit::TestCase
GIVEN_QUERY_01 = "tag=rock%20%27n%27%20roll"
def test_process_to_array
- result_nil = BlogHelper::csv_to_array(nil)
- assert("nil should return nil!", result_nil == nil)
- result_00 = BlogHelper::csv_to_array(STRING_00)
- assert("Unexpected result for #{STRING_00}!", result_00 == [])
- result_01 = BlogHelper::csv_to_array(STRING_01)
- assert("Unexpected result for #{STRING_01}!", result_01 == ["tag_1"])
- result_02 = BlogHelper::csv_to_array(STRING_02)
- assert("Unexpected result for #{STRING_02}!", result_02 == Array["tag_1", "tag_2"])
- result_03 = BlogHelper::csv_to_array(STRING_03)
- assert("Unexpected result for #{STRING_03}!", result_03 == Array["tag_1", "tag_2", "tag_3"])
- result_04 = BlogHelper::csv_to_array(STRING_04)
- assert("Unexpected result for #{STRING_04}!", result_04 == Array["hacks", "love", "rock 'n' roll"])
+ result_nil = Karakuri::csv_to_array(nil)
+ assert(result_nil == nil, "nil should return nil!")
+ result_00 = Karakuri::csv_to_array(STRING_00)
+ assert(result_00 == [], "Unexpected result for #{STRING_00}!")
+ result_01 = Karakuri::csv_to_array(STRING_01)
+ assert(result_01 == ["tag_1"], "Unexpected result for #{STRING_01}!")
+ result_02 = Karakuri::csv_to_array(STRING_02)
+ assert(result_02 == Array["tag_1", "tag_2"], "Unexpected result for #{STRING_02}!")
+ result_03 = Karakuri::csv_to_array(STRING_03)
+ assert(result_03 == Array["tag_1", "tag_2", "tag_3"], "Unexpected result for #{STRING_03}!")
+ result_04 = Karakuri::csv_to_array(STRING_04)
+ assert(result_04 == Array["hacks", "love", "rock 'n' roll"], "Unexpected result for #{STRING_04}!")
end
def test_tag_link_list
- result_nil = BlogHelper::tag_link_list(nil)
+ result_nil = Karakuri::tag_link_list(nil)
assert("Unexpected mapping for nil!", result_nil == nil)
- result_00 = BlogHelper::tag_link_list(STRING_00)
+ result_00 = Karakuri::tag_link_list(STRING_00)
assert("Unexpected mapping for #{STRING_00}!", result_00 == "")
- result_01 = BlogHelper::tag_link_list(STRING_01)
+ result_01 = Karakuri::tag_link_list(STRING_01)
assert("Unexpected mapping for #{STRING_01}!", result_01 == "<a href=/tagged?tag=tag_1 >tag_1</a> ")
- result_02 = BlogHelper::tag_link_list(STRING_02)
- assert("Unexpected mapping for #{STRING_02}!", result_02 == "<a href=/tagged?tag=tag_1 >tag_1</a> <a href=/tagged?tag=tag_2 >tag_2</a> ")
- result_03 = BlogHelper::tag_link_list(STRING_03)
- assert("Unexpected mapping for #{STRING_03}!", result_03 == "<a href=/tagged?tag=tag_1 >tag_1</a> <a href=/tagged?tag=tag_2 >tag_2</a> <a href=/tagged?tag=tag_3 >tag_3</a> ")
- result_04 = BlogHelper::tag_link_list(STRING_04)
- assert("Unexpected mapping for #{STRING_04}!", result_04 == "<a href=/tagged?tag=hacks >hacks</a> <a href=/tagged?tag=love >love</a> <a href=/tagged?tag=rock 'n' roll >rock 'n' roll</a> ")
+ result_02 = Karakuri::tag_link_list(STRING_02)
+ expected_result_02 = %{<a href="/tagged?tag=tag_1" alt="articles concerning tag_1" >tag_1</a> <a href="/tagged?tag=tag_2" alt="articles concerning tag_2" >tag_2</a> }
+ assert(result_02 == expected_result_02, "Unexpected mapping for #{STRING_02}!")
+ result_03 = Karakuri::tag_link_list(STRING_03)
+ expected_result_03 = %{<a href="/tagged?tag=tag_1" alt="articles concerning tag_1" >tag_1</a> <a href="/tagged?tag=tag_2" alt="articles concerning tag_2" >tag_2</a> <a href="/tagged?tag=tag_3" alt="articles concerning tag_3" >tag_3</a> }
+ assert(result_03 == expected_result_03, "Unexpected mapping for #{STRING_03}!")
+ result_04 = Karakuri::tag_link_list(STRING_04)
+ expected_result_04 = %{<a href="/tagged?tag=hacks" alt="articles concerning hacks" >hacks</a> <a href="/tagged?tag=love" alt="articles concerning love" >love</a> <a href="/tagged?tag=rock 'n' roll" alt="articles concerning rock 'n' roll" >rock 'n' roll</a> }
+ assert(result_04 == expected_result_04, "Unexpected mapping for #{STRING_04}!")
end
def test_short_url_bitly
- short_url = BlogHelper::short_url_bitly(TEST_URL, "", "")
+ short_url = Karakuri::short_url_bitly(TEST_URL, "", "")
assert(short_url == TEST_URL, "generated short url: '#{short_url}', but should be '#{TEST_URL}' since no login and/or api key are given.")
aok = false
begin
- short_url = BlogHelper::short_url_bitly("invalid url", BITLY_LOGIN, BITLY_API_KEY)
+ short_url = Karakuri::short_url_bitly("invalid url", BITLY_LOGIN, BITLY_API_KEY)
rescue URI::InvalidURIError
aok = true
ensure # make sure the result is checked & the remaining tests are executed
assert(aok, "Invalid url should have resulted in an InvalidURIError!")
- short_url = BlogHelper::short_url_bitly(TEST_URL, BITLY_LOGIN, BITLY_API_KEY)
+ short_url = Karakuri::short_url_bitly(TEST_URL, BITLY_LOGIN, BITLY_API_KEY)
assert(short_url != 'RATE_LIMIT_EXCEEDED', "Use your own login & api key if the demo account's rate limit is reached...")
assert(short_url == EXPECTED_SHORT_URL, "generated short url: '#{short_url}', but should be '#{EXPECTED_SHORT_URL}'")
end
end
def test_desired_tag
- result = BlogHelper::desired_tag(GIVEN_QUERY_01)
+ result = Karakuri::desired_tag(GIVEN_QUERY_01)
assert(result == EXPECTED_TAG_01, "Wrong tag extracted! Expected '#{EXPECTED_TAG_01}', but was '#{result}'")
- result = BlogHelper::desired_tag("tag=")
+ result = Karakuri::desired_tag("tag=")
assert(result == '', "Result expected to be empty, but was #{result}")
- result = BlogHelper::desired_tag("tag")
+ result = Karakuri::desired_tag("tag")
assert(result == '', "Result expected to be empty, but was #{result}")
- result = BlogHelper::desired_tag("")
+ result = Karakuri::desired_tag("")
assert(result == '', "Result expected to be empty, but was #{result}")
- result = BlogHelper::desired_tag(nil)
+ result = Karakuri::desired_tag(nil)
assert(result == nil, "Result expected to be nil, but was #{result}")
end
def test_desired_articles
@@ -93,17 +96,17 @@ def test_desired_articles
articles = Array.new()
articles << article_01_mock << article_02_mock << article_03_mock
- result = BlogHelper::desired_articles(articles, "love")
+ result = Karakuri::desired_articles(articles, "love")
assert(result != nil && result[0] != nil && result[0] == article_01_mock && result[1] != nil && result[1] == article_03_mock,
"Result expected to be first & second article, but was #{result.inspect}")
- result = BlogHelper::desired_articles(articles, "hacks")
+ result = Karakuri::desired_articles(articles, "hacks")
assert(result != nil && result.first != nil && result.first == article_01_mock, "Result expected to be first article, but was #{result.inspect}")
- result = BlogHelper::desired_articles(articles, nil)
+ result = Karakuri::desired_articles(articles, nil)
assert(result == nil, "Result expected to be nil, but was #{result}")
- result = BlogHelper::desired_articles(nil, nil)
+ result = Karakuri::desired_articles(nil, nil)
assert(result == nil, "Result expected to be nil, but was #{result}")
end

0 comments on commit 37e5c30

Please sign in to comment.