georgi-kontrol 0.1.5 → 0.1.6

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/examples/git_app.ru CHANGED
@@ -2,9 +2,15 @@ require 'kontrol'
2
2
  require 'bluecloth'
3
3
 
4
4
  class GitApp < Kontrol::Application
5
+
6
+ def initialize(path)
7
+ super
8
+ @store = GitStore.new(path)
9
+ end
10
+
5
11
  map do
6
12
  get '/(.*)' do |name|
7
- BlueCloth.new(store['pages', name + '.md']).to_html
13
+ BlueCloth.new(@store['pages', name + '.md']).to_html
8
14
  end
9
15
  end
10
16
  end
@@ -6,7 +6,11 @@ module Kontrol
6
6
 
7
7
  class << self
8
8
  def map(&block)
9
- @map = Builder.new(&block)
9
+ if block
10
+ @map = Builder.new(&block)
11
+ else
12
+ @map
13
+ end
10
14
  end
11
15
 
12
16
  def call(env)
@@ -16,26 +20,19 @@ module Kontrol
16
20
 
17
21
  include Helpers
18
22
 
19
- attr_reader :path, :store
23
+ attr_reader :path
20
24
 
21
25
  def initialize(path = '.')
22
- @path = File.expand_path(path)
23
-
24
- if File.directory?(File.join(path, '.git')) && ENV['RACK_ENV'] == 'production'
25
- @store = GitStore.new(path)
26
- else
27
- @store = GitStore::FileStore.new(path)
28
- end
26
+ @path = File.expand_path(path)
29
27
  end
30
28
 
31
- def templates
32
- store['templates']
29
+ def load_template(file)
30
+ ERB.new(File.read("#{path}/templates/#{file}"))
33
31
  end
34
32
 
35
33
  # Render template with given variables.
36
34
  def render_template(file, vars)
37
- template = templates[file] or raise "template #{file} not found"
38
- Template.render(template, self, file, vars)
35
+ Template.render(load_template(file), self, file, vars)
39
36
  end
40
37
 
41
38
  def render_layout(vars)
@@ -45,7 +42,8 @@ module Kontrol
45
42
  # Render named template and insert into layout with given variables.
46
43
  def render(name, vars = {})
47
44
  content = render_template(name, vars)
48
- if name[0, 1] == '_' || name.match(/\.rxml$/)
45
+
46
+ if name[0, 1] == '_' or vars[:layout] == false
49
47
  content
50
48
  else
51
49
  vars.merge!(:content => content)
@@ -112,8 +110,6 @@ module Kontrol
112
110
  Thread.current['request'] = Rack::Request.new(env)
113
111
  Thread.current['response'] = Rack::Response.new([], nil, { 'Content-Type' => '' })
114
112
 
115
- store.refresh!
116
-
117
113
  env['kontrol.app'] = self
118
114
 
119
115
  status, header, body = self.class.call(env)
@@ -121,75 +117,20 @@ module Kontrol
121
117
  response.status = status if response.status.nil?
122
118
  response.header.merge!(header)
123
119
  response.body = body if response.body.empty?
124
- response['Content-Length'] = response.body.size.to_s if response.status == 200
120
+
121
+ if response.status != 304
122
+ response.body ||= ''
123
+ response['Content-Length'] = response.body.size.to_s
124
+ end
125
+
125
126
  response['Content-Type'] = guess_content_type if response['Content-Type'].empty?
126
127
 
127
128
  response.finish
128
129
  end
129
130
 
130
131
  def inspect
131
- "#<Kontrol::Application @path=#{path}>"
132
- end
133
-
134
- MIME_TYPES = {
135
- "ai" => "application/postscript",
136
- "asc" => "text/plain",
137
- "avi" => "video/x-msvideo",
138
- "bin" => "application/octet-stream",
139
- "bmp" => "image/bmp",
140
- "class" => "application/octet-stream",
141
- "cer" => "application/pkix-cert",
142
- "crl" => "application/pkix-crl",
143
- "crt" => "application/x-x509-ca-cert",
144
- "css" => "text/css",
145
- "dms" => "application/octet-stream",
146
- "doc" => "application/msword",
147
- "dvi" => "application/x-dvi",
148
- "eps" => "application/postscript",
149
- "etx" => "text/x-setext",
150
- "exe" => "application/octet-stream",
151
- "gif" => "image/gif",
152
- "htm" => "text/html",
153
- "html" => "text/html",
154
- "ico" => "image/x-icon",
155
- "jpe" => "image/jpeg",
156
- "jpeg" => "image/jpeg",
157
- "jpg" => "image/jpeg",
158
- "js" => "text/javascript",
159
- "lha" => "application/octet-stream",
160
- "lzh" => "application/octet-stream",
161
- "mov" => "video/quicktime",
162
- "mp3" => "audio/mpeg",
163
- "mpe" => "video/mpeg",
164
- "mpeg" => "video/mpeg",
165
- "mpg" => "video/mpeg",
166
- "pbm" => "image/x-portable-bitmap",
167
- "pdf" => "application/pdf",
168
- "pgm" => "image/x-portable-graymap",
169
- "png" => "image/png",
170
- "pnm" => "image/x-portable-anymap",
171
- "ppm" => "image/x-portable-pixmap",
172
- "ppt" => "application/vnd.ms-powerpoint",
173
- "ps" => "application/postscript",
174
- "qt" => "video/quicktime",
175
- "ras" => "image/x-cmu-raster",
176
- "rb" => "text/plain",
177
- "rd" => "text/plain",
178
- "rtf" => "application/rtf",
179
- "rss" => "application/rss+xml",
180
- "sgm" => "text/sgml",
181
- "sgml" => "text/sgml",
182
- "tif" => "image/tiff",
183
- "tiff" => "image/tiff",
184
- "txt" => "text/plain",
185
- "xbm" => "image/x-xbitmap",
186
- "xls" => "application/vnd.ms-excel",
187
- "xml" => "text/xml",
188
- "xpm" => "image/x-xpixmap",
189
- "xwd" => "image/x-xwindowdump",
190
- "zip" => "application/zip",
191
- }
192
-
132
+ "#<#{self.class.name} @path=#{path}>"
133
+ end
193
134
  end
194
135
 
195
136
  end
data/lib/kontrol.rb CHANGED
@@ -4,9 +4,8 @@ require 'erb'
4
4
  require 'yaml'
5
5
  require 'logger'
6
6
 
7
- begin; require 'git_store'; rescue LoadError; end
8
-
9
7
  require 'kontrol/helpers'
8
+ require 'kontrol/mime_types'
10
9
  require 'kontrol/template'
11
10
  require 'kontrol/application'
12
11
  require 'kontrol/builder'
@@ -4,7 +4,7 @@ require 'rack/mock'
4
4
 
5
5
  describe Kontrol::Builder do
6
6
 
7
- REPO = File.expand_path(File.dirname(__FILE__) + '/repo')
7
+ REPO = File.exist?('/tmp') ? '/tmp/test' : File.expand_path(File.dirname(__FILE__) + '/repo')
8
8
 
9
9
  before do
10
10
  FileUtils.rm_rf REPO
@@ -12,6 +12,8 @@ describe Kontrol::Builder do
12
12
  Dir.chdir REPO
13
13
  `git init`
14
14
 
15
+ ENV['RACK_ENV'] = 'production'
16
+
15
17
  @class = Class.new(Kontrol::Application)
16
18
  @app = @class.new(REPO)
17
19
  @request = Rack::MockRequest.new(@app)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: georgi-kontrol
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthias Georgi
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-12-17 00:00:00 -08:00
12
+ date: 2008-04-12 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15