staticpress 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +9 -0
- data/.rbenv-version +1 -0
- data/.rvmrc +1 -0
- data/Gemfile +3 -0
- data/Rakefile +21 -0
- data/bin/staticpress +6 -0
- data/lib/skeleton/Gemfile +10 -0
- data/lib/skeleton/README.markdown +21 -0
- data/lib/skeleton/config.rb +14 -0
- data/lib/skeleton/config.ru +8 -0
- data/lib/skeleton/config.yml +63 -0
- data/lib/staticpress/booter.rb +7 -0
- data/lib/staticpress/cli.rb +123 -0
- data/lib/staticpress/configuration.rb +24 -0
- data/lib/staticpress/content/base.rb +122 -0
- data/lib/staticpress/content/category.rb +34 -0
- data/lib/staticpress/content/collection_content.rb +13 -0
- data/lib/staticpress/content/index.rb +20 -0
- data/lib/staticpress/content/page.rb +64 -0
- data/lib/staticpress/content/post.rb +88 -0
- data/lib/staticpress/content/resource_content.rb +28 -0
- data/lib/staticpress/content/static_content.rb +24 -0
- data/lib/staticpress/content/tag.rb +34 -0
- data/lib/staticpress/content/theme.rb +48 -0
- data/lib/staticpress/error.rb +4 -0
- data/lib/staticpress/helpers.rb +57 -0
- data/lib/staticpress/js_object.rb +51 -0
- data/lib/staticpress/metadata.rb +24 -0
- data/lib/staticpress/plugin.rb +33 -0
- data/lib/staticpress/plugins/blockquote.rb +6 -0
- data/lib/staticpress/plugins/gist.rb +6 -0
- data/lib/staticpress/plugins/titlecase.rb +6 -0
- data/lib/staticpress/plugins.rb +6 -0
- data/lib/staticpress/route.rb +123 -0
- data/lib/staticpress/server.rb +21 -0
- data/lib/staticpress/site.rb +57 -0
- data/lib/staticpress/theme.rb +43 -0
- data/lib/staticpress/version.rb +12 -0
- data/lib/staticpress/view_helpers.rb +35 -0
- data/lib/staticpress.rb +15 -0
- data/lib/themes/classic/assets/scripts/application.js +4 -0
- data/lib/themes/classic/assets/styles/all.sass +0 -0
- data/lib/themes/classic/includes/list_posts.haml +3 -0
- data/lib/themes/classic/layouts/archive.haml +0 -0
- data/lib/themes/classic/layouts/atom.haml +0 -0
- data/lib/themes/classic/layouts/default.haml +5 -0
- data/lib/themes/classic/layouts/index.haml +0 -0
- data/lib/themes/classic/layouts/post_index.haml +5 -0
- data/lib/themes/classic/views/default.haml +5 -0
- data/staticpress.gemspec +33 -0
- data/tests/lib/staticpress/cli_test.rb +65 -0
- data/tests/lib/staticpress/configuration_test.rb +4 -0
- data/tests/lib/staticpress/content/base_test.rb +9 -0
- data/tests/lib/staticpress/content/category_test.rb +62 -0
- data/tests/lib/staticpress/content/index_test.rb +45 -0
- data/tests/lib/staticpress/content/page_test.rb +133 -0
- data/tests/lib/staticpress/content/post_test.rb +81 -0
- data/tests/lib/staticpress/content/tag_test.rb +60 -0
- data/tests/lib/staticpress/content/theme_test.rb +103 -0
- data/tests/lib/staticpress/helpers_test.rb +57 -0
- data/tests/lib/staticpress/js_object_test.rb +45 -0
- data/tests/lib/staticpress/metadata_test.rb +19 -0
- data/tests/lib/staticpress/plugin_test.rb +4 -0
- data/tests/lib/staticpress/route_test.rb +210 -0
- data/tests/lib/staticpress/server_test.rb +4 -0
- data/tests/lib/staticpress/site_test.rb +25 -0
- data/tests/lib/staticpress/theme_test.rb +68 -0
- data/tests/lib/staticpress/view_helpers_test.rb +32 -0
- data/tests/lib/staticpress_test.rb +15 -0
- data/tests/sample_sites/test_blog/Gemfile +10 -0
- data/tests/sample_sites/test_blog/README.markdown +21 -0
- data/tests/sample_sites/test_blog/config.rb +14 -0
- data/tests/sample_sites/test_blog/config.ru +8 -0
- data/tests/sample_sites/test_blog/config.yml +4 -0
- data/tests/sample_sites/test_blog/content/_posts/2011-07-20-hello.markdown +5 -0
- data/tests/sample_sites/test_blog/content/_posts/2011-08-01-announcing-staticpress.markdown +7 -0
- data/tests/sample_sites/test_blog/content/_posts/2011-08-02-staticpress.markdown +7 -0
- data/tests/sample_sites/test_blog/content/_posts/2011-08-06-blogging-with-staticpress.markdown +7 -0
- data/tests/sample_sites/test_blog/content/_posts/2011-08-06-conferences.markdown +5 -0
- data/tests/sample_sites/test_blog/content/_posts/2011-08-06-in-charlotte.markdown +9 -0
- data/tests/sample_sites/test_blog/content/_posts/2011-08-20-forever.markdown +1 -0
- data/tests/sample_sites/test_blog/content/about.markdown +1 -0
- data/tests/sample_sites/test_blog/content/contact.markdown +3 -0
- data/tests/sample_sites/test_blog/content/foo/bar/baz.markdown +1 -0
- data/tests/sample_sites/test_blog/content/plain.txt +1 -0
- data/tests/sample_sites/test_blog/content/ruby.png +0 -0
- data/tests/sample_sites/test_blog/content/style1.css +3 -0
- data/tests/sample_sites/test_blog/content/style2.css.sass +2 -0
- data/tests/sample_sites/test_blog/content/style3.sass +2 -0
- data/tests/test_helper.rb +17 -0
- data.tar.gz.sig +0 -0
- metadata +255 -0
- metadata.gz.sig +3 -0
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'staticpress'
|
2
|
+
|
3
|
+
module Staticpress::Content
|
4
|
+
module ResourceContent
|
5
|
+
def gather_resources_from(paths)
|
6
|
+
paths.map do |child|
|
7
|
+
if child.directory?
|
8
|
+
spider_directory child do |resource|
|
9
|
+
find_by_path resource
|
10
|
+
end
|
11
|
+
else
|
12
|
+
find_by_path child
|
13
|
+
end
|
14
|
+
end.flatten.compact
|
15
|
+
end
|
16
|
+
|
17
|
+
def load_resource(route, base, stub)
|
18
|
+
catch :resource do
|
19
|
+
supported_extensions.detect do |extension|
|
20
|
+
path = base + "#{stub}.#{extension}"
|
21
|
+
throw :resource, new(route, path) if path.file?
|
22
|
+
end
|
23
|
+
|
24
|
+
nil
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'staticpress'
|
2
|
+
|
3
|
+
module Staticpress::Content
|
4
|
+
module StaticContent
|
5
|
+
# layout not needed for binary files
|
6
|
+
def layout
|
7
|
+
static? ? nil : super
|
8
|
+
end
|
9
|
+
|
10
|
+
def parse_slug(path, base_path)
|
11
|
+
path_string = path.to_s
|
12
|
+
|
13
|
+
if supported_extensions.any? { |ext| path_string.end_with? ext.to_s }
|
14
|
+
extensionless_path(path).to_s
|
15
|
+
else
|
16
|
+
path_string
|
17
|
+
end.sub(base_path.to_s, '').sub(/^\//, '')
|
18
|
+
end
|
19
|
+
|
20
|
+
def render_partial(locals = {})
|
21
|
+
static? ? template_path_content : super
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'staticpress'
|
2
|
+
require 'staticpress/content/base'
|
3
|
+
require 'staticpress/content/collection_content'
|
4
|
+
require 'staticpress/route'
|
5
|
+
|
6
|
+
module Staticpress::Content
|
7
|
+
class Tag < Base
|
8
|
+
extend CollectionContent
|
9
|
+
|
10
|
+
def sub_content
|
11
|
+
paginate(self.class.content_by_tag[route.params[:name]].sort)[(Integer route.params[:number]) - 1]
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.all
|
15
|
+
tags.map do |tag|
|
16
|
+
find_by_route Staticpress::Route.new(:content_type => self, :name => tag, :number => '1')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.tags
|
21
|
+
content_by_tag.keys
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.content_by_tag
|
25
|
+
reply = {}
|
26
|
+
Staticpress::Content::Post.all.each do |post|
|
27
|
+
(post.meta.tags || []).each do |tag|
|
28
|
+
(reply[tag] ||= []) << post
|
29
|
+
end
|
30
|
+
end
|
31
|
+
reply
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'staticpress'
|
2
|
+
require 'staticpress/content/base'
|
3
|
+
require 'staticpress/content/resource_content'
|
4
|
+
require 'staticpress/content/static_content'
|
5
|
+
require 'staticpress/route'
|
6
|
+
|
7
|
+
module Staticpress::Content
|
8
|
+
class Theme < Base
|
9
|
+
include StaticContent
|
10
|
+
extend ResourceContent
|
11
|
+
extend StaticContent
|
12
|
+
|
13
|
+
def static?
|
14
|
+
(Staticpress::Theme.new(route.params[:theme]).root + 'assets' + route.params[:asset_type] + route.params[:slug]).file?
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.all
|
18
|
+
gather_resources_from((Staticpress::Theme.theme.root + 'assets').children)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.find_by_path(path)
|
22
|
+
if path.file?
|
23
|
+
stubs = Staticpress::Route::REGEX_STUBS
|
24
|
+
regex = /#{stubs[:theme].regex}\/assets\/#{stubs[:asset_type].regex}\/#{stubs[:slug].regex}/
|
25
|
+
|
26
|
+
if filename_parts = parse_slug(path, (Staticpress.root + 'themes')).match(regex)
|
27
|
+
params = {
|
28
|
+
:content_type => self,
|
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)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
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
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'staticpress'
|
2
|
+
require 'staticpress/configuration'
|
3
|
+
|
4
|
+
module Staticpress
|
5
|
+
module Helpers
|
6
|
+
def config
|
7
|
+
Staticpress::Configuration.instance
|
8
|
+
end
|
9
|
+
|
10
|
+
def extensionless_basename(pathname)
|
11
|
+
path = pathname.basename.to_path
|
12
|
+
path[0...(path.length - pathname.extname.length)]
|
13
|
+
end
|
14
|
+
|
15
|
+
def extensionless_path(pathname)
|
16
|
+
path = pathname.to_path
|
17
|
+
Pathname.new path[0...(path.length - pathname.extname.length)]
|
18
|
+
end
|
19
|
+
|
20
|
+
def hash_from_array(array, &block)
|
21
|
+
reply = array.map do |object|
|
22
|
+
[ block.call(object), object ]
|
23
|
+
end
|
24
|
+
|
25
|
+
Hash[reply]
|
26
|
+
end
|
27
|
+
|
28
|
+
def paginate(range)
|
29
|
+
reply = []
|
30
|
+
|
31
|
+
def reply.[](*args)
|
32
|
+
super || []
|
33
|
+
end
|
34
|
+
|
35
|
+
range_count = range.count
|
36
|
+
per_page = config.posts_per_page
|
37
|
+
array = range.to_a
|
38
|
+
|
39
|
+
total_pages_count = (range_count / per_page) + ((range_count % per_page) == 0 ? 0 : 1)
|
40
|
+
(0...total_pages_count).each do |number|
|
41
|
+
reply << array[number * per_page, per_page]
|
42
|
+
end
|
43
|
+
|
44
|
+
reply
|
45
|
+
end
|
46
|
+
|
47
|
+
def spider_directory(dir, &block)
|
48
|
+
dir.children.map do |child|
|
49
|
+
if child.directory?
|
50
|
+
spider_directory child, &block
|
51
|
+
else
|
52
|
+
block.call child
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
|
3
|
+
require 'staticpress'
|
4
|
+
|
5
|
+
module Staticpress
|
6
|
+
class JSObject < OpenStruct
|
7
|
+
def -(other)
|
8
|
+
other_hash = other.to_hash
|
9
|
+
difference = to_hash.select do |key, value|
|
10
|
+
value != other_hash[key]
|
11
|
+
end
|
12
|
+
self.class.new difference
|
13
|
+
end
|
14
|
+
|
15
|
+
def [](key)
|
16
|
+
method_missing key.to_s.to_sym
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_hash
|
20
|
+
converted = {}
|
21
|
+
|
22
|
+
@table.each do |key, value|
|
23
|
+
converted[key] = self.class.converter(value, JSObject) { |v| v.to_hash }
|
24
|
+
end
|
25
|
+
|
26
|
+
converted
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.new(hash = {})
|
30
|
+
converted = {}
|
31
|
+
|
32
|
+
hash.each do |key, value|
|
33
|
+
converted[key] = converter(value, Hash) { |v| new v }
|
34
|
+
end
|
35
|
+
|
36
|
+
super converted
|
37
|
+
end
|
38
|
+
|
39
|
+
protected
|
40
|
+
|
41
|
+
def self.converter(value, from_class, &block)
|
42
|
+
if value.is_a? Array
|
43
|
+
value.map { |vv| converter vv, from_class, &block }
|
44
|
+
elsif value.is_a? from_class
|
45
|
+
block.call value
|
46
|
+
else
|
47
|
+
value
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'staticpress'
|
2
|
+
require 'staticpress/js_object'
|
3
|
+
|
4
|
+
module Staticpress
|
5
|
+
class Metadata < JSObject
|
6
|
+
def <<(other)
|
7
|
+
self
|
8
|
+
end
|
9
|
+
|
10
|
+
def inspect
|
11
|
+
details = to_hash.sort.map do |key, value|
|
12
|
+
"#{key}=#{value.inspect}"
|
13
|
+
end.join(', ')
|
14
|
+
|
15
|
+
parts = [
|
16
|
+
self.class,
|
17
|
+
(details unless details.empty?)
|
18
|
+
].compact
|
19
|
+
|
20
|
+
"#<#{parts.join(' ')}>"
|
21
|
+
end
|
22
|
+
alias :to_s :inspect
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'staticpress'
|
2
|
+
require 'staticpress/error'
|
3
|
+
require 'staticpress/helpers'
|
4
|
+
|
5
|
+
module Staticpress
|
6
|
+
module Plugin
|
7
|
+
extend Staticpress::Helpers
|
8
|
+
|
9
|
+
def self.activate_enabled
|
10
|
+
config.plugins.each do |plugin_name|
|
11
|
+
require find(plugin_name).to_s
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.find(name)
|
16
|
+
file_name = name.end_with?('.rb') ? name : "#{name}.rb"
|
17
|
+
|
18
|
+
plugin_locations.each do |location|
|
19
|
+
file = location + file_name
|
20
|
+
return file if file.file?
|
21
|
+
end
|
22
|
+
|
23
|
+
raise Staticpress::Error, "Plugin not found: #{name}"
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.plugin_locations
|
27
|
+
[
|
28
|
+
((Staticpress.blog_path + config.plugins_path) if config.plugins_path),
|
29
|
+
(Staticpress.root + 'staticpress' + 'plugins')
|
30
|
+
].compact
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
require 'staticpress'
|
2
|
+
require 'staticpress/error'
|
3
|
+
require 'staticpress/helpers'
|
4
|
+
require 'staticpress/site'
|
5
|
+
|
6
|
+
module Staticpress
|
7
|
+
class Route
|
8
|
+
extend Staticpress::Helpers
|
9
|
+
include Staticpress::Helpers
|
10
|
+
|
11
|
+
RegexStub = Struct.new :regex, :default
|
12
|
+
|
13
|
+
REGEX_STUBS = {
|
14
|
+
:asset_type => RegexStub.new(/(?<asset_type>fonts|images|scripts|styles)/),
|
15
|
+
:date => RegexStub.new(/(?<date>\d{4}-\d{2}-\d{2})/),
|
16
|
+
:year => RegexStub.new(/(?<year>\d{4})/),
|
17
|
+
:month => RegexStub.new(/(?<month>\d{2})/),
|
18
|
+
:day => RegexStub.new(/(?<day>\d{2})/),
|
19
|
+
:slug => RegexStub.new(/(?<slug>[0-9a-z\-_\.\/]+)/),
|
20
|
+
:title => RegexStub.new(/(?<title>[0-9a-z\-_]*)/),
|
21
|
+
:name => RegexStub.new(/(?<name>[0-9a-z\-_]*)/),
|
22
|
+
:number => RegexStub.new(/(?<number>\d+)/, '1'),
|
23
|
+
:theme => RegexStub.new(/(?<theme>[0-9a-z\-_]*)/)
|
24
|
+
}
|
25
|
+
|
26
|
+
attr_reader :params
|
27
|
+
|
28
|
+
def initialize(params)
|
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
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def ==(other)
|
39
|
+
other.respond_to?(:params) && (params == other.params)
|
40
|
+
end
|
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
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def route_options(title)
|
66
|
+
t = Time.now.utc
|
67
|
+
|
68
|
+
{
|
69
|
+
:date => "#{t.year}-#{'%02d' % t.month}-#{'%02d' % t.day}",
|
70
|
+
:year => t.year,
|
71
|
+
:month => '%02d' % t.month,
|
72
|
+
:day => '%02d' % t.day,
|
73
|
+
:title => title
|
74
|
+
}
|
75
|
+
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
|
+
end
|
123
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'staticpress'
|
2
|
+
require 'staticpress/error'
|
3
|
+
require 'staticpress/site'
|
4
|
+
|
5
|
+
module Staticpress
|
6
|
+
class Server
|
7
|
+
def initialize
|
8
|
+
@site = Staticpress::Site.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def call(env)
|
12
|
+
content = @site.find_content_by_url_path env['REQUEST_PATH']
|
13
|
+
|
14
|
+
if content
|
15
|
+
[ 200, { 'Content-Type' => 'text/html' }, [ content.render ] ]
|
16
|
+
else
|
17
|
+
[ 404, {}, [] ]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
require 'staticpress'
|
4
|
+
require 'staticpress/content/index'
|
5
|
+
require 'staticpress/content/category'
|
6
|
+
require 'staticpress/content/tag'
|
7
|
+
require 'staticpress/content/page'
|
8
|
+
require 'staticpress/content/post'
|
9
|
+
require 'staticpress/content/theme'
|
10
|
+
require 'staticpress/helpers'
|
11
|
+
require 'staticpress/metadata'
|
12
|
+
require 'staticpress/route'
|
13
|
+
|
14
|
+
module Staticpress
|
15
|
+
class Site
|
16
|
+
include Staticpress::Helpers
|
17
|
+
|
18
|
+
attr_reader :directory
|
19
|
+
|
20
|
+
def initialize
|
21
|
+
@directory = Staticpress.blog_path + config.source
|
22
|
+
end
|
23
|
+
|
24
|
+
def all_content
|
25
|
+
self.class.content_types.map(&:all).flatten
|
26
|
+
end
|
27
|
+
|
28
|
+
def find_content_by_url_path(url_path)
|
29
|
+
route = Staticpress::Route.from_url_path url_path
|
30
|
+
route.content if route
|
31
|
+
end
|
32
|
+
|
33
|
+
def meta
|
34
|
+
# or something...
|
35
|
+
all_content.inject(Staticpress::Metadata.new) do |m, page|
|
36
|
+
m << page.meta
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def save
|
41
|
+
destination = Staticpress.blog_path + config.destination
|
42
|
+
FileUtils.rm_r destination if destination.directory?
|
43
|
+
all_content.each &:save
|
44
|
+
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
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'staticpress'
|
2
|
+
require 'staticpress/helpers'
|
3
|
+
|
4
|
+
module Staticpress
|
5
|
+
class Theme
|
6
|
+
extend Staticpress::Helpers
|
7
|
+
include Staticpress::Helpers
|
8
|
+
|
9
|
+
attr_reader :root
|
10
|
+
|
11
|
+
def initialize(name)
|
12
|
+
@name = name
|
13
|
+
custom = Staticpress.blog_path + 'themes' + @name.to_s
|
14
|
+
@root = custom.directory? ? custom : Staticpress.root + 'themes' + @name.to_s
|
15
|
+
end
|
16
|
+
|
17
|
+
[
|
18
|
+
:include,
|
19
|
+
:layout,
|
20
|
+
:view
|
21
|
+
].each do |method_name|
|
22
|
+
define_method "default_#{method_name}" do
|
23
|
+
send("keyed_#{method_name}s")['default']
|
24
|
+
end unless method_name == :include
|
25
|
+
|
26
|
+
define_method "keyed_#{method_name}s" do
|
27
|
+
hash_from_array(send("#{method_name}s")) { |name| extensionless_basename name }
|
28
|
+
end
|
29
|
+
|
30
|
+
define_method "#{method_name}_for" do |name|
|
31
|
+
send("keyed_#{method_name}s")[name.to_s]
|
32
|
+
end
|
33
|
+
|
34
|
+
define_method "#{method_name}s" do
|
35
|
+
(root + "#{method_name}s").children
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.theme
|
40
|
+
@theme ||= new config.theme
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'staticpress'
|
2
|
+
require 'staticpress/helpers'
|
3
|
+
require 'staticpress/plugin'
|
4
|
+
require 'staticpress/plugins'
|
5
|
+
|
6
|
+
module Staticpress
|
7
|
+
class ViewHelpers
|
8
|
+
include Staticpress::Helpers
|
9
|
+
|
10
|
+
attr_reader :meta, :page, :theme
|
11
|
+
|
12
|
+
def initialize(page)
|
13
|
+
@page = page
|
14
|
+
@meta, @theme = page.meta, page.theme
|
15
|
+
Staticpress::Plugin.activate_enabled
|
16
|
+
class << self
|
17
|
+
Staticpress::Plugins.constants.each do |plugin|
|
18
|
+
include Staticpress::Plugins.const_get(plugin)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# TODO site_meta should be an aggregate all metadata
|
24
|
+
def site_meta
|
25
|
+
end
|
26
|
+
|
27
|
+
def partial(name, locals = {})
|
28
|
+
template_name = theme.include_for name
|
29
|
+
if template_name.file?
|
30
|
+
template = Tilt[template_name].new { template_name.read }
|
31
|
+
template.render self.class.new(page), locals
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/staticpress.rb
ADDED
File without changes
|
File without changes
|
File without changes
|
File without changes
|