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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a47e77c7be1810c15637823b7d63e8a41d349fe9
4
- data.tar.gz: 31a607bc832991a5251c46cec2082a961becc8a5
3
+ metadata.gz: c636a83e8c1760ba3efc8b772e9c2469f93326b1
4
+ data.tar.gz: 7dfa9640396ac0bc5ef31a2108c5806cbf4d1369
5
5
  SHA512:
6
- metadata.gz: c41b73c3bf5a2ec8c9a0fd7d5d6a99344b0819511ae5c2aa9c919feff458fd9f7ca6d5e10b9820f41d4077ba9fbbe2583151e96c615867ce234c133b7d9e05d7
7
- data.tar.gz: 37de02c4256222eedd533f053fa1f9e5de04a304fbf0430c4344bc474bcb2ff63dba7b1f11ddfbf458781d784c624e3a43134a854c0c7efc8dc5b73fbb5f37ec
6
+ metadata.gz: f86d71ebb02a8f8ae0d00cf8eef0534e06f1d14266c53fb88e4b5c3f49fc6d3e72dc6773910aac0f4ab862c22bc41e8127ed53dd556c001ce6db751b35556b40
7
+ data.tar.gz: f1e1468a3d1b20f24d0295d7e13f0a774c0a3a328c1b796df7e9b82320c857de10e0627de6df5750c71b3ad9b2778637b50e4b2bc8ba0d22711147f58ac8839b
data/ChangeLog.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.3 “Samara Vallis”
2
+
3
+ * Russian typograph doesn’t insert flying quotes tag anymore.
4
+ * Add separated `auto_flying_quotes` helper.
5
+
1
6
  ## 0.2.1
2
7
 
3
8
  * Fix encoding issue with Nokogiri in `english_typograph`.
@@ -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
@@ -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(text)
20
- text.gsub(/\s«[^»]+»/) { |i| flying_quotes i[2..-2], space: i[0] }.
21
- gsub(/^«[^»]+»/) { |i| flying_quotes i[1..-2], space: '' }
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
@@ -9,15 +9,7 @@ module EvilFront
9
9
  #
10
10
  # EvilFront::Russian.typograph_html(article.html)
11
11
  def typograph_html(html)
12
- return html if html.nil? or html.empty?
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
- # Apply all typograph methods to text
40
- def typograph_all(text)
41
- typograph(text)
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
- # Recursively apply typography to Nokogiri nodes
45
- def typograph_node!(node)
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( typograph_all(text) )
51
+ child.replace( yield(text) )
52
52
  else
53
- typograph_node! child
53
+ process_node! child, &block
54
54
  end
55
55
  end
56
56
  end
@@ -1,3 +1,3 @@
1
1
  module EvilFront
2
- VERSION = '0.2.1' unless defined? EvilFront::VERSION
2
+ VERSION = '0.3.0' unless defined? EvilFront::VERSION
3
3
  end
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">«&lt;br&gt;»</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 == '<span class="quotes">«a»</span>'
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>&lt;a&gt;</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.2.1
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-06 00:00:00.000000000 Z
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/flying_quote.rb
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