gnarly 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/gnarly/haml.rb +12 -0
  2. data/lib/gnarly/typhoeus.rb +48 -0
  3. metadata +4 -3
data/lib/gnarly/haml.rb CHANGED
@@ -7,6 +7,7 @@ module Gnarly
7
7
  def haml(name, &block)
8
8
  root = application.haml_root
9
9
  template = File.read "#{root}/#{name}.haml"
10
+ template.force_encoding "utf-8"
10
11
  engine = ::Haml::Engine.new template
11
12
  body = engine.render self
12
13
  if block
@@ -31,6 +32,17 @@ module Gnarly
31
32
  end
32
33
  end
33
34
 
35
+ def haml(file, url_mask=nil)
36
+ url_mask = "/#{file}" unless url_mask
37
+ url url_mask do
38
+ get do
39
+ provides "text/html" do
40
+ ok haml(file)
41
+ end
42
+ end
43
+ end
44
+ end
45
+
34
46
  end
35
47
 
36
48
  class Environment
@@ -0,0 +1,48 @@
1
+ require 'typhoeus'
2
+
3
+ require 'ap'
4
+
5
+ module Gnarly
6
+
7
+ module Typhoeus
8
+
9
+ def typhoeus(method, url, opts={})
10
+ response = ::Typhoeus::Request.send method, url, opts
11
+ if block_given?
12
+ r = yield response
13
+ case r
14
+ when ::Typhoeus::Response
15
+ Typhoeus.make_rack_response r
16
+ else
17
+ r
18
+ end
19
+ else
20
+ Typhoeus.make_rack_response response
21
+ end
22
+ end
23
+
24
+ def self.make_headers(response)
25
+ headers = {}
26
+ response.headers.split("\n").each do |ln|
27
+ a = ln.split(":", 2)
28
+ if a.size == 2
29
+ key = a.first.strip
30
+ unless ["status"].include?(key.downcase)
31
+ headers[key] = a.last.strip
32
+ end
33
+ end
34
+ end
35
+ headers
36
+ end
37
+
38
+ def self.make_rack_response(response)
39
+ [response.code, Typhoeus.make_headers(response), [response.body]]
40
+ end
41
+
42
+ end
43
+
44
+ class Environment
45
+ include Typhoeus
46
+ end
47
+
48
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 3
9
- version: 0.0.3
8
+ - 4
9
+ version: 0.0.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Kim Dalsgaard
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-08 00:00:00 +01:00
17
+ date: 2010-05-06 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
@@ -36,6 +36,7 @@ files:
36
36
  - lib/gnarly/request.rb
37
37
  - lib/gnarly/status.rb
38
38
  - lib/gnarly/system.rb
39
+ - lib/gnarly/typhoeus.rb
39
40
  - lib/gnarly/understands.rb
40
41
  - lib/gnarly/url.rb
41
42
  - lib/gnarly/uuid.rb