evil-front 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ChangeLog.md +5 -0
- data/lib/evil-front/helpers/auto_flying_quotes.rb +16 -0
- data/lib/evil-front/helpers/{flying_quote.rb → flying_quotes.rb} +0 -0
- data/lib/evil-front/russian.rb +5 -8
- data/lib/evil-front/typograph.rb +16 -16
- data/lib/evil-front/version.rb +1 -1
- data/spec/helpers_spec.rb +17 -1
- data/spec/russian_spec.rb +5 -5
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c636a83e8c1760ba3efc8b772e9c2469f93326b1
|
4
|
+
data.tar.gz: 7dfa9640396ac0bc5ef31a2108c5806cbf4d1369
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f86d71ebb02a8f8ae0d00cf8eef0534e06f1d14266c53fb88e4b5c3f49fc6d3e72dc6773910aac0f4ab862c22bc41e8127ed53dd556c001ce6db751b35556b40
|
7
|
+
data.tar.gz: f1e1468a3d1b20f24d0295d7e13f0a774c0a3a328c1b796df7e9b82320c857de10e0627de6df5750c71b3ad9b2778637b50e4b2bc8ba0d22711147f58ac8839b
|
data/ChangeLog.md
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
module EvilFront::Helpers
|
2
|
+
# Find quotes and add tags to flying quotes
|
3
|
+
#
|
4
|
+
# = auto_flying_quotes post.body
|
5
|
+
#
|
6
|
+
# Don’t forget to install styles by `quotes` Sass mixin.
|
7
|
+
def auto_flying_quotes(text = nil, &block)
|
8
|
+
text = if block_given?
|
9
|
+
capture(&block).strip
|
10
|
+
else
|
11
|
+
EvilFront.escape(text)
|
12
|
+
end
|
13
|
+
text = EvilFront::Russian.auto_flying_quotes(text)
|
14
|
+
EvilFront.html_safe(text)
|
15
|
+
end
|
16
|
+
end
|
File without changes
|
data/lib/evil-front/russian.rb
CHANGED
@@ -16,9 +16,11 @@ module EvilFront
|
|
16
16
|
end
|
17
17
|
|
18
18
|
# Find quotes in text and make them flying
|
19
|
-
def self.auto_flying_quotes(
|
20
|
-
|
21
|
-
|
19
|
+
def self.auto_flying_quotes(html)
|
20
|
+
process_html(html) do |text|
|
21
|
+
text.gsub(/\s«[^»]+»/) { |i| flying_quotes i[2..-2], space: i[0] }.
|
22
|
+
gsub(/^«[^»]+»/) { |i| flying_quotes i[1..-2], space: '' }
|
23
|
+
end
|
22
24
|
end
|
23
25
|
|
24
26
|
# Mark quotes to move first quote before the text line.
|
@@ -45,10 +47,5 @@ module EvilFront
|
|
45
47
|
def self.use_right_symbols(text)
|
46
48
|
StandaloneTypograf::Typograf.new(text).prepare
|
47
49
|
end
|
48
|
-
|
49
|
-
# Apply all typograph methods to text
|
50
|
-
def self.typograph_all(text)
|
51
|
-
auto_flying_quotes(typograph(text))
|
52
|
-
end
|
53
50
|
end
|
54
51
|
end
|
data/lib/evil-front/typograph.rb
CHANGED
@@ -9,15 +9,7 @@ module EvilFront
|
|
9
9
|
#
|
10
10
|
# EvilFront::Russian.typograph_html(article.html)
|
11
11
|
def typograph_html(html)
|
12
|
-
|
13
|
-
|
14
|
-
if html.include? '<'
|
15
|
-
nodes = Nokogiri::HTML::DocumentFragment.parse(html, 'utf-8')
|
16
|
-
typograph_node! nodes
|
17
|
-
nodes.to_html
|
18
|
-
else
|
19
|
-
typograph_all(html)
|
20
|
-
end
|
12
|
+
process_html(html) { |text| typograph(text) }
|
21
13
|
end
|
22
14
|
|
23
15
|
# Insert non-break spaces and mark quotes to have nice text.
|
@@ -36,21 +28,29 @@ module EvilFront
|
|
36
28
|
|
37
29
|
private
|
38
30
|
|
39
|
-
#
|
40
|
-
def
|
41
|
-
|
31
|
+
# Parse HTML and run block only on texts
|
32
|
+
def process_html(html, &block)
|
33
|
+
return html if html.nil? or html.empty?
|
34
|
+
|
35
|
+
if html.include? '<'
|
36
|
+
nodes = Nokogiri::HTML::DocumentFragment.parse(html, 'utf-8')
|
37
|
+
process_node!(nodes, &block)
|
38
|
+
nodes.to_html
|
39
|
+
else
|
40
|
+
yield(html)
|
41
|
+
end
|
42
42
|
end
|
43
43
|
|
44
|
-
#
|
45
|
-
def
|
44
|
+
# Run block on every text node recursively
|
45
|
+
def process_node!(node, &block)
|
46
46
|
return if %w(pre code kbd script style math).include? node.name
|
47
47
|
|
48
48
|
node.children.each do |child|
|
49
49
|
if child.is_a? Nokogiri::XML::Text
|
50
50
|
text = EvilFront.escape(child.content)
|
51
|
-
child.replace(
|
51
|
+
child.replace( yield(text) )
|
52
52
|
else
|
53
|
-
|
53
|
+
process_node! child, &block
|
54
54
|
end
|
55
55
|
end
|
56
56
|
end
|
data/lib/evil-front/version.rb
CHANGED
data/spec/helpers_spec.rb
CHANGED
@@ -37,6 +37,22 @@ describe EvilFront::Helpers do
|
|
37
37
|
|
38
38
|
end
|
39
39
|
|
40
|
+
describe 'auto_flying_quotes' do
|
41
|
+
|
42
|
+
it 'set quotes to text' do
|
43
|
+
auto_flying_quotes('от «a»').should ==
|
44
|
+
'от<span class="space-before-quote"> </span>' +
|
45
|
+
'<span class="quotes">«a»</span>'
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'escapes HTML' do
|
49
|
+
auto_flying_quotes('от «<br>»').should ==
|
50
|
+
'от<span class="space-before-quote"> </span>' +
|
51
|
+
'<span class="quotes">«<br>»</span>'
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
40
56
|
describe 'ruble' do
|
41
57
|
|
42
58
|
it 'returns span' do
|
@@ -81,7 +97,7 @@ describe EvilFront::Helpers do
|
|
81
97
|
typograph_by_locale('"a"').should == '“a”'
|
82
98
|
|
83
99
|
I18n.locale = :ru
|
84
|
-
typograph_by_locale('"a"').should == '
|
100
|
+
typograph_by_locale('"a"').should == '«a»'
|
85
101
|
end
|
86
102
|
|
87
103
|
it 'returns origin text on unknown locale' do
|
data/spec/russian_spec.rb
CHANGED
@@ -46,6 +46,11 @@ describe EvilFront::Russian do
|
|
46
46
|
'<span class="quotes">«тесте»</span>.'
|
47
47
|
end
|
48
48
|
|
49
|
+
it 'works with HTML' do
|
50
|
+
EvilFront::Russian.auto_flying_quotes('<a>«ссылка»</a>').should ==
|
51
|
+
'<a><span class="quotes">«ссылка»</span></a>'
|
52
|
+
end
|
53
|
+
|
49
54
|
end
|
50
55
|
|
51
56
|
describe 'typograph' do
|
@@ -90,11 +95,6 @@ describe EvilFront::Russian do
|
|
90
95
|
'<b><a></b>'
|
91
96
|
end
|
92
97
|
|
93
|
-
it 'inserts flying quotes' do
|
94
|
-
EvilFront::Russian.typograph_html('<a>"ссылка"</a>').should ==
|
95
|
-
'<a><span class="quotes">«ссылка»</span></a>'
|
96
|
-
end
|
97
|
-
|
98
98
|
end
|
99
99
|
|
100
100
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: evil-front
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrey Sitnik
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-02-
|
11
|
+
date: 2014-02-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: i18n
|
@@ -180,10 +180,11 @@ files:
|
|
180
180
|
- lib/evil-front.rb
|
181
181
|
- lib/evil-front/english.rb
|
182
182
|
- lib/evil-front/helpers.rb
|
183
|
+
- lib/evil-front/helpers/auto_flying_quotes.rb
|
183
184
|
- lib/evil-front/helpers/capitalize_first.rb
|
184
185
|
- lib/evil-front/helpers/disable_mobile_zoom.rb
|
185
186
|
- lib/evil-front/helpers/english_typograph.rb
|
186
|
-
- lib/evil-front/helpers/
|
187
|
+
- lib/evil-front/helpers/flying_quotes.rb
|
187
188
|
- lib/evil-front/helpers/head_content.rb
|
188
189
|
- lib/evil-front/helpers/head_tag.rb
|
189
190
|
- lib/evil-front/helpers/ruble.rb
|