als_typograf 0.0.5 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -4,20 +4,19 @@ require 'rake'
4
4
  begin
5
5
  require 'jeweler'
6
6
  Jeweler::Tasks.new do |gem|
7
- gem.name = "als_typograf"
7
+ gem.name = 'als_typograf'
8
8
  gem.summary = %Q{ArtLebedevStudio.RemoteTypograf}
9
9
  gem.description = %Q{ruby-implementation of ArtLebedevStudio.RemoteTypograf class (web-service client)}
10
- gem.email = "rotuka@rotuka.com"
11
- gem.homepage = "http://github.com/rotuka/als_typograf"
12
- gem.authors = ["Alexander Semyonov"]
10
+ gem.email = 'rotuka@rotuka.com'
11
+ gem.homepage = 'http://github.com/rotuka/als_typograf'
12
+ gem.authors = ['Alexander Semyonov']
13
13
  gem.add_dependency 'activesupport', '>= 2.3.4'
14
- gem.add_dependency 'httparty', '>= 0.4.5'
15
- gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
16
- gem.add_development_dependency "yard", ">= 0"
14
+ gem.add_development_dependency 'shoulda', '>= 0'
15
+ gem.add_development_dependency 'yard', '>= 0'
17
16
  end
18
17
  Jeweler::GemcutterTasks.new
19
18
  rescue LoadError
20
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ puts 'Jeweler (or a dependency) not available. Install it with: gem install jeweler'
21
20
  end
22
21
 
23
22
  require 'rake/testtask'
@@ -36,7 +35,7 @@ begin
36
35
  end
37
36
  rescue LoadError
38
37
  task :rcov do
39
- abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
38
+ abort 'RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov'
40
39
  end
41
40
  end
42
41
 
@@ -49,7 +48,7 @@ begin
49
48
  end
50
49
  rescue LoadError
51
50
  task :reek do
52
- abort "Reek is not available. In order to run reek, you must: sudo gem install reek"
51
+ abort 'Reek is not available. In order to run reek, you must: sudo gem install reek'
53
52
  end
54
53
  end
55
54
 
@@ -61,7 +60,7 @@ begin
61
60
  end
62
61
  rescue LoadError
63
62
  task :roodi do
64
- abort "Roodi is not available. In order to run roodi, you must: sudo gem install roodi"
63
+ abort 'Roodi is not available. In order to run roodi, you must: sudo gem install roodi'
65
64
  end
66
65
  end
67
66
 
@@ -70,7 +69,7 @@ begin
70
69
  YARD::Rake::YardocTask.new
71
70
  rescue LoadError
72
71
  task :yardoc do
73
- abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
72
+ abort 'YARD is not available. In order to run yardoc, you must: sudo gem install yard'
74
73
  end
75
74
  end
76
75
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.5
1
+ 0.1.0
data/als_typograf.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{als_typograf}
8
- s.version = "0.0.5"
8
+ s.version = "0.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Alexander Semyonov"]
12
- s.date = %q{2009-11-26}
12
+ s.date = %q{2010-01-24}
13
13
  s.description = %q{ruby-implementation of ArtLebedevStudio.RemoteTypograf class (web-service client)}
14
14
  s.email = %q{rotuka@rotuka.com}
15
15
  s.extra_rdoc_files = [
@@ -52,19 +52,16 @@ Gem::Specification.new do |s|
52
52
 
53
53
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
54
54
  s.add_runtime_dependency(%q<activesupport>, [">= 2.3.4"])
55
- s.add_runtime_dependency(%q<httparty>, [">= 0.4.5"])
56
- s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
55
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
57
56
  s.add_development_dependency(%q<yard>, [">= 0"])
58
57
  else
59
58
  s.add_dependency(%q<activesupport>, [">= 2.3.4"])
60
- s.add_dependency(%q<httparty>, [">= 0.4.5"])
61
- s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
59
+ s.add_dependency(%q<shoulda>, [">= 0"])
62
60
  s.add_dependency(%q<yard>, [">= 0"])
63
61
  end
64
62
  else
65
63
  s.add_dependency(%q<activesupport>, [">= 2.3.4"])
66
- s.add_dependency(%q<httparty>, [">= 0.4.5"])
67
- s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
64
+ s.add_dependency(%q<shoulda>, [">= 0"])
68
65
  s.add_dependency(%q<yard>, [">= 0"])
69
66
  end
70
67
  end
data/lib/als_typograf.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  $KCODE = 'u'
2
2
 
3
- require 'activesupport'
3
+ require 'active_support'
4
4
  require 'httparty'
5
5
 
6
6
  # ruby-implementation of ArtLebedevStudio.RemoteTypograf class (web-service client)
@@ -102,7 +102,7 @@ module AlsTypograf
102
102
  # @option custom_options [String] :max_nobr (3) How many symbols around dash to surround with +<nobr>+ tag
103
103
  # @option custom_options [String] :encoding ('UTF-8') Encoding of text
104
104
  def self.process(text, custom_options = {})
105
- Request.new.process_text(text, custom_options.reverse_merge(options))
105
+ Request.process_text(text, custom_options.reverse_merge(options))
106
106
  end
107
107
  end
108
108
 
@@ -1,18 +1,20 @@
1
+ require 'net/http'
2
+
1
3
  module AlsTypograf
2
4
  # The request class
3
- class Request
4
- include HTTParty
5
- base_uri 'typograf.artlebedev.ru'
6
- format :xml
7
- headers('Content-Type' => 'text/xml',
8
- 'Host' => 'typograf.artlebedev.ru',
9
- 'SOAPAction' => '"http://typograf.artlebedev.ru/webservices/ProcessText"')
5
+ module Request
6
+ @@url = URI.parse('http://typograf.artlebedev.ru/webservices/typograf.asmx')
7
+ @@result_regexp = /<ProcessTextResult>\s*((.|\n)*?)\s*<\/ProcessTextResult>/m
10
8
 
11
9
  # Process text with remote web-service
12
10
  # @param [String] text text to process
13
11
  # @param [Hash] options options for web-service
14
- def process_text(text, options = {})
15
- soap_request = <<-END_SOAP
12
+ def self.process_text(text, options = {})
13
+ request = Net::HTTP::Post.new(@@url.path, {
14
+ 'Content-Type' => 'text/xml',
15
+ 'SOAPAction' => '"http://typograf.artlebedev.ru/webservices/ProcessText"'
16
+ })
17
+ request.body = <<-END_SOAP
16
18
  <?xml version="1.0" encoding="#{options[:encoding]}" ?>
17
19
  <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
18
20
  <soap:Body>
@@ -25,11 +27,24 @@ module AlsTypograf
25
27
  </ProcessText>
26
28
  </soap:Body>
27
29
  </soap:Envelope>
28
- END_SOAP
29
- response = self.class.post('/webservices/typograf.asmx', :body => soap_request)
30
- response['soap:Envelope']['soap:Body']['ProcessTextResponse']['ProcessTextResult'].gsub(/&amp;/, '&').gsub(/&lt;/, '<').gsub(/&gt;/, '>').gsub(/\t$/, '')
30
+ END_SOAP
31
+
32
+ response = Net::HTTP.new(@@url.host, @@url.port).start do |http|
33
+ http.request(request)
34
+ end
35
+
36
+ case response
37
+ when Net::HTTPSuccess
38
+ result = if @@result_regexp =~ response.body
39
+ $1.gsub(/&gt;/, '>').gsub(/&lt;/, '<').gsub(/&amp;/, '&').gsub(/(\t|\n)$/, '')
40
+ else
41
+ text
42
+ end
43
+ else
44
+ text
45
+ end
31
46
  rescue ::Exception => exception
32
- return text
47
+ text
33
48
  end
34
49
  end
35
50
  end
data/test/helper.rb CHANGED
@@ -2,7 +2,7 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
2
  $LOAD_PATH.unshift(File.dirname(__FILE__))
3
3
 
4
4
  require 'rubygems'
5
- require 'activerecord'
5
+ require 'active_record'
6
6
  require 'shoulda'
7
7
  require 'redgreen' rescue nil
8
8
  require 'als_typograf'
@@ -11,8 +11,8 @@ require 'active_support/test_case'
11
11
  class ActiveSupport::TestCase
12
12
  def self.process_assertions(assertions)
13
13
  assertions.each do |from, to|
14
- should "process '#{from}' to '#{to}'" do
15
- assert_equal to, AlsTypograf.process(from)
14
+ should "process [#{from}] to [#{to}]" do
15
+ assert_equal(to, AlsTypograf.process(from))
16
16
  end
17
17
  end
18
18
  end
@@ -38,7 +38,7 @@ def load_schema
38
38
  end
39
39
 
40
40
  if db_adapter.nil?
41
- raise "No DB Adapter selected. Pass the DB= option to pick one, or install Sqlite or Sqlite3."
41
+ raise 'No DB Adapter selected. Pass the DB= option to pick one, or install Sqlite or Sqlite3.'
42
42
  end
43
43
 
44
44
  ActiveRecord::Base.establish_connection(config[db_adapter])
@@ -5,14 +5,14 @@ class AlsTypografTest < ActiveSupport::TestCase
5
5
  context 'with default configuration' do
6
6
  setup { AlsTypograf.default_options! }
7
7
  process_assertions({
8
- '- Это "Типограф"?' => "<p>— Это «Типограф»?</p>",
8
+ '- Это "Типограф"?' => "<p>— Это «Типограф»?<br />\n</p>",
9
9
  })
10
10
  end
11
11
 
12
12
  context 'no p' do
13
13
  setup { AlsTypograf.use_p = false }
14
14
  process_assertions({
15
- '- Это "Типограф"?' => "— Это «Типограф»?",
15
+ '- Это "Типограф"?' => "— Это «Типограф»?<br />",
16
16
  })
17
17
  end
18
18
 
@@ -23,16 +23,16 @@ class ArticleTest < ActiveSupport::TestCase
23
23
  context 'with an Article' do
24
24
  setup do
25
25
  @article = Article.create(:title => '- Does it "Article"?',
26
- :content => 'Yes, this is an "Article"...')
26
+ :content => 'Да, это - "Статья"...')
27
27
  AlsTypograf.default_options!
28
28
  end
29
29
 
30
30
  should 'typograf article’s content with default options' do
31
- assert_equal '<p>Yes, this is an «Article»…</p>', @article.content
31
+ assert_equal "<p>Да, это — «Статья»...<br />\n</p>", @article.content
32
32
  end
33
33
 
34
34
  should 'typograf article’s title with custom options' do
35
- assert_equal ' Does it «Article»?', @article.title
35
+ assert_equal " Does it Article”?", @article.title
36
36
  end
37
37
  end
38
38
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: als_typograf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Semyonov
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-26 00:00:00 +03:00
12
+ date: 2010-01-24 00:00:00 +03:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -23,17 +23,7 @@ dependencies:
23
23
  version: 2.3.4
24
24
  version:
25
25
  - !ruby/object:Gem::Dependency
26
- name: httparty
27
- type: :runtime
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: 0.4.5
34
- version:
35
- - !ruby/object:Gem::Dependency
36
- name: thoughtbot-shoulda
26
+ name: shoulda
37
27
  type: :development
38
28
  version_requirement:
39
29
  version_requirements: !ruby/object:Gem::Requirement