staticpress 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. data.tar.gz.sig +0 -0
  2. data/docs/Gemfile +8 -0
  3. data/{tests/sample_sites/test_blog → docs}/README.markdown +0 -0
  4. data/{tests/sample_sites/test_blog → docs}/config.ru +0 -0
  5. data/docs/config.yml +2 -0
  6. data/docs/content/docs/diving-deeper.markdown +3 -0
  7. data/docs/content/docs/setup.markdown +15 -0
  8. data/docs/content/index.markdown +1 -0
  9. data/features/happy_path.feature +36 -1
  10. data/features/step_definitions/staticpress_steps.rb +1 -1
  11. data/lib/skeleton/Gemfile +0 -2
  12. data/lib/staticpress/booter.rb +1 -1
  13. data/lib/staticpress/cli.rb +2 -2
  14. data/lib/staticpress/content/base.rb +66 -23
  15. data/lib/staticpress/content/category.rb +12 -3
  16. data/lib/staticpress/content/collection_content.rb +0 -4
  17. data/lib/staticpress/content/index.rb +10 -3
  18. data/lib/staticpress/content/page.rb +32 -17
  19. data/lib/staticpress/content/post.rb +22 -27
  20. data/lib/staticpress/content/resource_content.rb +11 -3
  21. data/lib/staticpress/content/static_content.rb +10 -4
  22. data/lib/staticpress/content/tag.rb +12 -3
  23. data/lib/staticpress/content/theme.rb +17 -19
  24. data/lib/staticpress/helpers.rb +4 -0
  25. data/lib/staticpress/route.rb +21 -95
  26. data/lib/staticpress/server.rb +1 -3
  27. data/lib/staticpress/site.rb +20 -16
  28. data/lib/staticpress/version.rb +1 -1
  29. data/tests/staticpress/configuration_test.rb +4 -0
  30. data/tests/staticpress/content/base_test.rb +271 -0
  31. data/tests/staticpress/content/category_test.rb +29 -0
  32. data/tests/staticpress/content/index_test.rb +6 -0
  33. data/tests/staticpress/content/page_test.rb +37 -0
  34. data/tests/staticpress/content/post_test.rb +45 -0
  35. data/tests/staticpress/content/tag_test.rb +33 -0
  36. data/tests/staticpress/content/theme_test.rb +29 -0
  37. data/tests/{lib/staticpress → staticpress}/helpers_test.rb +2 -2
  38. data/tests/staticpress/js_object_test.rb +43 -0
  39. data/tests/staticpress/metadata_test.rb +16 -0
  40. data/tests/staticpress/plugin_test.rb +4 -0
  41. data/tests/staticpress/pusher_test.rb +9 -0
  42. data/tests/{lib/staticpress → staticpress}/route_test.rb +19 -41
  43. data/tests/{lib/staticpress → staticpress}/server_test.rb +5 -14
  44. data/tests/staticpress/site_test.rb +21 -0
  45. data/tests/staticpress/theme_test.rb +86 -0
  46. data/tests/staticpress/view_helpers_test.rb +28 -0
  47. data/tests/{lib/staticpress_test.rb → staticpress_test.rb} +3 -3
  48. data/tests/{sample_sites/test_blog → test_blog}/Gemfile +0 -2
  49. data/tests/test_blog/README.markdown +21 -0
  50. data/tests/test_blog/config.ru +8 -0
  51. data/tests/{sample_sites/test_blog → test_blog}/config.yml +0 -0
  52. data/tests/{sample_sites/test_blog → test_blog}/content/_posts/2011-07-20-hello.markdown +0 -0
  53. data/tests/{sample_sites/test_blog → test_blog}/content/_posts/2011-08-01-announcing-staticpress.markdown +0 -0
  54. data/tests/{sample_sites/test_blog → test_blog}/content/_posts/2011-08-02-staticpress.markdown +0 -0
  55. data/tests/{sample_sites/test_blog → test_blog}/content/_posts/2011-08-06-blogging-with-staticpress.markdown +0 -0
  56. data/tests/{sample_sites/test_blog → test_blog}/content/_posts/2011-08-06-conferences.markdown +0 -0
  57. data/tests/{sample_sites/test_blog → test_blog}/content/_posts/2011-08-06-in-charlotte.markdown +0 -0
  58. data/tests/{sample_sites/test_blog → test_blog}/content/_posts/2011-08-20-forever.markdown +0 -0
  59. data/tests/{sample_sites/test_blog → test_blog}/content/about.markdown +0 -0
  60. data/tests/{sample_sites/test_blog → test_blog}/content/contact.markdown +0 -0
  61. data/tests/{sample_sites/test_blog → test_blog}/content/foo/bar/baz.markdown +0 -0
  62. data/tests/test_blog/content/index.markdown +1 -0
  63. data/tests/{sample_sites/test_blog → test_blog}/content/plain.txt +0 -0
  64. data/tests/{sample_sites/test_blog → test_blog}/content/ruby.png +0 -0
  65. data/tests/{sample_sites/test_blog → test_blog}/content/style1.css +0 -0
  66. data/tests/{sample_sites/test_blog → test_blog}/content/style2.css.sass +0 -0
  67. data/tests/{sample_sites/test_blog → test_blog}/content/style3.sass +0 -0
  68. data/tests/{sample_sites/test_blog → test_blog}/themes/test_theme/assets/scripts/application.js +0 -0
  69. data/tests/{sample_sites/test_blog → test_blog}/themes/test_theme/assets/styles/all.sass +0 -0
  70. data/tests/{sample_sites/test_blog → test_blog}/themes/test_theme/includes/list_posts.haml +0 -0
  71. data/tests/{sample_sites/test_blog → test_blog}/themes/test_theme/layouts/archive.haml +0 -0
  72. data/tests/{sample_sites/test_blog → test_blog}/themes/test_theme/layouts/atom.haml +0 -0
  73. data/tests/{sample_sites/test_blog → test_blog}/themes/test_theme/layouts/default.haml +0 -0
  74. data/tests/{sample_sites/test_blog → test_blog}/themes/test_theme/layouts/index.haml +0 -0
  75. data/tests/{sample_sites/test_blog → test_blog}/themes/test_theme/layouts/post_index.haml +0 -0
  76. data/tests/{sample_sites/test_blog → test_blog}/themes/test_theme/views/default.haml +0 -0
  77. data/tests/{test_helper.rb → test_case.rb} +9 -5
  78. metadata +81 -73
  79. metadata.gz.sig +0 -0
  80. data/tests/lib/staticpress/configuration_test.rb +0 -4
  81. data/tests/lib/staticpress/content/base_test.rb +0 -6
  82. data/tests/lib/staticpress/content/category_test.rb +0 -62
  83. data/tests/lib/staticpress/content/index_test.rb +0 -45
  84. data/tests/lib/staticpress/content/page_test.rb +0 -147
  85. data/tests/lib/staticpress/content/post_test.rb +0 -89
  86. data/tests/lib/staticpress/content/tag_test.rb +0 -60
  87. data/tests/lib/staticpress/content/theme_test.rb +0 -114
  88. data/tests/lib/staticpress/js_object_test.rb +0 -45
  89. data/tests/lib/staticpress/metadata_test.rb +0 -19
  90. data/tests/lib/staticpress/plugin_test.rb +0 -4
  91. data/tests/lib/staticpress/pusher_test.rb +0 -9
  92. data/tests/lib/staticpress/site_test.rb +0 -26
  93. data/tests/lib/staticpress/theme_test.rb +0 -86
  94. data/tests/lib/staticpress/view_helpers_test.rb +0 -33
data.tar.gz.sig CHANGED
Binary file
data/docs/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source :rubygems
2
+
3
+ gem 'staticpress', :path => '..'
4
+
5
+ gem 'compass'
6
+ gem 'haml'
7
+ gem 'rdiscount'
8
+ gem 'sass'
File without changes
data/docs/config.yml ADDED
@@ -0,0 +1,2 @@
1
+ ---
2
+ :title: Staticpress Documentation
@@ -0,0 +1,3 @@
1
+ # Diving Deeper
2
+
3
+
@@ -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
@@ -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 route`
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
@@ -7,7 +7,7 @@ Given /^a blog exists$/ do
7
7
  end
8
8
 
9
9
  Given /^a blog with content exists$/ do
10
- step("a blog exists")
10
+ step('a blog exists')
11
11
  Staticpress::CLI.new.create_page('about')
12
12
  Staticpress::CLI.new.create('hello-goodbye')
13
13
  end
data/lib/skeleton/Gemfile CHANGED
@@ -5,6 +5,4 @@ gem 'staticpress'
5
5
  gem 'compass'
6
6
  gem 'haml'
7
7
  gem 'rdiscount'
8
- gem 'rubypants'
9
- gem 'RedCloth'
10
8
  gem 'sass'
@@ -1,6 +1,6 @@
1
1
  ENV['BUNDLE_GEMFILE'] ||= File.expand_path('./Gemfile')
2
2
 
3
- if File.exists?(ENV['BUNDLE_GEMFILE']) && !defined? Bundler
3
+ if File.exists?(ENV['BUNDLE_GEMFILE'])
4
4
  require 'bundler'
5
5
 
6
6
  Bundler.require
@@ -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 :route, :template_path
17
+ attr_reader :params
17
18
 
18
- def initialize(route, template_path)
19
- @route = route
20
- @template_path = template_path
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?(:route) && (route == other.route)
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 inspect
47
- parts = [ "url_path=#{route.url_path}" ]
48
-
49
- "#<#{self.class} #{parts.join ', '}>"
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 + route.url_path.sub(/^\//, '')
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
- FileUtils.mkdir_p output_path.dirname
90
- output_path.open('w') { |f| f.write render }
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(route.url_path)
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.supported_extensions
129
- Tilt.mappings.keys.map &:to_sym
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/route'
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[route.params[:name]].sort)[(Integer route.params[:number]) - 1]
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
- find_by_route Staticpress::Route.new(:content_type => self, :name => category, :number => '1')
25
+ new :name => category, :number => '1'
17
26
  end
18
27
  end
19
28
 
@@ -2,10 +2,6 @@ require 'staticpress'
2
2
 
3
3
  module Staticpress::Content
4
4
  module CollectionContent
5
- def find_by_route(route)
6
- new(route, template_path)
7
- end
8
-
9
5
  def template_path
10
6
  theme.view_for(type) || theme.view_for(:default)
11
7
  end
@@ -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)[(Integer route.params[:number]) - 1]
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
- (find_by_route Staticpress::Route.new(:content_type => self, :number => '1'))
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 + route.params[:slug]).file?
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
- params = {
40
- :content_type => self,
41
- :slug => parse_slug(path, (Staticpress.blog_path + config.source_path))
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
- date = route.params
20
- Time.utc date[:year], date[:month], date[:day]
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(route.params[:title])
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
- params = {
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