rack-emoji 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +69 -0
- data/Rakefile +9 -0
- data/example/sinatra/Rakefile +1 -0
- data/example/sinatra/app.rb +27 -0
- data/lib/rack/emoji.rb +46 -0
- data/lib/rack/emoji/version.rb +5 -0
- data/rack-emoji.gemspec +24 -0
- data/test/regexp_test.rb +32 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8cd6ba7624c28c76c2421b67806726c1b8da963e
|
4
|
+
data.tar.gz: f6992a6ed9f6c72c76bd2d19d6b07ce1d4402742
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1730a047f80c1dd3a50ddeaf1518a10602f3fed2e5ec40a80db76f380fd32829cfc3befe04adacbc2c7b982f3533bdb5c59209c1c24bffc4ef910f3508cb8c9d
|
7
|
+
data.tar.gz: ebcba38c5e3155b1ed08dea9488ca2e53b31c0fc917b5625ee7780bd81c9b7c38852ed6fa593349db74220db0eef89d9f41b04732b2c201779f3220bd570f2be
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 SATO Naoya
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
# Rack::Emoji
|
2
|
+
|
3
|
+
Quickly and easily use emoji with rack based application
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'rack-emoji'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install rack-emoji
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
To get started, need a copy of emoji images.
|
22
|
+
Edit your Rakefile:
|
23
|
+
|
24
|
+
```
|
25
|
+
# Rakefile
|
26
|
+
load 'tasks/emoji.rake'
|
27
|
+
```
|
28
|
+
|
29
|
+
```
|
30
|
+
$ rake emoji # copied to your public directory
|
31
|
+
```
|
32
|
+
|
33
|
+
Edit your rack application file as follows:
|
34
|
+
|
35
|
+
```
|
36
|
+
require 'rack/emoji'
|
37
|
+
|
38
|
+
use Rack::Emoji, :width => 50, :height => 50
|
39
|
+
|
40
|
+
...
|
41
|
+
|
42
|
+
run app
|
43
|
+
```
|
44
|
+
|
45
|
+
Just use emoji name.
|
46
|
+
|
47
|
+
```
|
48
|
+
# your.html/erb/haml...
|
49
|
+
:dog:
|
50
|
+
```
|
51
|
+
|
52
|
+
## Options
|
53
|
+
|
54
|
+
- dir (for emoji image directory)
|
55
|
+
- width
|
56
|
+
- height
|
57
|
+
- style
|
58
|
+
|
59
|
+
## Contributing
|
60
|
+
|
61
|
+
1. Fork it ( http://github.com/stny/rack-emoji/fork )
|
62
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
63
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
64
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
65
|
+
5. Create new Pull Request
|
66
|
+
|
67
|
+
## Acknowledgment
|
68
|
+
|
69
|
+
[github/gemoji](https://github.com/github/gemoji)
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
load 'tasks/emoji.rake'
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'sinatra'
|
2
|
+
require 'rack/emoji'
|
3
|
+
|
4
|
+
use Rack::Emoji, :width => 50, :height => 50
|
5
|
+
|
6
|
+
set :public_folder, File.dirname(__FILE__) + '/public'
|
7
|
+
|
8
|
+
get '/' do
|
9
|
+
erb :index
|
10
|
+
end
|
11
|
+
|
12
|
+
__END__
|
13
|
+
|
14
|
+
@@layout
|
15
|
+
<!DOCTYPE html>
|
16
|
+
<html>
|
17
|
+
<head>
|
18
|
+
<title>Rack::Emoji Example :100:</title>
|
19
|
+
<meta charset="utf-8">
|
20
|
+
</head>
|
21
|
+
<body>
|
22
|
+
<%= yield %>
|
23
|
+
</body>
|
24
|
+
</html>
|
25
|
+
|
26
|
+
@@index
|
27
|
+
<p>:dog:</p>
|
data/lib/rack/emoji.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require "rack/emoji/version"
|
2
|
+
require 'gemoji'
|
3
|
+
|
4
|
+
module Rack
|
5
|
+
class Emoji
|
6
|
+
|
7
|
+
HTML_REGEXP = /(.*<body[^>]*>)(.*)(<\/body>.*)/m
|
8
|
+
|
9
|
+
def initialize(app, options = {})
|
10
|
+
@app = app
|
11
|
+
@dir = options.fetch(:dir, "images/emoji")
|
12
|
+
@height = options.fetch(:height, 20)
|
13
|
+
@width = options.fetch(:width, 20)
|
14
|
+
@style = options.fetch(:style, "vertical-align:middle;")
|
15
|
+
end
|
16
|
+
|
17
|
+
def call(env)
|
18
|
+
status, headers, response = @app.call(env)
|
19
|
+
|
20
|
+
if headers["Content-Type"] && headers["Content-Type"].include?("text/html")
|
21
|
+
new_response = emojify(response)
|
22
|
+
headers['Content-Length'] = new_response.length.to_s
|
23
|
+
[status, headers, [new_response]]
|
24
|
+
else
|
25
|
+
[status, headers, response]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def emojify(response)
|
30
|
+
response_str = ""
|
31
|
+
response.each { |s| response_str << s }
|
32
|
+
_, header, body, footer = response_str.match(HTML_REGEXP).to_a
|
33
|
+
|
34
|
+
body = body.gsub(/:([a-z0-9\+\-_]+):/) do |match|
|
35
|
+
if ::Emoji.names.include?($1)
|
36
|
+
%Q{<img alt="#{$1}" src="#{@dir}/#{$1}.png" style="#{@style}" width="#{@width}" height="#{@height}" />}
|
37
|
+
else
|
38
|
+
match
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
header + body + footer
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
data/rack-emoji.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rack/emoji/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rack-emoji"
|
8
|
+
spec.version = Rack::Emoji::VERSION
|
9
|
+
spec.authors = ["SATO Naoya"]
|
10
|
+
spec.email = ["s@tonaoya.com"]
|
11
|
+
spec.summary = "Rack middleware for emoji"
|
12
|
+
spec.description = "Easily setup emoji for use with rack app."
|
13
|
+
spec.homepage = "http://github.com/stny/rack-emoji"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
+
|
23
|
+
spec.add_dependency "gemoji", "~> 1.5"
|
24
|
+
end
|
data/test/regexp_test.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'rack/emoji'
|
3
|
+
|
4
|
+
class RegexpTest < Minitest::Test
|
5
|
+
|
6
|
+
SIMPLE = <<-EOS
|
7
|
+
<!doctype html>
|
8
|
+
<html>
|
9
|
+
<head></head>
|
10
|
+
<body>
|
11
|
+
</body>
|
12
|
+
</html>
|
13
|
+
EOS
|
14
|
+
|
15
|
+
ATTRIBUTE = <<-EOS
|
16
|
+
<!doctype html>
|
17
|
+
<html>
|
18
|
+
<head></head>
|
19
|
+
<body class="ringo">
|
20
|
+
</body>
|
21
|
+
</html>
|
22
|
+
EOS
|
23
|
+
|
24
|
+
def test_simple_regexp
|
25
|
+
assert_match Rack::Emoji::HTML_REGEXP, SIMPLE
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_attribute_regexp
|
29
|
+
assert_match Rack::Emoji::HTML_REGEXP, ATTRIBUTE
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack-emoji
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- SATO Naoya
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: gemoji
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.5'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.5'
|
41
|
+
description: Easily setup emoji for use with rack app.
|
42
|
+
email:
|
43
|
+
- s@tonaoya.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- example/sinatra/Rakefile
|
54
|
+
- example/sinatra/app.rb
|
55
|
+
- lib/rack/emoji.rb
|
56
|
+
- lib/rack/emoji/version.rb
|
57
|
+
- rack-emoji.gemspec
|
58
|
+
- test/regexp_test.rb
|
59
|
+
homepage: http://github.com/stny/rack-emoji
|
60
|
+
licenses:
|
61
|
+
- MIT
|
62
|
+
metadata: {}
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
requirements: []
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 2.2.1
|
80
|
+
signing_key:
|
81
|
+
specification_version: 4
|
82
|
+
summary: Rack middleware for emoji
|
83
|
+
test_files:
|
84
|
+
- test/regexp_test.rb
|