postmarkdown 0.0.9 → 0.0.10
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.
- checksums.yaml +4 -4
- data/Gemfile +0 -1
- data/README.markdown +14 -1
- data/app/controllers/posts_controller.rb +3 -1
- data/app/models/post.rb +13 -6
- data/gemfiles/rails3_1.gemfile +0 -1
- data/gemfiles/rails3_2.gemfile +0 -1
- data/gemfiles/rails4_0.gemfile +0 -1
- data/lib/postmarkdown/config.rb +2 -0
- data/lib/postmarkdown/version.rb +1 -1
- data/spec/integrations/posts_spec.rb +22 -0
- data/spec/lib/generators/postmarkdown/post_generator_spec.rb +18 -18
- data/spec/spec_helper.rb +1 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6352f57fb6998050fa57cf5ee679df6ab6642fdb
|
4
|
+
data.tar.gz: ea8152b8c4e31e39cc5f29c502c527a09b9790ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf0b4f0856b75a9f0b8566b458562ea68b4fa36c0498c67871a98982a5d2c6e943abc18dfd853332e72a084aadc4c50fb1717e74943facca5c2917cd974b9212
|
7
|
+
data.tar.gz: 219b3e2557bf1244f59708e4ebeb266db801ea232a7380a4329a0dfda0a2630c47db3e01baa15b48f9270c22b77adb2483049105c0cd398e148a6939c9c870ce
|
data/Gemfile
CHANGED
data/README.markdown
CHANGED
@@ -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(
|
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
|
data/app/models/post.rb
CHANGED
@@ -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.
|
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
|
-
|
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
|
-
|
124
|
+
visible.first
|
118
125
|
end
|
119
126
|
|
120
127
|
def last
|
121
|
-
|
128
|
+
visible.last
|
122
129
|
end
|
123
130
|
|
124
131
|
def feed
|
125
|
-
|
132
|
+
visible.first(10)
|
126
133
|
end
|
127
134
|
|
128
135
|
def feed_last_modified
|
data/gemfiles/rails3_1.gemfile
CHANGED
data/gemfiles/rails3_2.gemfile
CHANGED
data/gemfiles/rails4_0.gemfile
CHANGED
data/lib/postmarkdown/config.rb
CHANGED
@@ -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}/[^/]+]
|
data/lib/postmarkdown/version.rb
CHANGED
@@ -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
|
-
|
18
|
-
run_generator %w(test-post)
|
17
|
+
Time.zone.stub(:now).and_return Time.utc(2012, 1, 1, 10, 20, 30)
|
19
18
|
|
20
|
-
|
19
|
+
run_generator %w(test-post)
|
21
20
|
|
22
|
-
|
21
|
+
Dir.glob('tmp/app/posts/*').should == ['tmp/app/posts/2012-01-01-102030-test-post.markdown']
|
23
22
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
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
|
-
|
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
|
-
|
36
|
+
run_generator %w(test-post_with_underscores)
|
38
37
|
|
39
|
-
|
38
|
+
Dir.glob('tmp/app/posts/*').should == ['tmp/app/posts/2012-01-01-102030-test-post_with_underscores.markdown']
|
40
39
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
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
|
|
data/spec/spec_helper.rb
CHANGED
@@ -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
|
-
|
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.
|
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-
|
14
|
+
date: 2014-02-18 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: rails
|