staticpress 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/docs/Gemfile +8 -0
- data/{tests/sample_sites/test_blog → docs}/README.markdown +0 -0
- data/{tests/sample_sites/test_blog → docs}/config.ru +0 -0
- data/docs/config.yml +2 -0
- data/docs/content/docs/diving-deeper.markdown +3 -0
- data/docs/content/docs/setup.markdown +15 -0
- data/docs/content/index.markdown +1 -0
- data/features/happy_path.feature +36 -1
- data/features/step_definitions/staticpress_steps.rb +1 -1
- data/lib/skeleton/Gemfile +0 -2
- data/lib/staticpress/booter.rb +1 -1
- data/lib/staticpress/cli.rb +2 -2
- data/lib/staticpress/content/base.rb +66 -23
- data/lib/staticpress/content/category.rb +12 -3
- data/lib/staticpress/content/collection_content.rb +0 -4
- data/lib/staticpress/content/index.rb +10 -3
- data/lib/staticpress/content/page.rb +32 -17
- data/lib/staticpress/content/post.rb +22 -27
- data/lib/staticpress/content/resource_content.rb +11 -3
- data/lib/staticpress/content/static_content.rb +10 -4
- data/lib/staticpress/content/tag.rb +12 -3
- data/lib/staticpress/content/theme.rb +17 -19
- data/lib/staticpress/helpers.rb +4 -0
- data/lib/staticpress/route.rb +21 -95
- data/lib/staticpress/server.rb +1 -3
- data/lib/staticpress/site.rb +20 -16
- data/lib/staticpress/version.rb +1 -1
- data/tests/staticpress/configuration_test.rb +4 -0
- data/tests/staticpress/content/base_test.rb +271 -0
- data/tests/staticpress/content/category_test.rb +29 -0
- data/tests/staticpress/content/index_test.rb +6 -0
- data/tests/staticpress/content/page_test.rb +37 -0
- data/tests/staticpress/content/post_test.rb +45 -0
- data/tests/staticpress/content/tag_test.rb +33 -0
- data/tests/staticpress/content/theme_test.rb +29 -0
- data/tests/{lib/staticpress → staticpress}/helpers_test.rb +2 -2
- data/tests/staticpress/js_object_test.rb +43 -0
- data/tests/staticpress/metadata_test.rb +16 -0
- data/tests/staticpress/plugin_test.rb +4 -0
- data/tests/staticpress/pusher_test.rb +9 -0
- data/tests/{lib/staticpress → staticpress}/route_test.rb +19 -41
- data/tests/{lib/staticpress → staticpress}/server_test.rb +5 -14
- data/tests/staticpress/site_test.rb +21 -0
- data/tests/staticpress/theme_test.rb +86 -0
- data/tests/staticpress/view_helpers_test.rb +28 -0
- data/tests/{lib/staticpress_test.rb → staticpress_test.rb} +3 -3
- data/tests/{sample_sites/test_blog → test_blog}/Gemfile +0 -2
- data/tests/test_blog/README.markdown +21 -0
- data/tests/test_blog/config.ru +8 -0
- data/tests/{sample_sites/test_blog → test_blog}/config.yml +0 -0
- data/tests/{sample_sites/test_blog → test_blog}/content/_posts/2011-07-20-hello.markdown +0 -0
- data/tests/{sample_sites/test_blog → test_blog}/content/_posts/2011-08-01-announcing-staticpress.markdown +0 -0
- data/tests/{sample_sites/test_blog → test_blog}/content/_posts/2011-08-02-staticpress.markdown +0 -0
- data/tests/{sample_sites/test_blog → test_blog}/content/_posts/2011-08-06-blogging-with-staticpress.markdown +0 -0
- data/tests/{sample_sites/test_blog → test_blog}/content/_posts/2011-08-06-conferences.markdown +0 -0
- data/tests/{sample_sites/test_blog → test_blog}/content/_posts/2011-08-06-in-charlotte.markdown +0 -0
- data/tests/{sample_sites/test_blog → test_blog}/content/_posts/2011-08-20-forever.markdown +0 -0
- data/tests/{sample_sites/test_blog → test_blog}/content/about.markdown +0 -0
- data/tests/{sample_sites/test_blog → test_blog}/content/contact.markdown +0 -0
- data/tests/{sample_sites/test_blog → test_blog}/content/foo/bar/baz.markdown +0 -0
- data/tests/test_blog/content/index.markdown +1 -0
- data/tests/{sample_sites/test_blog → test_blog}/content/plain.txt +0 -0
- data/tests/{sample_sites/test_blog → test_blog}/content/ruby.png +0 -0
- data/tests/{sample_sites/test_blog → test_blog}/content/style1.css +0 -0
- data/tests/{sample_sites/test_blog → test_blog}/content/style2.css.sass +0 -0
- data/tests/{sample_sites/test_blog → test_blog}/content/style3.sass +0 -0
- data/tests/{sample_sites/test_blog → test_blog}/themes/test_theme/assets/scripts/application.js +0 -0
- data/tests/{sample_sites/test_blog → test_blog}/themes/test_theme/assets/styles/all.sass +0 -0
- data/tests/{sample_sites/test_blog → test_blog}/themes/test_theme/includes/list_posts.haml +0 -0
- data/tests/{sample_sites/test_blog → test_blog}/themes/test_theme/layouts/archive.haml +0 -0
- data/tests/{sample_sites/test_blog → test_blog}/themes/test_theme/layouts/atom.haml +0 -0
- data/tests/{sample_sites/test_blog → test_blog}/themes/test_theme/layouts/default.haml +0 -0
- data/tests/{sample_sites/test_blog → test_blog}/themes/test_theme/layouts/index.haml +0 -0
- data/tests/{sample_sites/test_blog → test_blog}/themes/test_theme/layouts/post_index.haml +0 -0
- data/tests/{sample_sites/test_blog → test_blog}/themes/test_theme/views/default.haml +0 -0
- data/tests/{test_helper.rb → test_case.rb} +9 -5
- metadata +81 -73
- metadata.gz.sig +0 -0
- data/tests/lib/staticpress/configuration_test.rb +0 -4
- data/tests/lib/staticpress/content/base_test.rb +0 -6
- data/tests/lib/staticpress/content/category_test.rb +0 -62
- data/tests/lib/staticpress/content/index_test.rb +0 -45
- data/tests/lib/staticpress/content/page_test.rb +0 -147
- data/tests/lib/staticpress/content/post_test.rb +0 -89
- data/tests/lib/staticpress/content/tag_test.rb +0 -60
- data/tests/lib/staticpress/content/theme_test.rb +0 -114
- data/tests/lib/staticpress/js_object_test.rb +0 -45
- data/tests/lib/staticpress/metadata_test.rb +0 -19
- data/tests/lib/staticpress/plugin_test.rb +0 -4
- data/tests/lib/staticpress/pusher_test.rb +0 -9
- data/tests/lib/staticpress/site_test.rb +0 -26
- data/tests/lib/staticpress/theme_test.rb +0 -86
- data/tests/lib/staticpress/view_helpers_test.rb +0 -33
data.tar.gz.sig
CHANGED
Binary file
|
data/docs/Gemfile
ADDED
File without changes
|
File without changes
|
data/docs/config.yml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# Zero To Blogging
|
2
|
+
|
3
|
+
## Pre-requisites
|
4
|
+
|
5
|
+
Staticpress is written in Ruby, so the first thing you will need is a Ruby interpreter. Chances are you have one on your system already, but if not the [official site can get you setup](http://www.ruby-lang.org/en/). Ruby comes with a package manager called RubyGem (gem) that makes installing Ruby libraries (known as gems) super easy.
|
6
|
+
|
7
|
+
Once you have Ruby, open a terminal and type `gem install staticpress`. This command installs Staticpress so you can use it. Staticpress is a command line application, so leave your terminal open. If you ever get stuck and need a quick tip, run `staticpress help [task]`.
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
When you want to create a new Staticpress blog, simply run `staticpress new <path-to-blog> [name-of-blog]`. Staticpress will create the `<path-to-blog>` for you if it does not exist. `[name-of-blog]` is optional. If you leave it out, Staticpress will make up a blog name from `<path-to-blog>`. Either way, `cd` into `<path-to-blog>`; this will be the place you need to be for all the other commands to work. By the way Staticpress uses several conventions to keep things simple. For instance many commands you are asked to type on the terminal take parameters. Required parameters will `<look-like-this>`, while optional parameters will `[look-like-this]`.
|
12
|
+
|
13
|
+
## Hello, World
|
14
|
+
|
15
|
+
After creating a new blog, you will probably want to create a new post. Type `staticpress create <title>` to create a new post. Staticpress will create a new empty post in `content/_posts/`. Open this file with your favorite text editor and start pontificating. When your are done, type `staticpress serve` to turn on the local development server. Open your favorite browser and navigate to [http://localhost:4000/](http://localhost:4000) to preview your post. Congratulations!
|
@@ -0,0 +1 @@
|
|
1
|
+
hello
|
data/features/happy_path.feature
CHANGED
@@ -9,6 +9,10 @@ Feature: The happy path
|
|
9
9
|
Then the exit status should be 0
|
10
10
|
And the output should contain "Usage"
|
11
11
|
|
12
|
+
Given I run `staticpress -h`
|
13
|
+
Then the exit status should be 0
|
14
|
+
And the output should contain "Usage"
|
15
|
+
|
12
16
|
Given I run `staticpress --help`
|
13
17
|
Then the exit status should be 0
|
14
18
|
And the output should contain "Usage"
|
@@ -17,6 +21,10 @@ Feature: The happy path
|
|
17
21
|
Then the exit status should be 0
|
18
22
|
And the output should contain "Staticpress"
|
19
23
|
|
24
|
+
Given I run `staticpress -v`
|
25
|
+
Then the exit status should be 0
|
26
|
+
And the output should contain "Staticpress"
|
27
|
+
|
20
28
|
Given I run `staticpress --version`
|
21
29
|
Then the exit status should be 0
|
22
30
|
And the output should contain "Staticpress"
|
@@ -71,7 +79,7 @@ Feature: The happy path
|
|
71
79
|
|
72
80
|
Scenario: Listing all routes
|
73
81
|
Given a blog with content exists
|
74
|
-
When I run `staticpress list
|
82
|
+
When I run `staticpress list url_path`
|
75
83
|
Then the output should contain "/"
|
76
84
|
And the output should contain "/about"
|
77
85
|
And the output should contain "/hello-goodbye"
|
@@ -85,6 +93,33 @@ Feature: The happy path
|
|
85
93
|
| public/index.html |
|
86
94
|
| public/about/index.html |
|
87
95
|
|
96
|
+
Scenario: Building a site a custom homepage
|
97
|
+
Given a blog with content exists
|
98
|
+
And I write to "content/index.markdown" with:
|
99
|
+
"""
|
100
|
+
---
|
101
|
+
title: Custom Home Page
|
102
|
+
---
|
103
|
+
in custom page
|
104
|
+
"""
|
105
|
+
When I run `staticpress build`
|
106
|
+
Then the file "public/index.html" should contain exactly:
|
107
|
+
"""
|
108
|
+
<!DOCTYPE html>
|
109
|
+
<html>
|
110
|
+
<head>
|
111
|
+
<title>Custom Home Page | Transient Thoughts</title>
|
112
|
+
<link href='/assets/basic/styles/all.css' rel='stylesheet' type='text/css' />
|
113
|
+
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js'></script>
|
114
|
+
<script src='/assets/basic/scripts/application.js'></script>
|
115
|
+
</head>
|
116
|
+
<body>
|
117
|
+
<p>in custom page</p>
|
118
|
+
</body>
|
119
|
+
</html>
|
120
|
+
|
121
|
+
"""
|
122
|
+
|
88
123
|
Scenario: Pushing a compiled site to a remote location
|
89
124
|
Given a blog with content exists
|
90
125
|
And the blog has been previously built
|
data/lib/skeleton/Gemfile
CHANGED
data/lib/staticpress/booter.rb
CHANGED
data/lib/staticpress/cli.rb
CHANGED
@@ -20,8 +20,8 @@ module Staticpress
|
|
20
20
|
|
21
21
|
default_task :help
|
22
22
|
|
23
|
-
map '--help' => :help
|
24
|
-
map '--version' => :version
|
23
|
+
map ['-h', '--help'] => :help
|
24
|
+
map ['-v', '--version'] => :version
|
25
25
|
|
26
26
|
desc 'help [task]', 'Describe available tasks or one specific task'
|
27
27
|
def help(*args)
|
@@ -5,6 +5,7 @@ require 'yaml'
|
|
5
5
|
|
6
6
|
require 'staticpress'
|
7
7
|
require 'staticpress/metadata'
|
8
|
+
require 'staticpress/route'
|
8
9
|
require 'staticpress/theme'
|
9
10
|
require 'staticpress/view_helpers'
|
10
11
|
|
@@ -13,15 +14,25 @@ module Staticpress::Content
|
|
13
14
|
extend Staticpress::Helpers
|
14
15
|
include Staticpress::Helpers
|
15
16
|
|
16
|
-
attr_reader :
|
17
|
+
attr_reader :params
|
17
18
|
|
18
|
-
def initialize(
|
19
|
-
|
20
|
-
|
19
|
+
def initialize(params)
|
20
|
+
clean_params = params.select { |key, value| value }.map do |key, value|
|
21
|
+
cast_value = case Staticpress::Route::REGEX_STUBS[key].klass
|
22
|
+
when :integer then Integer value rescue value
|
23
|
+
when :symbol then value.to_sym
|
24
|
+
else value
|
25
|
+
end
|
26
|
+
|
27
|
+
[ key, cast_value ]
|
28
|
+
end
|
29
|
+
|
30
|
+
@params = optional_param_defaults.merge Hash[clean_params]
|
21
31
|
end
|
22
32
|
|
23
33
|
def ==(other)
|
24
|
-
other.respond_to?(:
|
34
|
+
other.respond_to?(:params) && (params == other.params) &&
|
35
|
+
other.respond_to?(:url_path) && (url_path == other.url_path)
|
25
36
|
end
|
26
37
|
|
27
38
|
def content
|
@@ -43,12 +54,12 @@ module Staticpress::Content
|
|
43
54
|
template_path.file?
|
44
55
|
end
|
45
56
|
|
46
|
-
def
|
47
|
-
|
48
|
-
|
49
|
-
|
57
|
+
def full_title
|
58
|
+
[
|
59
|
+
title,
|
60
|
+
config.title
|
61
|
+
].join config.title_separators.site
|
50
62
|
end
|
51
|
-
alias to_s inspect
|
52
63
|
|
53
64
|
def layout
|
54
65
|
if meta.layout || config.markup_templates.include?(template_path.extname[1..-1])
|
@@ -61,8 +72,12 @@ module Staticpress::Content
|
|
61
72
|
Staticpress::Metadata.new(content.names.include?('frontmatter') ? YAML.load(content[:frontmatter]) : {})
|
62
73
|
end
|
63
74
|
|
75
|
+
def optional_param_defaults
|
76
|
+
{}
|
77
|
+
end
|
78
|
+
|
64
79
|
def output_path
|
65
|
-
base = Staticpress.blog_path + config.destination_path +
|
80
|
+
base = Staticpress.blog_path + config.destination_path + url_path.sub(/^\//, '')
|
66
81
|
(config.index_file && config.markup_templates.include?(template_path.extname[1..-1])) ? base + config.index_file : base
|
67
82
|
end
|
68
83
|
|
@@ -86,8 +101,10 @@ module Staticpress::Content
|
|
86
101
|
end
|
87
102
|
|
88
103
|
def save
|
89
|
-
|
90
|
-
|
104
|
+
unless output_path.file?
|
105
|
+
FileUtils.mkdir_p output_path.dirname
|
106
|
+
output_path.open('w') { |f| f.write render }
|
107
|
+
end
|
91
108
|
end
|
92
109
|
|
93
110
|
def template_context
|
@@ -110,23 +127,49 @@ module Staticpress::Content
|
|
110
127
|
self.class.theme
|
111
128
|
end
|
112
129
|
|
113
|
-
def full_title
|
114
|
-
[
|
115
|
-
title,
|
116
|
-
config.title
|
117
|
-
].join config.title_separators.site
|
118
|
-
end
|
119
|
-
|
120
130
|
def title
|
121
131
|
if meta.title
|
122
132
|
meta.title
|
123
133
|
else
|
124
|
-
titleize(
|
134
|
+
titleize(url_path)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
def to_s
|
139
|
+
"#<#{self.class} url_path=#{url_path}, params=#{Hash[params.sort]}>"
|
140
|
+
end
|
141
|
+
|
142
|
+
def url_path
|
143
|
+
# grab url pattern for content type
|
144
|
+
pattern = config.routes[self.class.type].clone
|
145
|
+
|
146
|
+
# regex to find optional segment in pattern
|
147
|
+
# NOTE cannot find more than one optional segment per pattern
|
148
|
+
optional_segment_finder = /\((?<optional_segment>.+)\)\?/
|
149
|
+
|
150
|
+
# replace optional segment in pattern with result of block
|
151
|
+
# optional segments should have one keys
|
152
|
+
pattern.gsub! optional_segment_finder do |optional_segment|
|
153
|
+
# http://www.rubular.com/r/LiOup53CI1
|
154
|
+
# http://www.rubular.com/r/TE7E9ZdtKF
|
155
|
+
|
156
|
+
# grab the key from optional segment
|
157
|
+
optional_key = /:(?<optional_key>[0-9a-z_]+)/.match(optional_segment)[:optional_key].to_sym
|
158
|
+
|
159
|
+
# if params has the optional key and params optional key is not the key's default, remove optional segment indicators
|
160
|
+
# otherwise return nil to remove optional segment entirely
|
161
|
+
optional_segment_finder.match(optional_segment)[:optional_segment] if params[optional_key] && (params[optional_key] != optional_param_defaults[optional_key])
|
162
|
+
end
|
163
|
+
|
164
|
+
# actually do conversion from pattern to url path
|
165
|
+
Staticpress::Route::REGEX_STUBS.keys.inject(pattern) do |p, key|
|
166
|
+
p.gsub /:#{key}/, params[key].to_s
|
125
167
|
end
|
126
168
|
end
|
127
169
|
|
128
|
-
def self.
|
129
|
-
|
170
|
+
def self.find_by_url_path(url_path)
|
171
|
+
params = Staticpress::Route.extract_params config.routes[type], url_path
|
172
|
+
new params if params
|
130
173
|
end
|
131
174
|
|
132
175
|
def self.theme
|
@@ -1,19 +1,28 @@
|
|
1
1
|
require 'staticpress'
|
2
2
|
require 'staticpress/content/base'
|
3
3
|
require 'staticpress/content/collection_content'
|
4
|
-
require 'staticpress/
|
4
|
+
require 'staticpress/content/resource_content'
|
5
5
|
|
6
6
|
module Staticpress::Content
|
7
7
|
class Category < Base
|
8
8
|
extend CollectionContent
|
9
|
+
extend ResourceContent
|
10
|
+
|
11
|
+
def optional_param_defaults
|
12
|
+
{ :number => 1 }
|
13
|
+
end
|
9
14
|
|
10
15
|
def sub_content
|
11
|
-
paginate(self.class.content_by_category[
|
16
|
+
paginate(self.class.content_by_category[params[:name]].sort)[params[:number] - 1]
|
17
|
+
end
|
18
|
+
|
19
|
+
def template_path
|
20
|
+
self.class.template_path
|
12
21
|
end
|
13
22
|
|
14
23
|
def self.all
|
15
24
|
categories.map do |category|
|
16
|
-
|
25
|
+
new :name => category, :number => '1'
|
17
26
|
end
|
18
27
|
end
|
19
28
|
|
@@ -1,19 +1,26 @@
|
|
1
1
|
require 'staticpress'
|
2
2
|
require 'staticpress/content/base'
|
3
3
|
require 'staticpress/content/collection_content'
|
4
|
-
require 'staticpress/route'
|
5
4
|
|
6
5
|
module Staticpress::Content
|
7
6
|
class Index < Base
|
8
7
|
extend CollectionContent
|
9
8
|
|
9
|
+
def optional_param_defaults
|
10
|
+
{ :number => 1 }
|
11
|
+
end
|
12
|
+
|
10
13
|
def sub_content
|
11
|
-
paginate(Staticpress::Content::Post.all)[
|
14
|
+
paginate(Staticpress::Content::Post.all)[params[:number] - 1]
|
15
|
+
end
|
16
|
+
|
17
|
+
def template_path
|
18
|
+
self.class.template_path
|
12
19
|
end
|
13
20
|
|
14
21
|
def self.all
|
15
22
|
[
|
16
|
-
|
23
|
+
new(:number => '1')
|
17
24
|
]
|
18
25
|
end
|
19
26
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
1
3
|
require 'staticpress'
|
2
4
|
require 'staticpress/content/base'
|
3
5
|
require 'staticpress/content/resource_content'
|
@@ -7,11 +9,36 @@ require 'staticpress/route'
|
|
7
9
|
module Staticpress::Content
|
8
10
|
class Page < Base
|
9
11
|
include StaticContent
|
12
|
+
include ResourceContent
|
10
13
|
extend ResourceContent
|
11
14
|
extend StaticContent
|
12
15
|
|
16
|
+
attr_reader :extension, :full_slug
|
17
|
+
|
18
|
+
def initialize(params)
|
19
|
+
super
|
20
|
+
|
21
|
+
index = extensionless_basename Pathname.new(config.index_file)
|
22
|
+
|
23
|
+
@full_slug = params[:slug]
|
24
|
+
@extension = find_supported_extension(Staticpress.blog_path + config.source_path + full_slug)
|
25
|
+
|
26
|
+
if @extension.nil? && !template_path.file?
|
27
|
+
@full_slug = [
|
28
|
+
params[:slug],
|
29
|
+
index
|
30
|
+
].reject(&:empty?).join('/')
|
31
|
+
@extension = find_supported_extension(Staticpress.blog_path + config.source_path + full_slug)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
13
35
|
def static?
|
14
|
-
(Staticpress.blog_path + config.source_path +
|
36
|
+
(Staticpress.blog_path + config.source_path + params[:slug]).file?
|
37
|
+
end
|
38
|
+
|
39
|
+
def template_path
|
40
|
+
slug = extension ? "#{full_slug}.#{extension}" : full_slug
|
41
|
+
Staticpress.blog_path + config.source_path + slug
|
15
42
|
end
|
16
43
|
|
17
44
|
def self.all
|
@@ -36,25 +63,13 @@ module Staticpress::Content
|
|
36
63
|
|
37
64
|
def self.find_by_path(path)
|
38
65
|
if path.file?
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
find_by_route Staticpress::Route.new(params)
|
66
|
+
raw_slug = parse_slug(path, (Staticpress.blog_path + config.source_path)).first
|
67
|
+
basename = extensionless_basename Pathname.new(config.index_file)
|
68
|
+
slug = raw_slug.sub(/.*(\/?#{basename})$/, '')
|
69
|
+
new :slug => slug
|
45
70
|
end
|
46
71
|
end
|
47
72
|
|
48
|
-
def self.find_by_route(route)
|
49
|
-
return nil unless route
|
50
|
-
|
51
|
-
base = Staticpress.blog_path + config.source_path
|
52
|
-
path = base + route.params[:slug]
|
53
|
-
return new(route, path) if path.file?
|
54
|
-
|
55
|
-
load_resource route, base, route.params[:slug]
|
56
|
-
end
|
57
|
-
|
58
73
|
def self.template
|
59
74
|
<<-TEMPLATE
|
60
75
|
in page
|
@@ -5,8 +5,16 @@ require 'staticpress/route'
|
|
5
5
|
|
6
6
|
module Staticpress::Content
|
7
7
|
class Post < Base
|
8
|
+
include ResourceContent
|
8
9
|
extend ResourceContent
|
9
10
|
|
11
|
+
attr_reader :extension
|
12
|
+
|
13
|
+
def initialize(params)
|
14
|
+
super
|
15
|
+
@extension = find_supported_extension template_path
|
16
|
+
end
|
17
|
+
|
10
18
|
def <=>(other)
|
11
19
|
other.respond_to?(:created_at) ? (created_at <=> other.created_at) : super
|
12
20
|
end
|
@@ -16,15 +24,24 @@ module Staticpress::Content
|
|
16
24
|
end
|
17
25
|
|
18
26
|
def created_on
|
19
|
-
|
20
|
-
|
27
|
+
Time.utc params[:year], params[:month], params[:day]
|
28
|
+
end
|
29
|
+
|
30
|
+
def template_path
|
31
|
+
name = [
|
32
|
+
params[:year],
|
33
|
+
params[:month],
|
34
|
+
params[:day],
|
35
|
+
(extension ? "#{params[:title]}.#{extension}" : params[:title])
|
36
|
+
].join('-')
|
37
|
+
Staticpress.blog_path + config.posts_source_path + name
|
21
38
|
end
|
22
39
|
|
23
40
|
def title
|
24
41
|
if meta.title
|
25
42
|
meta.title
|
26
43
|
else
|
27
|
-
titleize(
|
44
|
+
titleize(params[:title])
|
28
45
|
end
|
29
46
|
end
|
30
47
|
|
@@ -51,36 +68,14 @@ module Staticpress::Content
|
|
51
68
|
def self.find_by_path(path)
|
52
69
|
if path.file?
|
53
70
|
stubs = Staticpress::Route::REGEX_STUBS
|
54
|
-
regex = /#{stubs[:year].regex}-#{stubs[:month].regex}-#{stubs[:day].regex}-#{stubs[:title].regex}/
|
71
|
+
regex = /#{stubs[:year].regex}-#{stubs[:month].regex}-#{stubs[:day].regex}-#{stubs[:title].regex}\.(.+)/
|
55
72
|
|
56
73
|
if filename_parts = path.basename.to_s.match(regex)
|
57
|
-
|
58
|
-
:content_type => self,
|
59
|
-
:year => filename_parts[:year],
|
60
|
-
:month => filename_parts[:month],
|
61
|
-
:day => filename_parts[:day],
|
62
|
-
:title => filename_parts[:title]
|
63
|
-
}
|
64
|
-
find_by_route Staticpress::Route.new(params)
|
74
|
+
new hash_from_match_data(filename_parts)
|
65
75
|
end
|
66
76
|
end
|
67
77
|
end
|
68
78
|
|
69
|
-
def self.find_by_route(route)
|
70
|
-
return nil unless route
|
71
|
-
|
72
|
-
base = Staticpress.blog_path + config.posts_source_path
|
73
|
-
parts = route.params
|
74
|
-
stub = [
|
75
|
-
parts[:year],
|
76
|
-
parts[:month],
|
77
|
-
parts[:day],
|
78
|
-
parts[:title]
|
79
|
-
].join '-'
|
80
|
-
|
81
|
-
load_resource route, base, stub
|
82
|
-
end
|
83
|
-
|
84
79
|
def self.template
|
85
80
|
now = Time.now.utc
|
86
81
|
|