typograf 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -1
- data/lib/typograf/client.rb +20 -2
- data/lib/typograf/version.rb +1 -1
- data/spec/typograf_spec.rb +4 -0
- data/typograf.gemspec +2 -0
- metadata +19 -3
data/README.md
CHANGED
@@ -59,7 +59,7 @@ You can pass second argument - hash of options.
|
|
59
59
|
:length => 0
|
60
60
|
},
|
61
61
|
:acronym => 1, # выделять сокращения: 1 — выделять; 0 — не выделять
|
62
|
-
:symbols => 0, # как выводить типографированный текст: 0 — буквенными символами ( ); 1 — числовыми ( )
|
62
|
+
:symbols => 0, # как выводить типографированный текст: 0 — буквенными символами ( ); 1 — числовыми ( ); 2 - просто символами
|
63
63
|
# добавляет дополнительные атрибуты к ссылкам
|
64
64
|
:link => {
|
65
65
|
:target => '',
|
data/lib/typograf/client.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'net/http'
|
3
|
+
require 'htmlentities'
|
3
4
|
|
4
5
|
module Typograf
|
5
6
|
class NetworkError < StandardError
|
@@ -50,7 +51,10 @@ module Typograf
|
|
50
51
|
}
|
51
52
|
|
52
53
|
def form_xml(options)
|
53
|
-
o = options
|
54
|
+
o = options.dup
|
55
|
+
|
56
|
+
o[:symbols] = 1 if o[:symbols] == 2
|
57
|
+
|
54
58
|
xml = <<-XML_TEMPLATE
|
55
59
|
<?xml version="1.0" encoding="windows-1251" ?>
|
56
60
|
<preferences>
|
@@ -62,10 +66,18 @@ module Typograf
|
|
62
66
|
<newline insert="#{o[:newline][:insert]}"><![CDATA[#{o[:newline][:tag]}]]></newline>
|
63
67
|
<cmsNewLine valid="#{o[:cms_new_line]}" />
|
64
68
|
<dos-text delete="#{o[:dos_text]}" />
|
69
|
+
XML_TEMPLATE
|
70
|
+
|
71
|
+
if o[:nowraped][:nonbsp] != 0
|
72
|
+
xml = xml.chomp(" \n") + <<-XML_TEMPLATE
|
65
73
|
<nowraped insert="#{o[:nowraped][:insert]}" nonbsp="#{o[:nowraped][:nobsp]}" length="#{o[:nowraped][:length]}">
|
66
74
|
<start><![CDATA[#{o[:nowraped][:start]}]]></start>
|
67
75
|
<end><![CDATA[#{o[:nowraped][:end]}]]></end>
|
68
76
|
</nowraped>
|
77
|
+
XML_TEMPLATE
|
78
|
+
end
|
79
|
+
|
80
|
+
xml = xml.chomp(" \n") + <<-XML_TEMPLATE
|
69
81
|
<hanging-punct insert="#{o[:hanging_punct]}" />
|
70
82
|
<hanging-line delete="#{o[:hanging_line]}" />
|
71
83
|
<minus-sign><![CDATA[#{o[:minus_sign]}]]></minus-sign>
|
@@ -75,6 +87,7 @@ module Typograf
|
|
75
87
|
<link target="#{o[:link][:target]}" class="#{o[:link][:class]}" />
|
76
88
|
</preferences>
|
77
89
|
XML_TEMPLATE
|
90
|
+
|
78
91
|
xml.gsub(/^\s|\s$/, '')
|
79
92
|
end
|
80
93
|
|
@@ -95,6 +108,7 @@ module Typograf
|
|
95
108
|
def initialize(options = {})
|
96
109
|
@url = URI.parse(options.delete(:url) || URL)
|
97
110
|
# @chr = options.delete(:chr) || 'UTF-8'
|
111
|
+
@options = options
|
98
112
|
@xml = if options.keys.length > 0
|
99
113
|
form_xml( deep_merge(DEFAULT_PREFERENCES, options) )
|
100
114
|
end
|
@@ -130,7 +144,11 @@ module Typograf
|
|
130
144
|
raise NetworkError, "Ошибка: вы забыли передать текст"
|
131
145
|
end
|
132
146
|
|
133
|
-
|
147
|
+
if @options[:symbols] == 2
|
148
|
+
HTMLEntities.new.decode(body.chomp)
|
149
|
+
else
|
150
|
+
body.chomp
|
151
|
+
end
|
134
152
|
end
|
135
153
|
end
|
136
154
|
end
|
data/lib/typograf/version.rb
CHANGED
data/spec/typograf_spec.rb
CHANGED
@@ -11,6 +11,10 @@ describe Typograf do
|
|
11
11
|
Typograf.process("- Это \"Типограф\"?\n— Нет, это «Типограф»!", :paragraph => {:insert => 0}).should eq "— Это «Типограф»?<br />\n— Нет, это «Типограф»!"
|
12
12
|
end
|
13
13
|
|
14
|
+
it ".process support nowraped and symbols options" do
|
15
|
+
Typograf.process("В этом тексте \t много пробелов.", :nowraped => {:nonbsp => 0}, :paragraph => {:insert => 0}, :symbols => 2 ).should eq 'В этом тексте много пробелов.'
|
16
|
+
end
|
17
|
+
|
14
18
|
it "should raise 404 error" do
|
15
19
|
lambda {Typograf.process("Тест", :url => 'http://www.typograf.ru/404')}.should raise_error Typograf::NetworkError
|
16
20
|
end
|
data/typograf.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: typograf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,6 +11,22 @@ bindir: bin
|
|
11
11
|
cert_chain: []
|
12
12
|
date: 2012-12-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: htmlentities
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
14
30
|
- !ruby/object:Gem::Dependency
|
15
31
|
name: rake
|
16
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -76,7 +92,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
76
92
|
version: '0'
|
77
93
|
segments:
|
78
94
|
- 0
|
79
|
-
hash:
|
95
|
+
hash: 256397741
|
80
96
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
97
|
none: false
|
82
98
|
requirements:
|
@@ -85,7 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
85
101
|
version: '0'
|
86
102
|
segments:
|
87
103
|
- 0
|
88
|
-
hash:
|
104
|
+
hash: 256397741
|
89
105
|
requirements: []
|
90
106
|
rubyforge_project:
|
91
107
|
rubygems_version: 1.8.24
|