als_typograf 0.2.0 → 0.3.0
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/.gitignore +3 -17
- data/.rspec +3 -0
- data/Gemfile +13 -0
- data/Rakefile +6 -52
- data/als_typograf.gemspec +18 -61
- data/lib/active_model/typograf.rb +2 -0
- data/lib/als_typograf.rb +30 -16
- data/lib/als_typograf/request.rb +27 -17
- data/lib/als_typograf/version.rb +3 -0
- data/spec/active_model/typograf_spec.rb +39 -0
- data/spec/als_typograf_spec.rb +28 -0
- data/spec/spec_helper.rb +19 -0
- data/{test → spec/support}/database.yml +2 -2
- data/spec/support/schema.rb +35 -0
- metadata +110 -91
- data/rails/init.rb +0 -1
- data/test/helper.rb +0 -49
- data/test/schema.rb +0 -7
- data/test/unit/als_typograf_test.rb +0 -19
- data/test/unit/article_test.rb +0 -44
data/.gitignore
CHANGED
|
@@ -1,18 +1,3 @@
|
|
|
1
|
-
## MAC OS
|
|
2
|
-
.DS_Store
|
|
3
|
-
|
|
4
|
-
## TEXTMATE
|
|
5
|
-
*.tmproj
|
|
6
|
-
tmtags
|
|
7
|
-
|
|
8
|
-
## EMACS
|
|
9
|
-
*~
|
|
10
|
-
\#*
|
|
11
|
-
.\#*
|
|
12
|
-
|
|
13
|
-
## VIM
|
|
14
|
-
*.swp
|
|
15
|
-
|
|
16
1
|
## PROJECT::GENERAL
|
|
17
2
|
.yardoc
|
|
18
3
|
coverage
|
|
@@ -21,5 +6,6 @@ doc
|
|
|
21
6
|
pkg
|
|
22
7
|
|
|
23
8
|
## PROJECT::SPECIFIC
|
|
24
|
-
|
|
25
|
-
|
|
9
|
+
*.log
|
|
10
|
+
*.db
|
|
11
|
+
Gemfile.lock
|
data/.rspec
ADDED
data/Gemfile
ADDED
data/Rakefile
CHANGED
|
@@ -1,54 +1,11 @@
|
|
|
1
|
-
require '
|
|
2
|
-
require 'rake'
|
|
1
|
+
require 'bundler/gem_tasks'
|
|
3
2
|
|
|
4
3
|
begin
|
|
5
|
-
require '
|
|
6
|
-
|
|
7
|
-
gem.name = 'als_typograf'
|
|
8
|
-
gem.summary = %Q{ArtLebedevStudio.RemoteTypograf}
|
|
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']
|
|
13
|
-
gem.add_dependency 'activesupport', '>= 2.3.4'
|
|
14
|
-
gem.add_development_dependency 'shoulda', '>= 0'
|
|
15
|
-
gem.add_development_dependency 'yard', '>= 0'
|
|
16
|
-
end
|
|
17
|
-
Jeweler::GemcutterTasks.new
|
|
18
|
-
rescue LoadError
|
|
19
|
-
puts 'Jeweler (or a dependency) not available. Install it with: gem install jeweler'
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
require 'rake/testtask'
|
|
23
|
-
Rake::TestTask.new(:test) do |test|
|
|
24
|
-
test.libs << 'lib' << 'test'
|
|
25
|
-
test.pattern = 'test/**/*_test.rb'
|
|
26
|
-
test.verbose = true
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
begin
|
|
30
|
-
require 'rcov/rcovtask'
|
|
31
|
-
Rcov::RcovTask.new do |test|
|
|
32
|
-
test.libs << 'test'
|
|
33
|
-
test.pattern = 'test/**/*_test.rb'
|
|
34
|
-
test.verbose = true
|
|
35
|
-
end
|
|
36
|
-
rescue LoadError
|
|
37
|
-
task :rcov do
|
|
38
|
-
abort 'RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov'
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
begin
|
|
43
|
-
require 'reek/adapters/rake_task'
|
|
44
|
-
Reek::RakeTask.new do |t|
|
|
45
|
-
t.fail_on_error = true
|
|
46
|
-
t.verbose = false
|
|
47
|
-
t.source_files = 'lib/**/*.rb'
|
|
48
|
-
end
|
|
4
|
+
require 'rspec/core/rake_task'
|
|
5
|
+
RSpec::Core::RakeTask.new(:spec)
|
|
49
6
|
rescue LoadError
|
|
50
|
-
task :
|
|
51
|
-
abort '
|
|
7
|
+
task :spec do
|
|
8
|
+
abort 'RSpec is not available. In order to run specs, you must run: gem install rspec'
|
|
52
9
|
end
|
|
53
10
|
end
|
|
54
11
|
|
|
@@ -73,7 +30,4 @@ rescue LoadError
|
|
|
73
30
|
end
|
|
74
31
|
end
|
|
75
32
|
|
|
76
|
-
task :
|
|
77
|
-
task :default => :test
|
|
78
|
-
desc 'Push release to github and gemcutter and install gem in the system'
|
|
79
|
-
task :push => %w(git:release release install)
|
|
33
|
+
task :default => :spec
|
data/als_typograf.gemspec
CHANGED
|
@@ -1,68 +1,25 @@
|
|
|
1
|
-
# Generated by jeweler
|
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
|
4
1
|
# -*- encoding: utf-8 -*-
|
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
|
3
|
+
require 'als_typograf/version'
|
|
5
4
|
|
|
6
5
|
Gem::Specification.new do |s|
|
|
7
|
-
s.name
|
|
8
|
-
s.version
|
|
6
|
+
s.name = %q{als_typograf}
|
|
7
|
+
s.version = AlsTypograf::VERSION
|
|
8
|
+
s.authors = ['Alexander Semyonov']
|
|
9
|
+
s.email = 'al@semyonov.us'
|
|
10
|
+
s.homepage = 'http://github.com/alsemyonov/als_typograf'
|
|
11
|
+
s.summary = 'ArtLebedevStudio.RemoteTypograf'
|
|
12
|
+
s.description = 'Ruby client for ArtLebedevStudio.RemoteTypograf service'
|
|
9
13
|
|
|
10
|
-
s.
|
|
11
|
-
s.
|
|
12
|
-
s.
|
|
13
|
-
s.
|
|
14
|
-
s.email = %q{rotuka@rotuka.com}
|
|
15
|
-
s.extra_rdoc_files = [
|
|
16
|
-
"LICENSE",
|
|
17
|
-
"README.rdoc"
|
|
18
|
-
]
|
|
19
|
-
s.files = [
|
|
20
|
-
".document",
|
|
21
|
-
".gitignore",
|
|
22
|
-
"LICENSE",
|
|
23
|
-
"README.rdoc",
|
|
24
|
-
"Rakefile",
|
|
25
|
-
"VERSION",
|
|
26
|
-
"als_typograf.gemspec",
|
|
27
|
-
"lib/active_model/typograf.rb",
|
|
28
|
-
"lib/als_typograf.rb",
|
|
29
|
-
"lib/als_typograf/request.rb",
|
|
30
|
-
"rails/init.rb",
|
|
31
|
-
"test/database.yml",
|
|
32
|
-
"test/helper.rb",
|
|
33
|
-
"test/schema.rb",
|
|
34
|
-
"test/unit/als_typograf_test.rb",
|
|
35
|
-
"test/unit/article_test.rb"
|
|
36
|
-
]
|
|
37
|
-
s.homepage = %q{http://github.com/rotuka/als_typograf}
|
|
38
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
|
39
|
-
s.require_paths = ["lib"]
|
|
40
|
-
s.rubygems_version = %q{1.3.7}
|
|
41
|
-
s.summary = %q{ArtLebedevStudio.RemoteTypograf}
|
|
42
|
-
s.test_files = [
|
|
43
|
-
"test/schema.rb",
|
|
44
|
-
"test/helper.rb",
|
|
45
|
-
"test/unit/article_test.rb",
|
|
46
|
-
"test/unit/als_typograf_test.rb"
|
|
47
|
-
]
|
|
14
|
+
s.files = `git ls-files`.split("\n")
|
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
16
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
|
17
|
+
s.require_paths = %w(lib)
|
|
48
18
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
s.add_runtime_dependency(%q<activesupport>, [">= 2.3.4"])
|
|
55
|
-
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
|
56
|
-
s.add_development_dependency(%q<yard>, [">= 0"])
|
|
57
|
-
else
|
|
58
|
-
s.add_dependency(%q<activesupport>, [">= 2.3.4"])
|
|
59
|
-
s.add_dependency(%q<shoulda>, [">= 0"])
|
|
60
|
-
s.add_dependency(%q<yard>, [">= 0"])
|
|
61
|
-
end
|
|
62
|
-
else
|
|
63
|
-
s.add_dependency(%q<activesupport>, [">= 2.3.4"])
|
|
64
|
-
s.add_dependency(%q<shoulda>, [">= 0"])
|
|
65
|
-
s.add_dependency(%q<yard>, [">= 0"])
|
|
66
|
-
end
|
|
19
|
+
s.add_runtime_dependency('activesupport', ['>= 2.3.4'])
|
|
20
|
+
s.add_development_dependency('activerecord', ['>= 2.3.4'])
|
|
21
|
+
s.add_development_dependency('sqlite3')
|
|
22
|
+
s.add_development_dependency('rspec')
|
|
23
|
+
s.add_development_dependency('yard')
|
|
67
24
|
end
|
|
68
25
|
|
data/lib/als_typograf.rb
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
require 'active_support/core_ext/hash/reverse_merge'
|
|
3
|
+
require 'als_typograf/version'
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
# ruby-implementation of ArtLebedevStudio.RemoteTypograf class (web-service client)
|
|
5
|
+
# Ruby client for ArtLebedevStudio.RemoteTypograf web-service
|
|
6
6
|
# @author Alexander Semyonov
|
|
7
7
|
module AlsTypograf
|
|
8
8
|
autoload :Request, 'als_typograf/request'
|
|
9
|
-
autoload :ActiveRecord, 'als_typograf/active_record'
|
|
10
9
|
|
|
11
10
|
HTML_ENTITIES = 1
|
|
12
11
|
XML_ENTITIES = 2
|
|
@@ -14,16 +13,19 @@ module AlsTypograf
|
|
|
14
13
|
MIXED_ENTITIES = 4
|
|
15
14
|
|
|
16
15
|
DEFAULT_OPTIONS = {
|
|
17
|
-
:
|
|
18
|
-
:
|
|
19
|
-
:
|
|
20
|
-
:
|
|
21
|
-
:
|
|
16
|
+
entity_type: NO_ENTITIES,
|
|
17
|
+
use_br: true,
|
|
18
|
+
use_p: true,
|
|
19
|
+
max_nobr: 3,
|
|
20
|
+
encoding: 'UTF-8',
|
|
21
|
+
debug: false
|
|
22
22
|
}
|
|
23
23
|
VALID_OPTIONS = DEFAULT_OPTIONS.keys.join('|')
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
class << self
|
|
26
|
+
attr_accessor :options
|
|
27
|
+
end
|
|
28
|
+
self.options = DEFAULT_OPTIONS.dup
|
|
27
29
|
|
|
28
30
|
# Get a global AlsTypograf option
|
|
29
31
|
# @param [String, Symbol] param option name
|
|
@@ -40,7 +42,7 @@ module AlsTypograf
|
|
|
40
42
|
|
|
41
43
|
# Reset default options
|
|
42
44
|
def self.default_options!
|
|
43
|
-
|
|
45
|
+
self.options = DEFAULT_OPTIONS.dup
|
|
44
46
|
end
|
|
45
47
|
|
|
46
48
|
# Set option #entity_type to HTML (e. g. , —)
|
|
@@ -66,13 +68,13 @@ module AlsTypograf
|
|
|
66
68
|
# Option to replace \n with +<br />+
|
|
67
69
|
# @param [Boolean] value to use +<br />+ or not
|
|
68
70
|
def self.use_br=(value)
|
|
69
|
-
self[:use_br] = value
|
|
71
|
+
self[:use_br] = value
|
|
70
72
|
end
|
|
71
73
|
|
|
72
74
|
# Option to wrap paragraphs with +<p></p>+
|
|
73
75
|
# @param [Boolean] value to wrap para or not
|
|
74
76
|
def self.use_p=(value)
|
|
75
|
-
self[:use_p] = value
|
|
77
|
+
self[:use_p] = value
|
|
76
78
|
end
|
|
77
79
|
|
|
78
80
|
# How many symbols around dash to surround with +<nobr>+ tag
|
|
@@ -81,6 +83,10 @@ module AlsTypograf
|
|
|
81
83
|
self[:max_nobr] = value ? value : 0
|
|
82
84
|
end
|
|
83
85
|
|
|
86
|
+
def self.debug?
|
|
87
|
+
!!self[:debug]
|
|
88
|
+
end
|
|
89
|
+
|
|
84
90
|
def self.method_missing(method_name, *args)
|
|
85
91
|
case method_name.to_s
|
|
86
92
|
when /^(#{VALID_OPTIONS})=$/
|
|
@@ -88,7 +94,7 @@ module AlsTypograf
|
|
|
88
94
|
when /^(#{VALID_OPTIONS})$/
|
|
89
95
|
self[method_name.to_sym]
|
|
90
96
|
else
|
|
91
|
-
super
|
|
97
|
+
super
|
|
92
98
|
end
|
|
93
99
|
end
|
|
94
100
|
|
|
@@ -103,6 +109,14 @@ module AlsTypograf
|
|
|
103
109
|
def self.process(text, custom_options = {})
|
|
104
110
|
Request.process_text(text, custom_options.reverse_merge(options))
|
|
105
111
|
end
|
|
112
|
+
|
|
113
|
+
# @param [Exception] exception
|
|
114
|
+
def self.log_exception(exception)
|
|
115
|
+
if debug?
|
|
116
|
+
$stderr.puts exception.message
|
|
117
|
+
$stderr.puts exception.backtrace.join("\n")
|
|
118
|
+
end
|
|
119
|
+
end
|
|
106
120
|
end
|
|
107
121
|
|
|
108
122
|
if defined? ActiveModel
|
data/lib/als_typograf/request.rb
CHANGED
|
@@ -1,19 +1,24 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
1
2
|
require 'net/http'
|
|
2
3
|
|
|
3
4
|
module AlsTypograf
|
|
4
5
|
# The request class
|
|
5
6
|
module Request
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
SERVICE_URL = URI.parse('http://typograf.artlebedev.ru/webservices/typograf.asmx')
|
|
8
|
+
RESULT_REGEXP = /<ProcessTextResult>\s*((.|\n)*?)\s*<\/ProcessTextResult>/
|
|
8
9
|
|
|
9
10
|
# Process text with remote web-service
|
|
10
11
|
# @param [String] text text to process
|
|
11
12
|
# @param [Hash] options options for web-service
|
|
12
13
|
def self.process_text(text, options = {})
|
|
13
|
-
|
|
14
|
+
text = text.encode(options[:encoding])
|
|
15
|
+
|
|
16
|
+
#noinspection RubyStringKeysInHashInspection
|
|
17
|
+
request = Net::HTTP::Post.new(SERVICE_URL.path, {
|
|
14
18
|
'Content-Type' => 'text/xml',
|
|
15
|
-
'SOAPAction'
|
|
19
|
+
'SOAPAction' => '"http://typograf.artlebedev.ru/webservices/ProcessText"'
|
|
16
20
|
})
|
|
21
|
+
|
|
17
22
|
request.body = <<-END_SOAP
|
|
18
23
|
<?xml version="1.0" encoding="#{options[:encoding]}" ?>
|
|
19
24
|
<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/">
|
|
@@ -27,23 +32,28 @@ module AlsTypograf
|
|
|
27
32
|
</ProcessText>
|
|
28
33
|
</soap:Body>
|
|
29
34
|
</soap:Envelope>
|
|
30
|
-
END_SOAP
|
|
35
|
+
END_SOAP
|
|
31
36
|
|
|
32
|
-
response = Net::HTTP.new(
|
|
37
|
+
response = Net::HTTP.new(SERVICE_URL.host, SERVICE_URL.port).start do |http|
|
|
33
38
|
http.request(request)
|
|
34
39
|
end
|
|
35
40
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
41
|
+
response.body.force_encoding(options[:encoding]) if response.body.respond_to?(:force_encoding)
|
|
42
|
+
|
|
43
|
+
text = case response
|
|
44
|
+
when Net::HTTPSuccess
|
|
45
|
+
if RESULT_REGEXP =~ response.body
|
|
46
|
+
$1.gsub(/>/, '>').gsub(/</, '<').gsub(/&/, '&').gsub(/(\t|\n)$/, '')
|
|
47
|
+
else
|
|
48
|
+
text
|
|
49
|
+
end
|
|
50
|
+
else
|
|
51
|
+
text
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
text.encode(options[:encoding])
|
|
55
|
+
rescue StandardError => e
|
|
56
|
+
AlsTypograf.log_exception(e)
|
|
47
57
|
text
|
|
48
58
|
end
|
|
49
59
|
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
require 'active_model/typograf'
|
|
4
|
+
|
|
5
|
+
describe ActiveModel::Typograf do
|
|
6
|
+
class Article < ActiveRecord::Base
|
|
7
|
+
typograf(:content)
|
|
8
|
+
typograf(:title => {:use_p => false, :use_br => false})
|
|
9
|
+
typograf(:skills, :achievements, :description, :use_br => false)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
subject { Article }
|
|
13
|
+
|
|
14
|
+
it 'have class method #typograf' do
|
|
15
|
+
Article.should respond_to(:typograf)
|
|
16
|
+
end
|
|
17
|
+
%w(typograf_fields typograf_current_fields).each do |field|
|
|
18
|
+
it "have instance method \##{field}" do
|
|
19
|
+
Article.new.should respond_to(field)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it 'load schema correctly' do
|
|
24
|
+
Article.all.should == []
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
context 'with an Article' do
|
|
28
|
+
before do
|
|
29
|
+
@article = Article.create(:title => '- Does it "Article"?',
|
|
30
|
+
:content => 'Да, это - "Статья"...')
|
|
31
|
+
AlsTypograf.default_options!
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
subject { @article }
|
|
35
|
+
|
|
36
|
+
its(:content) { should == "<p>Да, это — «Статья»...<br />\n</p>" }
|
|
37
|
+
its(:title) { should == '— Does it «Article»?' }
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
|
|
4
|
+
describe AlsTypograf do
|
|
5
|
+
def self.process_assertions(assertions)
|
|
6
|
+
assertions.each do |from, to|
|
|
7
|
+
it "process [#{from}] to [#{to}]" do
|
|
8
|
+
AlsTypograf.process(from).should == to
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
context '.default_options!' do
|
|
14
|
+
before { AlsTypograf.default_options! }
|
|
15
|
+
|
|
16
|
+
process_assertions({
|
|
17
|
+
'- Это "Типограф"?' => "<p>— Это «Типограф»?<br />\n</p>",
|
|
18
|
+
})
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
context '.use_p == false' do
|
|
22
|
+
before { AlsTypograf.use_p = false }
|
|
23
|
+
|
|
24
|
+
process_assertions({
|
|
25
|
+
'- Это "Типограф"?' => '— Это «Типограф»?<br />',
|
|
26
|
+
})
|
|
27
|
+
end
|
|
28
|
+
end
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
SPEC_ROOT = File.expand_path('../..', __FILE__)
|
|
2
|
+
require 'bundler/setup'
|
|
3
|
+
require 'rspec'
|
|
4
|
+
require 'active_record'
|
|
5
|
+
require 'als_typograf'
|
|
6
|
+
|
|
7
|
+
Encoding.default_internal = 'utf-8'
|
|
8
|
+
Encoding.default_external = 'utf-8'
|
|
9
|
+
|
|
10
|
+
Dir[File.join(SPEC_ROOT, 'spec/support/**/*.rb')].each {|f| require f}
|
|
11
|
+
|
|
12
|
+
#noinspection RubyResolve
|
|
13
|
+
RSpec.configure do |config|
|
|
14
|
+
config.mock_with :rspec
|
|
15
|
+
config.order = 'random'
|
|
16
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
|
17
|
+
config.filter_run focus: true
|
|
18
|
+
config.run_all_when_everything_filtered = true
|
|
19
|
+
end
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
sqlite:
|
|
2
2
|
:adapter: sqlite
|
|
3
|
-
:database:
|
|
3
|
+
:database: spec/support/als_typograf_plugin.sqlite.db
|
|
4
4
|
|
|
5
5
|
sqlite3:
|
|
6
6
|
:adapter: sqlite3
|
|
7
|
-
:database:
|
|
7
|
+
:database: spec/support/als_typograf_plugin.sqlite3.db
|
|
8
8
|
|
|
9
9
|
postgresql:
|
|
10
10
|
:adapter: postgresql
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
require 'active_record'
|
|
2
|
+
require 'logger'
|
|
3
|
+
|
|
4
|
+
config = YAML::load(File.read(File.join(SPEC_ROOT, 'spec/support/database.yml')))
|
|
5
|
+
ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + '/debug.log')
|
|
6
|
+
|
|
7
|
+
db_adapter = ENV['DB']
|
|
8
|
+
|
|
9
|
+
# no db passed, try one of these fine config-free DBs before bombing.
|
|
10
|
+
db_adapter ||=
|
|
11
|
+
begin
|
|
12
|
+
require 'sqlite'
|
|
13
|
+
'sqlite'
|
|
14
|
+
rescue MissingSourceFile
|
|
15
|
+
begin
|
|
16
|
+
require 'sqlite3'
|
|
17
|
+
'sqlite3'
|
|
18
|
+
rescue MissingSourceFile
|
|
19
|
+
nil
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
if db_adapter.nil?
|
|
24
|
+
raise 'No DB Adapter selected. Pass the DB= option to pick one, or install Sqlite or Sqlite3.'
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
ActiveRecord::Base.establish_connection(config[db_adapter])
|
|
28
|
+
|
|
29
|
+
ActiveRecord::Schema.define(:version => 0) do
|
|
30
|
+
create_table :articles, :force => true do |t|
|
|
31
|
+
t.string :title
|
|
32
|
+
t.text :content, :skills, :achievements, :description,
|
|
33
|
+
:foo, :bar, :baz
|
|
34
|
+
end
|
|
35
|
+
end
|
metadata
CHANGED
|
@@ -1,79 +1,106 @@
|
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: als_typograf
|
|
3
|
-
version: !ruby/object:Gem::Version
|
|
4
|
-
|
|
5
|
-
prerelease:
|
|
6
|
-
segments:
|
|
7
|
-
- 0
|
|
8
|
-
- 2
|
|
9
|
-
- 0
|
|
10
|
-
version: 0.2.0
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.3.0
|
|
5
|
+
prerelease:
|
|
11
6
|
platform: ruby
|
|
12
|
-
authors:
|
|
7
|
+
authors:
|
|
13
8
|
- Alexander Semyonov
|
|
14
9
|
autorequire:
|
|
15
10
|
bindir: bin
|
|
16
11
|
cert_chain: []
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
dependencies:
|
|
21
|
-
- !ruby/object:Gem::Dependency
|
|
12
|
+
date: 2013-01-11 00:00:00.000000000 Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
22
15
|
name: activesupport
|
|
23
|
-
|
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
|
25
17
|
none: false
|
|
26
|
-
requirements:
|
|
27
|
-
- -
|
|
28
|
-
- !ruby/object:Gem::Version
|
|
29
|
-
hash: 11
|
|
30
|
-
segments:
|
|
31
|
-
- 2
|
|
32
|
-
- 3
|
|
33
|
-
- 4
|
|
18
|
+
requirements:
|
|
19
|
+
- - ! '>='
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
34
21
|
version: 2.3.4
|
|
35
22
|
type: :runtime
|
|
36
|
-
version_requirements: *id001
|
|
37
|
-
- !ruby/object:Gem::Dependency
|
|
38
|
-
name: shoulda
|
|
39
23
|
prerelease: false
|
|
40
|
-
|
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
+
none: false
|
|
26
|
+
requirements:
|
|
27
|
+
- - ! '>='
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: 2.3.4
|
|
30
|
+
- !ruby/object:Gem::Dependency
|
|
31
|
+
name: activerecord
|
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
|
41
33
|
none: false
|
|
42
|
-
requirements:
|
|
43
|
-
- -
|
|
44
|
-
- !ruby/object:Gem::Version
|
|
45
|
-
|
|
46
|
-
segments:
|
|
47
|
-
- 0
|
|
48
|
-
version: "0"
|
|
34
|
+
requirements:
|
|
35
|
+
- - ! '>='
|
|
36
|
+
- !ruby/object:Gem::Version
|
|
37
|
+
version: 2.3.4
|
|
49
38
|
type: :development
|
|
50
|
-
version_requirements: *id002
|
|
51
|
-
- !ruby/object:Gem::Dependency
|
|
52
|
-
name: yard
|
|
53
39
|
prerelease: false
|
|
54
|
-
|
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
55
41
|
none: false
|
|
56
|
-
requirements:
|
|
57
|
-
- -
|
|
58
|
-
- !ruby/object:Gem::Version
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
42
|
+
requirements:
|
|
43
|
+
- - ! '>='
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
version: 2.3.4
|
|
46
|
+
- !ruby/object:Gem::Dependency
|
|
47
|
+
name: sqlite3
|
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
|
49
|
+
none: false
|
|
50
|
+
requirements:
|
|
51
|
+
- - ! '>='
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '0'
|
|
63
54
|
type: :development
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
55
|
+
prerelease: false
|
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
57
|
+
none: false
|
|
58
|
+
requirements:
|
|
59
|
+
- - ! '>='
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
- !ruby/object:Gem::Dependency
|
|
63
|
+
name: rspec
|
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
|
65
|
+
none: false
|
|
66
|
+
requirements:
|
|
67
|
+
- - ! '>='
|
|
68
|
+
- !ruby/object:Gem::Version
|
|
69
|
+
version: '0'
|
|
70
|
+
type: :development
|
|
71
|
+
prerelease: false
|
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
73
|
+
none: false
|
|
74
|
+
requirements:
|
|
75
|
+
- - ! '>='
|
|
76
|
+
- !ruby/object:Gem::Version
|
|
77
|
+
version: '0'
|
|
78
|
+
- !ruby/object:Gem::Dependency
|
|
79
|
+
name: yard
|
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
|
81
|
+
none: false
|
|
82
|
+
requirements:
|
|
83
|
+
- - ! '>='
|
|
84
|
+
- !ruby/object:Gem::Version
|
|
85
|
+
version: '0'
|
|
86
|
+
type: :development
|
|
87
|
+
prerelease: false
|
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
89
|
+
none: false
|
|
90
|
+
requirements:
|
|
91
|
+
- - ! '>='
|
|
92
|
+
- !ruby/object:Gem::Version
|
|
93
|
+
version: '0'
|
|
94
|
+
description: Ruby client for ArtLebedevStudio.RemoteTypograf service
|
|
95
|
+
email: al@semyonov.us
|
|
67
96
|
executables: []
|
|
68
|
-
|
|
69
97
|
extensions: []
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
- LICENSE
|
|
73
|
-
- README.rdoc
|
|
74
|
-
files:
|
|
98
|
+
extra_rdoc_files: []
|
|
99
|
+
files:
|
|
75
100
|
- .document
|
|
76
101
|
- .gitignore
|
|
102
|
+
- .rspec
|
|
103
|
+
- Gemfile
|
|
77
104
|
- LICENSE
|
|
78
105
|
- README.rdoc
|
|
79
106
|
- Rakefile
|
|
@@ -82,48 +109,40 @@ files:
|
|
|
82
109
|
- lib/active_model/typograf.rb
|
|
83
110
|
- lib/als_typograf.rb
|
|
84
111
|
- lib/als_typograf/request.rb
|
|
85
|
-
-
|
|
86
|
-
-
|
|
87
|
-
-
|
|
88
|
-
-
|
|
89
|
-
-
|
|
90
|
-
-
|
|
91
|
-
|
|
92
|
-
homepage: http://github.com/rotuka/als_typograf
|
|
112
|
+
- lib/als_typograf/version.rb
|
|
113
|
+
- spec/active_model/typograf_spec.rb
|
|
114
|
+
- spec/als_typograf_spec.rb
|
|
115
|
+
- spec/spec_helper.rb
|
|
116
|
+
- spec/support/database.yml
|
|
117
|
+
- spec/support/schema.rb
|
|
118
|
+
homepage: http://github.com/alsemyonov/als_typograf
|
|
93
119
|
licenses: []
|
|
94
|
-
|
|
95
120
|
post_install_message:
|
|
96
|
-
rdoc_options:
|
|
97
|
-
|
|
98
|
-
require_paths:
|
|
121
|
+
rdoc_options: []
|
|
122
|
+
require_paths:
|
|
99
123
|
- lib
|
|
100
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
|
124
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
101
125
|
none: false
|
|
102
|
-
requirements:
|
|
103
|
-
- -
|
|
104
|
-
- !ruby/object:Gem::Version
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
- 0
|
|
108
|
-
version: "0"
|
|
109
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
126
|
+
requirements:
|
|
127
|
+
- - ! '>='
|
|
128
|
+
- !ruby/object:Gem::Version
|
|
129
|
+
version: '0'
|
|
130
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
131
|
none: false
|
|
111
|
-
requirements:
|
|
112
|
-
- -
|
|
113
|
-
- !ruby/object:Gem::Version
|
|
114
|
-
|
|
115
|
-
segments:
|
|
116
|
-
- 0
|
|
117
|
-
version: "0"
|
|
132
|
+
requirements:
|
|
133
|
+
- - ! '>='
|
|
134
|
+
- !ruby/object:Gem::Version
|
|
135
|
+
version: '0'
|
|
118
136
|
requirements: []
|
|
119
|
-
|
|
120
137
|
rubyforge_project:
|
|
121
|
-
rubygems_version: 1.
|
|
138
|
+
rubygems_version: 1.8.24
|
|
122
139
|
signing_key:
|
|
123
140
|
specification_version: 3
|
|
124
141
|
summary: ArtLebedevStudio.RemoteTypograf
|
|
125
|
-
test_files:
|
|
126
|
-
-
|
|
127
|
-
-
|
|
128
|
-
-
|
|
129
|
-
-
|
|
142
|
+
test_files:
|
|
143
|
+
- spec/active_model/typograf_spec.rb
|
|
144
|
+
- spec/als_typograf_spec.rb
|
|
145
|
+
- spec/spec_helper.rb
|
|
146
|
+
- spec/support/database.yml
|
|
147
|
+
- spec/support/schema.rb
|
|
148
|
+
has_rdoc:
|
data/rails/init.rb
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
require 'als_typograf'
|
data/test/helper.rb
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
2
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
3
|
-
|
|
4
|
-
require 'rubygems'
|
|
5
|
-
require 'active_record'
|
|
6
|
-
require 'shoulda'
|
|
7
|
-
require 'redgreen' rescue nil
|
|
8
|
-
require 'als_typograf'
|
|
9
|
-
require 'active_support/test_case'
|
|
10
|
-
require 'logger'
|
|
11
|
-
|
|
12
|
-
class ActiveSupport::TestCase
|
|
13
|
-
def self.process_assertions(assertions)
|
|
14
|
-
assertions.each do |from, to|
|
|
15
|
-
should "process [#{from}] to [#{to}]" do
|
|
16
|
-
assert_equal(to, AlsTypograf.process(from))
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def load_schema
|
|
23
|
-
config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
|
|
24
|
-
ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
|
|
25
|
-
|
|
26
|
-
db_adapter = ENV['DB']
|
|
27
|
-
|
|
28
|
-
# no db passed, try one of these fine config-free DBs before bombing.
|
|
29
|
-
db_adapter ||=
|
|
30
|
-
begin
|
|
31
|
-
require 'sqlite'
|
|
32
|
-
'sqlite'
|
|
33
|
-
rescue MissingSourceFile
|
|
34
|
-
begin
|
|
35
|
-
require 'sqlite3'
|
|
36
|
-
'sqlite3'
|
|
37
|
-
rescue MissingSourceFile
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
if db_adapter.nil?
|
|
42
|
-
raise 'No DB Adapter selected. Pass the DB= option to pick one, or install Sqlite or Sqlite3.'
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
ActiveRecord::Base.establish_connection(config[db_adapter])
|
|
46
|
-
load(File.dirname(__FILE__) + "/schema.rb")
|
|
47
|
-
require File.dirname(__FILE__) + '/../rails/init.rb'
|
|
48
|
-
end
|
|
49
|
-
|
data/test/schema.rb
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
require 'helper'
|
|
2
|
-
|
|
3
|
-
class AlsTypografTest < ActiveSupport::TestCase
|
|
4
|
-
# TODO: need more tests or not?
|
|
5
|
-
context 'with default configuration' do
|
|
6
|
-
setup { AlsTypograf.default_options! }
|
|
7
|
-
process_assertions({
|
|
8
|
-
'- Это "Типограф"?' => "<p>— Это «Типограф»?<br />\n</p>",
|
|
9
|
-
})
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
context 'no p' do
|
|
13
|
-
setup { AlsTypograf.use_p = false }
|
|
14
|
-
process_assertions({
|
|
15
|
-
'- Это "Типограф"?' => "— Это «Типограф»?<br />",
|
|
16
|
-
})
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
end
|
data/test/unit/article_test.rb
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
require 'helper'
|
|
2
|
-
require 'shoulda/active_record/matchers'
|
|
3
|
-
require 'shoulda/active_record/macros'
|
|
4
|
-
|
|
5
|
-
load_schema
|
|
6
|
-
|
|
7
|
-
class Article < ActiveRecord::Base
|
|
8
|
-
typograf(:content)
|
|
9
|
-
typograf(:title => {:use_p => false, :use_br => false})
|
|
10
|
-
typograf(:skills, :achievements, :description, :use_br => false)
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
class ArticleTest < ActiveSupport::TestCase
|
|
14
|
-
extend Shoulda::ActiveRecord::Macros
|
|
15
|
-
|
|
16
|
-
should "have class method #typograf" do
|
|
17
|
-
assert Article.respond_to?(:typograf)
|
|
18
|
-
end
|
|
19
|
-
%w(typograf_fields typograf_current_fields).each do |field|
|
|
20
|
-
should "have instance method \##{field}" do
|
|
21
|
-
assert Article.instance_methods.include?(field)
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
should 'load schema correctly' do
|
|
26
|
-
assert_equal [], Article.all
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
context 'with an Article' do
|
|
30
|
-
setup do
|
|
31
|
-
@article = Article.create(:title => '- Does it "Article"?',
|
|
32
|
-
:content => 'Да, это - "Статья"...')
|
|
33
|
-
AlsTypograf.default_options!
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
should 'typograf article’s content with default options' do
|
|
37
|
-
assert_equal "<p>Да, это — «Статья»...<br />\n</p>", @article.content
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
should 'typograf article’s title with custom options' do
|
|
41
|
-
assert_equal "— Does it «Article»?", @article.title
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
end
|