Complete overhaul of smart quotes to "typographer"

See README for details

Contributes to #50
This commit is contained in:
Andy Meneely
2015-04-07 00:16:06 -04:00
parent 674397c005
commit a5d1cb60f2
11 changed files with 259 additions and 95 deletions
-46
View File
@@ -1,46 +0,0 @@
require 'spec_helper'
require 'squib/args/smart_quotes'
describe Squib::Args::SmartQuotes do
it 'does nothing on a non-quoted string' do
expect(subject.quotify('nothing')).to eq('nothing')
end
it 'left quotes at the beginning' do
expect(subject.quotify('"foo')).to eq("\u201Cfoo")
end
it 'left quotes in the middle of the string' do
expect(subject.quotify('hello "foo')).to eq("hello \u201Cfoo")
end
it 'right quotes at the end of a string' do
expect(subject.quotify('foo"')).to eq("foo\u201D")
end
it 'handles the entire string quoted' do
expect(subject.quotify('"foo"')).to eq("\u201Cfoo\u201D")
end
it "quotes in the middle of the string" do
expect(subject.quotify('hello "foo" world')).to eq("hello \u201Cfoo\u201D world")
end
it "allows custom quotes for different character sets" do
expect(subject.quotify('hello "foo" world', %w({ }))).to eq("hello {foo} world")
end
it "processes dumb quotes" do
expect(subject.process('hello "foo" world', :dumb)).to eq("hello \"foo\" world")
end
it "processes smart quotes" do
expect(subject.process('hello "foo" world', :smart)).to eq("hello \u201Cfoo\u201D world")
end
it "processes custom quotes" do
expect(subject.process('hello "foo" world', %w({ }))).to eq("hello {foo} world")
end
end
+71
View File
@@ -0,0 +1,71 @@
require 'spec_helper'
require 'squib/args/typographer'
describe Squib::Args::Typographer do
subject(:t) { Squib::Args::Typographer.new }
it 'does nothing on a non-quoted string' do
expect(t.process(%{nothing})).to eq(%{nothing})
end
it 'left quotes at the beginning' do
expect(t.process(%{"foo})).to eq(%{\u201Cfoo})
end
it 'left quotes in the middle of the string' do
expect(t.process(%{hello "foo})).to eq(%{hello \u201Cfoo})
end
it 'right quotes at the end' do
expect(t.process(%{foo"})).to eq(%{foo\u201D})
end
it 'handles the entire string quoted' do
expect(t.process(%{"foo"})).to eq(%{\u201Cfoo\u201D})
end
it "quotes in the middle of the string" do
expect(t.process(%{hello "foo" world})).to eq(%{hello \u201Cfoo\u201D world})
end
it "single left quotes at the beginning" do
expect(t.process(%{'foo})).to eq(%{\u2018foo})
end
it "single right quotes at the end" do
expect(t.process(%{foo'})).to eq(%{foo\u2019})
end
it "single quotes in the middle" do
expect(t.process(%{a 'foo' bar})).to eq(%{a \u2018foo\u2019 bar})
end
it "handles apostraphes" do
expect(t.process(%{can't})).to eq(%{can\u2019t})
end
it "single quotes inside double quotes" do
expect(t.process(%{"'I can't do that', he said"})).to eq(%{\u201C\u2019I can\u2019t do that\u2019, he said\u201D})
end
it "replaces the straightforward ones" do
expect(t.process(%{``hi...'' -- ---})).to eq(%{\u201Chi\u2026\u201D \u2013 \u2014})
end
it "does nothing on lone quotes" do
expect(t.process(%{"})).to eq(%{"})
expect(t.process(%{'})).to eq(%{'})
end
it "ignores stuff in <tags>" do
expect(t.process(%{<span weight="bold">"can't"</span>})).to eq(%{<span weight="bold">\u201Ccan\u2019t\u201D</span>})
end
context 'configured' do
#TODO
end
end
+60 -4
View File
@@ -12,13 +12,17 @@ cairo: rounded_rectangle([0, 0, 825, 1125, 0, 0])
cairo: set_source_color(["#0000"])
cairo: fill([])
cairo: restore([])
cairo: antialias=(["subpixel"])
cairo: antialias=(["subpixel"])
cairo: antialias=(["subpixel"])
cairo: save([])
cairo: set_source_color([:black])
cairo: translate([200, 0])
cairo: translate([0, 0])
cairo: rotate([0])
cairo: move_to([0, 0])
pango font: size=([18432])
pango: font_description=([MockDouble])
pango: text=(["Middle align: Take 1 :tool: and gain 2 :health:. Take 2 :tool: and gain 3 :purse:"])
pango: text=(["Take 1 :tool: and gain 2 :health:."])
pango: width=([184320])
pango: height=([307200])
pango: wrap=([#<Pango::Layout::WrapMode word-char>])
@@ -27,7 +31,7 @@ pango: alignment=([#<Pango::Layout::Alignment left>])
pango: justify=([false])
pango: spacing=([0])
cairo: update_pango_layout([MockDouble])
pango: markup=(["Middle align: Take 1 :tool: and gain 2 :health:. Take 2 :tool: and gain 3 :purse:"])
pango: markup=(["Take 1 :tool: and gain 2 :health:."])
cairo: move_to([0, 0.0])
cairo: update_pango_layout([MockDouble])
cairo: show_pango_layout([MockDouble])
@@ -36,4 +40,56 @@ cairo: set_source_color([:cyan])
cairo: set_line_width([2.0])
cairo: stroke([])
cairo: restore([])
surface: write_to_png(["_output/embed_00.png"])
cairo: save([])
cairo: set_source_color([:black])
cairo: translate([0, 0])
cairo: rotate([0])
cairo: move_to([0, 0])
pango font: size=([32768])
pango: font_description=([MockDouble])
pango: text=(["Take 1 :tool: and gain 2 :health:."])
pango: width=([184320])
pango: height=([307200])
pango: wrap=([#<Pango::Layout::WrapMode word-char>])
pango: ellipsize=([#<Pango::Layout::EllipsizeMode none>])
pango: alignment=([#<Pango::Layout::Alignment left>])
pango: justify=([false])
pango: spacing=([0])
cairo: update_pango_layout([MockDouble])
pango: markup=(["Take 1 :tool: and gain 2 :health:."])
cairo: move_to([0, 0.0])
cairo: update_pango_layout([MockDouble])
cairo: show_pango_layout([MockDouble])
cairo: rounded_rectangle([0, 0, 0, 0, 0, 0])
cairo: set_source_color([:cyan])
cairo: set_line_width([2.0])
cairo: stroke([])
cairo: restore([])
cairo: save([])
cairo: set_source_color([:black])
cairo: translate([0, 0])
cairo: rotate([0])
cairo: move_to([0, 0])
pango font: size=([46080])
pango: font_description=([MockDouble])
pango: text=(["Take 1 :tool: and gain 2 :health:."])
pango: width=([184320])
pango: height=([307200])
pango: wrap=([#<Pango::Layout::WrapMode word-char>])
pango: ellipsize=([#<Pango::Layout::EllipsizeMode none>])
pango: alignment=([#<Pango::Layout::Alignment left>])
pango: justify=([false])
pango: spacing=([0])
cairo: update_pango_layout([MockDouble])
pango: markup=(["Take 1 :tool: and gain 2 :health:."])
cairo: move_to([0, 0.0])
cairo: update_pango_layout([MockDouble])
cairo: show_pango_layout([MockDouble])
cairo: rounded_rectangle([0, 0, 0, 0, 0, 0])
cairo: set_source_color([:cyan])
cairo: set_line_width([2.0])
cairo: stroke([])
cairo: restore([])
surface: write_to_png(["_output/embed_multi_00.png"])
surface: write_to_png(["_output/embed_multi_01.png"])
surface: write_to_png(["_output/embed_multi_02.png"])
+8 -8
View File
@@ -331,7 +331,7 @@ cairo: translate([65, 400])
cairo: rotate([0])
cairo: move_to([0, 0])
pango: font_description=([MockDouble])
pango: text=(["This text has fixed width, fixed height, center-aligned, middle-valigned, has a red hint, and \u201Csmart quotes\u201D"])
pango: text=(["This text has fixed width, fixed height, center-aligned, middle-valigned, has a red hint, and \"smart quotes\""])
pango: width=([307200])
pango: height=([128000])
pango: wrap=([#<Pango::Layout::WrapMode word-char>])
@@ -354,7 +354,7 @@ cairo: translate([65, 400])
cairo: rotate([0])
cairo: move_to([0, 0])
pango: font_description=([MockDouble])
pango: text=(["This text has fixed width, fixed height, center-aligned, middle-valigned, has a red hint, and \u201Csmart quotes\u201D"])
pango: text=(["This text has fixed width, fixed height, center-aligned, middle-valigned, has a red hint, and \"smart quotes\""])
pango: width=([307200])
pango: height=([128000])
pango: wrap=([#<Pango::Layout::WrapMode word-char>])
@@ -829,8 +829,8 @@ cairo: translate([50, 1000])
cairo: rotate([0])
cairo: move_to([0, 0])
pango: font_description=([MockDouble])
pango: text=(["<b>Markup</b> is also <i>quite</i> <s>easy</s> awesome"])
pango: markup=(["<b>Markup</b> is also <i>quite</i> <s>easy</s> awesome"])
pango: text=(["<b>Markup</b> is <i>quite</i> <s>'easy'</s> <span fgcolor=\"#ff0000\">awesome</span>. Can't beat those \"smart\" 'quotes', now with 10--20% more en-dashes --- and em-dashes --- with explicit ellipses too..."])
pango: markup=(["foo"])
pango: width=([768000])
pango: height=([102400])
pango: wrap=([#<Pango::Layout::WrapMode word-char>])
@@ -853,8 +853,8 @@ cairo: translate([50, 1000])
cairo: rotate([0])
cairo: move_to([0, 0])
pango: font_description=([MockDouble])
pango: text=(["<b>Markup</b> is also <i>quite</i> <s>easy</s> awesome"])
pango: markup=(["<b>Markup</b> is also <i>quite</i> <s>easy</s> awesome"])
pango: text=(["<b>Markup</b> is <i>quite</i> <s>'easy'</s> <span fgcolor=\"#ff0000\">awesome</span>. Can't beat those \"smart\" 'quotes', now with 10--20% more en-dashes --- and em-dashes --- with explicit ellipses too..."])
pango: markup=(["foo"])
pango: width=([768000])
pango: height=([102400])
pango: wrap=([#<Pango::Layout::WrapMode word-char>])
@@ -877,8 +877,8 @@ cairo: translate([50, 1000])
cairo: rotate([0])
cairo: move_to([0, 0])
pango: font_description=([MockDouble])
pango: text=(["<b>Markup</b> is also <i>quite</i> <s>easy</s> awesome"])
pango: markup=(["<b>Markup</b> is also <i>quite</i> <s>easy</s> awesome"])
pango: text=(["<b>Markup</b> is <i>quite</i> <s>'easy'</s> <span fgcolor=\"#ff0000\">awesome</span>. Can't beat those \"smart\" 'quotes', now with 10--20% more en-dashes --- and em-dashes --- with explicit ellipses too..."])
pango: markup=(["foo"])
pango: width=([768000])
pango: height=([102400])
pango: wrap=([#<Pango::Layout::WrapMode word-char>])