gidget 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 hasmanytrees
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,19 @@
1
+ = gidget
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to gidget
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 hasmanytrees. See LICENSE.txt for
18
+ further details.
19
+
@@ -0,0 +1 @@
1
+ require 'gidget/server'
@@ -0,0 +1,10 @@
1
+ class String
2
+ def slugize
3
+ self.downcase.gsub(/&/, 'and').gsub(/\s+/, '-').gsub(/[^a-z0-9-]/, '')
4
+ end
5
+
6
+
7
+ def humanize
8
+ self.capitalize.gsub(/[-_]+/, ' ')
9
+ end
10
+ end
@@ -0,0 +1,34 @@
1
+ require 'yaml'
2
+ require 'gidget/ext'
3
+
4
+
5
+ module Gidget
6
+ class Post < Hash
7
+ def initialize(file_path)
8
+ file = File.open(file_path, "r")
9
+
10
+ # read the first paragraph and load it into a Hash with symbols as keys
11
+ self.update(YAML.load(file.gets("")).inject({}) { |h, (k,v)| h.merge(k.to_sym => v) })
12
+
13
+ file.close()
14
+
15
+ self[:file_path] = file_path
16
+
17
+ self[:request_path] = self[:date].strftime("/%Y/%m/%d/") + self[:title].slugize
18
+
19
+ self[:body] = lambda {
20
+ file = File.open(file_path, "r")
21
+
22
+ # ignore the first paragraph
23
+ file.gets("")
24
+
25
+ # capture the rest of the file
26
+ body = file.gets(nil)
27
+
28
+ file.close()
29
+
30
+ return body
31
+ }
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,25 @@
1
+ require 'singleton'
2
+ require 'gidget/post'
3
+
4
+
5
+ module Gidget
6
+ class PostIndex < Array
7
+ include Singleton
8
+
9
+
10
+ def initialize
11
+ paths = Dir.glob("posts/**/*.txt")
12
+
13
+ paths.each { |file_path|
14
+ self << Post.new(file_path)
15
+ }
16
+
17
+ self.replace self.sort_by { |p| p[:request_path] }.reverse!
18
+
19
+ puts "Post Index created, size = " + self.size.to_s
20
+ end
21
+ end
22
+
23
+
24
+ PostIndex.instance
25
+ end
@@ -0,0 +1,56 @@
1
+ require 'sinatra/base'
2
+ require 'gidget/post_index'
3
+
4
+
5
+ module Gidget
6
+ class Server < Sinatra::Base
7
+ set :haml, :format => :html5
8
+
9
+
10
+ get '/' do
11
+ expires(86400, :public)
12
+
13
+ haml :index, :locals => { :posts => PostIndex.instance }
14
+ end
15
+
16
+
17
+ get %r{^\/\d{4}\/\d{2}\/\d{2}\/\w+} do
18
+ post = nil
19
+
20
+ PostIndex.instance.each { |p|
21
+ if (p[:request_path] == request.path)
22
+ post = p
23
+ break
24
+ end
25
+ }
26
+
27
+ if (post != nil)
28
+ expires(86400, :public)
29
+
30
+ haml :post, :locals => { :post => post }
31
+ end
32
+ end
33
+
34
+
35
+ get %r{^\/\d{4}(\/\d{2}(\/\d{2})?)?$} do
36
+ posts = PostIndex.instance.select { |p|
37
+ p[:request_path] =~ %r{^#{request.path}}
38
+ }
39
+
40
+ expires(86400, :public)
41
+
42
+ haml :archive, :locals => { :posts => posts }
43
+ end
44
+
45
+
46
+ get %r{^\/\w+} do
47
+ begin
48
+ expires(86400, :public)
49
+
50
+ haml request.path.to_sym
51
+ rescue
52
+ pass
53
+ end
54
+ end
55
+ end
56
+ end
metadata ADDED
@@ -0,0 +1,181 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gidget
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Forrest Robertson
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-11-21 00:00:00 -07:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ type: :runtime
23
+ prerelease: false
24
+ name: sinatra
25
+ version_requirements: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 19
31
+ segments:
32
+ - 1
33
+ - 1
34
+ - 0
35
+ version: 1.1.0
36
+ requirement: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ type: :runtime
39
+ prerelease: false
40
+ name: haml
41
+ version_requirements: &id002 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ hash: 55
47
+ segments:
48
+ - 3
49
+ - 0
50
+ - 24
51
+ version: 3.0.24
52
+ requirement: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ type: :runtime
55
+ prerelease: false
56
+ name: rdiscount
57
+ version_requirements: &id003 !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ hash: 5
63
+ segments:
64
+ - 1
65
+ - 6
66
+ - 5
67
+ version: 1.6.5
68
+ requirement: *id003
69
+ - !ruby/object:Gem::Dependency
70
+ type: :development
71
+ prerelease: false
72
+ name: shoulda
73
+ version_requirements: &id004 !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ hash: 3
79
+ segments:
80
+ - 0
81
+ version: "0"
82
+ requirement: *id004
83
+ - !ruby/object:Gem::Dependency
84
+ type: :development
85
+ prerelease: false
86
+ name: bundler
87
+ version_requirements: &id005 !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ~>
91
+ - !ruby/object:Gem::Version
92
+ hash: 23
93
+ segments:
94
+ - 1
95
+ - 0
96
+ - 0
97
+ version: 1.0.0
98
+ requirement: *id005
99
+ - !ruby/object:Gem::Dependency
100
+ type: :development
101
+ prerelease: false
102
+ name: jeweler
103
+ version_requirements: &id006 !ruby/object:Gem::Requirement
104
+ none: false
105
+ requirements:
106
+ - - ~>
107
+ - !ruby/object:Gem::Version
108
+ hash: 1
109
+ segments:
110
+ - 1
111
+ - 5
112
+ - 1
113
+ version: 1.5.1
114
+ requirement: *id006
115
+ - !ruby/object:Gem::Dependency
116
+ type: :development
117
+ prerelease: false
118
+ name: rcov
119
+ version_requirements: &id007 !ruby/object:Gem::Requirement
120
+ none: false
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ hash: 3
125
+ segments:
126
+ - 0
127
+ version: "0"
128
+ requirement: *id007
129
+ description: Gidget is a minimalist blog engine designed to run on Heroku with a Git-based workflow.
130
+ email: forrest@hasmanytrees.com
131
+ executables: []
132
+
133
+ extensions: []
134
+
135
+ extra_rdoc_files:
136
+ - LICENSE.txt
137
+ - README.rdoc
138
+ files:
139
+ - lib/gidget.rb
140
+ - lib/gidget/ext.rb
141
+ - lib/gidget/post.rb
142
+ - lib/gidget/post_index.rb
143
+ - lib/gidget/server.rb
144
+ - LICENSE.txt
145
+ - README.rdoc
146
+ has_rdoc: true
147
+ homepage: http://github.com/hasmanytrees/gidget
148
+ licenses:
149
+ - MIT
150
+ post_install_message:
151
+ rdoc_options: []
152
+
153
+ require_paths:
154
+ - lib
155
+ required_ruby_version: !ruby/object:Gem::Requirement
156
+ none: false
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ hash: 3
161
+ segments:
162
+ - 0
163
+ version: "0"
164
+ required_rubygems_version: !ruby/object:Gem::Requirement
165
+ none: false
166
+ requirements:
167
+ - - ">="
168
+ - !ruby/object:Gem::Version
169
+ hash: 3
170
+ segments:
171
+ - 0
172
+ version: "0"
173
+ requirements: []
174
+
175
+ rubyforge_project:
176
+ rubygems_version: 1.3.7
177
+ signing_key:
178
+ specification_version: 3
179
+ summary: The smallest taco-loving blog engine in the world!
180
+ test_files: []
181
+