middleman-gemoji 0.0.8 → 0.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f1e4c131cc9751f78169b7f188d43aed54a88e57
4
- data.tar.gz: e36f0ffdd9878424bfbb44504c4387015fa1fa3b
3
+ metadata.gz: 182decec0a717e2365be5ef8b312b7cc09a104b7
4
+ data.tar.gz: 90a52cfb6fc2c390f1a4a33024d5fbc411e7dd8d
5
5
  SHA512:
6
- metadata.gz: 05bdcddd6c01bb1fa99b1f86f822975a4f8b85dfab110a9989b7fcaf2e5d5f8dd231926bc0f4d479991694665afa8cf34178b47db4aee248f52bf54a31e9a7e6
7
- data.tar.gz: b960acfbfac95f60a9c4255bc0ee77768d9c51d88bef0363fcbba50cceed5b51a9009b143754e1832ba8531a441b8813c2bf918db9b624724859f08669133b7c
6
+ metadata.gz: c12e825805d09bd3472ce76c306a4b1038c50afd1ded7ce65f8f6c32cfc8e9279d9efcad80d8b64b34bbfae8f87fc0d08b1e5f06f4c1276a0d79cdc8d5f8b14e
7
+ data.tar.gz: d0d50b426b9e6fb4eaf3095c94ab155f818e1fadb017053791613ac8ac8bc4c519b835a0a193eda8701633c8470c22ce64130dea0369b166d1b631e88bf2d6ec
@@ -0,0 +1,5 @@
1
+ # 0.1.0
2
+
3
+ - middleman-gemoji has ability to convert the `:emoji:` to `<img ~>` tag.
4
+ - If body-tag exists, this extension will convert only inner body-tag.
5
+ - If body-tag does not exists, this extension will convert all.
@@ -12,6 +12,10 @@ Feature: Emoji convert when build
12
12
  When I run `middleman build`
13
13
  Then the exit status should be 0
14
14
  And the file "build/index.html" should not contain "<p>:+1:</p>"
15
+ And the file "build/index.html" should contain:
16
+ """
17
+ <title>something title :+1:</title>
18
+ """
15
19
  And the file "build/index.html" should contain:
16
20
  """
17
21
  <p><img class="gemoji" alt="+1" src="/images/emoji/unicode/1f44d.png" /></p>
@@ -21,7 +25,7 @@ Feature: Emoji convert when build
21
25
  Given a fixture app "gemoji-app"
22
26
  When I run `middleman build`
23
27
  Then the exit status should be 0
24
- And the file "build/no-emoji.html" should contain "hoge"
28
+ And the file "build/no-emoji.html" should contain "<p>hoge</p>"
25
29
 
26
30
  Scenario: Convert ":+1+" to emoji with :size option
27
31
  Given a fixture app "gemoji-app"
@@ -4,6 +4,10 @@ Feature: Emoji convert under `middleman server`
4
4
  Given the Server is running at "gemoji-app"
5
5
  When I go to "/index.html"
6
6
  Then I should see:
7
+ """
8
+ <title>something title :+1:</title>
9
+ """
10
+ And I should see:
7
11
  """
8
12
  <p><img class="gemoji" alt="+1" src="/images/emoji/unicode/1f44d.png" /></p>
9
13
 
@@ -14,5 +18,9 @@ Feature: Emoji convert under `middleman server`
14
18
  When I go to "/no-emoji.html"
15
19
  Then I should see:
16
20
  """
17
- hoge
21
+ <title>something title :+1:</title>
22
+ """
23
+ And I should see:
24
+ """
25
+ <p>hoge</p>
18
26
  """
@@ -5,15 +5,24 @@ Feature: Emoji convert in Markdown
5
5
  When I run `middleman build`
6
6
  Then the exit status should be 0
7
7
  And the file "build/index.html" should not contain "<p>:+1:</p>"
8
+ And the file "build/index.html" should contain:
9
+ """
10
+ <title>something title :+1:</title>
11
+ """
8
12
  And the file "build/index.html" should contain:
9
13
  """
10
14
  <p><img class="gemoji" alt="+1" src="/images/emoji/unicode/1f44d.png" /></p>
15
+
11
16
  """
12
17
 
13
18
  Scenario: Convert content that doesn't have :emoji:
14
19
  Given a fixture app "haml-app"
15
20
  When I run `middleman build`
16
21
  Then the exit status should be 0
22
+ And the file "build/index.html" should contain:
23
+ """
24
+ <title>something title :+1:</title>
25
+ """
17
26
  And the file "build/no-emoji.html" should contain:
18
27
  """
19
28
  <p>hoge</p>
@@ -5,6 +5,10 @@ Feature: Emoji convert in Markdown
5
5
  When I run `middleman build`
6
6
  Then the exit status should be 0
7
7
  And the file "build/index.html" should not contain "<p>:+1:</p>"
8
+ And the file "build/index.html" should contain:
9
+ """
10
+ <title>something title :+1:</title>
11
+ """
8
12
  And the file "build/index.html" should contain:
9
13
  """
10
14
  <p><img class="gemoji" alt="+1" src="/images/emoji/unicode/1f44d.png" /></p>
@@ -15,6 +19,10 @@ Feature: Emoji convert in Markdown
15
19
  Given a fixture app "markdown-app"
16
20
  When I run `middleman build`
17
21
  Then the exit status should be 0
22
+ And the file "build/index.html" should contain:
23
+ """
24
+ <title>something title :+1:</title>
25
+ """
18
26
  And the file "build/no-emoji.html" should contain:
19
27
  """
20
28
  <p>hoge</p>
@@ -23,9 +31,11 @@ Feature: Emoji convert in Markdown
23
31
  Scenario: Convert ":+1+" to emoji under `middleman server`
24
32
  Given the Server is running at "markdown-app"
25
33
  When I go to "/index.html"
26
- Then I should see '<p><img class="gemoji" alt="+1" src="/images/emoji/unicode/1f44d.png" /></p>'
34
+ Then I should see '<title>something title :+1:</title>'
35
+ And I should see '<p><img class="gemoji" alt="+1" src="/images/emoji/unicode/1f44d.png" /></p>'
27
36
 
28
37
  Scenario: Convert content that doesn't have :emoji: under `middleman server`
29
38
  Given the Server is running at "markdown-app"
30
39
  When I go to "/no-emoji.html"
31
- Then I should see '<p>hoge</p>'
40
+ Then I should see '<title>something title :+1:</title>'
41
+ And I should see '<p>hoge</p>'
@@ -5,20 +5,30 @@ Feature: Emoji convert in Markdown
5
5
  When I run `middleman build`
6
6
  Then the exit status should be 0
7
7
  And the file "build/index.html" should not contain "<p>:+1:</p>"
8
+ And the file "build/index.html" should contain:
9
+ """
10
+ <title>something title :+1:</title>
11
+ """
8
12
  And the file "build/index.html" should contain '<p><img class="gemoji" alt="+1" src="/images/emoji/unicode/1f44d.png" /></p>'
9
13
 
10
14
  Scenario: Convert content that doesn't have :emoji:
11
15
  Given a fixture app "slim-app"
12
16
  When I run `middleman build`
13
17
  Then the exit status should be 0
18
+ And the file "build/index.html" should contain:
19
+ """
20
+ <title>something title :+1:</title>
21
+ """
14
22
  And the file "build/no-emoji.html" should contain '<p>hoge</p>'
15
23
 
16
24
  Scenario: Convert ":+1+" to emoji under `middleman server`
17
25
  Given the Server is running at "slim-app"
18
26
  When I go to "/index.html"
19
- Then I should see '<p><img class="gemoji" alt="+1" src="/images/emoji/unicode/1f44d.png" /></p>'
27
+ Then I should see '<title>something title :+1:</title>'
28
+ And I should see '<p><img class="gemoji" alt="+1" src="/images/emoji/unicode/1f44d.png" /></p>'
20
29
 
21
30
  Scenario: Convert content that doesn't have :emoji: under `middleman server`
22
31
  Given the Server is running at "slim-app"
23
32
  When I go to "/no-emoji.html"
24
- Then I should see '<p>hoge</p>'
33
+ Then I should see '<title>something title :+1:</title>'
34
+ And I should see '<p>hoge</p>'
@@ -0,0 +1,20 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <meta content="IE=edge" http-equiv="X-UA-Compatible">
5
+ <meta charset="utf-8">
6
+ <meta content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" name="viewport">
7
+
8
+ <!-- Use title if it's in the page YAML frontmatter -->
9
+ <title>something title :+1:</title>
10
+
11
+ <link href='//fonts.googleapis.com/css?family=Lato:300,400' rel='stylesheet' type='text/css'>
12
+
13
+ <%= stylesheet_link_tag :site %>
14
+ <%= javascript_include_tag :all %>
15
+ </head>
16
+
17
+ <body class="<%= page_classes %>">
18
+ <%= yield %>
19
+ </body>
20
+ </html>
@@ -1 +1 @@
1
- hoge
1
+ <p>hoge</p>
@@ -0,0 +1,20 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <meta content="IE=edge" http-equiv="X-UA-Compatible">
5
+ <meta charset="utf-8">
6
+ <meta content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" name="viewport">
7
+
8
+ <!-- Use title if it's in the page YAML frontmatter -->
9
+ <title>something title :+1:</title>
10
+
11
+ <link href='//fonts.googleapis.com/css?family=Lato:300,400' rel='stylesheet' type='text/css'>
12
+
13
+ <%= stylesheet_link_tag :site %>
14
+ <%= javascript_include_tag :all %>
15
+ </head>
16
+
17
+ <body class="<%= page_classes %>">
18
+ <%= yield %>
19
+ </body>
20
+ </html>
@@ -0,0 +1,20 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <meta content="IE=edge" http-equiv="X-UA-Compatible">
5
+ <meta charset="utf-8">
6
+ <meta content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" name="viewport">
7
+
8
+ <!-- Use title if it's in the page YAML frontmatter -->
9
+ <title>something title :+1:</title>
10
+
11
+ <link href='//fonts.googleapis.com/css?family=Lato:300,400' rel='stylesheet' type='text/css'>
12
+
13
+ <%= stylesheet_link_tag :site %>
14
+ <%= javascript_include_tag :all %>
15
+ </head>
16
+
17
+ <body class="<%= page_classes %>">
18
+ <%= yield %>
19
+ </body>
20
+ </html>
@@ -0,0 +1,20 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <meta content="IE=edge" http-equiv="X-UA-Compatible">
5
+ <meta charset="utf-8">
6
+ <meta content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" name="viewport">
7
+
8
+ <!-- Use title if it's in the page YAML frontmatter -->
9
+ <title>something title :+1:</title>
10
+
11
+ <link href='//fonts.googleapis.com/css?family=Lato:300,400' rel='stylesheet' type='text/css'>
12
+
13
+ <%= stylesheet_link_tag :site %>
14
+ <%= javascript_include_tag :all %>
15
+ </head>
16
+
17
+ <body class="<%= page_classes %>">
18
+ <%= yield %>
19
+ </body>
20
+ </html>
@@ -18,6 +18,14 @@ module Middleman
18
18
  def convert(content)
19
19
  return content if content.blank?
20
20
 
21
+ if has_body?(content)
22
+ emojify_inner_body(content)
23
+ else
24
+ emojify(content)
25
+ end
26
+ end
27
+
28
+ def emojify(content)
21
29
  content.to_str.gsub(/:([\w+-]+):/) do |match|
22
30
  emoji = Emoji.find_by_alias($1)
23
31
  if emoji
@@ -34,6 +42,18 @@ module Middleman
34
42
  end
35
43
  end
36
44
 
45
+ # emojify only in the body tag
46
+ def emojify_inner_body(content)
47
+ pattern = /<body.+?>(.+?)<\/body>/m
48
+ content.to_str.gsub(pattern) do |html|
49
+ emojify(html).gsub(pattern, '\1')
50
+ end
51
+ end
52
+
53
+ def has_body?(content)
54
+ !(/<body.+?>.+?<\/body>/m =~ content.to_str).nil?
55
+ end
56
+
37
57
  def src(path)
38
58
  %(src="#{File.join(@base_path, path)}")
39
59
  end
@@ -11,7 +11,7 @@ module Middleman
11
11
  def initialize(app, options_hash = {}, &block)
12
12
  super
13
13
  converter = Middleman::Gemoji::Converter.new(app, options)
14
- app.before_render do |content|
14
+ app.after_render do |content|
15
15
  converter.convert(content)
16
16
  end
17
17
  end
@@ -1,5 +1,5 @@
1
1
  module Middleman
2
2
  module Gemoji
3
- VERSION = '0.0.8'
3
+ VERSION = '0.1.0'
4
4
  end
5
5
  end
@@ -1,5 +1,4 @@
1
1
  require './test/test_helper'
2
- require 'middleman'
3
2
  require './lib/middleman-gemoji/converter'
4
3
 
5
4
  class TestConverter < Minitest::Test
@@ -27,20 +26,70 @@ class TestConverter < Minitest::Test
27
26
  end
28
27
  end
29
28
 
30
- def test_convert
31
- assert_equal(
32
- '<img class="gemoji" alt="+1" src="/images/emoji/unicode/1f44d.png" />',
33
- @converter.convert(':+1:')
34
- );
35
- end
36
-
37
29
  def test_convert_received_blank
38
30
  assert_equal('', @converter.convert(''))
39
31
  assert_equal(nil, @converter.convert(nil))
40
32
  end
41
33
 
42
- def test_convert_received_normal_string
43
- assert_equal('hoge', @converter.convert('hoge'));
34
+ def test_emojify
35
+ assert_equal(
36
+ '<img class="gemoji" alt="+1" src="/images/emoji/unicode/1f44d.png" />',
37
+ @converter.emojify(':+1:')
38
+ );
39
+ end
40
+
41
+ def test_emojify_received_normal_string
42
+ html = '<p>hoge</p>'
43
+ assert_equal(html, @converter.emojify(html));
44
+ end
45
+
46
+ def test_emojify_inner_body
47
+ html = "<html><head><title>something title :+1:</title></head><body>\n<p>somethig emoji :+1:</p>\n</body></html>"
48
+ result = @converter.emojify_inner_body(html)
49
+ assert_match(/1f44d.png/, result)
50
+ assert_match(/something title :\+1:/, result)
51
+ end
52
+
53
+ def test_emojify_inner_body_received_normal_string
54
+ html = '<p>hoge</p>'
55
+ assert_equal(html, @converter.emojify_inner_body(html))
56
+ end
57
+
58
+ def test_has_body_return_true
59
+ html = <<-'HTML'
60
+ <!doctype html>
61
+ <html>
62
+ <head>
63
+ <meta charset="utf-8">
64
+ <title>something title :+1:</title>
65
+ </head>
66
+ <body>
67
+ <p>:+1:</p>
68
+ </body>
69
+ </html>
70
+ HTML
71
+ assert_equal(true, @converter.has_body?(html))
72
+ end
73
+
74
+ def test_has_body_return_true__body_has_class
75
+ html = <<-'HTML'
76
+ <!doctype html>
77
+ <html>
78
+ <head>
79
+ <meta charset="utf-8">
80
+ <title>something title :+1:</title>
81
+ </head>
82
+ <body class="index">
83
+ <p>:+1:</p>
84
+ </body>
85
+ </html>
86
+ HTML
87
+ assert_equal(true, @converter.has_body?(html))
88
+ end
89
+
90
+ def test_has_body_return_false
91
+ html = '<p>somethig emoji :+1:</p>'
92
+ assert_equal(false, @converter.has_body?(html))
44
93
  end
45
94
 
46
95
  def test_src
@@ -1,3 +1,4 @@
1
+ require 'middleman'
1
2
  require 'minitest/autorun'
2
3
  require 'minitest/reporters'
3
4
  Minitest::Reporters.use!
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: middleman-gemoji
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuya Terajima
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-23 00:00:00.000000000 Z
11
+ date: 2016-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: middleman
@@ -159,6 +159,7 @@ extra_rdoc_files: []
159
159
  files:
160
160
  - .gitignore
161
161
  - .travis.yml
162
+ - CHANGELOG.md
162
163
  - Gemfile
163
164
  - LICENSE.txt
164
165
  - README.md
@@ -177,6 +178,7 @@ files:
177
178
  - fixtures/gemoji-app/source/images/emoji/unicode/.gitkeep
178
179
  - fixtures/gemoji-app/source/img/emoji/unicode/.gitkeep
179
180
  - fixtures/gemoji-app/source/index.html.erb
181
+ - fixtures/gemoji-app/source/layouts/layout.erb
180
182
  - fixtures/gemoji-app/source/no-emoji.html.erb
181
183
  - fixtures/gemoji-empty-app/config.rb
182
184
  - fixtures/gemoji-empty-app/source/images/.gitkeep
@@ -186,14 +188,17 @@ files:
186
188
  - fixtures/haml-app/config.rb
187
189
  - fixtures/haml-app/source/images/emoji/unicode/.gitkeep
188
190
  - fixtures/haml-app/source/index.html.haml
191
+ - fixtures/haml-app/source/layouts/layout.erb
189
192
  - fixtures/haml-app/source/no-emoji.html.haml
190
193
  - fixtures/markdown-app/config.rb
191
194
  - fixtures/markdown-app/source/images/emoji/unicode/.gitkeep
192
195
  - fixtures/markdown-app/source/index.html.md
196
+ - fixtures/markdown-app/source/layouts/layout.erb
193
197
  - fixtures/markdown-app/source/no-emoji.html.md
194
198
  - fixtures/slim-app/config.rb
195
199
  - fixtures/slim-app/source/images/emoji/unicode/.gitkeep
196
200
  - fixtures/slim-app/source/index.html.slim
201
+ - fixtures/slim-app/source/layouts/layout.erb
197
202
  - fixtures/slim-app/source/no-emoji.html.slim
198
203
  - lib/middleman-gemoji.rb
199
204
  - lib/middleman-gemoji/command.rb