acts_as_crafter 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +11 -0
- data/acts_as_crafter.gemspec +29 -0
- data/lib/acts_as_crafter.rb +47 -0
- data/lib/acts_as_crafter/railtie.rb +9 -0
- metadata +72 -0
data/README.textile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
h1. Mate, ActsAsCrafter, mate.
|
2
|
+
|
3
|
+
Mate, bring a little bit of "Marcus Crafter":http://github.com/crafterm awesomeness into your HTML responses with this Rack Middleware, mate.
|
4
|
+
|
5
|
+
h2. Mate, installation, mate.
|
6
|
+
|
7
|
+
Mate, Bundle it in to your app now, mate.
|
8
|
+
|
9
|
+
h2. Mate, features, mate.
|
10
|
+
|
11
|
+
Mate, just one feature. It fiddles with headings, list items and paragraphs in your HTML response to make sure you have the full Marcus Crafter experience anywhere, any time, mate.
|
@@ -0,0 +1,29 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = %q{acts_as_crafter}
|
3
|
+
s.version = "1.0.0"
|
4
|
+
|
5
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
6
|
+
s.authors = ["Justin French", "Vodka", "RailsCamp"]
|
7
|
+
s.date = %q{2010-11-14}
|
8
|
+
s.description = %q{Bring a little bit of Marcus Crafter awesomeness into your responses with this Rack Middleware}
|
9
|
+
s.summary = %q{Bring a little bit of Marcus Crafter awesomeness into your responses with this Rack Middleware}
|
10
|
+
s.email = %q{justin@indent.com.au}
|
11
|
+
s.homepage = %q{http://github.com/justinfrench/acts_as_crafter}
|
12
|
+
s.extra_rdoc_files = [
|
13
|
+
"README.textile"
|
14
|
+
]
|
15
|
+
s.files = Dir["**/*"]
|
16
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
s.rubygems_version = %q{1.3.5}
|
19
|
+
|
20
|
+
if s.respond_to? :specification_version then
|
21
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
22
|
+
s.specification_version = 3
|
23
|
+
|
24
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
25
|
+
else
|
26
|
+
end
|
27
|
+
else
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'rack/utils'
|
2
|
+
|
3
|
+
if defined?(Rails)
|
4
|
+
require 'acts_as_crafter/railtie'
|
5
|
+
end
|
6
|
+
|
7
|
+
module Rack
|
8
|
+
class ActsAsCrafter
|
9
|
+
include Rack::Utils
|
10
|
+
|
11
|
+
def initialize(app, opts={})
|
12
|
+
@app = app
|
13
|
+
end
|
14
|
+
|
15
|
+
def call(env)
|
16
|
+
status, headers, response = @app.call(env)
|
17
|
+
headers = HeaderHash.new(headers)
|
18
|
+
if !STATUS_WITH_NO_ENTITY_BODY.include?(status) &&
|
19
|
+
!headers['transfer-encoding'] &&
|
20
|
+
headers['content-type'] &&
|
21
|
+
headers['content-type'].include?("text/html")
|
22
|
+
puts "text/html!"
|
23
|
+
response.body = transform(response.body)
|
24
|
+
end
|
25
|
+
|
26
|
+
[status, headers, response]
|
27
|
+
end
|
28
|
+
|
29
|
+
protected
|
30
|
+
|
31
|
+
# Yup, this is ugly as hell, but I'm drinking Cîroc vodka out of a plastic cup at Rails Camp 8 in Perth.
|
32
|
+
def transform(body)
|
33
|
+
body.gsub(/<p(.*?)>(.*?)<\/p>/) { |s|
|
34
|
+
"<p#{$1}>Mate, #{($2[0..0] == "I" ? "I" : $2[0..0].downcase) + $2[1..-1].gsub(/\.$/, '')}, mate.</p>"
|
35
|
+
}.gsub(/<li>(.*?)<\/li>/) { |s|
|
36
|
+
"<li>Mate, #{($1[0..0] == "I" ? "I" : $1[0..0].downcase) + $1[1..-1].gsub(/\.$/, '')}, mate.</li>"
|
37
|
+
}.gsub(/<h1>(.*?)<\/h1>/) { |s|
|
38
|
+
"<h1>#{$1[0..-1].gsub(/\.$/, '')}, Mate!</h1>"
|
39
|
+
}.gsub(/<h2>(.*?)<\/h2>/) { |s|
|
40
|
+
"<h2>#{$1[0..-1].gsub(/\.$/, '')}, Mate!</h2>"
|
41
|
+
}.gsub(/<h3>(.*?)<\/h3>/) { |s|
|
42
|
+
"<h3>#{$1[0..-1].gsub(/\.$/, '')}, Mate!</h3>"
|
43
|
+
}.gsub(/\bwater\b/, "Cîroc")
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: acts_as_crafter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 1.0.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Justin French
|
14
|
+
- Vodka
|
15
|
+
- RailsCamp
|
16
|
+
autorequire:
|
17
|
+
bindir: bin
|
18
|
+
cert_chain: []
|
19
|
+
|
20
|
+
date: 2010-11-14 00:00:00 +11:00
|
21
|
+
default_executable:
|
22
|
+
dependencies: []
|
23
|
+
|
24
|
+
description: Bring a little bit of Marcus Crafter awesomeness into your responses with this Rack Middleware
|
25
|
+
email: justin@indent.com.au
|
26
|
+
executables: []
|
27
|
+
|
28
|
+
extensions: []
|
29
|
+
|
30
|
+
extra_rdoc_files:
|
31
|
+
- README.textile
|
32
|
+
files:
|
33
|
+
- acts_as_crafter.gemspec
|
34
|
+
- lib/acts_as_crafter/railtie.rb
|
35
|
+
- lib/acts_as_crafter.rb
|
36
|
+
- README.textile
|
37
|
+
has_rdoc: true
|
38
|
+
homepage: http://github.com/justinfrench/acts_as_crafter
|
39
|
+
licenses: []
|
40
|
+
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options:
|
43
|
+
- --charset=UTF-8
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
none: false
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
hash: 3
|
52
|
+
segments:
|
53
|
+
- 0
|
54
|
+
version: "0"
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
hash: 3
|
61
|
+
segments:
|
62
|
+
- 0
|
63
|
+
version: "0"
|
64
|
+
requirements: []
|
65
|
+
|
66
|
+
rubyforge_project:
|
67
|
+
rubygems_version: 1.3.7
|
68
|
+
signing_key:
|
69
|
+
specification_version: 3
|
70
|
+
summary: Bring a little bit of Marcus Crafter awesomeness into your responses with this Rack Middleware
|
71
|
+
test_files: []
|
72
|
+
|