ruhoh 1.1 → 2.1

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 (121) hide show
  1. data/Gemfile +3 -3
  2. data/README.md +3 -2
  3. data/Rakefile +1 -22
  4. data/bin/ruhoh +1 -5
  5. data/history.json +16 -0
  6. data/lib/ruhoh.rb +229 -84
  7. data/lib/ruhoh/base/collection.rb +280 -0
  8. data/lib/ruhoh/base/compiler.rb +55 -0
  9. data/lib/ruhoh/base/model.rb +220 -0
  10. data/lib/ruhoh/base/model_view.rb +152 -0
  11. data/lib/ruhoh/base/watcher.rb +25 -0
  12. data/lib/ruhoh/cache.rb +46 -0
  13. data/lib/ruhoh/client.rb +162 -0
  14. data/lib/ruhoh/collections.rb +172 -0
  15. data/lib/ruhoh/console_methods.rb +21 -0
  16. data/lib/ruhoh/{converters/converter.rb → converter.rb} +4 -1
  17. data/lib/ruhoh/programs/compile.rb +22 -0
  18. data/lib/ruhoh/programs/preview.rb +63 -0
  19. data/lib/ruhoh/programs/watch.rb +45 -0
  20. data/lib/ruhoh/resources/dash/collection.rb +10 -0
  21. data/lib/ruhoh/resources/dash/model.rb +5 -0
  22. data/lib/ruhoh/resources/dash/model_view.rb +5 -0
  23. data/lib/ruhoh/resources/dash/previewer.rb +13 -0
  24. data/lib/ruhoh/resources/data/collection.rb +9 -0
  25. data/lib/ruhoh/resources/data/collection_view.rb +23 -0
  26. data/lib/ruhoh/resources/javascripts/collection.rb +9 -0
  27. data/lib/ruhoh/resources/javascripts/collection_view.rb +46 -0
  28. data/lib/ruhoh/resources/javascripts/compiler.rb +5 -0
  29. data/lib/ruhoh/resources/layouts/client.rb +45 -0
  30. data/lib/ruhoh/resources/layouts/model.rb +16 -0
  31. data/lib/ruhoh/resources/media/collection.rb +9 -0
  32. data/lib/ruhoh/resources/media/compiler.rb +27 -0
  33. data/lib/ruhoh/resources/pages/client.rb +124 -0
  34. data/lib/ruhoh/resources/pages/collection.rb +86 -0
  35. data/lib/ruhoh/resources/pages/collection_view.rb +73 -0
  36. data/lib/ruhoh/resources/pages/compiler.rb +101 -0
  37. data/lib/ruhoh/resources/pages/model.rb +5 -0
  38. data/lib/ruhoh/resources/pages/model_view.rb +5 -0
  39. data/lib/ruhoh/resources/pages/previewer.rb +72 -0
  40. data/lib/ruhoh/resources/partials/model.rb +11 -0
  41. data/lib/ruhoh/resources/stylesheets/collection.rb +9 -0
  42. data/lib/ruhoh/resources/stylesheets/collection_view.rb +45 -0
  43. data/lib/ruhoh/resources/stylesheets/compiler.rb +5 -0
  44. data/lib/ruhoh/resources/theme/collection.rb +14 -0
  45. data/lib/ruhoh/resources/theme/compiler.rb +54 -0
  46. data/lib/ruhoh/resources/widgets/collection.rb +26 -0
  47. data/lib/ruhoh/resources/widgets/collection_view.rb +34 -0
  48. data/lib/ruhoh/resources/widgets/compiler.rb +27 -0
  49. data/lib/ruhoh/resources/widgets/model.rb +16 -0
  50. data/lib/ruhoh/routes.rb +29 -0
  51. data/lib/ruhoh/utils.rb +32 -49
  52. data/lib/ruhoh/version.rb +2 -2
  53. data/lib/ruhoh/views/helpers/categories.rb +38 -0
  54. data/lib/ruhoh/views/helpers/paginator.rb +39 -0
  55. data/lib/ruhoh/views/helpers/tags.rb +37 -0
  56. data/lib/ruhoh/views/master_view.rb +183 -0
  57. data/lib/ruhoh/views/rmustache.rb +24 -0
  58. data/ruhoh.gemspec +6 -82
  59. data/spec/spec_helper.rb +1 -1
  60. data/spec/support/shared_contexts.rb +6 -5
  61. data/system/{scaffolds/post.html → _scaffold.html} +1 -1
  62. data/system/{dash.html → dash/index.html} +37 -51
  63. data/system/{scaffolds/layout.html → layouts/_scaffold.html} +0 -0
  64. data/system/layouts/paginator.html +28 -0
  65. data/system/plugins/sprockets/javascripts/compiler.rb +25 -0
  66. data/system/plugins/sprockets/javascripts/previewer.rb +17 -0
  67. data/system/plugins/sprockets/stylesheets/compiler.rb +26 -0
  68. data/system/plugins/sprockets/stylesheets/previewer.rb +17 -0
  69. data/system/widgets/analytics/{layouts/getclicky.html → getclicky.html} +6 -2
  70. data/system/widgets/analytics/{layouts/google.html → google.html} +5 -1
  71. data/system/widgets/comments/{layouts/disqus.html → disqus.html} +6 -2
  72. data/system/widgets/comments/{layouts/facebook.html → facebook.html} +9 -2
  73. data/system/widgets/comments/{layouts/intensedebate.html → intensedebate.html} +5 -1
  74. data/system/widgets/comments/{layouts/livefyre.html → livefyre.html} +5 -1
  75. data/system/widgets/google_prettify/{layouts/google_prettify.html → default.html} +6 -2
  76. metadata +69 -66
  77. data/lib/ruhoh/client/client.rb +0 -306
  78. data/lib/ruhoh/client/console_methods.rb +0 -9
  79. data/lib/ruhoh/client/help.yml +0 -56
  80. data/lib/ruhoh/compiler.rb +0 -72
  81. data/lib/ruhoh/compilers/rss.rb +0 -39
  82. data/lib/ruhoh/compilers/theme.rb +0 -46
  83. data/lib/ruhoh/config.rb +0 -62
  84. data/lib/ruhoh/db.rb +0 -50
  85. data/lib/ruhoh/deployers/s3.rb +0 -71
  86. data/lib/ruhoh/page.rb +0 -106
  87. data/lib/ruhoh/parsers/javascripts.rb +0 -55
  88. data/lib/ruhoh/parsers/layouts.rb +0 -32
  89. data/lib/ruhoh/parsers/pages.rb +0 -79
  90. data/lib/ruhoh/parsers/partials.rb +0 -42
  91. data/lib/ruhoh/parsers/payload.rb +0 -49
  92. data/lib/ruhoh/parsers/posts.rb +0 -259
  93. data/lib/ruhoh/parsers/routes.rb +0 -20
  94. data/lib/ruhoh/parsers/scaffolds.rb +0 -35
  95. data/lib/ruhoh/parsers/site.rb +0 -19
  96. data/lib/ruhoh/parsers/stylesheets.rb +0 -63
  97. data/lib/ruhoh/parsers/theme_config.rb +0 -30
  98. data/lib/ruhoh/parsers/widgets.rb +0 -104
  99. data/lib/ruhoh/paths.rb +0 -83
  100. data/lib/ruhoh/previewer.rb +0 -48
  101. data/lib/ruhoh/program.rb +0 -68
  102. data/lib/ruhoh/templaters/asset_helpers.rb +0 -66
  103. data/lib/ruhoh/templaters/base_helpers.rb +0 -147
  104. data/lib/ruhoh/templaters/helpers.rb +0 -8
  105. data/lib/ruhoh/templaters/rmustache.rb +0 -70
  106. data/lib/ruhoh/urls.rb +0 -50
  107. data/lib/ruhoh/watch.rb +0 -78
  108. data/spec/config_spec.rb +0 -50
  109. data/spec/db_spec.rb +0 -91
  110. data/spec/page_spec.rb +0 -164
  111. data/spec/parsers/layouts_spec.rb +0 -41
  112. data/spec/parsers/pages_spec.rb +0 -120
  113. data/spec/parsers/posts_spec.rb +0 -309
  114. data/spec/parsers/routes_spec.rb +0 -39
  115. data/spec/parsers/site_spec.rb +0 -28
  116. data/spec/setup_spec.rb +0 -12
  117. data/system/scaffolds/draft.html +0 -9
  118. data/system/scaffolds/page.html +0 -4
  119. data/system/widgets/analytics/config.yml +0 -5
  120. data/system/widgets/comments/config.yml +0 -13
  121. data/system/widgets/google_prettify/config.yml +0 -1
data/spec/db_spec.rb DELETED
@@ -1,91 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module DB
4
- describe Ruhoh::DB do
5
- include_context "write_default_theme"
6
- include_context "default_setup"
7
-
8
- let(:whitelist){ Ruhoh::DB::WhiteList }
9
- context "database has not been updated" do
10
- it "should return nil for all whitelisted variables except payload" do
11
- whitelist.each do |var|
12
- result = Ruhoh::DB.__send__(var)
13
- next if var == :payload
14
- result.should be_nil
15
- end
16
- end
17
- end
18
-
19
- describe "#update" do
20
- it "should raise an exception when updating a variable not whitelisted" do
21
- lambda { Ruhoh::DB.update(:table) }.should raise_error
22
- end
23
-
24
- it "should run the site parser when updating :site, then set the variable to the result" do
25
- Ruhoh::Parsers::Site.should_receive(:generate).and_return({'test' => 'hi'})
26
- Ruhoh::DB.update(:site)
27
- Ruhoh::DB.site.should == {'test' => 'hi'}
28
- end
29
-
30
- it "should run the routes parser when updating :routes" do
31
- Ruhoh::Parsers::Routes.should_receive(:generate).and_return({'test' => 'hi'})
32
- Ruhoh::DB.update(:routes)
33
- Ruhoh::DB.routes.should == {'test' => 'hi'}
34
- end
35
-
36
- it "should run the posts parser when updating :posts" do
37
- Ruhoh::Parsers::Posts.should_receive(:generate).and_return({'test' => 'hi'})
38
- Ruhoh::DB.update(:posts)
39
- Ruhoh::DB.posts.should == {'test' => 'hi'}
40
- end
41
-
42
- it "should run the pages parser when updating :pages" do
43
- Ruhoh::Parsers::Pages.should_receive(:generate).and_return({'test' => 'hi'})
44
- Ruhoh::DB.update(:pages)
45
- Ruhoh::DB.pages.should == {'test' => 'hi'}
46
- end
47
-
48
- it "should run the layouts parser when updating :layouts" do
49
- Ruhoh::Parsers::Layouts.should_receive(:generate).and_return({'test' => 'hi'})
50
- Ruhoh::DB.update(:layouts)
51
- Ruhoh::DB.layouts.should == {'test' => 'hi'}
52
- end
53
-
54
- it "should run the partials parser when updating :partials" do
55
- Ruhoh::Parsers::Partials.should_receive(:generate).and_return({'test' => 'hi'})
56
- Ruhoh::DB.update(:partials)
57
- Ruhoh::DB.partials.should == {'test' => 'hi'}
58
- end
59
-
60
- it "should run the widgets parser when updating :widgets" do
61
- Ruhoh::Parsers::Widgets.should_receive(:generate).and_return({'test' => 'hi'})
62
- Ruhoh::DB.update(:widgets)
63
- Ruhoh::DB.widgets.should == {'test' => 'hi'}
64
- end
65
-
66
- it "should run the stylesheets parser when updating :stylesheets" do
67
- Ruhoh::Parsers::Stylesheets.should_receive(:generate).and_return({'test' => 'hi'})
68
- Ruhoh::DB.update(:stylesheets)
69
- Ruhoh::DB.stylesheets.should == {'test' => 'hi'}
70
- end
71
-
72
- it "should run the scripts parser when updating :javascripts" do
73
- Ruhoh::Parsers::Javascripts.should_receive(:generate).and_return({'test' => 'hi'})
74
- Ruhoh::DB.update(:javascripts)
75
- Ruhoh::DB.javascripts.should == {'test' => 'hi'}
76
- end
77
-
78
- end
79
-
80
- describe "#update_all" do
81
- it "should call update for all WhiteListed variables." do
82
- whitelist.each do |name|
83
- Ruhoh::DB.should_receive(:update).with(name).ordered
84
- end
85
- Ruhoh::DB.update_all
86
- end
87
- end
88
-
89
- end
90
-
91
- end
data/spec/page_spec.rb DELETED
@@ -1,164 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Page
4
-
5
- describe Ruhoh::Page do
6
-
7
- before(:each) do
8
- Ruhoh::Utils.stub(:parse_yaml_file).and_return({'theme' => "twitter"})
9
- Ruhoh::Paths.stub(:theme_is_valid?).and_return(true)
10
-
11
- end
12
-
13
- describe "Page initialization" do
14
- it "should setup default templater and converter" do
15
- page = Ruhoh::Page.new
16
-
17
- page.templater.should == Ruhoh::Templaters::RMustache
18
- end
19
- end
20
-
21
- describe "#change" do
22
- let(:page){ Ruhoh::Page.new }
23
- let(:posts) {
24
- {
25
- "dictionary" => {
26
- "#{Ruhoh.names.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("#{Ruhoh.names.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 == "#{Ruhoh.names.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 "#render" do
76
- let(:page){ Ruhoh::Page.new }
77
- it "should raise error if id not set" do
78
- lambda{ page.render }.should raise_error
79
- end
80
-
81
- it "should process layouts, then render using the @templater" do
82
- Ruhoh::DB.stub(:pages).and_return({"blah.md" => {}})
83
- page.change('blah.md')
84
- layout = "{{{content}}}"
85
- payload = {}
86
- page.should_receive(:process_layouts)
87
- page.should_receive(:expand_layouts).and_return(layout)
88
- page.should_receive(:payload).and_return(payload)
89
- page.templater.should_receive(:render).with(layout, payload)
90
- page.render
91
- end
92
- end
93
-
94
- pending "#process_layouts"
95
-
96
- pending "#expand_layouts"
97
-
98
- pending "#payload"
99
-
100
- pending "#content" do
101
- let(:page){ Ruhoh::Page.new }
102
-
103
- it "should raise error if id not set" do
104
- lambda{ page.content }.should raise_error
105
- end
106
-
107
- context "Id has been set" do
108
- # Set the id
109
- before(:all) do
110
- Ruhoh::DB.stub(:pages).and_return({"blah.md" => {}})
111
- page.change('blah.md')
112
- end
113
-
114
- it "should raise an error if the page file is malformed" do
115
- Ruhoh::Utils.should_receive(:parse_page_file).and_return({})
116
- lambda { page.content }.should raise_error
117
- end
118
-
119
- it "should send the files content to the templater" do
120
- Ruhoh::Utils.should_receive(:parse_page_file).and_return({"content" => "meep"})
121
- page.templater.should_receive(:parse).with("meep", page)
122
- page.converter.stub(:convert)
123
- page.content
124
- end
125
-
126
- it "should send the page to the converter, then set the result as @content" do
127
- Ruhoh::Utils.should_receive(:parse_page_file).and_return({"content" => "meep"})
128
- page.templater.stub(:parse)
129
- page.converter.should_receive(:convert).with(page).and_return("yay")
130
- page.content
131
- page.content.should == "yay"
132
- end
133
- end
134
- end
135
-
136
- describe "#compiled_path" do
137
- let(:page){ Ruhoh::Page.new }
138
-
139
- it "should raise error if id not set" do
140
- lambda{ page.compiled_path }.should raise_error
141
- end
142
-
143
- it "should return a relative filepath (no leading slash)" do
144
- Ruhoh::DB.stub(:pages).and_return({"blah.md" => {"url" => "/super/cool/blah-post.html"}})
145
- page.change('blah.md')
146
- page.compiled_path.should == "super/cool/blah-post.html"
147
- end
148
-
149
- it "should CGI.unescape the url ensure the filepath is correct." do
150
- Ruhoh::DB.stub(:pages).and_return({"blah.md" => {"url" => "/super/cool/%21blah-post%3D%29.html"}})
151
- page.change('blah.md')
152
- page.compiled_path.should == "super/cool/!blah-post=).html"
153
- end
154
-
155
- it "should specify an index.html file if url does not end in an .html extension" do
156
- Ruhoh::DB.stub(:pages).and_return({"blah.md" => {"url" => "/super/cool/blah-post"}})
157
- page.change('blah.md')
158
- page.compiled_path.should == "super/cool/blah-post/index.html"
159
- end
160
- end
161
-
162
- end
163
-
164
- end
@@ -1,41 +0,0 @@
1
- require 'spec_helper'
2
- module Layouts
3
- describe Ruhoh::Parsers::Layouts do
4
-
5
- before(:each) do
6
- expected_theme = "twitter"
7
- the_layouts_dir = File.join(SampleSitePath, Ruhoh.names.themes, expected_theme, Ruhoh.names.layouts)
8
- FileUtils.makedirs the_layouts_dir
9
- expected_layouts.each do |layout_name|
10
- full_file_name = File.join(the_layouts_dir, layout_name)
11
-
12
- File.open full_file_name, "w+" do |file|
13
- file.puts <<-TEXT
14
- ---
15
- title: #{layout_name} (test)
16
- ---
17
- TEXT
18
- end
19
- end
20
- end
21
-
22
- let(:expected_layouts) { %w{default.html page.html post.html} }
23
-
24
- describe "#generate" do
25
- let(:layouts){
26
- Ruhoh::Parsers::Layouts.generate
27
- }
28
-
29
- it 'should extract the correct layouts from a theme.' do
30
- layouts.keys.sort.should == ['default', 'page', 'post']
31
- end
32
-
33
- it 'should return a hash for each layout containing the keys "data" and "content"' do
34
- layouts.each_value { |value|
35
- value.should have_key("data")
36
- value.should have_key("content")
37
- }
38
- end
39
- end
40
- end
41
- end
@@ -1,120 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Pages
4
- describe Ruhoh::Parsers::Pages do
5
- describe "#generate" do
6
- include_context "write_default_theme"
7
- include_context "default_setup"
8
-
9
- before(:each) do
10
- the_pages_dir = File.join(SampleSitePath, Ruhoh.names.pages)
11
- Dir.mkdir the_pages_dir
12
- expected_pages.each do |page_name|
13
- full_file_name = File.join(the_pages_dir, page_name)
14
- File.open full_file_name, "w+" do |file|
15
- file.puts <<-TEXT
16
- ---
17
- title: #{page_name} (test)
18
- ---
19
- TEXT
20
- end
21
- end
22
- end
23
-
24
- let(:expected_pages) {
25
- %w{about.md archive.html categories.html index.html pages.html sitemap.txt tags.html}.sort
26
- }
27
-
28
- let(:pages){
29
- Ruhoh::Parsers::Pages.generate
30
- }
31
-
32
- it 'should extract valid pages from source directory.' do
33
- pages.keys.sort.should == expected_pages
34
- end
35
-
36
- it 'should return a properly formatted hash for each page' do
37
- pages.each_value { |value|
38
- value.should have_key("id")
39
- value.should have_key("url")
40
- value.should have_key("title")
41
- }
42
- end
43
-
44
- end
45
-
46
- describe "#is_valid_page?" do
47
- context "No user specified exclusions in config." do
48
- it "should return true for a valid page filepath" do
49
- filepath = 'about.md'
50
- Ruhoh::Parsers::Pages.is_valid_page?(filepath).should == true
51
- end
52
-
53
- it "should return false for a filepath beginning with ." do
54
- filepath = '.vim'
55
- Ruhoh::Parsers::Pages.is_valid_page?(filepath).should == false
56
- end
57
-
58
- end
59
-
60
- context "Exclude array is passed into config." do
61
- before(:each){
62
- Dir.mkdir SampleSitePath
63
- theme = "twitter"
64
- # Create base config.yml + base theme
65
- File.open(File.join(SampleSitePath, Ruhoh.names.config_data), "w+") { |file|
66
- file.puts <<-TEXT
67
- ---
68
- theme: '#{theme}'
69
- pages:
70
- exclude: ['^test', 'blah']
71
- ---
72
- TEXT
73
- }
74
- theme_dir = File.join(SampleSitePath, Ruhoh.names.themes, theme)
75
- FileUtils.makedirs theme_dir
76
- }
77
- include_context "default_setup"
78
-
79
- it "should return false for a page filepath matching a regular expression in pages exclude array" do
80
- filepath1 = 'test/about.md'
81
- filepath2 = 'test/yay.md'
82
- filepath3 = 'vest/yay.md'
83
- Ruhoh::Parsers::Pages.is_valid_page?(filepath1).should == false
84
- Ruhoh::Parsers::Pages.is_valid_page?(filepath2).should == false
85
- Ruhoh::Parsers::Pages.is_valid_page?(filepath3).should == true
86
- end
87
- end
88
-
89
- context "Exclude string is passed into config." do
90
- let(:filepath){'about.md'}
91
- before(:each){
92
- Dir.mkdir SampleSitePath
93
- theme = "twitter"
94
- # Create base config.yml + base theme
95
- File.open(File.join(SampleSitePath, Ruhoh.names.config_data), "w+") { |file|
96
- file.puts <<-TEXT
97
- ---
98
- theme: '#{theme}'
99
- pages:
100
- exclude: '#{filepath}$'
101
- ---
102
- TEXT
103
- }
104
- theme_dir = File.join(SampleSitePath, Ruhoh.names.themes, theme)
105
- FileUtils.makedirs theme_dir
106
- }
107
- include_context "default_setup"
108
-
109
- it "should return false for a page whose filepath matches a page exclude regular expression." do
110
- Ruhoh::Parsers::Pages.is_valid_page?(filepath).should == false
111
- end
112
- end
113
- end
114
-
115
- describe "#to_title"
116
- describe "#permalink"
117
-
118
- end
119
-
120
- end
@@ -1,309 +0,0 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
-
4
- module Posts
5
- describe Ruhoh::Parsers::Posts do
6
- include_context "write_default_theme"
7
- include_context "default_setup"
8
-
9
- pending "#generate" do
10
-
11
- it 'should return a valid data structures for core API' do
12
- posts = Ruhoh::Parsers::Posts.generate
13
-
14
- posts['dictionary'].should be_a_kind_of(Hash)
15
- posts['chronological'].should be_a_kind_of(Array)
16
- posts['collated'].should be_a_kind_of(Array)
17
- posts['tags'].should be_a_kind_of(Hash)
18
- posts['categories'].should be_a_kind_of(Hash)
19
- end
20
-
21
- end
22
-
23
- describe "#process" do
24
-
25
- context "A valid post" do
26
- pending 'should extract valid posts from source directory.' do
27
- Ruhoh::Parsers::Posts.process
28
- dictionary.keys.sort.should == ['_posts/2012-01-01-hello-world.md']
29
- end
30
-
31
- pending 'should return a properly formatted hash for each post' do
32
- dictionary = Ruhoh::Parsers::Posts.process
33
-
34
- dictionary.each_value { |value|
35
- value.should have_key("id")
36
- value.should have_key("url")
37
- value.should have_key("title")
38
- }
39
- end
40
- end
41
-
42
- context "A post with an invalid filename format" do
43
- it "should omit the post file and record it as invalid post" do
44
- post_path = 'test/hello-world.md'
45
- Ruhoh::Parsers::Posts.should_receive(:files).and_return([post_path])
46
- Ruhoh::Utils.stub(:parse_page_file).and_return({"data" => {"date" => "2012-01-01"}})
47
-
48
- dictionary = Ruhoh::Parsers::Posts.process
49
-
50
- dictionary.should_not include(post_path)
51
- end
52
- end
53
-
54
- context "A post with an invalid date in the filename" do
55
- it "should omit the post file and record it as invalid post" do
56
- post_path = 'test/2012-51-01-hello-world.md'
57
- Ruhoh::Parsers::Posts.should_receive(:files).and_return([post_path])
58
- Ruhoh::Utils.stub(:parse_page_file).and_return({"data" => {"title" => "meep"}})
59
-
60
- dictionary = Ruhoh::Parsers::Posts.process
61
-
62
- dictionary.should_not include(post_path)
63
- end
64
- end
65
-
66
- context "A post with an invalid date in the YAML Front Matter" do
67
- it "should omit the post file and record it as invalid post" do
68
- post_path = 'test/2012-01-01-hello-world.md'
69
- Ruhoh::Parsers::Posts.should_receive(:files).and_return([post_path])
70
- Ruhoh::Utils.stub(:parse_page_file).and_return({"data" => {"date" => "2012-51-01"}})
71
-
72
- dictionary = Ruhoh::Parsers::Posts.process
73
-
74
- dictionary.should_not include(post_path)
75
- end
76
- end
77
- end
78
-
79
- describe "#parse_page_filename" do
80
- it "should parse a post filename with DATE into corresponding metadata" do
81
- filename = '_posts/2011-10-10-my-post-title.md'
82
- data = Ruhoh::Parsers::Posts.parse_page_filename(filename)
83
-
84
- data['path'].should == "_posts/"
85
- data['date'].should == "2011-10-10"
86
- data['slug'].should == "my-post-title"
87
- data['extension'].should == ".md"
88
- end
89
-
90
- it "should parse a post filename without DATE into corresponding metadata" do
91
- filename = '_posts/my-post-title.md'
92
- data = Ruhoh::Parsers::Posts.parse_page_filename(filename)
93
- data['path'].should == "_posts/"
94
- data['date'].should == nil
95
- data['slug'].should == "my-post-title"
96
- data['extension'].should == ".md"
97
- end
98
-
99
- it "should return a blank hash if the filename has no extension and therefore invalid" do
100
- filename = '_posts/my-post-title'
101
- data = Ruhoh::Parsers::Posts.parse_page_filename(filename)
102
- data.should == {}
103
- end
104
- end
105
-
106
- describe "#permalink" do
107
- it "should return the default permalink style (/:categories/:year/:month/:day/:title.html)" do
108
- post = {"date" => "2012-01-02", "title" => "My Blog Post", "id" => "my-blog-post.md"}
109
- permalink = Ruhoh::Parsers::Posts.permalink(post)
110
- permalink.should == '/2012/01/02/my-blog-post.html'
111
- end
112
-
113
- it "should return the post specific permalink style" do
114
- post = {"id" => "my-blog-post.md", "date" => "2012-01-02", "title" => "My Blog Post", 'permalink' => '/:categories/:title' }
115
- permalink = Ruhoh::Parsers::Posts.permalink(post)
116
- permalink.should == '/my-blog-post'
117
- end
118
-
119
- context "A post with one category" do
120
- it "should include the category path in the permalink." do
121
- post = {"id" => "my-blog-post.md", "date" => "2012-01-02", "title" => "My Blog Post", 'categories'=> 'ruby/lessons/beginner', 'permalink' => '/:categories/:title' }
122
- permalink = Ruhoh::Parsers::Posts.permalink(post)
123
- permalink.should == '/ruby/lessons/beginner/my-blog-post'
124
- end
125
- end
126
-
127
- context "A post belonging in two separate categories" do
128
- it "should include the first category path in the permalink." do
129
- post = {"id" => "my-blog-post.md", "date" => "2012-01-02", "title" => "My Blog Post", 'categories'=> ['web', 'ruby/lessons/beginner'], 'permalink' => '/:categories/:title' }
130
- permalink = Ruhoh::Parsers::Posts.permalink(post)
131
- permalink.should == '/web/my-blog-post'
132
- end
133
- end
134
-
135
- context "A post with a literal permalink" do
136
- it "should use the literal permalink" do
137
- post = {"id" => "my-blog-post.md", "date" => "2012-01-02", "title" => "=) My Blog Post!", 'permalink' => '/dogs/and/cats/summer-pictures' }
138
- permalink = Ruhoh::Parsers::Posts.permalink(post)
139
- permalink.should == '/dogs/and/cats/summer-pictures'
140
- end
141
- end
142
-
143
- context "A post having special characters in the title" do
144
- it "should omit those characters." do
145
- post = {"id" => "my-blog-post.md", "date" => "2012-01-02", "title" => "=) My Blog Post!", 'permalink' => '/:title' }
146
- permalink = Ruhoh::Parsers::Posts.permalink(post)
147
- permalink.should_not == '/=)-my-blog-post-!'
148
- permalink.should == '/my-blog-post'
149
- end
150
- end
151
-
152
- context "A post having international characters in the title" do
153
- it "should omit those characters." do
154
- post = {"id" => "my-blog-post.md", "date" => "2012-01-02", "title" => "=) My Blog Post!", 'permalink' => '/:title' }
155
- post = {"id" => '안녕하세요-sérieux-è_é-三只熊.md', "date" => "2012-01-02", "title" => '안녕하세요-sérieux è_é-三只熊', 'permalink' => '/:title' }
156
- permalink = Ruhoh::Parsers::Posts.permalink(post)
157
- permalink.should == ('/'+CGI::escape('안녕하세요-sérieux-è_é-三只熊'))
158
- end
159
- end
160
- end
161
-
162
- describe "#to_title" do
163
- it "should prettify a filename slug for use as a title/header" do
164
- file_slug = 'my-post-title'
165
- title = Ruhoh::Parsers::Posts.to_title(file_slug)
166
- title.should == "My Post Title"
167
- end
168
- end
169
-
170
- describe "helpers" do
171
- let(:dictionary_stub) {
172
- {
173
- "a" => {"date"=>"2011-01-01", "id" => "a"},
174
- "b" => {"date"=>"2011-02-01", "id" => "b"},
175
- "c" => {"date"=>"2012-01-01", "id" => "c"},
176
- "d" => {"date"=>"2010-08-01", "id" => "d"},
177
- }
178
- }
179
- let(:ordered_posts_stub) {
180
- [
181
- {"date"=>"2012-01-01", "id" => "c"},
182
- {"date"=>"2011-02-01", "id" => "b"},
183
- {"date"=>"2011-01-01", "id" => "a"},
184
- {"date"=>"2010-08-01", "id" => "d"},
185
- ]
186
- }
187
- let(:collated_stub) {
188
- [
189
- {"year"=>"2012", "months"=>[{"month"=>"January", "posts"=>["c"]}]},
190
- {"year"=>"2011", "months"=>[{"month"=>"February", "posts"=>["b"]}, {"month"=>"January", "posts"=>["a"]}]},
191
- {"year"=>"2010", "months"=>[{"month"=>"August", "posts"=>["d"]}]}
192
- ]
193
- }
194
-
195
- describe "#ordered_posts" do
196
- it "should order a dictionary hash by date descending and return an Array" do
197
- ordered_posts = Ruhoh::Parsers::Posts.ordered_posts(dictionary_stub)
198
-
199
- ordered_posts.should be_a_kind_of(Array)
200
- ordered_posts.should == ordered_posts_stub
201
- end
202
- end
203
-
204
- describe "#build_chronology" do
205
- it 'should return an array of ids ordered by date descending' do
206
- chrono = Ruhoh::Parsers::Posts.build_chronology(ordered_posts_stub)
207
- chrono.should == ['c', 'b', 'a', 'd']
208
- end
209
- end
210
-
211
- describe "#collate" do
212
- it 'should return an array of years with nested months and nested, ordered post ids for each month.' do
213
- collated = Ruhoh::Parsers::Posts.collate(ordered_posts_stub)
214
- collated.should == collated_stub
215
- end
216
- end
217
-
218
- end
219
-
220
- describe "#parse_tags" do
221
- let(:ordered_posts_stub) {
222
- [
223
- {"id" => "c", "tags" => ['apple', 'orange']},
224
- {"id" => "b", "tags" => ['apple', 'pear']},
225
- {"id" => "a", "tags" => ['banana']},
226
- {"id" => "d", "tags" => 'kiwi' },
227
- ]
228
- }
229
- let(:tags){
230
- Ruhoh::Parsers::Posts.parse_tags(ordered_posts_stub)
231
- }
232
-
233
- it 'should return a dictionary of all tags on posts' do
234
- tags.keys.sort.should == ['apple', 'banana', 'kiwi', 'orange', 'pear']
235
- end
236
-
237
- it 'should return a dictionary containing tag objects having name, count and posts' do
238
- tags.each_value { |tag|
239
- tag.should have_key("name")
240
- tag.should have_key("count")
241
- tag.should have_key("posts")
242
- }
243
- end
244
-
245
- it 'should return a dictionary with tag objects having correct post id references.' do
246
- tags['apple']['posts'].should == ['c', 'b']
247
- tags['banana']['posts'].should == ['a']
248
- tags['kiwi']['posts'].should == ['d']
249
- tags['orange']['posts'].should == ['c']
250
- tags['pear']['posts'].should == ['b']
251
- end
252
-
253
- it 'should return a dictionary containing correct tag counts' do
254
- tags['apple']['count'].should == 2
255
- tags['banana']['count'].should == 1
256
- tags['kiwi']['count'].should == 1
257
- tags['orange']['count'].should == 1
258
- tags['pear']['count'].should == 1
259
- end
260
-
261
- end
262
-
263
- describe "#parse_categories" do
264
- let(:ordered_posts_stub) {
265
- [
266
- {"id" => "c", "categories" => ['web', ['ruby', 'tutorials']] },
267
- {"id" => "b", "categories" => ['web', ['ruby']] },
268
- {"id" => "a", "categories" => ['web', 'python'] },
269
- {"id" => "d", "categories" => 'erlang' },
270
- ]
271
- }
272
-
273
- let(:categories) {
274
- categories = Ruhoh::Parsers::Posts.parse_categories(ordered_posts_stub)
275
- }
276
-
277
- it 'should return a dictionary of all post categories' do
278
- categories.keys.sort.should == ['erlang', 'python', 'ruby', 'ruby/tutorials', 'web']
279
- end
280
-
281
- it 'should return a dictionary containing category objects having name, count and posts' do
282
- categories.each_value { |cat|
283
- cat.should have_key("name")
284
- cat.should have_key("count")
285
- cat.should have_key("posts")
286
- }
287
- end
288
-
289
- it 'should return a dictionary with category objects having correct post id references.' do
290
- categories['erlang']['posts'].should == ['d']
291
- categories['python']['posts'].should == ['a']
292
- categories['ruby']['posts'].should == ['b']
293
- categories['ruby/tutorials']['posts'].should == ['c']
294
- categories['web']['posts'].should == ['c','b','a']
295
- end
296
-
297
- it 'should return a dictionary containing correct tag counts' do
298
- categories['erlang']['count'].should == 1
299
- categories['python']['count'].should == 1
300
- categories['ruby']['count'].should == 1
301
- categories['ruby/tutorials']['count'].should == 1
302
- categories['web']['count'].should == 3
303
- end
304
-
305
- end
306
-
307
- end
308
-
309
- end