Permalink
Browse files

added option to `allow_preview`

- defaults to false
- if set to true future posts can been seen in the browser
  • Loading branch information...
1 parent 1b5a263 commit f148ff1f7293622c6774d9fc2b97a2cc30894b4a @jess jess committed Feb 15, 2014
Showing with 50 additions and 1 deletion.
  1. +23 −0 README.markdown
  2. +3 −1 app/models/post.rb
  3. +2 −0 lib/postmarkdown/config.rb
  4. +22 −0 spec/integrations/posts_spec.rb
View
@@ -156,6 +156,29 @@ What about mapping Postmarkdown to root? We got you covered:
postmarkdown :as => ''
root :to => 'posts#index'
+## Allow Preview
+
+By default Postmarkdown will only select posts that are dated before the
+current date. If you're writing a post to be published sometime in the
+future, you won't be able to view it in the browser.
+
+To override this behavior, add the following to an initializer
+(`config/initializers/postmarkdown.rb`):
+
+ Postmarkdown::Config.options[:allow_preview] = true
+
+Now, if you create a post with a future date, you can view it at
+the url of the individual post (posts#show route). Example:
+
+ $ rails generate postmarkdown:post future-post --date=2050-01-01
+
+Using the default routes, you could view the file at
+`http://localhost:3000/posts/2050/01/01/future-post`
+
+However, the post will not show up in your feed or index views until the
+current date reaches the date of your post.
+
+
## Example Directory Structure
├── app
View
@@ -115,7 +115,9 @@ def where(conditions = {})
end
def find(id)
- where(:to_param => id, :visible => true).first or raise ActiveRecord::RecordNotFound, "Could not find post with ID #{id.inspect}"
+ options = {:to_param => id}
+ options[:visible] = true unless Postmarkdown::Config.options[:allow_preview]
+ where(options).first or raise ActiveRecord::RecordNotFound, "Could not find post with ID #{id.inspect}"
end
def first
@@ -15,6 +15,8 @@ module Config
Postmarkdown::Config.options[:layout] = 'application'
+Postmarkdown::Config.options[:allow_preview] = false
+
Postmarkdown::Config.options[:permalink_regex] = {}
Postmarkdown::Config.options[:permalink_regex][:day] = %r[\d{4}/\d{2}/\d{2}/[^/]+]
Postmarkdown::Config.options[:permalink_regex][:month] = %r[\d{4}/\d{2}/[^/]+]
@@ -190,6 +190,28 @@ def article_titles
end
end
+ context "allow_preview" do
+ before { time_travel_to '2011-04-30' }
+
+ context "allow_preview = false (default)" do
+ it 'should not find the future post' do
+ lambda do
+ visit post_path('2011/05/01/full-metadata')
+ end.should raise_error(ActiveRecord::RecordNotFound)
+ end
+ end
+
+ context "allow_preview = true" do
+ before { Postmarkdown::Config.options[:allow_preview] = true }
+ after { Postmarkdown::Config.options[:allow_preview] = false }
+
+ it 'should show the post' do
+ visit post_path('2011/05/01/full-metadata')
+ page.should have_content('Post with full metadata') # title
+ end
+ end
+ end
+
context 'theme' do
before { @original_layout = Postmarkdown::Config.options[:layout] }
after { Postmarkdown::Config.options[:layout] = @original_layout }

0 comments on commit f148ff1

Please sign in to comment.