postview 0.7.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.
Files changed (71) hide show
  1. data/HISTORY +67 -0
  2. data/INFO +14 -0
  3. data/LICENSE +0 -0
  4. data/README.rdoc +103 -0
  5. data/Rakefile +174 -0
  6. data/VERSION +8 -0
  7. data/bin/postview +51 -0
  8. data/lib/postview.rb +68 -0
  9. data/lib/postview/about.rb +34 -0
  10. data/lib/postview/application.rb +130 -0
  11. data/lib/postview/cli.rb +71 -0
  12. data/lib/postview/cli/create_command.rb +362 -0
  13. data/lib/postview/cli/server_command.rb +115 -0
  14. data/lib/postview/helpers.rb +21 -0
  15. data/lib/postview/patches.rb +11 -0
  16. data/lib/postview/settings.rb +107 -0
  17. data/lib/postview/site.rb +51 -0
  18. data/lib/postview/version.rb +27 -0
  19. data/tasks/documentation.rake +21 -0
  20. data/tasks/history.rake +7 -0
  21. data/tasks/homepage.rake +10 -0
  22. data/tasks/package.rake +11 -0
  23. data/tasks/version.rake +56 -0
  24. data/test/application_test.rb +122 -0
  25. data/test/extensions.rb +23 -0
  26. data/test/fixtures/application/config.ru +6 -0
  27. data/test/fixtures/application/config/settings.yml +22 -0
  28. data/test/fixtures/application/empty.yml +0 -0
  29. data/test/fixtures/application/posts/20090529-postview_blogware.ruby.sinatra.mkd +4 -0
  30. data/test/fixtures/application/posts/20090602-postview_blogware.ruby.sinatra.mkd +4 -0
  31. data/test/fixtures/application/posts/archive/20080529-postview_blogware.ruby.sinatra.mkd +4 -0
  32. data/test/fixtures/application/posts/archive/20080602-postview_blogware.ruby.sinatra.mkd +4 -0
  33. data/test/fixtures/application/posts/drafts/20090730-draft_postview_blogware.ruby.sinatra.mkd +4 -0
  34. data/test/fixtures/application/themes/gemstone/about.erb +0 -0
  35. data/test/fixtures/application/themes/gemstone/archive/index.erb +0 -0
  36. data/test/fixtures/application/themes/gemstone/archive/show.erb +17 -0
  37. data/test/fixtures/application/themes/gemstone/images/banners/banner.jpg +0 -0
  38. data/test/fixtures/application/themes/gemstone/images/favicon.ico +0 -0
  39. data/test/fixtures/application/themes/gemstone/images/trojan.com +0 -0
  40. data/test/fixtures/application/themes/gemstone/index.erb +0 -0
  41. data/test/fixtures/application/themes/gemstone/javascripts/gemstone.js +1 -0
  42. data/test/fixtures/application/themes/gemstone/layout.erb +0 -0
  43. data/test/fixtures/application/themes/gemstone/posts/index.erb +0 -0
  44. data/test/fixtures/application/themes/gemstone/posts/show.erb +0 -0
  45. data/test/fixtures/application/themes/gemstone/search.erb +0 -0
  46. data/test/fixtures/application/themes/gemstone/stylesheets/gemstone.css +1 -0
  47. data/test/fixtures/application/themes/gemstone/tags/index.erb +0 -0
  48. data/test/fixtures/application/themes/gemstone/tags/show.erb +0 -0
  49. data/test/helper.rb +9 -0
  50. data/test/settings_test.rb +72 -0
  51. data/test/site_test.rb +62 -0
  52. data/themes/default/about.erb +24 -0
  53. data/themes/default/archive/index.erb +21 -0
  54. data/themes/default/archive/show.erb +17 -0
  55. data/themes/default/error.erb +0 -0
  56. data/themes/default/images/favicon.ico +0 -0
  57. data/themes/default/images/logo.png +0 -0
  58. data/themes/default/images/navigation-bar.gif +0 -0
  59. data/themes/default/images/postview.png +0 -0
  60. data/themes/default/images/rack.png +0 -0
  61. data/themes/default/images/ruby.png +0 -0
  62. data/themes/default/images/sinatra.png +0 -0
  63. data/themes/default/index.erb +38 -0
  64. data/themes/default/layout.erb +117 -0
  65. data/themes/default/posts/index.erb +21 -0
  66. data/themes/default/posts/show.erb +17 -0
  67. data/themes/default/search.erb +40 -0
  68. data/themes/default/stylesheets/postview.css +238 -0
  69. data/themes/default/tags/index.erb +12 -0
  70. data/themes/default/tags/show.erb +40 -0
  71. metadata +158 -0
@@ -0,0 +1,122 @@
1
+ $LOAD_PATH.unshift("#{File.dirname(__FILE__)}/..")
2
+
3
+ require 'lib/postview'
4
+ require 'test/unit'
5
+ require 'rack/test'
6
+ require 'test/helper'
7
+
8
+ class TestApplication < Test::Unit::TestCase
9
+
10
+ include Rack::Test::Methods
11
+
12
+ def app
13
+ @app = Postview::Application
14
+
15
+ @app.set :root, "#{File.dirname(__FILE__)}/.."
16
+ @app.set :environment, :test
17
+ @app
18
+ end
19
+
20
+ def test_should_return_ok_for_theme_resources
21
+ get app.theme_path "/images/favicon.ico" do |response|
22
+ assert response.ok?
23
+ assert_equal "http://example.org/images/favicon.ico/", last_request.url
24
+ end
25
+
26
+ get app.theme_path "/javascripts/gemstone.js" do |response|
27
+ assert response.ok?
28
+ assert_equal "http://example.org/javascripts/gemstone.js/", last_request.url
29
+ end
30
+
31
+ get app.theme_path "/stylesheets/gemstone.css" do |response|
32
+ assert response.ok?
33
+ assert_equal "http://example.org/stylesheets/gemstone.css/", last_request.url
34
+ end
35
+
36
+ get app.theme_path "/images/banners/banner.jpg" do |response|
37
+ assert response.ok?
38
+ assert_equal "http://example.org/images/banners/banner.jpg/", last_request.url
39
+ end
40
+
41
+ # TOFIX: Fix test to check security.
42
+ get app.theme_path "/images/trojan.com" do |response|
43
+ #assert !response.ok?
44
+ end
45
+ end
46
+
47
+ def test_should_return_ok_in_root_path
48
+ get app.root_path do |response|
49
+ assert response.ok?
50
+ end
51
+ end
52
+
53
+ def test_should_return_ok_in_posts_path
54
+ get app.posts_path do |response|
55
+ assert response.ok?
56
+ end
57
+ end
58
+
59
+ def test_should_return_ok_in_posts_path_with_params
60
+ get app.posts_path "/2009/06/02/postview_blogware" do |response|
61
+ assert response.ok?
62
+ assert_equal "http://example.org/posts/2009/06/02/postview_blogware/", last_request.url
63
+ end
64
+ end
65
+
66
+ def test_should_return_ok_in_tags_path
67
+ get app.tags_path do |response|
68
+ assert response.ok?
69
+ assert_equal "http://example.org/tags/", last_request.url
70
+ end
71
+ end
72
+
73
+ def test_should_return_ok_in_tags_path_with_params
74
+ get app.tags_path "ruby" do |response|
75
+ assert response.ok?
76
+ assert_equal "http://example.org/tags/ruby/", last_request.url
77
+ end
78
+ end
79
+
80
+ def test_should_return_ok_in_archive_path
81
+ get app.archive_path do |response|
82
+ assert response.ok?
83
+ end
84
+ end
85
+
86
+ def test_should_return_ok_in_archive_path_with_params
87
+ get app.archive_path "2008/06/02/postview_blogware" do |response|
88
+ assert response.ok?
89
+ assert_equal "http://example.org/archive/2008/06/02/postview_blogware/", last_request.url
90
+ end
91
+ end
92
+
93
+ def test_should_return_ok_in_drafts_path
94
+ get app.drafts_path do |response|
95
+ assert response.ok?
96
+ assert_equal "http://example.org/drafts/", last_request.url
97
+ end
98
+ end
99
+
100
+ def test_should_return_ok_in_drafts_path_with_params
101
+ get app.drafts_path "2009/07/30/draft_postview_blogware" do |response|
102
+ assert response.ok?
103
+ assert_equal "http://example.org/drafts/2009/07/30/draft_postview_blogware/", last_request.url
104
+ end
105
+ end
106
+
107
+ def test_should_return_ok_in_about_path
108
+ get app.about_path do |response|
109
+ assert response.ok?
110
+ end
111
+ end
112
+
113
+ def test_should_return_ok_in_search_path
114
+ get app.search_path, :anythink => "postview" do |response|
115
+ assert response.ok?
116
+ assert_equal "postview", last_request.params.values.to_s
117
+ assert_equal "http://example.org/search/?anythink=postview", last_request.url
118
+ end
119
+ end
120
+
121
+ end
122
+
@@ -0,0 +1,23 @@
1
+ # This code extracted from book "Ruby Best Practices" and the code be found
2
+ # in http://github.com/sandal/rbp/blob/master/testing/test_unit_extensions.rb
3
+ module Test::Unit
4
+ # Used to fix a minor minitest/unit incompatibility in flexmock
5
+ AssertionFailedError = Class.new(StandardError)
6
+
7
+ class TestCase
8
+
9
+ def self.must(name, &block)
10
+ test_name = "test_#{name.gsub(/\s+/,'_')}".to_sym
11
+ defined = instance_method(test_name) rescue false
12
+ raise "#{test_name} is already defined in #{self}" if defined
13
+ if block_given?
14
+ define_method(test_name, &block)
15
+ else
16
+ define_method(test_name) do
17
+ flunk "No implementation provided for #{name}"
18
+ end
19
+ end
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,6 @@
1
+ require 'rubygems'
2
+ require 'postview'
3
+ log = File.open("tmp/postview.log", "a+")
4
+ $stdout.reopen(log)
5
+ $stderr.reopen(log)
6
+ run Postview::Application
@@ -0,0 +1,22 @@
1
+ ---
2
+ :site:
3
+ :author: Jack Ducklet
4
+ :domain: jackd.example.com
5
+ :directory: path/to/site
6
+ :email: jack.ducklet@example.com
7
+ :title: Postview
8
+ :theme: default
9
+ :subtitle: Post your articles
10
+ :theme: gemstone
11
+ :directories:
12
+ :posts: posts
13
+ :archive: posts/archive
14
+ :drafts: posts/drafts
15
+ :sections:
16
+ :about: about
17
+ :posts: posts
18
+ :root: /
19
+ :archive: archive
20
+ :search: search
21
+ :tags: tags
22
+ :drafts: drafts
File without changes
@@ -0,0 +1,4 @@
1
+ Postview - Blogware
2
+ ===================
3
+
4
+ Fixture
@@ -0,0 +1,4 @@
1
+ Postview - Blogware
2
+ ===================
3
+
4
+ Fixture
@@ -0,0 +1,4 @@
1
+ Postview - Blogware
2
+ ===================
3
+
4
+ Fixture
@@ -0,0 +1,4 @@
1
+ Postview - Blogware
2
+ ===================
3
+
4
+ Fixture
@@ -0,0 +1,4 @@
1
+ Draft - Postview - Blogware
2
+ ===========================
3
+
4
+ Fixture
@@ -0,0 +1,17 @@
1
+ <div class="entry">
2
+
3
+ <h1><%= link_to post.title, posts_path, post %></h1>
4
+
5
+ <span class="entry-meta">
6
+ Published at <%= post.publish_date.strftime('%A, %B %d, %Y') %>,
7
+ tagged with <%= post.tags.map{ |tag| link_to tag.capitalize, tags_path, tag, :title => tag.capitalize }.join(', ') %>.
8
+ </span>
9
+
10
+ <div class="text">
11
+
12
+ <%= post.content %>
13
+
14
+ </div><!--text-->
15
+
16
+ </div><!--entry-->
17
+
@@ -0,0 +1 @@
1
+ gemstone='gemstone'
data/test/helper.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'ruby-debug'
2
+
3
+ module Postview
4
+ PATH = Pathname.new("test/fixtures/application").expand_path
5
+ class Settings
6
+ FILE = PATH.join("config/settings.yml").expand_path
7
+ end
8
+ end
9
+
@@ -0,0 +1,72 @@
1
+ $LOAD_PATH.unshift("#{File.dirname(__FILE__)}/..")
2
+
3
+ require 'lib/postview'
4
+ require 'test/unit'
5
+ require 'test/helper'
6
+
7
+ class SettingsTest < Test::Unit::TestCase
8
+
9
+ def setup
10
+ @attributes = {
11
+ :site => {
12
+ :title => "Postview",
13
+ :subtitle => "Post your articles",
14
+ :author => "Jack Ducklet",
15
+ :email => "jack.ducklet@example.com",
16
+ :domain => "jackd.example.com",
17
+ :directory => "path/to/site",
18
+ :theme => "gemstone"
19
+ },
20
+ :directories => {
21
+ :posts => "posts",
22
+ :archive => "posts/archive",
23
+ :drafts => "posts/drafts"
24
+ },
25
+ :sections => {
26
+ :root => "/",
27
+ :posts => "posts",
28
+ :tags => "tags",
29
+ :archive => "archive",
30
+ :drafts => "drafts",
31
+ :search => "search",
32
+ :about => "about"
33
+ }
34
+ }
35
+ @settings = Postview::Settings.load
36
+ end
37
+
38
+ def test_should_check_settings
39
+ @attributes.each do |method, values|
40
+ values.collect do |key, value|
41
+ assert_equal value, @settings.send(method)[key]
42
+ end
43
+ end
44
+ end
45
+
46
+ def test_should_build_site
47
+ assert_not_nil @settings.build_site
48
+ assert_not_nil @settings.build_site.find
49
+ assert_not_nil @settings.build_site.find_archived
50
+ assert_not_nil @settings.build_site.find_drafted
51
+ end
52
+
53
+ def test_should_rescue_exception_and_load_defaults
54
+ settings = Postview::Settings.load_file("file/not/found.yml")
55
+ @attributes.each do |method, values|
56
+ values.collect do |key, value|
57
+ assert_equal value, @settings.send(method)[key]
58
+ end
59
+ end
60
+ end
61
+
62
+ def test_should_rescue_exception_for_empty_file_and_load_defaults
63
+ settings = Postview::Settings.load_file("#{Postview::ROOT}/test/fixtures/empty.yml")
64
+ @attributes.each do |method, values|
65
+ values.collect do |key, value|
66
+ assert_not_nil settings.send(method)[key]
67
+ end
68
+ end
69
+ end
70
+
71
+ end
72
+
data/test/site_test.rb ADDED
@@ -0,0 +1,62 @@
1
+ $LOAD_PATH.unshift("#{File.dirname(__FILE__)}/..")
2
+
3
+ require 'lib/postview'
4
+ require 'test/unit'
5
+ require 'test/helper'
6
+ require 'test/extensions'
7
+
8
+ class TestSite < Test::Unit::TestCase
9
+
10
+ def setup
11
+ @site = Postview::Settings.load.build_site
12
+ end
13
+
14
+ must "check all attributes" do
15
+ assert_equal 'Postview', @site.title
16
+ assert_equal 'Post your articles', @site.subtitle
17
+ assert_equal 'Jack Ducklet', @site.author
18
+ assert_equal 'jack.ducklet@example.com', @site.email
19
+ assert_equal 'jackd.example.com', @site.domain
20
+ assert_equal 'path/to/site', @site.directory
21
+ assert_equal 'gemstone', @site.theme
22
+ end
23
+
24
+ must "find all posts" do
25
+ posts = @site.find.all_posts
26
+ assert_not_nil posts
27
+ assert_equal 2, posts.size
28
+ posts.collect do |post|
29
+ assert_match %r{\d{4}\d{4}-(\.*)\.*}, post.file.to_s
30
+ end
31
+ end
32
+
33
+ must "find all tags" do
34
+ tags = @site.find.all_tags
35
+ assert_not_nil tags
36
+ assert_equal 2, tags.size
37
+ end
38
+
39
+ must "find all archived posts" do
40
+ assert 2, @site.find_archived.all_posts.size
41
+ @site.find_archived.all_posts.collect do |post|
42
+ assert_match %r{\d{4}\d{4}-(\.*)\.*}, post.file.to_s
43
+ end
44
+ end
45
+
46
+ must "find all drafts" do
47
+ assert 1, @site.find_drafted.all_posts.size
48
+ @site.find_drafted.all_posts.collect do |draft|
49
+ assert_match %r{\d{4}\d{4}-(\.*)\.*}, draft.file.to_s
50
+ end
51
+ end
52
+
53
+ must "find one post" do
54
+ assert_not_nil @site.find.post(*%w(2009 06 02 postview))
55
+ end
56
+
57
+ must "search posts" do
58
+ assert 2, @site.find.posts('postview').size
59
+ end
60
+
61
+ end
62
+
@@ -0,0 +1,24 @@
1
+ <div class="entry">
2
+
3
+ <h1><%= link_to title_path(:about, site.title), :about %></h1>
4
+
5
+ <div class="text">
6
+
7
+ <%=Postview::About.to_html%>
8
+
9
+ <p>
10
+ <%=Postview.name%> uses the following libraries/projects:
11
+ </p>
12
+
13
+ <ul>
14
+ <li><%=link_to "#{Rack.name} v#{Rack::version}", "http://rack.rubyforge.org/"%></li>
15
+ <li><%=link_to "#{Sinatra.name} v#{Sinatra::VERSION}", "http://www.sinatrarb.com/"%></li>
16
+ <li><%=link_to "#{Sinatra::Mapping.name}", "http://sinatra-mapping.rubyforge.org/"%></li>
17
+ <li><%=link_to "#{Maruku.name} v#{Maruku::VERSION}", "http://maruku.rubyforge.org/"%></li>
18
+ <li><%=link_to "#{Postage::Version}", "http://postage.rubyforge.org/"%></li>
19
+ </ul>
20
+
21
+ </div><!--text-->
22
+
23
+ </div><!--entry-->
24
+
@@ -0,0 +1,21 @@
1
+ <div class="entry">
2
+
3
+ <h1><%=title_path :archive%></h1>
4
+
5
+ <div class="text">
6
+
7
+ <dl>
8
+ <% for post in posts %>
9
+ <dt>
10
+ <b><%=link_to "#{post.publish_date} - #{post.title}", archive_path, post, :title => post.title%></b>
11
+ (<%= post.tags.map{ |tag| link_to tag.capitalize, tags_path, tag, :title => tag.capitalize }.join(', ') %>)
12
+ </dt>
13
+
14
+ <dd>
15
+ <%=post.summary%>
16
+ </dd>
17
+ <% end %>
18
+ </dl>
19
+ </div><!--text-->
20
+ </div><!--entry-->
21
+