staticpress 0.6.2 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/NOTES.markdown +23 -0
- data/Rakefile +1 -6
- data/docs/content/docs/plugins/pagination.haml +30 -0
- data/docs/content/docs/samples/page.markdown +14 -0
- data/docs/content/docs/samples/post.markdown +18 -0
- data/docs/content/docs/themes.markdown +47 -0
- data/lib/skeleton/config.yml +1 -0
- data/lib/staticpress/cli.rb +5 -9
- data/lib/staticpress/content/base.rb +8 -10
- data/lib/staticpress/content/category.rb +17 -4
- data/lib/staticpress/content/collection_content.rb +1 -3
- data/lib/staticpress/content/index.rb +6 -3
- data/lib/staticpress/content/page.rb +4 -0
- data/lib/staticpress/content/post.rb +4 -1
- data/lib/staticpress/content/resource_content.rb +2 -8
- data/lib/staticpress/content/tag.rb +17 -4
- data/lib/staticpress/content/theme.rb +1 -1
- data/lib/staticpress/helpers.rb +5 -5
- data/lib/staticpress/plugins/menu.rb +1 -1
- data/lib/staticpress/plugins/pagination.rb +38 -0
- data/lib/staticpress/theme.rb +45 -17
- data/lib/staticpress/version.rb +1 -1
- data/lib/themes/basic/includes/github.haml +2 -0
- data/lib/themes/basic/layouts/default.haml +1 -0
- data/lib/themes/basic/views/page_paged.haml +6 -0
- data/{tests → spec/fixtures}/test_blog/Gemfile +0 -0
- data/{tests → spec/fixtures}/test_blog/README.markdown +0 -0
- data/{tests → spec/fixtures}/test_blog/config.ru +0 -0
- data/{tests → spec/fixtures}/test_blog/config.yml +0 -0
- data/{tests → spec/fixtures}/test_blog/content/_posts/2011-07-20-hello.markdown +0 -0
- data/{tests → spec/fixtures}/test_blog/content/_posts/2011-08-01-announcing-staticpress.markdown +0 -0
- data/{tests → spec/fixtures}/test_blog/content/_posts/2011-08-02-staticpress.markdown +0 -0
- data/{tests → spec/fixtures}/test_blog/content/_posts/2011-08-06-blogging-with-staticpress.markdown +0 -0
- data/{tests → spec/fixtures}/test_blog/content/_posts/2011-08-06-conferences.markdown +0 -0
- data/{tests → spec/fixtures}/test_blog/content/_posts/2011-08-06-in-charlotte.markdown +0 -0
- data/{tests → spec/fixtures}/test_blog/content/_posts/2011-08-20-forever.markdown +0 -0
- data/{tests → spec/fixtures}/test_blog/content/_posts/2012-09-19-unpublished.markdown +0 -0
- data/{tests → spec/fixtures}/test_blog/content/about.markdown +0 -0
- data/{tests → spec/fixtures}/test_blog/content/chain.html.markdown.erb +0 -0
- data/{tests → spec/fixtures}/test_blog/content/chained.markdown.erb +0 -0
- data/{tests → spec/fixtures}/test_blog/content/contact.markdown +0 -0
- data/{tests → spec/fixtures}/test_blog/content/foo/bar/baz.markdown +0 -0
- data/{tests → spec/fixtures}/test_blog/content/index.markdown +0 -0
- data/{tests → spec/fixtures}/test_blog/content/plain.txt +0 -0
- data/{tests → spec/fixtures}/test_blog/content/ruby.png +0 -0
- data/{tests → spec/fixtures}/test_blog/content/style1.css +0 -0
- data/{tests → spec/fixtures}/test_blog/content/style2.css.sass +0 -0
- data/{tests → spec/fixtures}/test_blog/content/style3.sass +0 -0
- data/{tests → spec/fixtures}/test_blog/themes/test_theme/assets/scripts/application.js +0 -0
- data/{tests → spec/fixtures}/test_blog/themes/test_theme/assets/styles/all.sass +0 -0
- data/{tests → spec/fixtures}/test_blog/themes/test_theme/includes/list_posts.haml +0 -0
- data/{lib/themes/basic → spec/fixtures/test_blog/themes/test_theme}/layouts/archive.haml +0 -0
- data/{lib/themes/basic → spec/fixtures/test_blog/themes/test_theme}/layouts/atom.haml +0 -0
- data/{tests → spec/fixtures}/test_blog/themes/test_theme/layouts/default.haml +0 -0
- data/{tests → spec/fixtures}/test_blog/themes/test_theme/layouts/index.haml +0 -0
- data/{tests → spec/fixtures}/test_blog/themes/test_theme/layouts/post_index.haml +0 -0
- data/{tests → spec/fixtures}/test_blog/themes/test_theme/views/default.haml +0 -0
- data/spec/integration/editing_blog_contents_spec.rb +52 -0
- data/spec/integration/editing_blog_spec.rb +42 -0
- data/spec/integration/getting_started_spec.rb +29 -0
- data/spec/spec_helper.rb +35 -0
- data/spec/support/custom_matchers.rb +15 -0
- data/spec/support/fixtures.rb +35 -0
- data/spec/support/integration_support.rb +230 -0
- data/spec/support/unit_support.rb +18 -0
- data/spec/unit/staticpress/content/base_spec.rb +327 -0
- data/spec/unit/staticpress/content/category_spec.rb +60 -0
- data/spec/unit/staticpress/content/index_spec.rb +48 -0
- data/spec/unit/staticpress/content/page_spec.rb +70 -0
- data/spec/unit/staticpress/content/post_spec.rb +54 -0
- data/spec/unit/staticpress/content/resource_content_spec.rb +21 -0
- data/spec/unit/staticpress/content/tag_spec.rb +53 -0
- data/spec/unit/staticpress/content/theme_spec.rb +31 -0
- data/spec/unit/staticpress/helpers_spec.rb +72 -0
- data/spec/unit/staticpress/js_object_spec.rb +61 -0
- data/spec/unit/staticpress/metadata_spec.rb +15 -0
- data/spec/unit/staticpress/route_spec.rb +219 -0
- data/spec/unit/staticpress/server_spec.rb +23 -0
- data/spec/unit/staticpress/settings_spec.rb +19 -0
- data/spec/unit/staticpress/site_spec.rb +26 -0
- data/spec/unit/staticpress/theme_spec.rb +80 -0
- data/spec/unit/staticpress/view_helpers_spec.rb +40 -0
- data/spec/unit/staticpress_spec.rb +27 -0
- data/staticpress.gemspec +3 -4
- metadata +133 -136
- data/features/editing_blog.feature +0 -24
- data/features/editing_blog_contents.feature +0 -40
- data/features/getting_started.feature +0 -17
- data/features/step_definitions/editing_blog_contents_steps.rb +0 -128
- data/features/step_definitions/editing_blog_steps.rb +0 -52
- data/features/step_definitions/getting_started_steps.rb +0 -51
- data/features/support/env.rb +0 -30
- data/lib/themes/basic/layouts/post_index.haml +0 -15
- data/lib/themes/basic/views/default.haml +0 -10
- data/tests/staticpress/configuration_test.rb +0 -4
- data/tests/staticpress/content/base_test.rb +0 -291
- data/tests/staticpress/content/category_test.rb +0 -48
- data/tests/staticpress/content/index_test.rb +0 -40
- data/tests/staticpress/content/page_test.rb +0 -56
- data/tests/staticpress/content/post_test.rb +0 -42
- data/tests/staticpress/content/resource_content_test.rb +0 -17
- data/tests/staticpress/content/tag_test.rb +0 -39
- data/tests/staticpress/content/theme_test.rb +0 -26
- data/tests/staticpress/helpers_test.rb +0 -63
- data/tests/staticpress/js_object_test.rb +0 -47
- data/tests/staticpress/metadata_test.rb +0 -14
- data/tests/staticpress/plugin_test.rb +0 -4
- data/tests/staticpress/pusher_test.rb +0 -9
- data/tests/staticpress/route_test.rb +0 -186
- data/tests/staticpress/server_test.rb +0 -17
- data/tests/staticpress/settings_test.rb +0 -13
- data/tests/staticpress/site_test.rb +0 -20
- data/tests/staticpress/theme_test.rb +0 -83
- data/tests/staticpress/view_helpers_test.rb +0 -32
- data/tests/staticpress_test.rb +0 -18
- data/tests/test_blog/themes/test_theme/layouts/archive.haml +0 -0
- data/tests/test_blog/themes/test_theme/layouts/atom.haml +0 -0
- data/tests/test_case.rb +0 -54
data/NOTES.markdown
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
* .new passes params to #initialize
|
2
|
+
* #initialize manually calculates full path to template from params and populates @template_types
|
3
|
+
* Base#template_types is looped over in Base#render_partial
|
4
|
+
* Base#template_extension joins Base#template_types and prepends with . if not empty
|
5
|
+
* #template_path uses Base#template_extension to create full path to source
|
6
|
+
|
7
|
+
|
8
|
+
* http://chriseppstein.github.com/blog/2012/08/23/sass-3-2-is-released/
|
9
|
+
|
10
|
+
|
11
|
+
* http://jekyllbootstrap.com/
|
12
|
+
* http://vitobotta.com/how-to-migrate-from-wordpress-to-jekyll/
|
13
|
+
* http://vitobotta.com/sinatra-contact-form-jekyll/
|
14
|
+
|
15
|
+
* http://nanoc.stoneship.org/docs/
|
16
|
+
|
17
|
+
* https://github.com/darthapo/gumdrop
|
18
|
+
|
19
|
+
|
20
|
+
* https://npmjs.org/package/blake
|
21
|
+
* https://npmjs.org/package/punch
|
22
|
+
* https://npmjs.org/package/yassg
|
23
|
+
* https://npmjs.org/package/wintersmith
|
data/Rakefile
CHANGED
@@ -1,11 +1,6 @@
|
|
1
1
|
require 'bundler/gem_tasks'
|
2
|
-
require 'rake/testtask'
|
3
2
|
|
4
|
-
task :default => [ :
|
5
|
-
|
6
|
-
Rake::TestTask.new(:tests) do |t|
|
7
|
-
t.pattern = 'tests/**/*_test.rb'
|
8
|
-
end
|
3
|
+
task :default => [ :notes ]
|
9
4
|
|
10
5
|
desc 'Enumerate annotations. Optionally takes a pipe-separated list of tags to process'
|
11
6
|
task :notes, :types do |t, args|
|
@@ -0,0 +1,30 @@
|
|
1
|
+
---
|
2
|
+
menu:
|
3
|
+
position: 1.6.0
|
4
|
+
text: Pagination
|
5
|
+
---
|
6
|
+
|
7
|
+
%h1 Pagination
|
8
|
+
|
9
|
+
%table{ :style => 'border-collapse: separate; border-spacing: 0.5rem 0;' }
|
10
|
+
%caption / is the default page and is the same as /page/3. Post 1 is the oldest, Post 9 is the newest.
|
11
|
+
%thead
|
12
|
+
%tr
|
13
|
+
- ['/page/3', '/page/2', '/'].each do |th|
|
14
|
+
%th= th
|
15
|
+
%tfoot
|
16
|
+
%tr
|
17
|
+
%td past...
|
18
|
+
%td 1 2 3
|
19
|
+
%td ...future
|
20
|
+
%tbody
|
21
|
+
:ruby
|
22
|
+
pages = [
|
23
|
+
[1, 4, 7],
|
24
|
+
[2, 5, 8],
|
25
|
+
[3, 6, 9]
|
26
|
+
]
|
27
|
+
- pages.each do |tr|
|
28
|
+
%tr
|
29
|
+
- tr.each do |td|
|
30
|
+
%td Post #{td}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
---
|
2
|
+
title: Sample Staticpress Page
|
3
|
+
---
|
4
|
+
|
5
|
+
---
|
6
|
+
---
|
7
|
+
title: Sample Page
|
8
|
+
menu:
|
9
|
+
text: Alternate text for menu
|
10
|
+
position: 0
|
11
|
+
published: false
|
12
|
+
---
|
13
|
+
|
14
|
+
This page is written with markdown. Of course you could use any templating language you want.
|
@@ -0,0 +1,18 @@
|
|
1
|
+
---
|
2
|
+
title: Sample Staticpress Post
|
3
|
+
---
|
4
|
+
|
5
|
+
---
|
6
|
+
---
|
7
|
+
title: Sample Post
|
8
|
+
created_at: 2012-01-01 00:00:00 UTC
|
9
|
+
categories:
|
10
|
+
- one:
|
11
|
+
- nested
|
12
|
+
tags:
|
13
|
+
- one
|
14
|
+
- one
|
15
|
+
published: false
|
16
|
+
---
|
17
|
+
|
18
|
+
This post is written with markdown. Of course you could use any templating language you want.
|
@@ -5,3 +5,50 @@ menu:
|
|
5
5
|
---
|
6
6
|
|
7
7
|
# Themes
|
8
|
+
|
9
|
+
Themes determine the markup, look and behavior for a site. Markup is determined by Layouts and Views, while look and behavior is controlled via assets. Layouts provide general markup for the site title and global navigation. Views provide a template file for rendering generated content, such as a category page. Technically the `default` Layout and View are the only files required for a Theme, but providing a `post_paged` View is a good idea. Layouts and Views are looked up according to the preference table, however individual Posts and Pages can override their normal Layout by specifying `:layout` in frontmatter.
|
10
|
+
|
11
|
+
When rendering Staticpress selects an appropriate `template_path`, depending on what is being rendered. When a Page or Post is rendering (for instance `/about`), the `template_path` is the actual file in `content/` in the site. The Layout is selected according to the table, unless it is overridden on a case-by-case basis.
|
12
|
+
|
13
|
+
When Staticpress renders a generated page (for instance `/tags/programming`) the `template_path` is set to a View. The heuristic for selecting a View is the same as selecting a Layout. Again see the preference table.
|
14
|
+
|
15
|
+
Files inside the assets directory will be rendered similarly to static Page files when the site is generated or served. These files are pre-processed with Tilt (like all other files) so you can use whatever format you like.
|
16
|
+
|
17
|
+
|
18
|
+
## Layouts And Views Lookup
|
19
|
+
|
20
|
+
<table>
|
21
|
+
<thead>
|
22
|
+
<tr><th>File Name</th><th>Description</th><th>Example URL</th></tr>
|
23
|
+
</thead>
|
24
|
+
<tbody>
|
25
|
+
<tr><td>page </td><td>a page (Layout only) </td><td>/about</td></tr>
|
26
|
+
<tr><td>post </td><td>a single post (Layout only) </td><td>/2012/11/10/hello</td></tr>
|
27
|
+
<tr><td>category </td><td>generated page for all categories </td><td>/categories</td></tr>
|
28
|
+
<tr><td>tag </td><td>generated page for all tags </td><td>/tags</td></tr>
|
29
|
+
<tr><td>post_paged </td><td>use for paging through multiple posts </td><td>/page/3</td></tr>
|
30
|
+
<tr><td>category_paged, post_paged </td><td>use for paging through multiple posts in a specific category </td><td>/categories/programming/page/2</td></tr>
|
31
|
+
<tr><td>tag_paged, post_paged </td><td>use for paging through multiple posts in a specific tag </td><td>/tags/ruby/page/1</td></tr>
|
32
|
+
<tr><td>post_index, post_paged </td><td>use for paging through multiple posts when no page is specified </td><td>/</td></tr>
|
33
|
+
<tr><td>category_index, post_index, category_paged, post_paged </td><td>use for paging through multiple posts in a specific category when no page is specified </td><td>/categories/programming</td></tr>
|
34
|
+
<tr><td>tag_index, post_index, tag_paged, post_paged </td><td>use for paging through multiple posts in a specific tag when no page is specified </td><td>/tags/ruby</td></tr>
|
35
|
+
<tr><td>default </td><td>used if more specific Layout or View is not available </td><td></td></tr>
|
36
|
+
</tbody>
|
37
|
+
</table>
|
38
|
+
|
39
|
+
|
40
|
+
## Minimal Theme Layout
|
41
|
+
|
42
|
+
themes/<theme-name>/
|
43
|
+
├── assets/
|
44
|
+
│ ├── fonts/
|
45
|
+
│ ├── images/
|
46
|
+
│ ├── scripts/
|
47
|
+
│ │ └── application.js
|
48
|
+
│ └── styles/
|
49
|
+
│ └── application.css
|
50
|
+
├── layouts/
|
51
|
+
│ └── default.extension
|
52
|
+
└── views/
|
53
|
+
├── default.extension
|
54
|
+
└── post_paged.extension
|
data/lib/skeleton/config.yml
CHANGED
data/lib/staticpress/cli.rb
CHANGED
@@ -80,18 +80,14 @@ in config.yml
|
|
80
80
|
FileUtils.cp source, destination
|
81
81
|
end
|
82
82
|
|
83
|
-
desc 'fork_theme [theme-name]', 'Copies [theme-name]\'s files into <path-to-blog>/themes/[theme-name]'
|
83
|
+
desc 'fork_theme [theme-name] [new-theme-name]', 'Copies [theme-name]\'s files into <path-to-blog>/themes/[theme-name]'
|
84
84
|
long_desc <<-DESCRIPTION
|
85
85
|
Copies [theme-name]'s files into <path-to-blog>/themes/[theme-name] for
|
86
|
-
customizations. If [theme-name] is blank, copies the currently configured theme
|
86
|
+
customizations. If [theme-name] is blank, copies the currently configured theme. Specify a new name to copy to by passing both [theme-name] and [new-theme-name]
|
87
87
|
DESCRIPTION
|
88
|
-
def fork_theme(name =
|
89
|
-
|
90
|
-
|
91
|
-
destination = Staticpress.blog_path + 'themes' + theme_name
|
92
|
-
|
93
|
-
FileUtils.mkdir_p destination
|
94
|
-
FileUtils.cp_r source.children, destination
|
88
|
+
def fork_theme(name = config.theme, new_name = name)
|
89
|
+
theme = Staticpress::Theme.new name
|
90
|
+
theme.copy_to new_name
|
95
91
|
end
|
96
92
|
|
97
93
|
desc 'list [method]', 'Send [method] to every content and output the result, or list all content if [method] is not present'
|
@@ -35,18 +35,14 @@ module Staticpress::Content
|
|
35
35
|
|
36
36
|
regex_frontmatter = /^-{3}${1}(?<frontmatter>.*)^-{3}${1}/m
|
37
37
|
regex_text = /(?<text>.*)/m
|
38
|
-
regex =
|
38
|
+
regex = /(#{regex_frontmatter})?#{regex_text}/
|
39
39
|
|
40
40
|
c = template_path_content
|
41
41
|
|
42
42
|
@content = if Tilt.mappings.include?(template_path.extname[1..-1])
|
43
|
-
c.match
|
43
|
+
c.match regex
|
44
44
|
else
|
45
|
-
|
46
|
-
def reply.names
|
47
|
-
keys.map &:to_s
|
48
|
-
end
|
49
|
-
reply
|
45
|
+
{ :text => c }
|
50
46
|
end
|
51
47
|
end
|
52
48
|
|
@@ -67,8 +63,7 @@ module Staticpress::Content
|
|
67
63
|
|
68
64
|
def layout
|
69
65
|
if meta.layout || config.markup_templates.include?(template_path.extname[1..-1])
|
70
|
-
|
71
|
-
Tilt.new theme.layout_for(layout_name).to_s
|
66
|
+
Tilt.new theme.layout_for(*preferred_layout_names).to_s
|
72
67
|
end
|
73
68
|
end
|
74
69
|
|
@@ -77,7 +72,10 @@ module Staticpress::Content
|
|
77
72
|
end
|
78
73
|
|
79
74
|
def meta
|
80
|
-
Staticpress::Metadata.new(content
|
75
|
+
Staticpress::Metadata.new(content[:frontmatter] ? YAML.load(content[:frontmatter]) : {})
|
76
|
+
rescue Psych::SyntaxError => e
|
77
|
+
warn "Could not parse frontmatter for #{template_path}", content[:frontmatter]
|
78
|
+
raise e
|
81
79
|
end
|
82
80
|
|
83
81
|
def optional_param_defaults
|
@@ -1,8 +1,7 @@
|
|
1
1
|
module Staticpress::Content
|
2
2
|
class Category < Base
|
3
3
|
include CollectionContent
|
4
|
-
|
5
|
-
extend ResourceContent
|
4
|
+
include ResourceContent
|
6
5
|
|
7
6
|
attr_reader :name
|
8
7
|
|
@@ -23,8 +22,22 @@ module Staticpress::Content
|
|
23
22
|
paginate(self.class.content_by_category[params[:name]].sort)[params[:number] - 1]
|
24
23
|
end
|
25
24
|
|
26
|
-
def
|
27
|
-
|
25
|
+
def preferred_layout_names
|
26
|
+
reply = []
|
27
|
+
|
28
|
+
if params[:name].nil?
|
29
|
+
reply << :category
|
30
|
+
else
|
31
|
+
if params[:number].nil?
|
32
|
+
reply << :category_index
|
33
|
+
reply << :post_index
|
34
|
+
end
|
35
|
+
|
36
|
+
reply << :category_paged
|
37
|
+
reply << :post_paged
|
38
|
+
end
|
39
|
+
|
40
|
+
reply
|
28
41
|
end
|
29
42
|
|
30
43
|
def self.all
|
@@ -1,13 +1,11 @@
|
|
1
1
|
module Staticpress::Content
|
2
2
|
module CollectionContent
|
3
|
-
include ResourceContent
|
4
|
-
|
5
3
|
def template_types
|
6
4
|
find_supported_extensions template_path
|
7
5
|
end
|
8
6
|
|
9
7
|
def template_path
|
10
|
-
theme.view_for(
|
8
|
+
theme.view_for(*preferred_layout_names)
|
11
9
|
end
|
12
10
|
end
|
13
11
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Staticpress::Content
|
2
2
|
class Index < Base
|
3
3
|
include CollectionContent
|
4
|
-
|
4
|
+
include ResourceContent
|
5
5
|
|
6
6
|
def optional_param_defaults
|
7
7
|
{ :number => pages_count }
|
@@ -15,8 +15,11 @@ module Staticpress::Content
|
|
15
15
|
paginate(self.class.all_posts.sort)[params[:number] - 1]
|
16
16
|
end
|
17
17
|
|
18
|
-
def
|
19
|
-
|
18
|
+
def preferred_layout_names
|
19
|
+
reply = []
|
20
|
+
reply << :post_index if params[:number].nil?
|
21
|
+
reply << :post_paged
|
22
|
+
reply
|
20
23
|
end
|
21
24
|
|
22
25
|
def self.all
|
@@ -34,6 +34,10 @@ module Staticpress::Content
|
|
34
34
|
(Staticpress.blog_path + config.source_path + params[:slug]).file?
|
35
35
|
end
|
36
36
|
|
37
|
+
def preferred_layout_names
|
38
|
+
[meta.layout, :page]
|
39
|
+
end
|
40
|
+
|
37
41
|
def template_path
|
38
42
|
Staticpress.blog_path + config.source_path + "#{full_slug}#{template_extension}"
|
39
43
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
module Staticpress::Content
|
2
2
|
class Post < Base
|
3
3
|
include ResourceContent
|
4
|
-
extend ResourceContent
|
5
4
|
|
6
5
|
def initialize(params)
|
7
6
|
super
|
@@ -21,6 +20,10 @@ module Staticpress::Content
|
|
21
20
|
Time.utc params[:year], params[:month], params[:day]
|
22
21
|
end
|
23
22
|
|
23
|
+
def preferred_layout_names
|
24
|
+
[meta.layout, :post]
|
25
|
+
end
|
26
|
+
|
24
27
|
def template_path
|
25
28
|
name = [
|
26
29
|
params[:year],
|
@@ -13,14 +13,8 @@ module Staticpress::Content
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def gather_resources_from(paths)
|
16
|
-
paths
|
17
|
-
|
18
|
-
spider_directory child do |resource|
|
19
|
-
find_by_path resource
|
20
|
-
end
|
21
|
-
else
|
22
|
-
find_by_path child
|
23
|
-
end
|
16
|
+
spider_map paths do |resource|
|
17
|
+
find_by_path resource
|
24
18
|
end.flatten.compact
|
25
19
|
end
|
26
20
|
|
@@ -1,8 +1,7 @@
|
|
1
1
|
module Staticpress::Content
|
2
2
|
class Tag < Base
|
3
3
|
include CollectionContent
|
4
|
-
|
5
|
-
extend ResourceContent
|
4
|
+
include ResourceContent
|
6
5
|
|
7
6
|
attr_reader :name
|
8
7
|
|
@@ -23,8 +22,22 @@ module Staticpress::Content
|
|
23
22
|
paginate(self.class.content_by_tag[params[:name]].sort)[params[:number] - 1]
|
24
23
|
end
|
25
24
|
|
26
|
-
def
|
27
|
-
|
25
|
+
def preferred_layout_names
|
26
|
+
reply = []
|
27
|
+
|
28
|
+
if params[:name].nil?
|
29
|
+
reply << :tag
|
30
|
+
else
|
31
|
+
if params[:number].nil?
|
32
|
+
reply << :tag_index
|
33
|
+
reply << :post_index
|
34
|
+
end
|
35
|
+
|
36
|
+
reply << :tag_paged
|
37
|
+
reply << :post_paged
|
38
|
+
end
|
39
|
+
|
40
|
+
reply
|
28
41
|
end
|
29
42
|
|
30
43
|
def self.all
|
data/lib/staticpress/helpers.rb
CHANGED
@@ -49,12 +49,12 @@ module Staticpress
|
|
49
49
|
Staticpress::Settings.instance
|
50
50
|
end
|
51
51
|
|
52
|
-
def
|
53
|
-
|
54
|
-
if
|
55
|
-
|
52
|
+
def spider_map(paths, &block)
|
53
|
+
paths.map do |path|
|
54
|
+
if path.directory?
|
55
|
+
spider_map path.children, &block
|
56
56
|
else
|
57
|
-
block.call
|
57
|
+
block.call path
|
58
58
|
end
|
59
59
|
end
|
60
60
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# https://github.com/amatsuda/kaminari
|
2
|
+
|
3
|
+
module Staticpress::Plugins
|
4
|
+
module Pagination
|
5
|
+
def pagination_menu(current_number, menu_options = {})
|
6
|
+
tag :menu, { :type => :toolbar }.merge(menu_options) do
|
7
|
+
numbered_pages = Staticpress::Content::Index.published.map do |page|
|
8
|
+
number = page.params[:number]
|
9
|
+
pagination_item number, number, number == current_number
|
10
|
+
end.join
|
11
|
+
|
12
|
+
first_page = 1
|
13
|
+
last_page = Staticpress::Content::Index.published.count
|
14
|
+
|
15
|
+
oldest_page = pagination_item 'Oldest', first_page, current_number == first_page
|
16
|
+
older_page = pagination_item 'Older', current_number - 1, current_number <= first_page
|
17
|
+
newer_page = pagination_item 'Newer', current_number + 1, current_number >= last_page
|
18
|
+
newest_page = pagination_item 'Newest', last_page, current_number == last_page
|
19
|
+
|
20
|
+
oldest_page + older_page + numbered_pages + newer_page + newest_page
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def pagination_item(text, number, is_current)
|
25
|
+
tag :li do
|
26
|
+
if is_current
|
27
|
+
tag :span, :class => 'current-page' do
|
28
|
+
text
|
29
|
+
end
|
30
|
+
else
|
31
|
+
tag :a, :href => "/page/#{number}" do
|
32
|
+
text
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|