staticpress 0.3.0 → 0.4.0
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.
- 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
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
require 'staticpress'
|
|
2
|
+
require 'staticpress/content/static_content'
|
|
2
3
|
|
|
3
4
|
module Staticpress::Content
|
|
4
5
|
module ResourceContent
|
|
6
|
+
# FIXME add tests
|
|
7
|
+
def find_supported_extension(extensionless_path)
|
|
8
|
+
Staticpress::Content::StaticContent.supported_extensions.detect do |extension|
|
|
9
|
+
extension.to_sym if Pathname.new("#{extensionless_path}.#{extension}").file?
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
5
13
|
def gather_resources_from(paths)
|
|
6
14
|
paths.map do |child|
|
|
7
15
|
if child.directory?
|
|
@@ -14,11 +22,11 @@ module Staticpress::Content
|
|
|
14
22
|
end.flatten.compact
|
|
15
23
|
end
|
|
16
24
|
|
|
17
|
-
def load_resource(
|
|
25
|
+
def load_resource(base, stub, params)
|
|
18
26
|
catch :resource do
|
|
19
|
-
supported_extensions.
|
|
27
|
+
Staticpress::Content::StaticContent.supported_extensions.each do |extension|
|
|
20
28
|
path = base + "#{stub}.#{extension}"
|
|
21
|
-
throw :resource, new(
|
|
29
|
+
throw :resource, new(params) if path.file?
|
|
22
30
|
end
|
|
23
31
|
|
|
24
32
|
nil
|
|
@@ -10,15 +10,21 @@ module Staticpress::Content
|
|
|
10
10
|
def parse_slug(path, base_path)
|
|
11
11
|
path_string = path.to_s
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
clean = lambda { |str| str.sub(base_path.to_s, '').sub(/^\//, '') }
|
|
14
|
+
|
|
15
|
+
if Staticpress::Content::StaticContent.supported_extensions.any? { |ext| path_string.end_with? ext.to_s }
|
|
16
|
+
[ clean.call(extensionless_path(path).to_s), path.extname.sub(/^\./, '').to_sym ]
|
|
15
17
|
else
|
|
16
|
-
path_string
|
|
17
|
-
end
|
|
18
|
+
[ clean.call(path_string), nil ]
|
|
19
|
+
end
|
|
18
20
|
end
|
|
19
21
|
|
|
20
22
|
def render_partial(locals = {})
|
|
21
23
|
static? ? template_path_content : super
|
|
22
24
|
end
|
|
25
|
+
|
|
26
|
+
def self.supported_extensions
|
|
27
|
+
Tilt.mappings.keys.reject { |mapping| mapping == '' }.map &:to_sym
|
|
28
|
+
end
|
|
23
29
|
end
|
|
24
30
|
end
|
|
@@ -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 Tag < 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_tag[
|
|
16
|
+
paginate(self.class.content_by_tag[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
|
tags.map do |tag|
|
|
16
|
-
|
|
25
|
+
new :name => tag, :number => '1'
|
|
17
26
|
end
|
|
18
27
|
end
|
|
19
28
|
|
|
@@ -6,12 +6,25 @@ require 'staticpress/route'
|
|
|
6
6
|
|
|
7
7
|
module Staticpress::Content
|
|
8
8
|
class Theme < Base
|
|
9
|
+
include ResourceContent
|
|
9
10
|
include StaticContent
|
|
10
11
|
extend ResourceContent
|
|
11
12
|
extend StaticContent
|
|
12
13
|
|
|
14
|
+
attr_reader :extension
|
|
15
|
+
|
|
16
|
+
def initialize(params)
|
|
17
|
+
super
|
|
18
|
+
@extension = find_supported_extension template_path
|
|
19
|
+
end
|
|
20
|
+
|
|
13
21
|
def static?
|
|
14
|
-
(Staticpress::Theme.new(
|
|
22
|
+
(Staticpress::Theme.new(params[:theme]).root + 'assets' + params[:asset_type] + params[:slug]).file?
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def template_path
|
|
26
|
+
slug = extension ? "#{params[:slug]}.#{extension}" : params[:slug]
|
|
27
|
+
Staticpress::Theme.new(params[:theme]).root + 'assets' + params[:asset_type] + slug
|
|
15
28
|
end
|
|
16
29
|
|
|
17
30
|
def self.all
|
|
@@ -23,26 +36,11 @@ module Staticpress::Content
|
|
|
23
36
|
stubs = Staticpress::Route::REGEX_STUBS
|
|
24
37
|
regex = /#{stubs[:theme].regex}\/assets\/#{stubs[:asset_type].regex}\/#{stubs[:slug].regex}/
|
|
25
38
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
:theme => filename_parts[:theme],
|
|
30
|
-
:asset_type => filename_parts[:asset_type],
|
|
31
|
-
:slug => filename_parts[:slug]
|
|
32
|
-
}
|
|
33
|
-
find_by_route Staticpress::Route.new(params)
|
|
39
|
+
# FIXME send parse_slug something more intelligent as second parameter
|
|
40
|
+
if match = regex.match(parse_slug(path, Staticpress.root + 'themes').first)
|
|
41
|
+
new hash_from_match_data(match)
|
|
34
42
|
end
|
|
35
43
|
end
|
|
36
44
|
end
|
|
37
|
-
|
|
38
|
-
def self.find_by_route(route)
|
|
39
|
-
return nil unless route
|
|
40
|
-
|
|
41
|
-
base = Staticpress::Theme.new(route.params[:theme]).root + 'assets' + route.params[:asset_type]
|
|
42
|
-
path = base + route.params[:slug]
|
|
43
|
-
return new(route, path) if path.file?
|
|
44
|
-
|
|
45
|
-
load_resource route, base, route.params[:slug]
|
|
46
|
-
end
|
|
47
45
|
end
|
|
48
46
|
end
|
data/lib/staticpress/helpers.rb
CHANGED
data/lib/staticpress/route.rb
CHANGED
|
@@ -1,68 +1,40 @@
|
|
|
1
1
|
require 'staticpress'
|
|
2
|
-
require 'staticpress/error'
|
|
3
2
|
require 'staticpress/helpers'
|
|
4
|
-
require 'staticpress/site'
|
|
5
3
|
|
|
6
4
|
module Staticpress
|
|
7
|
-
|
|
5
|
+
module Route
|
|
8
6
|
extend Staticpress::Helpers
|
|
9
|
-
include Staticpress::Helpers
|
|
10
7
|
|
|
11
|
-
RegexStub = Struct.new :
|
|
8
|
+
RegexStub = Struct.new :klass, :regex
|
|
12
9
|
|
|
13
10
|
REGEX_STUBS = {
|
|
14
|
-
:asset_type => RegexStub.new(/(?<asset_type>fonts|images|scripts|styles)/),
|
|
15
|
-
:date
|
|
16
|
-
:year
|
|
17
|
-
:month
|
|
18
|
-
:day
|
|
19
|
-
:slug
|
|
20
|
-
:title
|
|
21
|
-
:name
|
|
22
|
-
:number
|
|
23
|
-
:theme
|
|
11
|
+
:asset_type => RegexStub.new(:string, /(?<asset_type>fonts|images|scripts|styles)/),
|
|
12
|
+
:date => RegexStub.new(:date, /(?<date>\d{4}-\d{2}-\d{2})/),
|
|
13
|
+
:year => RegexStub.new(:string, /(?<year>\d{4})/),
|
|
14
|
+
:month => RegexStub.new(:string, /(?<month>\d{2})/),
|
|
15
|
+
:day => RegexStub.new(:string, /(?<day>\d{2})/),
|
|
16
|
+
:slug => RegexStub.new(:string, /(?<slug>[0-9a-z\-_\.\/]*)/),
|
|
17
|
+
:title => RegexStub.new(:string, /(?<title>[0-9a-z\-_]*)/),
|
|
18
|
+
:name => RegexStub.new(:string, /(?<name>[0-9a-z\-_]*)/),
|
|
19
|
+
:number => RegexStub.new(:integer, /(?<number>\d+)/),
|
|
20
|
+
:theme => RegexStub.new(:string, /(?<theme>[0-9a-z\-_]*)/)
|
|
24
21
|
}
|
|
25
22
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
# TODO apply default values to all params for which a default value exist
|
|
30
|
-
# TODO ensure all param values are correct type (not always strings)
|
|
31
|
-
@params = if params.key?(:number)
|
|
32
|
-
params[:number] ? params : params.merge(:number => REGEX_STUBS[:number].default)
|
|
33
|
-
else
|
|
34
|
-
params
|
|
23
|
+
def self.extract_params(pattern, url_path)
|
|
24
|
+
if match = regex_for_pattern(pattern).match(url_path)
|
|
25
|
+
hash_from_match_data match
|
|
35
26
|
end
|
|
36
27
|
end
|
|
37
28
|
|
|
38
|
-
def
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
def content
|
|
43
|
-
params[:content_type].find_by_route self
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
def inspect
|
|
47
|
-
parts = [
|
|
48
|
-
"url_path=#{url_path}",
|
|
49
|
-
"content_type=#{params[:content_type]}"
|
|
50
|
-
]
|
|
51
|
-
|
|
52
|
-
p = Hash[self.params.clone.sort]
|
|
53
|
-
p.delete :content_type
|
|
54
|
-
parts << "params=#{p}"
|
|
55
|
-
|
|
56
|
-
"#<#{self.class} #{parts.join ', '}>"
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
def route
|
|
60
|
-
route_options(route_title).inject(route_pattern) do |reply, (key, value)|
|
|
61
|
-
reply.gsub /:#{key}/, value.to_s
|
|
29
|
+
def self.regex_for_pattern(pattern)
|
|
30
|
+
regex = REGEX_STUBS.inject("^#{pattern}$") do |snip, (key, value)|
|
|
31
|
+
snip.gsub /:#{key}/, value.regex.source
|
|
62
32
|
end
|
|
33
|
+
|
|
34
|
+
Regexp.new regex
|
|
63
35
|
end
|
|
64
36
|
|
|
65
|
-
def route_options(title)
|
|
37
|
+
def self.route_options(title)
|
|
66
38
|
t = Time.now.utc
|
|
67
39
|
|
|
68
40
|
{
|
|
@@ -73,51 +45,5 @@ module Staticpress
|
|
|
73
45
|
:title => title
|
|
74
46
|
}
|
|
75
47
|
end
|
|
76
|
-
|
|
77
|
-
def route_pattern
|
|
78
|
-
config.routes[type]
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
def url_path
|
|
82
|
-
return nil unless params[:content_type]
|
|
83
|
-
|
|
84
|
-
pattern = config.routes[params[:content_type].type].clone
|
|
85
|
-
|
|
86
|
-
# http://www.rubular.com/r/UTV5dNDq6c
|
|
87
|
-
optional_segment_finder = /\((?<optional_segment>.+)\)\?/
|
|
88
|
-
pattern.gsub! optional_segment_finder do |match|
|
|
89
|
-
# http://www.rubular.com/r/LiOup53CI1
|
|
90
|
-
optional_key = /:(?<optional_key>[0-9a-z_]+)/.match(match)[:optional_key].to_sym
|
|
91
|
-
optional_segment_finder.match(match)[:optional_segment] unless params[optional_key] == REGEX_STUBS[optional_key].default
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
REGEX_STUBS.keys.inject(pattern) do |p, key|
|
|
95
|
-
p.gsub /:#{key}/, params[key].to_s
|
|
96
|
-
end
|
|
97
|
-
end
|
|
98
|
-
alias :to_s :url_path
|
|
99
|
-
|
|
100
|
-
def self.from_url_path(url_path)
|
|
101
|
-
catch :route do
|
|
102
|
-
Staticpress::Site.content_types.each do |content_type|
|
|
103
|
-
if match = regex_for_pattern(config.routes[content_type.type]).match(url_path)
|
|
104
|
-
params = { :content_type => content_type }
|
|
105
|
-
match.names.each { |match_key| params[match_key.to_sym] = match[match_key] }
|
|
106
|
-
route = new params
|
|
107
|
-
throw :route, route if route.content
|
|
108
|
-
end
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
nil
|
|
112
|
-
end
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
def self.regex_for_pattern(pattern)
|
|
116
|
-
regex = REGEX_STUBS.inject("^#{pattern}$") do |snip, (key, value)|
|
|
117
|
-
snip.gsub /:#{key}/, value.regex.source
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
Regexp.new regex
|
|
121
|
-
end
|
|
122
48
|
end
|
|
123
49
|
end
|
data/lib/staticpress/server.rb
CHANGED
|
@@ -9,9 +9,7 @@ module Staticpress
|
|
|
9
9
|
end
|
|
10
10
|
|
|
11
11
|
def call(env)
|
|
12
|
-
content = @site.
|
|
13
|
-
|
|
14
|
-
if content
|
|
12
|
+
if content = @site.find_content_by_env(env)
|
|
15
13
|
[ 200, { 'Content-Type' => content.content_type }, [ content.render ] ]
|
|
16
14
|
else
|
|
17
15
|
[ 404, {}, [] ]
|
data/lib/staticpress/site.rb
CHANGED
|
@@ -9,10 +9,19 @@ require 'staticpress/content/post'
|
|
|
9
9
|
require 'staticpress/content/theme'
|
|
10
10
|
require 'staticpress/helpers'
|
|
11
11
|
require 'staticpress/metadata'
|
|
12
|
-
require 'staticpress/route'
|
|
13
12
|
|
|
14
13
|
module Staticpress
|
|
15
14
|
class Site
|
|
15
|
+
# ordered by priority
|
|
16
|
+
CONTENT_TYPES = [
|
|
17
|
+
Staticpress::Content::Page,
|
|
18
|
+
Staticpress::Content::Post,
|
|
19
|
+
Staticpress::Content::Index,
|
|
20
|
+
Staticpress::Content::Category,
|
|
21
|
+
Staticpress::Content::Tag,
|
|
22
|
+
Staticpress::Content::Theme
|
|
23
|
+
]
|
|
24
|
+
|
|
16
25
|
include Staticpress::Helpers
|
|
17
26
|
|
|
18
27
|
attr_reader :directory
|
|
@@ -22,12 +31,18 @@ module Staticpress
|
|
|
22
31
|
end
|
|
23
32
|
|
|
24
33
|
def all_content
|
|
25
|
-
|
|
34
|
+
CONTENT_TYPES.map(&:all).flatten
|
|
26
35
|
end
|
|
27
36
|
|
|
28
|
-
def
|
|
29
|
-
|
|
30
|
-
|
|
37
|
+
def find_content_by_env(env)
|
|
38
|
+
catch :content do
|
|
39
|
+
CONTENT_TYPES.detect do |content_type|
|
|
40
|
+
content = content_type.find_by_url_path env['REQUEST_PATH']
|
|
41
|
+
throw :content, content if content && content.exist?
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
nil
|
|
45
|
+
end
|
|
31
46
|
end
|
|
32
47
|
|
|
33
48
|
def meta
|
|
@@ -42,16 +57,5 @@ module Staticpress
|
|
|
42
57
|
FileUtils.rm_r destination if destination.directory?
|
|
43
58
|
all_content.each &:save
|
|
44
59
|
end
|
|
45
|
-
|
|
46
|
-
def self.content_types
|
|
47
|
-
[
|
|
48
|
-
Staticpress::Content::Index,
|
|
49
|
-
Staticpress::Content::Category,
|
|
50
|
-
Staticpress::Content::Tag,
|
|
51
|
-
Staticpress::Content::Page,
|
|
52
|
-
Staticpress::Content::Post,
|
|
53
|
-
Staticpress::Content::Theme
|
|
54
|
-
]
|
|
55
|
-
end
|
|
56
60
|
end
|
|
57
61
|
end
|
data/lib/staticpress/version.rb
CHANGED
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
require_relative '../../test_case'
|
|
2
|
+
|
|
3
|
+
require 'staticpress/content/base'
|
|
4
|
+
require 'staticpress/content/category'
|
|
5
|
+
require 'staticpress/content/index'
|
|
6
|
+
require 'staticpress/content/page'
|
|
7
|
+
require 'staticpress/content/post'
|
|
8
|
+
require 'staticpress/content/tag'
|
|
9
|
+
require 'staticpress/content/theme'
|
|
10
|
+
|
|
11
|
+
class ContentBaseTest < TestCase
|
|
12
|
+
let(:category) { Staticpress::Content::Category.new :name => 'programming' }
|
|
13
|
+
let(:category_1) { Staticpress::Content::Category.new(:name => 'programming', :number => '1') }
|
|
14
|
+
let(:category_2) { Staticpress::Content::Category.new(:name => 'programming', :number => '2') }
|
|
15
|
+
|
|
16
|
+
let(:index) { Staticpress::Content::Index.new :number => 1 }
|
|
17
|
+
let(:index_2) { Staticpress::Content::Index.new :number => 2 }
|
|
18
|
+
|
|
19
|
+
let(:page) { Staticpress::Content::Page.new(:slug => 'about') }
|
|
20
|
+
let(:second_page) { Staticpress::Content::Page.new :slug => 'contact' }
|
|
21
|
+
let(:page_root) { Staticpress::Content::Page.new :slug => '' }
|
|
22
|
+
let(:style_2) { Staticpress::Content::Page.new :slug => 'style2.css' }
|
|
23
|
+
let(:page_nested) { Staticpress::Content::Page.new :slug => 'foo/bar/baz' }
|
|
24
|
+
let(:static_bin) { Staticpress::Content::Page.new :slug => 'ruby.png' }
|
|
25
|
+
let(:static_txt) { Staticpress::Content::Page.new :slug => 'plain.txt' }
|
|
26
|
+
let(:page_fake) { Staticpress::Content::Page.new :slug => 'i/dont/exist' }
|
|
27
|
+
|
|
28
|
+
let(:post) { Staticpress::Content::Post.new(:year => '2011', :month => '07', :day => '20', :title => 'hello') }
|
|
29
|
+
|
|
30
|
+
let(:tag) { Staticpress::Content::Tag.new :name => 'charlotte' }
|
|
31
|
+
|
|
32
|
+
let(:asset_style) { Staticpress::Content::Theme.new :theme => 'test_theme', :asset_type => 'styles', :slug => 'all' }
|
|
33
|
+
let(:asset_script) { Staticpress::Content::Theme.new :theme => 'test_theme', :asset_type => 'scripts', :slug => 'application.js' }
|
|
34
|
+
|
|
35
|
+
def test__equalsequals
|
|
36
|
+
assert_operator category, :==, Staticpress::Content::Category.new(:name => 'programming')
|
|
37
|
+
refute_operator category, :==, nil
|
|
38
|
+
|
|
39
|
+
assert_operator index, :==, Staticpress::Content::Index.new(:number => 1)
|
|
40
|
+
refute_operator index, :==, index_2
|
|
41
|
+
refute_operator index, :==, nil
|
|
42
|
+
|
|
43
|
+
assert_operator page, :==, Staticpress::Content::Page.new(:slug => 'about')
|
|
44
|
+
refute_operator page, :==, second_page
|
|
45
|
+
refute_operator page, :==, nil
|
|
46
|
+
assert_operator static_bin, :==, Staticpress::Content::Page.new(:slug => 'ruby.png')
|
|
47
|
+
refute_operator static_bin, :==, nil
|
|
48
|
+
refute_operator static_bin, :==, static_txt
|
|
49
|
+
|
|
50
|
+
assert_operator post, :==, Staticpress::Content::Post.new(:year => '2011', :month => '07', :day => '20', :title => 'hello')
|
|
51
|
+
refute_operator post, :==, nil
|
|
52
|
+
|
|
53
|
+
assert_operator tag, :==, Staticpress::Content::Tag.new(:name => 'charlotte')
|
|
54
|
+
refute_operator tag, :==, nil
|
|
55
|
+
|
|
56
|
+
assert_operator asset_style, :==, Staticpress::Content::Theme.new(:theme => 'test_theme', :asset_type => 'styles', :slug => 'all')
|
|
57
|
+
refute_operator asset_style, :==, nil
|
|
58
|
+
|
|
59
|
+
refute_operator Staticpress::Content::Category.new(:name => 'programming'), :==, Staticpress::Content::Tag.new(:name => 'programming')
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def test_content_type
|
|
63
|
+
assert_equal 'text/html', page.content_type
|
|
64
|
+
assert_equal 'text/css', style_2.content_type
|
|
65
|
+
assert_equal 'image/png', static_bin.content_type
|
|
66
|
+
assert_equal 'text/plain', static_txt.content_type
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def test_exist?
|
|
70
|
+
assert category.exist?, "#{category} does not exist"
|
|
71
|
+
assert index.exist?, "#{index} does not exist"
|
|
72
|
+
|
|
73
|
+
assert page.exist?, "#{page} does not exist"
|
|
74
|
+
assert second_page.exist?, "#{second_page} does not exist"
|
|
75
|
+
assert static_bin.exist?, "#{static_bin} does not exist"
|
|
76
|
+
assert static_txt.exist?, "#{static_txt} does not exist"
|
|
77
|
+
assert page_root.exist?, "#{page_root} does not exist"
|
|
78
|
+
|
|
79
|
+
assert post.exist?, "#{post} does not exist"
|
|
80
|
+
assert tag.exist?, "#{tag} does not exist"
|
|
81
|
+
|
|
82
|
+
assert asset_style.exist?, "#{asset_style} does not exist"
|
|
83
|
+
assert asset_script.exist?, "#{asset_script} does not exist"
|
|
84
|
+
|
|
85
|
+
refute page_fake.exist?, "#{page_fake} exists"
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def test_find_by_url_path
|
|
89
|
+
assert_equal category, Staticpress::Content::Category.find_by_url_path('/category/programming')
|
|
90
|
+
assert_equal index, Staticpress::Content::Index.find_by_url_path('/')
|
|
91
|
+
|
|
92
|
+
assert_equal page_root, Staticpress::Content::Page.find_by_url_path('/')
|
|
93
|
+
assert_equal page, Staticpress::Content::Page.find_by_url_path('/about')
|
|
94
|
+
assert_equal static_bin, Staticpress::Content::Page.find_by_url_path('/ruby.png')
|
|
95
|
+
|
|
96
|
+
assert_equal post, Staticpress::Content::Post.find_by_url_path('/2011/07/20/hello')
|
|
97
|
+
assert_equal tag, Staticpress::Content::Tag.find_by_url_path('/tag/charlotte')
|
|
98
|
+
|
|
99
|
+
assert_equal asset_style, Staticpress::Content::Theme.find_by_url_path('/assets/test_theme/styles/all')
|
|
100
|
+
assert_equal asset_script, Staticpress::Content::Theme.find_by_url_path('/assets/test_theme/scripts/application.js')
|
|
101
|
+
|
|
102
|
+
assert_nil Staticpress::Content::Theme.find_by_url_path(nil)
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def test_full_title
|
|
106
|
+
assert_equal 'Foo -> Bar -> Baz | Test Blog', page_nested.full_title
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def test_output_path
|
|
110
|
+
assert_equal (Staticpress.blog_path + 'public' + 'about' + 'index.html'), page.output_path
|
|
111
|
+
assert_equal (Staticpress.blog_path + 'public' + 'index.html'), page_root.output_path
|
|
112
|
+
assert_equal (Staticpress.blog_path + 'public' + 'style2.css'), style_2.output_path
|
|
113
|
+
assert_equal (Staticpress.blog_path + 'public' + 'ruby.png'), static_bin.output_path
|
|
114
|
+
assert_equal (Staticpress.blog_path + 'public' + 'plain.txt'), static_txt.output_path
|
|
115
|
+
assert_equal (Staticpress.blog_path + 'public' + '2011' + '07' + '20' + 'hello' + 'index.html'), post.output_path
|
|
116
|
+
assert_equal (Staticpress.blog_path + 'public' + 'assets' + 'test_theme' + 'styles' + 'all'), asset_style.output_path
|
|
117
|
+
assert_equal (Staticpress.blog_path + 'public' + 'assets' + 'test_theme' + 'scripts' + 'application.js'), asset_script.output_path
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def test_params
|
|
121
|
+
expected = { :name => 'charlotte', :number => 1 }
|
|
122
|
+
assert_equal expected, tag.params
|
|
123
|
+
assert_equal expected, Staticpress::Content::Tag.new(:name => 'charlotte', :number => nil).params
|
|
124
|
+
assert_equal expected, Staticpress::Content::Tag.new(:name => 'charlotte', :number => 1).params
|
|
125
|
+
assert_equal expected, Staticpress::Content::Tag.new(:name => 'charlotte', :number => '1').params
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def test_raw
|
|
129
|
+
assert_equal '= partial :list_posts, :posts => page.sub_content', category.raw
|
|
130
|
+
|
|
131
|
+
assert_equal 'in page', page.raw
|
|
132
|
+
assert_equal "in page\n\nin page", second_page.raw
|
|
133
|
+
assert_equal 'this file intentionally left blank', static_txt.raw
|
|
134
|
+
|
|
135
|
+
assert_equal 'in post', post.raw
|
|
136
|
+
assert_equal '= partial :list_posts, :posts => page.sub_content', tag.raw
|
|
137
|
+
assert_equal '@import "compass/reset/utilities"', asset_style.raw
|
|
138
|
+
|
|
139
|
+
expected = <<-JS
|
|
140
|
+
(function ($) {
|
|
141
|
+
$(document).ready(function () {
|
|
142
|
+
});
|
|
143
|
+
})(jQuery);
|
|
144
|
+
JS
|
|
145
|
+
assert_equal expected.strip, asset_script.raw
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
def test_render
|
|
149
|
+
expected_page = <<-HTML
|
|
150
|
+
<!DOCTYPE html>
|
|
151
|
+
<html>
|
|
152
|
+
<head>
|
|
153
|
+
<title>About | Test Blog</title>
|
|
154
|
+
</head>
|
|
155
|
+
<body>
|
|
156
|
+
<p>in page</p>
|
|
157
|
+
</body>
|
|
158
|
+
</html>
|
|
159
|
+
HTML
|
|
160
|
+
assert_equal expected_page, page.render
|
|
161
|
+
|
|
162
|
+
expected_style2 = <<-CSS
|
|
163
|
+
body{color:green}
|
|
164
|
+
CSS
|
|
165
|
+
assert_equal expected_style2, style_2.render
|
|
166
|
+
|
|
167
|
+
assert_equal 'this file intentionally left blank', static_txt.render
|
|
168
|
+
refute_raises(Sass::SyntaxError) { asset_style.render }
|
|
169
|
+
|
|
170
|
+
expected = <<-SASS
|
|
171
|
+
SASS
|
|
172
|
+
assert_equal expected, asset_style.render
|
|
173
|
+
|
|
174
|
+
expected = <<-JS
|
|
175
|
+
(function ($) {
|
|
176
|
+
$(document).ready(function () {
|
|
177
|
+
});
|
|
178
|
+
})(jQuery);
|
|
179
|
+
JS
|
|
180
|
+
assert_equal expected, asset_script.render
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
def test_render_partial
|
|
184
|
+
assert_equal "<p>in page</p>\n", page.render_partial
|
|
185
|
+
assert_equal "<p>in page</p>\n\n<p>in page</p>\n", second_page.render_partial
|
|
186
|
+
|
|
187
|
+
expected_style2 = <<-CSS
|
|
188
|
+
body{color:green}
|
|
189
|
+
CSS
|
|
190
|
+
assert_equal expected_style2, style_2.render_partial
|
|
191
|
+
|
|
192
|
+
assert_equal 'this file intentionally left blank', static_txt.render_partial
|
|
193
|
+
assert_equal "<p>in post</p>\n", post.render_partial
|
|
194
|
+
|
|
195
|
+
refute_raises(Sass::SyntaxError) { asset_style.render_partial }
|
|
196
|
+
expected = <<-SASS
|
|
197
|
+
SASS
|
|
198
|
+
|
|
199
|
+
assert_equal expected, asset_style.render_partial
|
|
200
|
+
expected = <<-JS
|
|
201
|
+
(function ($) {
|
|
202
|
+
$(document).ready(function () {
|
|
203
|
+
});
|
|
204
|
+
})(jQuery);
|
|
205
|
+
JS
|
|
206
|
+
assert_equal expected, asset_script.render_partial
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
def test_save
|
|
210
|
+
static_bin.save
|
|
211
|
+
assert_equal static_bin.template_path.binread, static_bin.output_path.binread
|
|
212
|
+
|
|
213
|
+
static_txt.save
|
|
214
|
+
assert_equal static_txt.template_path.read, static_txt.output_path.read
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
def test_template_engine_options
|
|
218
|
+
expected = Compass.sass_engine_options.merge :line_comments => false, :style => :compressed
|
|
219
|
+
assert_eql expected, asset_style.template_engine_options
|
|
220
|
+
assert_equal({}, asset_script.template_engine_options)
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
def test_template_type
|
|
224
|
+
assert_equal :markdown, page.template_type
|
|
225
|
+
assert_equal :sass, asset_style.template_type
|
|
226
|
+
assert_equal :js, asset_script.template_type
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
def test_title
|
|
230
|
+
assert_equal 'Foo -> Bar -> Baz', page_nested.title
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
def test_to_s
|
|
234
|
+
assert_equal '#<Staticpress::Content::Category url_path=/category/programming, params={:name=>"programming", :number=>1}>', category.to_s
|
|
235
|
+
assert_equal '#<Staticpress::Content::Category url_path=/category/programming, params={:name=>"programming", :number=>1}>', Staticpress::Content::Category.new(:name => 'programming', :number => nil).to_s
|
|
236
|
+
|
|
237
|
+
assert_equal '#<Staticpress::Content::Index url_path=/, params={:number=>1}>', index.to_s
|
|
238
|
+
assert_equal '#<Staticpress::Content::Index url_path=/page/2, params={:number=>2}>', index_2.to_s
|
|
239
|
+
|
|
240
|
+
assert_equal '#<Staticpress::Content::Page url_path=/, params={:slug=>""}>', page_root.to_s
|
|
241
|
+
assert_equal '#<Staticpress::Content::Page url_path=/about, params={:slug=>"about"}>', page.to_s
|
|
242
|
+
assert_equal '#<Staticpress::Content::Page url_path=/ruby.png, params={:slug=>"ruby.png"}>', static_bin.to_s
|
|
243
|
+
|
|
244
|
+
assert_equal '#<Staticpress::Content::Post url_path=/2011/07/20/hello, params={:day=>"20", :month=>"07", :title=>"hello", :year=>"2011"}>', post.to_s
|
|
245
|
+
|
|
246
|
+
assert_equal '#<Staticpress::Content::Tag url_path=/tag/charlotte, params={:name=>"charlotte", :number=>1}>', tag.to_s
|
|
247
|
+
|
|
248
|
+
assert_equal '#<Staticpress::Content::Theme url_path=/assets/test_theme/styles/all, params={:asset_type=>"styles", :slug=>"all", :theme=>"test_theme"}>', asset_style.to_s
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
def test_url_path
|
|
252
|
+
assert_equal '/category/programming', category.url_path
|
|
253
|
+
assert_equal '/category/programming', category_1.url_path
|
|
254
|
+
assert_equal '/category/programming/page/2', category_2.url_path
|
|
255
|
+
|
|
256
|
+
assert_equal '/', index.url_path
|
|
257
|
+
assert_equal '/page/2', index_2.url_path
|
|
258
|
+
|
|
259
|
+
assert_equal '/', page_root.url_path
|
|
260
|
+
assert_equal '/about', page.url_path
|
|
261
|
+
assert_equal '/contact', second_page.url_path
|
|
262
|
+
assert_equal '/ruby.png', static_bin.url_path
|
|
263
|
+
assert_equal '/plain.txt', static_txt.url_path
|
|
264
|
+
|
|
265
|
+
assert_equal '/2011/07/20/hello', post.url_path
|
|
266
|
+
|
|
267
|
+
assert_equal '/2011/07/20/hello', post.url_path
|
|
268
|
+
assert_equal '/tag/charlotte', tag.url_path
|
|
269
|
+
assert_equal '/assets/test_theme/styles/all', asset_style.url_path
|
|
270
|
+
end
|
|
271
|
+
end
|