From 2693449a34649868e9fd73b62141d486bc68a1f0 Mon Sep 17 00:00:00 2001 From: Pavel Forkert Date: Wed, 16 Mar 2011 00:36:25 +0200 Subject: [PATCH 1/6] now it should typography nested quotes properly --- Gemfile | 12 ++---------- lib/typography/core.rb | 10 ++++++---- lib/typography/helper.rb | 2 ++ spec/debug.log | 1 - spec/spec_helper.rb | 6 ++---- spec/typography_spec.rb | 12 ++++++++++++ typography.gemspec | 3 ++- 7 files changed, 26 insertions(+), 20 deletions(-) delete mode 100755 spec/debug.log diff --git a/Gemfile b/Gemfile index 5f0e11b..e45e65f 100644 --- a/Gemfile +++ b/Gemfile @@ -1,10 +1,2 @@ -source :gemcutter - -gem "actionpack" - -group :development, :test do - gem "rspec", ">=2.0.0" - gem "autotest" -end - - +source :rubygems +gemspec diff --git a/lib/typography/core.rb b/lib/typography/core.rb index 9dce206..09205e5 100755 --- a/lib/typography/core.rb +++ b/lib/typography/core.rb @@ -11,8 +11,8 @@ def initialize(str, options = {}) def typography #apostrophe @out.gsub!(/(\w)'(\w)/, '\1’\2') -# @out.gsub!(/\“/,'„') -# @out.gsub!(/\”/,'“') + @out.gsub!(/\“/,'„') + @out.gsub!(/\”/,'“') #russian quotes @out = replace_quotes '«', '»', '„', '“', 'а-яА-Я' @@ -61,12 +61,14 @@ def replace_quotes(left1 = '“', right1 = '”', left2 = '‘', right2 while replace_quotes.call do end # second level + str.gsub!('&', "\0&") replace_second_level_quotes = lambda do - str.gsub! Regexp.new("#{left1}(.*)#{left1}(.*)#{right1}(.*)#{right1}", Regexp::MULTILINE | Regexp::IGNORECASE) do |match| - "#{left1}#{$1}#{left2}#{$2}#{right2}#{$3}#{right1}" + str.gsub! Regexp.new("#{left1}([^\0`]*)\0#{left1}([^\0]*)\0#{right1}", Regexp::MULTILINE | Regexp::IGNORECASE) do + "#{left1}#{$1}#{left2}#{$2}#{right2}" end end while replace_second_level_quotes.call do end + str.gsub!("\0", '') str end diff --git a/lib/typography/helper.rb b/lib/typography/helper.rb index 88482c2..e32458d 100755 --- a/lib/typography/helper.rb +++ b/lib/typography/helper.rb @@ -1,4 +1,6 @@ # encoding: utf-8 +require 'action_view' + module ActionView::Helpers::TextHelper def ty(text, options = {}) TypographyHelper::Core.new(text.html_safe, options).typography diff --git a/spec/debug.log b/spec/debug.log deleted file mode 100755 index 7750903..0000000 --- a/spec/debug.log +++ /dev/null @@ -1 +0,0 @@ -# Logfile created on Sun Sep 07 04:55:44 +0400 2008 by / diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 77daed8..80acab9 100755 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,6 +1,4 @@ $KCODE = 'u' require 'rubygems' -require 'action_pack' -require 'action_view' -require File.join File.dirname(__FILE__), '../lib/typography' - +require 'bundler' +Bundler.require(:default, :development) diff --git a/spec/typography_spec.rb b/spec/typography_spec.rb index 316e54d..0d62f0e 100755 --- a/spec/typography_spec.rb +++ b/spec/typography_spec.rb @@ -158,5 +158,17 @@ ty('Испанцы говорят, что целовать мужчину без усов, - всё равно что есть яйцо без соли').should == 'Испанцы говорят, что целовать мужчину без усов, — всё равно что есть яйцо без соли' end + it "should typography nested quotes properly" do + text = %{

"Кто-то прибежал" Кто-то прибежал Кто-то прибежал Кто-то прибежал Кто-то прибежал Кто-то прибежал Кто-то прибежал Кто-то прибежал Кто-то прибежал

"Кто-то прибежал Кто-то прибежал"  Кто-то прибежал «Кто-то прибежал К»

} + expected_text = %{

«Кто-то прибежал» Кто-то прибежал Кто-то прибежал Кто-то прибежал Кто-то прибежал Кто-то прибежал Кто-то прибежал Кто-то прибежал Кто-то прибежал

«Кто-то прибежал Кто-то прибежал»  Кто-то прибежал «Кто-то прибежал К»

} + ty(text).should == expected_text + end + + it "should typography nested quotes properly on real-world examples" do + text = %{

Об очередном ляпе «налоговой библии» пишет в своей статье для «ЗН в Украине» пишет кандидат юридических наук, доцент кандидат юридических наук, доцент Данил Гетманцев.

«Даже при последующем выполнении плательщиком требований налоговой службы его счета будут находиться под арестом»

} + expected_text = %{

Об очередном ляпе «налоговой библии» пишет в своей статье для «ЗН в Украине» пишет кандидат юридических наук, доцент кандидат юридических наук, доцент Данил Гетманцев.

«Даже при последующем выполнении плательщиком требований налоговой службы его счета будут находиться под арестом»

} + ty(text).should == expected_text + end + end diff --git a/typography.gemspec b/typography.gemspec index 8275999..278ae76 100644 --- a/typography.gemspec +++ b/typography.gemspec @@ -22,8 +22,9 @@ spec = Gem::Specification.new do |s| s.extra_rdoc_files = ["README.rdoc"] s.rdoc_options = ["--main", "README.rdoc"] - s.add_development_dependency "rspec", ">= 2.0.0" s.add_dependency "actionpack" + s.add_development_dependency "rspec", ">= 2.0.0" + s.add_development_dependency "autotest" end From 08d4c30a100e0a0c2b249706d315c87ff838bace Mon Sep 17 00:00:00 2001 From: Pavel Forkert Date: Wed, 16 Mar 2011 00:38:18 +0200 Subject: [PATCH 2/6] some changes in gemspec file --- typography.gemspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/typography.gemspec b/typography.gemspec index 278ae76..f5d39c8 100644 --- a/typography.gemspec +++ b/typography.gemspec @@ -4,9 +4,9 @@ $:.unshift lib unless $:.include?(lib) require 'typography/version' -spec = Gem::Specification.new do |s| +Gem::Specification.new do |s| s.authors = ["Dmitry Shaposhnik", "Anton Versal", "Igor Gladkoborodov", "Pravosud Pavel"] - s.email = ["dmitry@shaposhnik.name", "ant.ver@gmail.com", "igor@workisfun.ru" ] + s.email = ["dmitry@shaposhnik.name", "ant.ver@gmail.com", "igor@workisfun.ru"] s.date = "2010-11-22" s.homepage = "https://github.com/VerAnt/typography" s.rubyforge_project = "" From 28f986fa58af0f8e926e22f2594432320d84291c Mon Sep 17 00:00:00 2001 From: Pavel Forkert Date: Wed, 16 Mar 2011 00:39:17 +0200 Subject: [PATCH 3/6] version bump --- lib/typography/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/typography/version.rb b/lib/typography/version.rb index 84bc2b4..d3216e4 100644 --- a/lib/typography/version.rb +++ b/lib/typography/version.rb @@ -1,4 +1,4 @@ module TypographyHelper GEM_NAME = "typography" - VERSION = "0.3.0" + VERSION = "0.3.1" end From db8babf2a3c6182ee636fabeff088230f121fbc7 Mon Sep 17 00:00:00 2001 From: Pavel Forkert Date: Wed, 16 Mar 2011 00:45:25 +0200 Subject: [PATCH 4/6] added default rake task --- Rakefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index f073dc2..6195e06 100755 --- a/Rakefile +++ b/Rakefile @@ -1,4 +1,6 @@ require "rspec/core/rake_task" desc "Test typography plugin." -RSpec::Core::RakeTask.new('spec') +RSpec::Core::RakeTask.new(:spec) + +task :default => :spec \ No newline at end of file From a94d335c178dae85cd0df284691b3a2b799235dd Mon Sep 17 00:00:00 2001 From: Pavel Forkert Date: Sat, 19 Mar 2011 18:04:17 +0200 Subject: [PATCH 5/6] added to_s in ty() helper --- lib/typography/helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/typography/helper.rb b/lib/typography/helper.rb index e32458d..fa8c7b2 100755 --- a/lib/typography/helper.rb +++ b/lib/typography/helper.rb @@ -3,7 +3,7 @@ module ActionView::Helpers::TextHelper def ty(text, options = {}) - TypographyHelper::Core.new(text.html_safe, options).typography + TypographyHelper::Core.new(text.to_s.html_safe, options).typography end def ty_simple(text, html_options={}) simple_format ty(text), html_options From 898e7b6bb39866bba97bc433791d5c4aa5155bdf Mon Sep 17 00:00:00 2001 From: Alex Rozumiy Date: Wed, 13 Apr 2011 11:15:45 +0300 Subject: [PATCH 6/6] Added support for html tags in quotes --- lib/typography/core.rb | 2 +- spec/typography_spec.rb | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/typography/core.rb b/lib/typography/core.rb index 09205e5..bfe1338 100755 --- a/lib/typography/core.rb +++ b/lib/typography/core.rb @@ -48,7 +48,7 @@ def replace_quotes(left1 = '“', right1 = '”', left2 = '‘', right2 replace_quotes = lambda do old_str = str.dup - str.gsub!(Regexp.new("(\"|\'|")([#{letters}].*?[^\\s])\\1", Regexp::MULTILINE | Regexp::IGNORECASE)) do |match| + str.gsub!(Regexp.new("(\"|\'|")((\s*<[^>]+>\s*)?[#{letters}]((<[^>]+>)|.)*?[^\\s])\\1", Regexp::MULTILINE | Regexp::IGNORECASE)) do |match| inside, before, after = $2, $`, $' if after.match(/^([^<]+>|>)/) || before.match(/<[^>]+$/) #inside tag match diff --git a/spec/typography_spec.rb b/spec/typography_spec.rb index 0d62f0e..8487f60 100755 --- a/spec/typography_spec.rb +++ b/spec/typography_spec.rb @@ -27,6 +27,15 @@ ty('Text "текст" text "Другой текст" ').should == 'Text «текст» text «Другой текст» ' end + it "should make russian quotes for quotes with first russian letter, beginning with html tag" do + ty('"текст"').should == '«текст»' + ty('Text "текст" text').should == 'Text «текст» text' + end + + it "should make russian quotes for quotes with html tag" do + ty('Текст "Начало текста текст"').should == 'Текст «Начало текста текст»' + end + it "should do the same with single quotes" do ty('\'текст\'').should == '«текст»' ty('Text \'текст\' text').should == 'Text «текст» text'