ruhoh 0.0.2 → 0.0.3

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 (87) hide show
  1. data/Gemfile +13 -0
  2. data/README.md +5 -53
  3. data/Rakefile +56 -0
  4. data/bin/ruhoh +23 -14
  5. data/lib/ruhoh/client/client.rb +310 -0
  6. data/lib/ruhoh/client/help.yml +56 -0
  7. data/lib/ruhoh/compiler.rb +16 -19
  8. data/lib/ruhoh/converters/converter.rb +30 -3
  9. data/lib/ruhoh/db.rb +7 -17
  10. data/lib/ruhoh/deployers/s3.rb +71 -0
  11. data/lib/ruhoh/friend.rb +71 -0
  12. data/lib/ruhoh/page.rb +41 -11
  13. data/lib/ruhoh/parsers/drafts.rb +54 -0
  14. data/lib/ruhoh/parsers/layouts.rb +14 -9
  15. data/lib/ruhoh/parsers/pages.rb +47 -35
  16. data/lib/ruhoh/parsers/partials.rb +14 -2
  17. data/lib/ruhoh/parsers/posts.rb +139 -88
  18. data/lib/ruhoh/parsers/routes.rb +4 -8
  19. data/lib/ruhoh/parsers/site.rb +2 -8
  20. data/lib/ruhoh/previewer.rb +48 -0
  21. data/lib/ruhoh/templaters/base.rb +53 -0
  22. data/lib/ruhoh/templaters/helpers.rb +159 -0
  23. data/lib/ruhoh/templaters/rmustache.rb +29 -0
  24. data/lib/ruhoh/utils.rb +25 -7
  25. data/lib/ruhoh/version.rb +1 -1
  26. data/lib/ruhoh/watch.rb +22 -9
  27. data/lib/ruhoh.rb +74 -29
  28. data/ruhoh.gemspec +70 -9
  29. data/scaffolds/blog/_config.yml +33 -0
  30. data/scaffolds/blog/_drafts/.gitkeep +0 -0
  31. data/scaffolds/blog/_posts/.gitkeep +0 -0
  32. data/scaffolds/blog/_site.yml +16 -0
  33. data/scaffolds/blog/_templates/partials/categories_list +3 -0
  34. data/scaffolds/blog/_templates/partials/pages_list +7 -0
  35. data/scaffolds/blog/_templates/partials/posts_collate +9 -0
  36. data/scaffolds/blog/_templates/partials/posts_list +1 -0
  37. data/scaffolds/blog/_templates/partials/tags_list +3 -0
  38. data/scaffolds/blog/_templates/syntax/google_prettify/default.css +52 -0
  39. data/scaffolds/blog/_templates/syntax/google_prettify/desert.css +34 -0
  40. data/scaffolds/blog/_templates/syntax/google_prettify/sons-of-obsidian.css +117 -0
  41. data/scaffolds/blog/_templates/syntax/google_prettify/sunburst.css +51 -0
  42. data/scaffolds/blog/_templates/syntax/google_prettify/twitter-bootstrap.css +30 -0
  43. data/scaffolds/blog/_templates/themes/twitter/bootstrap/css/bootstrap.min.css +689 -0
  44. data/scaffolds/blog/_templates/themes/twitter/bootstrap/img/glyphicons-halflings-white.png +0 -0
  45. data/scaffolds/blog/_templates/themes/twitter/bootstrap/img/glyphicons-halflings.png +0 -0
  46. data/scaffolds/blog/_templates/themes/twitter/css/style.css +68 -0
  47. data/scaffolds/blog/_templates/themes/twitter/layouts/default.html +64 -0
  48. data/scaffolds/blog/_templates/themes/twitter/layouts/page.html +13 -0
  49. data/scaffolds/blog/_templates/themes/twitter/layouts/post.html +55 -0
  50. data/scaffolds/blog/_templates/themes/twitter/manifest.yml +11 -0
  51. data/scaffolds/blog/about.md +5 -0
  52. data/scaffolds/blog/archive.html +11 -0
  53. data/scaffolds/blog/categories.html +21 -0
  54. data/scaffolds/blog/config.ru +9 -0
  55. data/scaffolds/blog/index.html +13 -0
  56. data/scaffolds/blog/pages.html +14 -0
  57. data/scaffolds/blog/tags.html +21 -0
  58. data/scaffolds/layout.html +3 -0
  59. data/scaffolds/page.html +6 -0
  60. data/scaffolds/post.html +8 -0
  61. data/scaffolds/theme/css/style.css +0 -0
  62. data/scaffolds/theme/images/.gitkeep +0 -0
  63. data/scaffolds/theme/layouts/default.html +17 -0
  64. data/scaffolds/theme/layouts/page.html +7 -0
  65. data/scaffolds/theme/layouts/post.html +8 -0
  66. data/scaffolds/theme/partials/.gitkeep +0 -0
  67. data/spec/db_spec.rb +88 -0
  68. data/spec/page_spec.rb +200 -0
  69. data/spec/parsers/layouts_spec.rb +32 -0
  70. data/spec/parsers/pages_spec.rb +97 -0
  71. data/spec/parsers/posts_spec.rb +301 -0
  72. data/spec/parsers/routes_spec.rb +45 -0
  73. data/spec/parsers/site_spec.rb +32 -0
  74. data/spec/setup_spec.rb +72 -0
  75. data/spec/spec_helper.rb +23 -0
  76. data/system_partials/analytics/getclicky +12 -0
  77. data/system_partials/analytics/google +11 -0
  78. data/system_partials/comments/disqus +13 -0
  79. data/system_partials/comments/facebook +9 -0
  80. data/system_partials/comments/intensedebate +6 -0
  81. data/system_partials/comments/livefyre +6 -0
  82. data/system_partials/syntax/google_prettify +11 -0
  83. metadata +84 -23
  84. data/lib/ruhoh/client.rb +0 -28
  85. data/lib/ruhoh/preview.rb +0 -36
  86. data/lib/ruhoh/templaters/helper_mustache.rb +0 -109
  87. data/lib/ruhoh/templaters/templater.rb +0 -39
@@ -0,0 +1,68 @@
1
+ /* Override some defaults */
2
+ html, body {
3
+ background-color: #eee;
4
+ }
5
+ .navbar {
6
+ margin-bottom: 0;
7
+ }
8
+ .navbar .container{
9
+ width:940px;
10
+ }
11
+ .container > footer {
12
+ margin-top: 20px;
13
+ }
14
+ .container > footer p {
15
+ text-align: center; /* center align it with the container */
16
+ }
17
+
18
+ /* The white background content wrapper */
19
+ .content {
20
+ background-color: #fff;
21
+ padding: 20px;
22
+ margin: 0 -20px; /* negative indent the amount of the padding to maintain the grid system */
23
+ -webkit-border-radius: 0 0 6px 6px;
24
+ -moz-border-radius: 0 0 6px 6px;
25
+ border-radius: 0 0 6px 6px;
26
+ -webkit-box-shadow: 0 1px 2px rgba(0,0,0,.15);
27
+ -moz-box-shadow: 0 1px 2px rgba(0,0,0,.15);
28
+ box-shadow: 0 1px 2px rgba(0,0,0,.15);
29
+ }
30
+
31
+ /* Page header tweaks */
32
+ .page-header {
33
+ background-color: #f5f5f5;
34
+ padding: 20px 20px 10px;
35
+ margin: -20px -20px 20px;
36
+ }
37
+
38
+ /* tag_box ======================================================== */
39
+
40
+ .tag_box {
41
+ list-style:none;
42
+ margin:0;
43
+ padding:5px 0 ;
44
+ overflow:hidden;
45
+ }
46
+ .tag_box li {
47
+ line-height:28px;
48
+ }
49
+ .tag_box.inline li {
50
+ float:left;
51
+ }
52
+ .tag_box a {
53
+ padding: 3px 6px;
54
+ margin: 2px;
55
+ background: #eee;
56
+ color:#005F6B;
57
+ border-radius: 3px;
58
+ text-decoration:none;
59
+ }
60
+ .tag_box a span{
61
+ vertical-align:super;
62
+ font-size:0.8em;
63
+ }
64
+ .tag_box a.active {
65
+ background:#57A957;
66
+ border:1px solid #4C964D;
67
+ color:#FFF;
68
+ }
@@ -0,0 +1,64 @@
1
+ ---
2
+ ---
3
+ <!DOCTYPE html>
4
+ <html lang="en">
5
+ <head>
6
+ <meta charset="utf-8">
7
+ <title>{{ page.title }}</title>
8
+ {{# page.description }}
9
+ <meta name="description" content="{{ . }}">
10
+ {{/ page.description }}
11
+ <meta name="author" content="{{ site.author.name }}">
12
+
13
+ <!-- Le HTML5 shim, for IE6-8 support of HTML elements -->
14
+ <!--[if lt IE 9]>
15
+ <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
16
+ <![endif]-->
17
+
18
+ <!-- Le styles -->
19
+ <link href="{{ THEME_PATH }}/bootstrap/css/bootstrap.min.css" rel="stylesheet">
20
+ <link href="{{ THEME_PATH }}/css/style.css?body=1" rel="stylesheet" type="text/css" media="all">
21
+
22
+ <!-- Le fav and touch icons -->
23
+ <!-- Update these with your own images
24
+ <link rel="shortcut icon" href="images/favicon.ico">
25
+ <link rel="apple-touch-icon" href="images/apple-touch-icon.png">
26
+ <link rel="apple-touch-icon" sizes="72x72" href="images/apple-touch-icon-72x72.png">
27
+ <link rel="apple-touch-icon" sizes="114x114" href="images/apple-touch-icon-114x114.png">
28
+ -->
29
+ </head>
30
+
31
+ <body>
32
+
33
+ <div class="navbar">
34
+ <div class="navbar-inner">
35
+ <div class="container">
36
+ <a class="brand" href="/">{{ site.title }}</a>
37
+ <ul class="nav">
38
+ {{# site.navigation?to_pages }}
39
+ {{> pages_list }}
40
+ {{/ site.navigation?to_pages }}
41
+ </ul>
42
+ </div>
43
+ </div>
44
+ </div>
45
+
46
+ <div class="container">
47
+
48
+ <div class="content">
49
+ {{ content }}
50
+ </div>
51
+
52
+ <footer>
53
+ <p>&copy; {{ site.author.name }} 2012
54
+ with help from <a href="http://ruhoh.com" target="_blank" title="The Definitive Technical Blogging Framework">ruhoh</a>
55
+ and <a href="http://twitter.github.com/bootstrap/" target="_blank">Twitter Bootstrap</a>
56
+ </p>
57
+ </footer>
58
+
59
+ </div> <!-- /container -->
60
+
61
+ {{{ syntax }}}
62
+ {{{ analytics }}}
63
+ </body>
64
+ </html>
@@ -0,0 +1,13 @@
1
+ ---
2
+ layout : default
3
+ ---
4
+
5
+ <div class="page-header">
6
+ <h1>{{ page.title }} {{# page.tagline }} <small>{{ . }}</small>{{/ page.tagline }}</h1>
7
+ </div>
8
+
9
+ <div class="row">
10
+ <div class="span12">
11
+ {{ content }}
12
+ </div>
13
+ </div>
@@ -0,0 +1,55 @@
1
+ ---
2
+ layout : default
3
+ ---
4
+ <div class="page-header">
5
+ <h1>{{ page.title }} {{# page.tagline }} <small>{{ . }}</small>{{/ page.tagline }}</h1>
6
+ </div>
7
+
8
+ <div class="row">
9
+ <div class="span8">
10
+ {{ content }}
11
+ <hr>
12
+ <div class="pagination">
13
+ <ul>
14
+ <ul>
15
+ {{# page?previous }}
16
+ <li class="prev"><a href="{{ url }}" title="{{ title }}">&larr; Previous</a></li>
17
+ {{/ page?previous }}
18
+ {{^ page?previous }}
19
+ <li class="prev disabled"><a>&larr; Previous</a></li>
20
+ {{/ page?previous }}
21
+
22
+ <li><a href="/archive.html">Archive</a></li>
23
+
24
+ {{# page?next }}
25
+ <li class="next"><a href="{{ url }}" title="{{ title }}">Next &rarr;</a></li>
26
+ {{/ page?next }}
27
+ {{^ page?next }}
28
+ <li class="next disabled"><a>Next &rarr;</a>
29
+ {{/ page?next }}
30
+ </ul>
31
+ </ul>
32
+ </div>
33
+ <hr>
34
+ {{{ comments }}}
35
+ </div>
36
+
37
+ <div class="span4">
38
+ <h4>Published</h4>
39
+ <div class="date"><span>{{ page.date }}</span></div>
40
+ <br>
41
+ <h4>Categories</h4>
42
+ <ul class="tag_box">
43
+ {{# page.categories?to_categories }}
44
+ {{> categories_list }}
45
+ {{/ page.categories?to_categories }}
46
+ </ul>
47
+ <br>
48
+ <h4>Tags</h4>
49
+ <ul class="tag_box">
50
+ {{# page.tags?to_tags }}
51
+ {{> tags_list }}
52
+ {{/ page.tags?to_tags }}
53
+ </ul>
54
+ </div>
55
+ </div>
@@ -0,0 +1,11 @@
1
+ ---
2
+ name : twitter
3
+ website : http://twitter.github.com/bootstrap
4
+ git_url : git://github.com/ruhoh/theme-twitter.git
5
+ source_url : https://github.com/ruhoh/theme-twitter
6
+ author:
7
+ name : "Jacob Thornton and Mark Otto"
8
+ website : http://twitter.github.com/bootstrap
9
+
10
+ ruhoh:
11
+ version: '0.0.x'
@@ -0,0 +1,5 @@
1
+ ---
2
+ layout : page
3
+ ---
4
+
5
+ ## About Me
@@ -0,0 +1,11 @@
1
+ ---
2
+ layout: page
3
+ title : Archive
4
+ header : Post Archive
5
+ tagline : "hello i am jade"
6
+ group: navigation
7
+ ---
8
+
9
+ {{# _posts.collated }}
10
+ {{> posts_collate }}
11
+ {{/ _posts.collated }}
@@ -0,0 +1,21 @@
1
+ ---
2
+ layout: page
3
+ title: Categories
4
+ header: Posts By Category
5
+ group: navigation
6
+ ---
7
+
8
+ <ul class="tag_box inline">
9
+ {{# ?to_categories }}
10
+ {{> categories_list }}
11
+ {{/ ?to_categories }}
12
+ </ul>
13
+
14
+ {{# ?to_categories }}
15
+ <h2>{{ name }} ({{ count }})</h2>
16
+ <ul>
17
+ {{# posts?to_posts }}
18
+ {{> posts_list }}
19
+ {{/ posts?to_posts }}
20
+ </ul>
21
+ {{/ ?to_categories }}
@@ -0,0 +1,9 @@
1
+ require 'rack'
2
+ require 'ruhoh'
3
+
4
+ Ruhoh.setup
5
+
6
+ use Rack::Lint
7
+ use Rack::ShowExceptions
8
+ use Rack::Static, {:urls => ["/#{Ruhoh.folders.media}", "/#{Ruhoh.folders.templates}"]}
9
+ run Ruhoh::Previewer.new
@@ -0,0 +1,13 @@
1
+ ---
2
+ title: Home
3
+ description:
4
+
5
+ layout : page
6
+ ---
7
+
8
+ <h3>Start</h3>
9
+ <p>
10
+ Ruhoh is all about the command-line.
11
+ <br>Check out the goods:
12
+ </p>
13
+ <pre><code>$ ruhoh help</code></pre>
@@ -0,0 +1,14 @@
1
+ ---
2
+ layout: page
3
+ title: Pages
4
+ header: Pages
5
+ group: navigation
6
+ ---
7
+
8
+ <h2>All Pages</h2>
9
+
10
+ <ul>
11
+ {{# ?to_pages }}
12
+ {{> pages_list }}
13
+ {{/ ?to_pages }}
14
+ </ul>
@@ -0,0 +1,21 @@
1
+ ---
2
+ layout: page
3
+ title: Tags
4
+ header: Posts By Tag
5
+ group: navigation
6
+ ---
7
+
8
+
9
+ <ul class="tag_box inline">
10
+ {{# ?to_tags }}
11
+ {{> tags_list }}
12
+ {{/ ?to_tags }}
13
+ </ul>
14
+
15
+
16
+ {{# ?to_tags }}
17
+ <h2 id="{{name}}-ref">{{name}}</h2>
18
+ {{# posts?to_posts }}
19
+ <li><a href="{{url}}">{{title}}</a></li>
20
+ {{/ posts?to_posts }}
21
+ {{/ ?to_tags }}
@@ -0,0 +1,3 @@
1
+ ---
2
+ layout: default
3
+ ---
@@ -0,0 +1,6 @@
1
+ ---
2
+ title:
3
+ description:
4
+
5
+ layout: page
6
+ ---
@@ -0,0 +1,8 @@
1
+ ---
2
+ title:
3
+ description:
4
+ categories:
5
+ tags: []
6
+
7
+ layout: post
8
+ ---
File without changes
File without changes
@@ -0,0 +1,17 @@
1
+ ---
2
+ ---
3
+ <!DOCTYPE html>
4
+ <html lang="en">
5
+ <head>
6
+ <meta charset="utf-8">
7
+ <link href="{{ THEME_PATH }}/css/style.css" rel="stylesheet" type="text/css" media="all">
8
+ </head>
9
+ <body>
10
+
11
+ <div class="content">
12
+ {{ content }}
13
+ </div>
14
+
15
+ {{{ analytics }}}
16
+ </body>
17
+ </html>
@@ -0,0 +1,7 @@
1
+ ---
2
+ layout : default
3
+ ---
4
+
5
+ <h1>{{ page.title }}</h1>
6
+
7
+ {{ content }}
@@ -0,0 +1,8 @@
1
+ ---
2
+ layout : default
3
+ ---
4
+
5
+ {{ content }}
6
+
7
+ {{{ comments }}}
8
+
File without changes
data/spec/db_spec.rb ADDED
@@ -0,0 +1,88 @@
1
+ require 'spec_helper'
2
+
3
+ module DB
4
+
5
+ describe Ruhoh::DB do
6
+ let(:whitelist){
7
+ [:site, :routes, :posts, :pages, :layouts, :partials]
8
+ }
9
+
10
+ before(:each) do
11
+ Ruhoh::Utils.stub(:parse_file_as_yaml).and_return({'theme' => "twitter"})
12
+ Ruhoh.setup(SampleSitePath)
13
+ end
14
+
15
+ context "database has not been updated" do
16
+ it "should return nil for all whitelisted variables" do
17
+ whitelist.each do |var|
18
+ result = Ruhoh::DB.__send__ var
19
+ result.should be_nil
20
+ end
21
+ end
22
+ end
23
+
24
+ describe "#update" do
25
+
26
+ it "should raise an exception when updating a variable not whitelisted" do
27
+ lambda { Ruhoh::DB.update(:table) }.should raise_error
28
+ end
29
+
30
+ it "should run the site parser when updating :site, then set the variable to the result" do
31
+ Ruhoh::Parsers::Site.should_receive(:generate).and_return({'test' => 'hi'})
32
+ Ruhoh::DB.update(:site)
33
+ Ruhoh::DB.site.should == {'test' => 'hi'}
34
+ end
35
+
36
+ it "should run the routes parser when updating :routes" do
37
+ Ruhoh::Parsers::Routes.should_receive(:generate).and_return({'test' => 'hi'})
38
+ Ruhoh::DB.update(:routes)
39
+ Ruhoh::DB.routes.should == {'test' => 'hi'}
40
+ end
41
+
42
+ it "should run the posts parser when updating :posts" do
43
+ Ruhoh::Parsers::Posts.should_receive(:generate).and_return({'test' => 'hi'})
44
+ Ruhoh::DB.update(:posts)
45
+ Ruhoh::DB.posts.should == {'test' => 'hi'}
46
+ end
47
+
48
+ it "should run the drafts parser when updating :drafts" do
49
+ Ruhoh::Parsers::Drafts.should_receive(:generate).and_return({'test' => 'hi'})
50
+ Ruhoh::DB.update(:drafts)
51
+ Ruhoh::DB.drafts.should == {'test' => 'hi'}
52
+ end
53
+
54
+ it "should run the pages parser when updating :pages" do
55
+ Ruhoh::Parsers::Pages.should_receive(:generate).and_return({'test' => 'hi'})
56
+ Ruhoh::DB.update(:pages)
57
+ Ruhoh::DB.pages.should == {'test' => 'hi'}
58
+ end
59
+
60
+ it "should run the layouts parser when updating :layouts" do
61
+ Ruhoh::Parsers::Layouts.should_receive(:generate).and_return({'test' => 'hi'})
62
+ Ruhoh::DB.update(:layouts)
63
+ Ruhoh::DB.layouts.should == {'test' => 'hi'}
64
+ end
65
+
66
+ it "should run the partials parser when updating :partials" do
67
+ Ruhoh::Parsers::Partials.should_receive(:generate).and_return({'test' => 'hi'})
68
+ Ruhoh::DB.update(:partials)
69
+ Ruhoh::DB.partials.should == {'test' => 'hi'}
70
+ end
71
+ end
72
+
73
+ describe "#update!" do
74
+ it "should call update for all WhiteListed variables." do
75
+ Ruhoh::DB.should_receive(:update).with(:site).ordered
76
+ Ruhoh::DB.should_receive(:update).with(:posts).ordered
77
+ Ruhoh::DB.should_receive(:update).with(:drafts).ordered
78
+ Ruhoh::DB.should_receive(:update).with(:pages).ordered
79
+ Ruhoh::DB.should_receive(:update).with(:routes).ordered
80
+ Ruhoh::DB.should_receive(:update).with(:layouts).ordered
81
+ Ruhoh::DB.should_receive(:update).with(:partials).ordered
82
+ Ruhoh::DB.update!
83
+ end
84
+ end
85
+
86
+ end
87
+
88
+ end
data/spec/page_spec.rb ADDED
@@ -0,0 +1,200 @@
1
+ require 'spec_helper'
2
+
3
+ module Page
4
+
5
+ describe Ruhoh::Page do
6
+
7
+ before(:each) do
8
+ Ruhoh::Utils.stub(:parse_file_as_yaml).and_return({'theme' => "twitter"})
9
+ Ruhoh.setup(SampleSitePath)
10
+ end
11
+
12
+ describe "Page initialization" do
13
+ it "should setup default templater and converter" do
14
+ page = Ruhoh::Page.new
15
+
16
+ page.templater.should == Ruhoh::Templaters::Base
17
+ page.converter.should == Ruhoh::Converter
18
+ end
19
+ end
20
+
21
+ describe "#change" do
22
+ let(:page){ Ruhoh::Page.new }
23
+ let(:posts) {
24
+ {
25
+ "dictionary" => {
26
+ "_posts/sample-id.md" => {"title" => "a cool title"}
27
+ }
28
+ }
29
+ }
30
+ let(:pages) {
31
+ {
32
+ "about/index.md" => {"title" => "about me =)"}
33
+ }
34
+ }
35
+
36
+ context "A page with invalid id" do
37
+ it "should raise error" do
38
+ lambda { page.change('some-id.md') }.should raise_error
39
+ end
40
+ end
41
+
42
+ context "A page with valid id" do
43
+ context "belonging to a post" do
44
+ before(:all) do
45
+ Ruhoh::Parsers::Posts.stub(:generate).and_return(posts)
46
+ Ruhoh::DB.update(:posts)
47
+ page.change("_posts/sample-id.md")
48
+ end
49
+ it "should query the posts dictionary and set @data to result" do
50
+ page.data.should == {"title" => "a cool title"}
51
+ end
52
+ it "should set @id to the valid id" do
53
+ page.id.should == "_posts/sample-id.md"
54
+ end
55
+ end
56
+
57
+ context "belonging to a page" do
58
+ before(:all) do
59
+ Ruhoh::Parsers::Pages.stub(:generate).and_return(pages)
60
+ Ruhoh::DB.update(:pages)
61
+ page.change("about/index.md")
62
+ end
63
+ it "should query the pages dictionary and set @data to result." do
64
+ page.data.should == {"title" => "about me =)"}
65
+ end
66
+ it "should set @id to the valid id" do
67
+ page.id.should == "about/index.md"
68
+ end
69
+ end
70
+
71
+ end
72
+
73
+ end
74
+
75
+ describe "#change_with_url" do
76
+ let(:page){ Ruhoh::Page.new }
77
+
78
+ context "An invalid URL" do
79
+ it "should raise error" do
80
+ lambda { page.change_with_url('/cool-url') }.should raise_error
81
+ end
82
+ end
83
+
84
+ context "A valid URL" do
85
+ let(:routes){
86
+ { "/super/cool/page-id.html" => "page-id.md" }
87
+ }
88
+ before(:all) do
89
+ Ruhoh::Parsers::Routes.stub(:generate).and_return(routes)
90
+ Ruhoh::DB.update(:routes)
91
+ end
92
+
93
+ it "should call self.change with the proper id from the routes hash" do
94
+ page.should_receive(:change).with("page-id.md")
95
+ page.change_with_url("/super/cool/page-id.html")
96
+ end
97
+ end
98
+ end
99
+
100
+ describe "#render" do
101
+ let(:page){ Ruhoh::Page.new }
102
+ it "should raise error if id not set" do
103
+ lambda{ page.render }.should raise_error
104
+ end
105
+
106
+ it "should process layouts, content, then render using the @templater" do
107
+ Ruhoh::DB.stub(:pages).and_return({"blah.md" => {}})
108
+ page.change('blah.md')
109
+
110
+ page.should_receive(:process_layouts)
111
+ page.should_receive(:process_content)
112
+ page.templater.should_receive(:render).with(page)
113
+ page.render
114
+ end
115
+ end
116
+
117
+ pending "#process_layouts"
118
+
119
+ describe "#process_content" do
120
+ let(:page){ Ruhoh::Page.new }
121
+
122
+ it "should raise error if id not set" do
123
+ lambda{ page.process_content }.should raise_error
124
+ end
125
+
126
+ context "Id has been set" do
127
+ # Set the id
128
+ before(:all) do
129
+ Ruhoh::DB.stub(:pages).and_return({"blah.md" => {}})
130
+ page.change('blah.md')
131
+ end
132
+
133
+ it "should raise an error if the page file is malformed" do
134
+ Ruhoh::Utils.should_receive(:parse_file).and_return({})
135
+ lambda { page.process_content }.should raise_error
136
+ end
137
+
138
+ it "should send the files content to the templater" do
139
+ Ruhoh::Utils.should_receive(:parse_file).and_return({"content" => "meep"})
140
+ page.templater.should_receive(:parse).with("meep", page)
141
+ page.converter.stub(:convert)
142
+ page.process_content
143
+ end
144
+
145
+ it "should send the page to the converter, then set the result as @content" do
146
+ Ruhoh::Utils.should_receive(:parse_file).and_return({"content" => "meep"})
147
+ page.templater.stub(:parse)
148
+ page.converter.should_receive(:convert).with(page).and_return("yay")
149
+ page.process_content
150
+ page.content.should == "yay"
151
+ end
152
+ end
153
+ end
154
+
155
+ describe "#attributes" do
156
+ let(:page){ Ruhoh::Page.new }
157
+
158
+ it "should raise error if id not set" do
159
+ lambda{ page.attributes }.should raise_error
160
+ end
161
+
162
+ it "should be a hash with content value set" do
163
+ Ruhoh::DB.stub(:pages).and_return({"blah.md" => {}})
164
+ page.change('blah.md')
165
+
166
+ page.attributes.should be_a_kind_of Hash
167
+ page.attributes.should have_key("content")
168
+ end
169
+
170
+ end
171
+
172
+ describe "#compiled_path" do
173
+ let(:page){ Ruhoh::Page.new }
174
+
175
+ it "should raise error if id not set" do
176
+ lambda{ page.compiled_path }.should raise_error
177
+ end
178
+
179
+ it "should return a relative filepath (no leading slash)" do
180
+ Ruhoh::DB.stub(:pages).and_return({"blah.md" => {"url" => "/super/cool/blah-post.html"}})
181
+ page.change('blah.md')
182
+ page.compiled_path.should == "super/cool/blah-post.html"
183
+ end
184
+
185
+ it "should CGI.unescape the url ensure the filepath is correct." do
186
+ Ruhoh::DB.stub(:pages).and_return({"blah.md" => {"url" => "/super/cool/%21blah-post%3D%29.html"}})
187
+ page.change('blah.md')
188
+ page.compiled_path.should == "super/cool/!blah-post=).html"
189
+ end
190
+
191
+ it "should specify an index.html file if url does not end in an .html extension" do
192
+ Ruhoh::DB.stub(:pages).and_return({"blah.md" => {"url" => "/super/cool/blah-post"}})
193
+ page.change('blah.md')
194
+ page.compiled_path.should == "super/cool/blah-post/index.html"
195
+ end
196
+ end
197
+
198
+ end
199
+
200
+ end