gitstuff-preview 0.0.1 → 0.0.2
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/Gemfile.lock +1 -1
- data/README.markdown +9 -0
- data/config.ru +1 -0
- data/lib/gitstuff-preview/server.rb +29 -25
- data/lib/gitstuff-preview/version.rb +1 -1
- metadata +4 -4
data/Gemfile.lock
CHANGED
data/README.markdown
CHANGED
@@ -0,0 +1,9 @@
|
|
1
|
+
# gitstuff-preview
|
2
|
+
|
3
|
+
This is a handy gem for previewing [Gitstuff](http://gitstuff.com) site templates.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
`gem install gitstuff-preview`, then run `gitstuff-preview` in the directory that has your Gitstuff files.
|
8
|
+
|
9
|
+
If you'd like it on a port other than 3000, run it with `gitstuff-preview -p <port>`.
|
data/config.ru
CHANGED
@@ -10,33 +10,35 @@ BASE_PATH = ENV['BASE_PATH'] || "./"
|
|
10
10
|
|
11
11
|
class Server < Sinatra::Base
|
12
12
|
|
13
|
-
def render_index(context={})
|
14
|
-
|
13
|
+
def render_index(context={}, options={})
|
14
|
+
context[:posts] = []
|
15
15
|
Dir["#{BASE_PATH}/posts/*.yml"][0,10].each do |file|
|
16
16
|
slug = File.basename(file, ".yml")
|
17
17
|
post = get_post_content(slug, file)
|
18
|
-
post
|
19
|
-
|
18
|
+
post.url = "/#{slug}"
|
19
|
+
post.content = RDiscount.new(post.content).to_html
|
20
|
+
context[:posts] << post.to_hash
|
20
21
|
end
|
21
|
-
render_page(
|
22
|
+
render_page(context, options)
|
22
23
|
end
|
23
24
|
|
24
25
|
def render_post(slug, context={})
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
post.content = RDiscount.new(post.content).to_html
|
31
|
-
template = Liquid::Template.parse(File.read File.join(BASE_PATH, 'layouts', 'post.html.liquid'))
|
32
|
-
template.render Hashie::Mash.new(context.merge(post.to_hash))
|
26
|
+
post = get_post_content(slug)
|
27
|
+
post.content = RDiscount.new(post.content).to_html
|
28
|
+
context[:posts] = [post.to_hash]
|
29
|
+
context[:single_post] = true
|
30
|
+
render_page(context)
|
33
31
|
end
|
34
32
|
|
35
33
|
def get_post_content(slug, path=nil)
|
36
|
-
path ||= File.join(BASE_PATH
|
34
|
+
path ||= File.join("#{BASE_PATH}posts", slug) + ".yml"
|
37
35
|
begin
|
38
36
|
post_data = Hashie::Mash.new YAML.load_file(path)
|
39
|
-
post_data[
|
37
|
+
post_data[:content] = File.read(path).sub /---.*---\n/m, ''
|
38
|
+
post_data[:author] = Hashie::Mash.new :name => "Author Name", :email => "author@example.com"
|
39
|
+
post_data[:gravatar] = "http://www.gravatar.com/avatar/#{Digest::MD5.hexdigest(post_data.author.email)}"
|
40
|
+
post_data.created_at = Time.now
|
41
|
+
post_data.modified_at = Time.now
|
40
42
|
post_data
|
41
43
|
rescue => e
|
42
44
|
puts "!! Error loading #{path}"
|
@@ -45,9 +47,10 @@ class Server < Sinatra::Base
|
|
45
47
|
end
|
46
48
|
end
|
47
49
|
|
48
|
-
def render_page(
|
49
|
-
layout =
|
50
|
-
layout
|
50
|
+
def render_page(context, options={})
|
51
|
+
layout = options[:layout] || 'index.html.liquid'
|
52
|
+
layout = Liquid::Template.parse(File.read File.join(BASE_PATH, 'templates', layout))
|
53
|
+
layout.render Hashie::Mash.new context
|
51
54
|
end
|
52
55
|
|
53
56
|
def search_form
|
@@ -55,22 +58,18 @@ class Server < Sinatra::Base
|
|
55
58
|
end
|
56
59
|
|
57
60
|
def basic_metadata
|
58
|
-
{
|
59
|
-
:root_path =>
|
61
|
+
Hashie::Mash.new({
|
62
|
+
:root_path => request.url.match(/(^.*\/{2}[^\/]*)/)[1],
|
60
63
|
:asset_path => '/assets',
|
61
64
|
:search_form => search_form
|
62
|
-
}
|
65
|
+
})
|
63
66
|
end
|
64
67
|
|
65
68
|
def default_metadata
|
66
69
|
hash = {
|
67
|
-
:author => { :name => "Author Name", :email => "author@example.com" },
|
68
|
-
:created_at => Time.now,
|
69
|
-
:modified_at => Time.now,
|
70
70
|
:previous_page => '#',
|
71
71
|
:next_page => '#',
|
72
72
|
}
|
73
|
-
hash['gravatar'] = "http://www.gravatar.com/avatar/#{Digest::MD5.hexdigest(hash[:author][:email])}"
|
74
73
|
hash.merge(basic_metadata)
|
75
74
|
end
|
76
75
|
|
@@ -86,6 +85,11 @@ class Server < Sinatra::Base
|
|
86
85
|
get '/search' do
|
87
86
|
render_page '', basic_metadata.merge({ :no_results => true, :query => params[:q] || 'some search query' })
|
88
87
|
end
|
88
|
+
|
89
|
+
get '/atom.xml' do
|
90
|
+
content_type 'application/atom+xml'
|
91
|
+
render_index default_metadata, :layout => 'atom.xml.liquid'
|
92
|
+
end
|
89
93
|
|
90
94
|
get '/:slug' do
|
91
95
|
render_post params[:slug], default_metadata
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gitstuff-preview
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jesse Kriss
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-11-
|
18
|
+
date: 2011-11-27 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: sinatra
|