tranzu-rack-tranzu 0.0.1 → 0.0.2
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/lib/rack/tranzu.rb +12 -5
- data/spec/tranzu_spec.rb +29 -11
- metadata +3 -3
data/lib/rack/tranzu.rb
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
require 'nokogiri'
|
|
2
|
-
require '
|
|
3
|
-
|
|
2
|
+
require 'active_resource'
|
|
4
3
|
|
|
5
4
|
module Rack
|
|
6
5
|
class Tranzu
|
|
7
6
|
|
|
8
|
-
def initialize(app, site_key)
|
|
7
|
+
def initialize(app, repository_url, site_key, password)
|
|
9
8
|
@app, @site_key = app, site_key
|
|
9
|
+
TextBlock.setup(repository_url, site_key, password)
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
def call(env)
|
|
@@ -98,10 +98,17 @@ module Rack
|
|
|
98
98
|
text_block ||= TextBlock.new(:site_key => @site_key, :source_text => source_text)
|
|
99
99
|
text_block.target_text = target_text
|
|
100
100
|
unless text_block.save
|
|
101
|
-
raise Exception.new("unable to save text block")
|
|
101
|
+
raise Exception.new("unable to save text block: #{text_block.errors.inspect}")
|
|
102
102
|
end
|
|
103
103
|
end
|
|
104
104
|
|
|
105
|
-
|
|
105
|
+
class TextBlock < ActiveResource::Base
|
|
106
106
|
|
|
107
|
+
def self.setup(repository_url, site_key, password)
|
|
108
|
+
self.site = repository_url
|
|
109
|
+
# use site_key and password to authenticate
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
end
|
|
107
114
|
end
|
data/spec/tranzu_spec.rb
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
require 'rack'
|
|
2
|
-
require 'lib/text_block'
|
|
3
2
|
require 'lib/rack/tranzu'
|
|
4
3
|
|
|
5
4
|
describe Rack::Tranzu do
|
|
5
|
+
|
|
6
6
|
def delete_all_text_blocks
|
|
7
|
-
text_blocks = TextBlock.find(:all)
|
|
7
|
+
text_blocks = Rack::Tranzu::TextBlock.find(:all)
|
|
8
8
|
text_blocks.each do |text_block|
|
|
9
9
|
text_block.destroy
|
|
10
10
|
end
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
before (:each) do
|
|
14
|
-
delete_all_text_blocks
|
|
15
14
|
@response_strings = []
|
|
16
15
|
@client_app = lambda {|env| [200, {'Content-Type' => 'text/html'}, @response_strings] }
|
|
17
|
-
@app = Rack::Tranzu.new(@client_app, "1234ABCD")
|
|
16
|
+
@app = Rack::Tranzu.new(@client_app, "http://localhost:3001", "1234ABCD", "password")
|
|
17
|
+
delete_all_text_blocks
|
|
18
18
|
@app.send(:record_text_block_with_translation, "This is an example of already translated text.", "Se ejemplifica texto ya traducido.")
|
|
19
19
|
end
|
|
20
20
|
|
|
@@ -24,7 +24,7 @@ describe Rack::Tranzu do
|
|
|
24
24
|
response = Rack::MockRequest.new(@app).get('/', 'HTTP_ACCEPT' => 'text/html')
|
|
25
25
|
|
|
26
26
|
|
|
27
|
-
source_text_items = TextBlock.find(:all).map {|text_block_translations| text_block_translations.source_text}
|
|
27
|
+
source_text_items = Rack::Tranzu::TextBlock.find(:all).map {|text_block_translations| text_block_translations.source_text}
|
|
28
28
|
source_text_items.sort.should == ["This is an example of already translated text.", "This is an example of untranslated text.", "This is another example of untranslated text."].sort
|
|
29
29
|
end
|
|
30
30
|
|
|
@@ -61,7 +61,7 @@ describe Rack::Tranzu do
|
|
|
61
61
|
end
|
|
62
62
|
|
|
63
63
|
it "should not translate any text blocks if the site id is not valid" do
|
|
64
|
-
@app = Rack::Tranzu.new(@client_app, "
|
|
64
|
+
@app = Rack::Tranzu.new(@client_app, "http://localhost:3001", "x1234ABCD", "password")
|
|
65
65
|
source_text = "<html><body><p>This is an example of already translated text.</p><p>This is an example of untranslated text.</p></body></html>"
|
|
66
66
|
@response_strings << source_text
|
|
67
67
|
response = Rack::MockRequest.new(@app).get('/', 'HTTP_ACCEPT' => 'text/html')
|
|
@@ -78,7 +78,7 @@ describe Rack::Tranzu do
|
|
|
78
78
|
it "should not attempt to translate non-html requests" do
|
|
79
79
|
@response_strings << "<adam>adam is studly</adam>"
|
|
80
80
|
@client_app = lambda {|env| [201, {'Content-Type' => 'text/xml', 'Content-Encoding' => 'gzip'}, @response_strings] }
|
|
81
|
-
@app = Rack::Tranzu.new(@client_app, "1234ABCD")
|
|
81
|
+
@app = Rack::Tranzu.new(@client_app, "http://localhost:3001", "1234ABCD", "password")
|
|
82
82
|
@app.should_not_receive(:translate_page)
|
|
83
83
|
response = Rack::MockRequest.new(@app).get('/', 'HTTP_ACCEPT' => 'text/xml')
|
|
84
84
|
response.body.should == @response_strings[0]
|
|
@@ -87,13 +87,31 @@ describe Rack::Tranzu do
|
|
|
87
87
|
end
|
|
88
88
|
end
|
|
89
89
|
|
|
90
|
-
it "should not strip out linefeeds from html"
|
|
90
|
+
it "should not strip out linefeeds from html" do
|
|
91
|
+
pending
|
|
92
|
+
@response_strings << "<html><body>\n<p>This is an example of already translated text.</p>\n<p>This is an example of untranslated text.</p>\n</body></html>"
|
|
93
|
+
response = Rack::MockRequest.new(@app).get('/', 'HTTP_ACCEPT' => 'text/html')
|
|
94
|
+
response.body.should == "<html><body\n><p> Se ejemplifica texto ya traducido.</p>\n<p>This is an example of untranslated text.</p>\n</body></html>"
|
|
95
|
+
end
|
|
91
96
|
|
|
92
|
-
it "should not strip out leading or trailing whitespace from text nodes"
|
|
97
|
+
it "should not strip out leading or trailing whitespace from text nodes" do
|
|
98
|
+
@response_strings << "<html><body><p> This is an example of already translated text.</p><p>This is an example of untranslated text.\n</p></body></html>"
|
|
99
|
+
response = Rack::MockRequest.new(@app).get('/', 'HTTP_ACCEPT' => 'text/html')
|
|
100
|
+
response.body.should == "<html><body><p> Se ejemplifica texto ya traducido.</p><p>This is an example of untranslated text.\n</p></body></html>"
|
|
101
|
+
end
|
|
93
102
|
|
|
94
|
-
it "should not change DOCTYPE if it exists in the application response'"
|
|
103
|
+
it "should not change DOCTYPE if it exists in the application response'" do
|
|
104
|
+
pending
|
|
105
|
+
@response_strings << "<DOCTYPE strange><html><body><p>This is an example of already translated text.</p><p>This is an example of untranslated text.</p></body></html>"
|
|
106
|
+
response = Rack::MockRequest.new(@app).get('/', 'HTTP_ACCEPT' => 'text/html')
|
|
107
|
+
response.body.should == "<DOCTYPE strange><html><body><p>Se ejemplifica texto ya traducido.</p><p>This is an example of untranslated text.</p></body></html>"
|
|
108
|
+
end
|
|
95
109
|
|
|
96
|
-
it "should not add DOCTYPE if it is not in the application response"
|
|
110
|
+
it "should not add DOCTYPE if it is not in the application response" do
|
|
111
|
+
@response_strings << "<html><body><p>This is an example of already translated text.</p><p>This is an example of untranslated text.</p></body></html>"
|
|
112
|
+
response = Rack::MockRequest.new(@app).get('/', 'HTTP_ACCEPT' => 'text/html')
|
|
113
|
+
response.body.should == "<html><body><p>Se ejemplifica texto ya traducido.</p><p>This is an example of untranslated text.</p></body></html>"
|
|
114
|
+
end
|
|
97
115
|
|
|
98
116
|
end
|
|
99
117
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: tranzu-rack-tranzu
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- John Reitano
|
|
@@ -19,9 +19,9 @@ dependencies:
|
|
|
19
19
|
version_requirement:
|
|
20
20
|
version_requirements: !ruby/object:Gem::Requirement
|
|
21
21
|
requirements:
|
|
22
|
-
- -
|
|
22
|
+
- - ">="
|
|
23
23
|
- !ruby/object:Gem::Version
|
|
24
|
-
version: "0
|
|
24
|
+
version: "0"
|
|
25
25
|
version:
|
|
26
26
|
description: Website translation middleware.
|
|
27
27
|
email: tranzuapp@gmail.com
|