postmarkdown 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 39584271054fe1a1f30ce61cde326c8c068c9f81
4
- data.tar.gz: b4cd96a67850bda71f46f55d1b0650942e6affa4
3
+ metadata.gz: 6352f57fb6998050fa57cf5ee679df6ab6642fdb
4
+ data.tar.gz: ea8152b8c4e31e39cc5f29c502c527a09b9790ac
5
5
  SHA512:
6
- metadata.gz: febf77d5f33061acf85b890173af01111b9fd92eb72e53ae9c201a5a882fa04060be035f45fb8d7ac0b736c949d4bc4e2f465208a1f0b16f90d94c5ace87259d
7
- data.tar.gz: 675831ce290bc902294d845041d4ce51268f39dd3ad4b10b26bac2753c317012cd0f24ce9323d85c8df2a348cc78bb06278a8f3f6e3cbac8c9a25d5e25c6bf5b
6
+ metadata.gz: bf0b4f0856b75a9f0b8566b458562ea68b4fa36c0498c67871a98982a5d2c6e943abc18dfd853332e72a084aadc4c50fb1717e74943facca5c2917cd974b9212
7
+ data.tar.gz: 219b3e2557bf1244f59708e4ebeb266db801ea232a7380a4329a0dfda0a2630c47db3e01baa15b48f9270c22b77adb2483049105c0cd398e148a6939c9c870ce
data/Gemfile CHANGED
@@ -2,5 +2,4 @@ source 'http://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
- gem 'timecop', :require => false
6
5
  gem 'generator_spec', :require => false
@@ -156,6 +156,20 @@ What about mapping Postmarkdown to root? We got you covered:
156
156
  postmarkdown :as => ''
157
157
  root :to => 'posts#index'
158
158
 
159
+ ## Previewing Future-dated Posts
160
+
161
+ By default, Postmarkdown will only show posts that are dated on or before today.
162
+ If you're writing a post to be published sometime in the future,
163
+ you won't be able to view it in the browser.
164
+
165
+ To override this behaviour, add the following to an initializer
166
+ (`config/initializers/postmarkdown.rb`):
167
+
168
+ Postmarkdown::Config.options[:allow_preview] = true
169
+
170
+ With the :allow_preview option set, you'll be able to view individual posts by
171
+ their URL but they will remain hidden from the index and feed until the post date.
172
+
159
173
  ## Example Directory Structure
160
174
 
161
175
  ├── app
@@ -178,7 +192,6 @@ What about mapping Postmarkdown to root? We got you covered:
178
192
 
179
193
  ## TODO
180
194
 
181
- * Syntax highlighting for code blocks
182
195
  * Generated routes should show example usage
183
196
  * Support more file formats, eg. textile
184
197
  * Built-in theme should have a link to the RSS Feed
@@ -21,8 +21,10 @@ class PostsController < ApplicationController
21
21
  helper_method :resource
22
22
 
23
23
  def collection
24
+ options = params.slice(:year, :month, :day)
25
+ options[:visible] = true
24
26
  @collection ||= begin
25
- posts = Post.where(params.slice(:year, :month, :day))
27
+ posts = Post.where(options)
26
28
  posts = Kaminari.paginate_array(posts).page(params[:page]).per(posts_per_page)
27
29
  posts
28
30
  end
@@ -81,6 +81,7 @@ class Post
81
81
  def visible?
82
82
  timestamp <= Time.zone.now
83
83
  end
84
+ alias_method :visible, :visible?
84
85
 
85
86
  def to_s
86
87
  "#{title.inspect} (#{slug})"
@@ -91,7 +92,11 @@ class Post
91
92
  file_extensions = Postmarkdown::Config.options[:markdown_file_extensions].join(',')
92
93
  @@posts ||= Dir.glob("#{directory}/*.{#{file_extensions}}").map do |filename|
93
94
  Post.new filename
94
- end.select(&:visible?).sort_by { |post| [post.date, post.slug] }.reverse
95
+ end.sort_by { |post| [post.date, post.slug] }.reverse
96
+ end
97
+
98
+ def visible
99
+ all.select(&:visible?)
95
100
  end
96
101
 
97
102
  def directory
@@ -100,7 +105,7 @@ class Post
100
105
 
101
106
  def where(conditions = {})
102
107
  conditions = conditions.symbolize_keys
103
- conditions.assert_valid_keys :year, :month, :day, :slug, :to_param
108
+ conditions.assert_valid_keys :year, :month, :day, :slug, :to_param, :visible
104
109
  [:year, :month, :day].each do |key|
105
110
  conditions[key] = conditions[key].to_i if conditions[key].present?
106
111
  end
@@ -110,19 +115,21 @@ class Post
110
115
  end
111
116
 
112
117
  def find(id)
113
- where(:to_param => id).first or raise ActiveRecord::RecordNotFound, "Could not find post with ID #{id.inspect}"
118
+ options = {:to_param => id}
119
+ options[:visible] = true unless Postmarkdown::Config.options[:allow_preview]
120
+ where(options).first or raise ActiveRecord::RecordNotFound, "Could not find post with ID #{id.inspect}"
114
121
  end
115
122
 
116
123
  def first
117
- all.first
124
+ visible.first
118
125
  end
119
126
 
120
127
  def last
121
- all.last
128
+ visible.last
122
129
  end
123
130
 
124
131
  def feed
125
- all.first(10)
132
+ visible.first(10)
126
133
  end
127
134
 
128
135
  def feed_last_modified
@@ -2,7 +2,6 @@
2
2
 
3
3
  source "http://rubygems.org"
4
4
 
5
- gem "timecop", :require=>false
6
5
  gem "generator_spec", :require=>false
7
6
  gem "rails", "~> 3.1.0"
8
7
 
@@ -2,7 +2,6 @@
2
2
 
3
3
  source "http://rubygems.org"
4
4
 
5
- gem "timecop", :require=>false
6
5
  gem "generator_spec", :require=>false
7
6
  gem "rails", "~> 3.2.0"
8
7
 
@@ -2,7 +2,6 @@
2
2
 
3
3
  source "http://rubygems.org"
4
4
 
5
- gem "timecop", :require=>false
6
5
  gem "generator_spec", :require=>false
7
6
  gem "rails", "~> 4.0.2"
8
7
 
@@ -15,6 +15,8 @@ Postmarkdown::Config.options[:posts_per_page] = 5
15
15
 
16
16
  Postmarkdown::Config.options[:layout] = 'application'
17
17
 
18
+ Postmarkdown::Config.options[:allow_preview] = false
19
+
18
20
  Postmarkdown::Config.options[:permalink_regex] = {}
19
21
  Postmarkdown::Config.options[:permalink_regex][:day] = %r[\d{4}/\d{2}/\d{2}/[^/]+]
20
22
  Postmarkdown::Config.options[:permalink_regex][:month] = %r[\d{4}/\d{2}/[^/]+]
@@ -1,3 +1,3 @@
1
1
  module Postmarkdown
2
- VERSION = '0.0.9'
2
+ VERSION = '0.0.10'
3
3
  end
@@ -190,6 +190,28 @@ describe 'Post views', :type => :request do
190
190
  end
191
191
  end
192
192
 
193
+ context "allow_preview" do
194
+ before { time_travel_to '2011-04-30' }
195
+
196
+ context "allow_preview = false (default)" do
197
+ it 'should not find the future post' do
198
+ lambda do
199
+ visit post_path('2011/05/01/full-metadata')
200
+ end.should raise_error(ActiveRecord::RecordNotFound)
201
+ end
202
+ end
203
+
204
+ context "allow_preview = true" do
205
+ before { Postmarkdown::Config.options[:allow_preview] = true }
206
+ after { Postmarkdown::Config.options[:allow_preview] = false }
207
+
208
+ it 'should show the post' do
209
+ visit post_path('2011/05/01/full-metadata')
210
+ page.should have_content('Post with full metadata') # title
211
+ end
212
+ end
213
+ end
214
+
193
215
  context 'theme' do
194
216
  before { @original_layout = Postmarkdown::Config.options[:layout] }
195
217
  after { Postmarkdown::Config.options[:layout] = @original_layout }
@@ -14,35 +14,35 @@ module Postmarkdown
14
14
 
15
15
  context 'with the slug parameter' do
16
16
  it 'creates a file for the slug and the current date' do
17
- Timecop.freeze(Time.utc(2012, 1, 1, 10, 20, 30)) do
18
- run_generator %w(test-post)
17
+ Time.zone.stub(:now).and_return Time.utc(2012, 1, 1, 10, 20, 30)
19
18
 
20
- Dir.glob('tmp/app/posts/*').should == ['tmp/app/posts/2012-01-01-102030-test-post.markdown']
19
+ run_generator %w(test-post)
21
20
 
22
- Post.all.count.should == 1
21
+ Dir.glob('tmp/app/posts/*').should == ['tmp/app/posts/2012-01-01-102030-test-post.markdown']
23
22
 
24
- post = Post.first
25
- post.slug.should == 'test-post'
26
- post.date.should == Date.parse('2012-01-01')
27
- post.title.should == 'Test post'
28
- end
23
+ Post.all.count.should == 1
24
+
25
+ post = Post.first
26
+ post.slug.should == 'test-post'
27
+ post.date.should == Date.parse('2012-01-01')
28
+ post.title.should == 'Test post'
29
29
  end
30
30
  end
31
31
 
32
32
  context 'with the slug parameter including an underscore' do
33
33
  it 'creates the correct file and sets the right values' do
34
- Timecop.freeze(Time.utc(2012, 1, 1, 10, 20, 30)) do
35
- run_generator %w(test-post_with_underscores)
34
+ Time.zone.stub(:now).and_return Time.utc(2012, 1, 1, 10, 20, 30)
36
35
 
37
- Dir.glob('tmp/app/posts/*').should == ['tmp/app/posts/2012-01-01-102030-test-post_with_underscores.markdown']
36
+ run_generator %w(test-post_with_underscores)
38
37
 
39
- Post.all.count.should == 1
38
+ Dir.glob('tmp/app/posts/*').should == ['tmp/app/posts/2012-01-01-102030-test-post_with_underscores.markdown']
40
39
 
41
- post = Post.first
42
- post.slug.should == 'test-post_with_underscores'
43
- post.date.should == Date.parse('2012-01-01')
44
- post.title.should == 'Test post_with_underscores'
45
- end
40
+ Post.all.count.should == 1
41
+
42
+ post = Post.first
43
+ post.slug.should == 'test-post_with_underscores'
44
+ post.date.should == Date.parse('2012-01-01')
45
+ post.title.should == 'Test post_with_underscores'
46
46
  end
47
47
  end
48
48
 
@@ -14,7 +14,6 @@ require 'capybara/rspec'
14
14
  require 'rspec/rails'
15
15
  require 'capybara/rails'
16
16
 
17
- require 'timecop'
18
17
  require 'generator_spec/test_case'
19
18
  Dir[File.expand_path('lib/generators/postmarkdown/*.rb')].each { |f| require f }
20
19
 
@@ -26,7 +25,7 @@ RSpec.configure do |config|
26
25
  config.order = :random
27
26
 
28
27
  config.after do
29
- Timecop.return
28
+ back_to_the_present
30
29
  FileUtils.rm_rf('spec/tmp/app/posts/.')
31
30
  end
32
31
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: postmarkdown
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Weathered
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2014-02-13 00:00:00.000000000 Z
14
+ date: 2014-02-18 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rails