rack-tidy-ffi 0.1

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/README.md ADDED
@@ -0,0 +1,19 @@
1
+ # RackTidyFFI
2
+
3
+ ## Rack middleware to tidy application output
4
+
5
+ - Works with ruby 1.9
6
+ - uses tidy_ffi instead of tidy (broken on 1.9 because of Ruby DL changes)
7
+
8
+
9
+ ## Installation
10
+
11
+ gem install rack-tidy-ffi
12
+
13
+ ## Usage
14
+
15
+ in your config.ru:
16
+
17
+ require 'rack-tidy-ffi'
18
+
19
+ use RackTidyFFI
@@ -0,0 +1,3 @@
1
+ class RackTidyFFI
2
+ VERSION = "0.1"
3
+ end
@@ -0,0 +1,25 @@
1
+ path = File.expand_path "../", __FILE__
2
+ require "#{path}/tidy-machine"
3
+
4
+ class RackTidyFFI
5
+ attr_accessor :headers
6
+
7
+ def initialize(app)
8
+ @app = app
9
+ end
10
+
11
+ def call(env)
12
+ @status, @headers, @response = @app.call(env)
13
+ # TODO: include all response attributes... needed?
14
+ # response_body = ""
15
+ # response_body = @response.each { |part| response_body += part }
16
+ if @headers["Content-Type"].include? "text/html"
17
+ response = TidyMachine.new(@response.first).tidy
18
+ response = "<!DOCTYPE HTML>\n#{response}"
19
+ @headers["Content-Length"] = response.length.to_s
20
+ @response = [response]
21
+ end
22
+ [@status, @headers, @response]
23
+ end
24
+
25
+ end
@@ -0,0 +1,20 @@
1
+ class TidyMachine
2
+ require 'tidy_ffi'
3
+
4
+ DEFAULT_OPTIONS = { :"tidy_mark" => false, :doctype => "omit" }
5
+
6
+ def initialize(text)
7
+ @text = text
8
+ # TODO: check doctype html5
9
+ #
10
+ # "<!DOCTYPE html>\n<html>\n<head>\n<title></title>\n</head>\n<body>\na string\n</body>\n</html>\n"
11
+ end
12
+
13
+ def tidy
14
+ TidyFFI::Tidy.with_options(:"tidy_mark" => false, indent: "yes", doctype: "omit").new(@text).clean
15
+ end
16
+
17
+ def self.tidy(text)
18
+ new(text).tidy
19
+ end
20
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-tidy-ffi
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ version: "0.1"
9
+ platform: ruby
10
+ authors:
11
+ - Francesco 'makevoid' Canessa
12
+ autorequire:
13
+ bindir: bin
14
+ cert_chain: []
15
+
16
+ date: 2011-03-15 00:00:00 +01:00
17
+ default_executable:
18
+ dependencies: []
19
+
20
+ description: Rack middleware to tidy application output using tidy_ffi gem - default output is indented and w/ html5 doctype - works with ruby1.9
21
+ email: makevoid@gmail.com
22
+ executables: []
23
+
24
+ extensions: []
25
+
26
+ extra_rdoc_files: []
27
+
28
+ files:
29
+ - README.md
30
+ - lib/rack-tidy-ffi/version.rb
31
+ - lib/rack-tidy-ffi.rb
32
+ - lib/tidy-machine.rb
33
+ has_rdoc: true
34
+ homepage: http://makevoid.com
35
+ licenses: []
36
+
37
+ post_install_message:
38
+ rdoc_options: []
39
+
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ segments:
48
+ - 0
49
+ version: "0"
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 0
57
+ version: "0"
58
+ requirements: []
59
+
60
+ rubyforge_project:
61
+ rubygems_version: 1.3.7
62
+ signing_key:
63
+ specification_version: 3
64
+ summary: Rack middleware to tidy application output
65
+ test_files: []
66
+