middleman-gemoji 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +13 -1
- data/fixtures/gemoji-file-exist/source/images/emoji/unicode/.gitkeep +0 -0
- data/lib/middleman-gemoji/converter.rb +68 -0
- data/lib/middleman-gemoji/extension.rb +3 -50
- data/lib/middleman-gemoji/version.rb +1 -1
- data/middleman-gemoji.gemspec +3 -0
- data/test/test_converter.rb +108 -0
- data/test/test_helper.rb +3 -0
- metadata +50 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f1e4c131cc9751f78169b7f188d43aed54a88e57
|
4
|
+
data.tar.gz: e36f0ffdd9878424bfbb44504c4387015fa1fa3b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 05bdcddd6c01bb1fa99b1f86f822975a4f8b85dfab110a9989b7fcaf2e5d5f8dd231926bc0f4d479991694665afa8cf34178b47db4aee248f52bf54a31e9a7e6
|
7
|
+
data.tar.gz: b960acfbfac95f60a9c4255bc0ee77768d9c51d88bef0363fcbba50cceed5b51a9009b143754e1832ba8531a441b8813c2bf918db9b624724859f08669133b7c
|
data/Rakefile
CHANGED
@@ -1,2 +1,14 @@
|
|
1
|
-
require
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rake/testtask'
|
2
3
|
|
4
|
+
task default: [:test, :cucumber]
|
5
|
+
|
6
|
+
Rake::TestTask.new do |test|
|
7
|
+
test.test_files = Dir['test/**/test_*.rb']
|
8
|
+
test.verbose = true
|
9
|
+
end
|
10
|
+
|
11
|
+
desc 'cucumber test'
|
12
|
+
task :cucumber do
|
13
|
+
sh 'cucumber --backtrace features/'
|
14
|
+
end
|
File without changes
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'gemoji'
|
2
|
+
|
3
|
+
module Middleman
|
4
|
+
module Gemoji
|
5
|
+
class Converter
|
6
|
+
attr_reader :app, :options, :base_path
|
7
|
+
|
8
|
+
def initialize(app, options)
|
9
|
+
if !app.is_a?(Middleman::Application)
|
10
|
+
raise "app is not Middleman::Application"
|
11
|
+
end
|
12
|
+
|
13
|
+
@app = app
|
14
|
+
@options = options
|
15
|
+
set_base_path
|
16
|
+
end
|
17
|
+
|
18
|
+
def convert(content)
|
19
|
+
return content if content.blank?
|
20
|
+
|
21
|
+
content.to_str.gsub(/:([\w+-]+):/) do |match|
|
22
|
+
emoji = Emoji.find_by_alias($1)
|
23
|
+
if emoji
|
24
|
+
image = []
|
25
|
+
image << %(alt="#{$1}")
|
26
|
+
image << src(emoji.image_filename)
|
27
|
+
image << size if size
|
28
|
+
image << style if style
|
29
|
+
|
30
|
+
%(<img class="gemoji" #{image.join(' ').strip} />)
|
31
|
+
else
|
32
|
+
match
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def src(path)
|
38
|
+
%(src="#{File.join(@base_path, path)}")
|
39
|
+
end
|
40
|
+
|
41
|
+
def size
|
42
|
+
%(width="#{@options[:size]}" height="#{@options[:size]}") if @options[:size]
|
43
|
+
end
|
44
|
+
|
45
|
+
def style
|
46
|
+
%(style="#{@options[:style]}") if @options[:style]
|
47
|
+
end
|
48
|
+
|
49
|
+
def emoji_file_exist?
|
50
|
+
Dir.exist?(
|
51
|
+
File.join(@app.root, @app.config.source, @options[:emoji_dir], 'unicode')
|
52
|
+
)
|
53
|
+
end
|
54
|
+
|
55
|
+
def set_base_path
|
56
|
+
@base_path = 'https://assets-cdn.github.com/images/icons/emoji/'
|
57
|
+
if emoji_file_exist?
|
58
|
+
if /^http/ =~ @app.config[:http_prefix]
|
59
|
+
@base_path = File.join(app.config[:http_prefix], options[:emoji_dir])
|
60
|
+
else
|
61
|
+
@base_path = File.join('/', app.config[:http_prefix], options[:emoji_dir])
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require_relative './converter'
|
2
2
|
|
3
3
|
module Middleman
|
4
4
|
module Gemoji
|
@@ -10,56 +10,9 @@ module Middleman
|
|
10
10
|
|
11
11
|
def initialize(app, options_hash = {}, &block)
|
12
12
|
super
|
13
|
-
|
14
|
-
File.join(app.root, app.config.source, options[:emoji_dir], 'unicode')
|
15
|
-
)
|
16
|
-
extension = self
|
17
|
-
|
13
|
+
converter = Middleman::Gemoji::Converter.new(app, options)
|
18
14
|
app.before_render do |content|
|
19
|
-
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def emojify(content)
|
24
|
-
@base_path = base_path
|
25
|
-
content.to_str.gsub(/:([\w+-]+):/) do |match|
|
26
|
-
emoji = Emoji.find_by_alias($1)
|
27
|
-
if emoji
|
28
|
-
image = []
|
29
|
-
image << %(alt="#{$1}")
|
30
|
-
image << src(emoji.image_filename)
|
31
|
-
image << size(options[:size]) if options[:size]
|
32
|
-
image << style(options[:style]) if options[:style]
|
33
|
-
|
34
|
-
%(<img class="gemoji" #{image.join(' ')} />)
|
35
|
-
else
|
36
|
-
match
|
37
|
-
end if content.present?
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def src(path)
|
42
|
-
%(src="#{File.join(@base_path, path)}")
|
43
|
-
end
|
44
|
-
|
45
|
-
def size(size)
|
46
|
-
%(width="#{size}" height="#{size}")
|
47
|
-
end
|
48
|
-
|
49
|
-
def style(style)
|
50
|
-
%(style="#{style}")
|
51
|
-
end
|
52
|
-
|
53
|
-
def base_path
|
54
|
-
if @emoji_exist
|
55
|
-
prefix = app.config[:http_prefix]
|
56
|
-
if prefix && (/^http/ =~ prefix)
|
57
|
-
File.join(app.config[:http_prefix], options[:emoji_dir])
|
58
|
-
else
|
59
|
-
File.join('/', app.config[:http_prefix], options[:emoji_dir])
|
60
|
-
end
|
61
|
-
else
|
62
|
-
'https://assets-cdn.github.com/images/icons/emoji/'
|
15
|
+
converter.convert(content)
|
63
16
|
end
|
64
17
|
end
|
65
18
|
end
|
data/middleman-gemoji.gemspec
CHANGED
@@ -28,4 +28,7 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.add_development_dependency "bundler", ">= 1.5"
|
29
29
|
spec.add_development_dependency "rake", ">= 10"
|
30
30
|
spec.add_development_dependency "slim", ">= 3.0"
|
31
|
+
spec.add_development_dependency "rb-inotify", "~> 0.9"
|
32
|
+
spec.add_development_dependency "minitest"
|
33
|
+
spec.add_development_dependency "minitest-reporters"
|
31
34
|
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
require './test/test_helper'
|
2
|
+
require 'middleman'
|
3
|
+
require './lib/middleman-gemoji/converter'
|
4
|
+
|
5
|
+
class TestConverter < Minitest::Test
|
6
|
+
def setup
|
7
|
+
@root = ENV['MM_ROOT']
|
8
|
+
ENV['MM_ROOT'] = File.join(Dir.pwd, 'fixtures', 'gemoji-file-exist')
|
9
|
+
@converter = converter
|
10
|
+
end
|
11
|
+
|
12
|
+
def teardown
|
13
|
+
ENV['MM_ROOT'] = @root
|
14
|
+
end
|
15
|
+
|
16
|
+
def converter(app: Middleman::Application.new, size: nil, style: nil, emoji_dir: 'images/emoji')
|
17
|
+
Middleman::Gemoji::Converter.new(app, {size: size, style: style, emoji_dir: emoji_dir})
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_initialize
|
21
|
+
assert_instance_of(Middleman::Application, @converter.app)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_initialize_raise_runtime_error
|
25
|
+
assert_raises RuntimeError do
|
26
|
+
converter(app: nil)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
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
|
+
def test_convert_received_blank
|
38
|
+
assert_equal('', @converter.convert(''))
|
39
|
+
assert_equal(nil, @converter.convert(nil))
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_convert_received_normal_string
|
43
|
+
assert_equal('hoge', @converter.convert('hoge'));
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_src
|
47
|
+
path = @converter.src('unicode/1f44d.png')
|
48
|
+
assert_equal('src="/images/emoji/unicode/1f44d.png"', path)
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_src_with_cdn
|
52
|
+
ENV['MM_ROOT'] = File.join(@converter.app.root, 'fixtures', 'gemoji-file-not-exist')
|
53
|
+
@converter.set_base_path
|
54
|
+
path = @converter.src('unicode/1f44d.png')
|
55
|
+
assert_equal(
|
56
|
+
'src="https://assets-cdn.github.com/images/icons/emoji/unicode/1f44d.png"',
|
57
|
+
path
|
58
|
+
)
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_size_rerutn_nil
|
62
|
+
@converter.options[:size] = nil
|
63
|
+
assert_nil(@converter.size)
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_size_return_string
|
67
|
+
@converter.options[:size] = 40
|
68
|
+
assert_equal('width="40" height="40"', @converter.size)
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_style_return_nil
|
72
|
+
@converter.options[:style] = nil
|
73
|
+
assert_nil(@converter.style)
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_style_return_string
|
77
|
+
@converter.options[:style] = 'padding-right: .2em'
|
78
|
+
assert_equal('style="padding-right: .2em"', @converter.style)
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_emoji_file_exist_return_true
|
82
|
+
assert_equal(true, @converter.emoji_file_exist?)
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_emoji_file_exist_return_false
|
86
|
+
ENV['MM_ROOT'] = File.join(@converter.app.root, 'fixtures', 'gemoji-file-not-exist')
|
87
|
+
assert_equal(false, @converter.emoji_file_exist?)
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_set_base_path__cdn
|
91
|
+
ENV['MM_ROOT'] = File.join(@converter.app.root, 'fixtures', 'gemoji-file-not-exist')
|
92
|
+
@converter.set_base_path
|
93
|
+
assert_equal(
|
94
|
+
'https://assets-cdn.github.com/images/icons/emoji/',
|
95
|
+
@converter.base_path
|
96
|
+
)
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_set_base_path__relative_path
|
100
|
+
assert_equal('/images/emoji', @converter.base_path)
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_set_base_path__full_path
|
104
|
+
@converter.app.config[:http_prefix] = 'http://example.com/'
|
105
|
+
@converter.set_base_path
|
106
|
+
assert_equal('http://example.com/images/emoji', @converter.base_path)
|
107
|
+
end
|
108
|
+
end
|
data/test/test_helper.rb
ADDED
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.
|
4
|
+
version: 0.0.8
|
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-
|
11
|
+
date: 2016-02-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: middleman
|
@@ -108,6 +108,48 @@ dependencies:
|
|
108
108
|
- - '>='
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '3.0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rb-inotify
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ~>
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0.9'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ~>
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0.9'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: minitest
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: minitest-reporters
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - '>='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - '>='
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
111
153
|
description: Github-flavored emoji plugin for Middleman.
|
112
154
|
email:
|
113
155
|
- terra@e2esound.com
|
@@ -140,6 +182,7 @@ files:
|
|
140
182
|
- fixtures/gemoji-empty-app/source/images/.gitkeep
|
141
183
|
- fixtures/gemoji-empty-app/source/img/.gitkeep
|
142
184
|
- fixtures/gemoji-empty-app/source/index.html.erb
|
185
|
+
- fixtures/gemoji-file-exist/source/images/emoji/unicode/.gitkeep
|
143
186
|
- fixtures/haml-app/config.rb
|
144
187
|
- fixtures/haml-app/source/images/emoji/unicode/.gitkeep
|
145
188
|
- fixtures/haml-app/source/index.html.haml
|
@@ -154,10 +197,13 @@ files:
|
|
154
197
|
- fixtures/slim-app/source/no-emoji.html.slim
|
155
198
|
- lib/middleman-gemoji.rb
|
156
199
|
- lib/middleman-gemoji/command.rb
|
200
|
+
- lib/middleman-gemoji/converter.rb
|
157
201
|
- lib/middleman-gemoji/extension.rb
|
158
202
|
- lib/middleman-gemoji/version.rb
|
159
203
|
- lib/middleman_extension.rb
|
160
204
|
- middleman-gemoji.gemspec
|
205
|
+
- test/test_converter.rb
|
206
|
+
- test/test_helper.rb
|
161
207
|
homepage: https://github.com/yterajima/middleman-gemoji
|
162
208
|
licenses:
|
163
209
|
- MIT
|
@@ -190,3 +236,5 @@ test_files:
|
|
190
236
|
- features/markdown.feature
|
191
237
|
- features/slim.feature
|
192
238
|
- features/support/env.rb
|
239
|
+
- test/test_converter.rb
|
240
|
+
- test/test_helper.rb
|