auto_html-contrib 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +5 -0
- data/Rakefile +5 -3
- data/auto_html-contrib.gemspec +17 -16
- data/bin/console +3 -3
- data/lib/auto_html.rb +9 -0
- data/lib/auto_html/gist.rb +22 -0
- data/lib/auto_html/google_maps.rb +68 -0
- data/lib/auto_html/instagram.rb +32 -0
- data/lib/auto_html/twitter.rb +25 -0
- data/lib/auto_html/vimeo.rb +49 -0
- data/lib/auto_html/youtube.rb +49 -0
- metadata +56 -8
- data/lib/auto_html/contrib.rb +0 -7
- data/lib/auto_html/contrib/version.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7fbfe9692fc95c2068d2105decb9be1e4e17bda1
|
4
|
+
data.tar.gz: 18244880bc20ba1316cc3957985fbbfb591d0dc8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b65ac54f8078558f52e04a05f065e6d7b686181f6b11c2f8fa445b5e735ff6b89206594e772e84b6f406266d1b9fcca912210e10cf04dffff8393251ea11def
|
7
|
+
data.tar.gz: a589a917d0376eeb661794783104ac432c0760815364a3475a8d2e36cbbac2620900e4596919f0c4c7bc9cca229943143e3623cbb9916ff08d83a0757d46bd15
|
data/.gitignore
CHANGED
data/.rubocop.yml
ADDED
data/Rakefile
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
require 'rubocop/rake_task'
|
3
4
|
|
4
5
|
RSpec::Core::RakeTask.new(:spec)
|
6
|
+
RuboCop::RakeTask.new
|
5
7
|
|
6
|
-
task :
|
8
|
+
task default: [:rubocop, :spec]
|
data/auto_html-contrib.gemspec
CHANGED
@@ -1,25 +1,26 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'auto_html/contrib/version'
|
5
2
|
|
6
3
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
8
|
-
spec.version =
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
4
|
+
spec.name = 'auto_html-contrib'
|
5
|
+
spec.version = '0.1.0'
|
6
|
+
spec.authors = ['Dejan Simic']
|
7
|
+
spec.email = ['desimic@gmail.com']
|
11
8
|
|
12
|
-
spec.summary =
|
13
|
-
spec.description =
|
14
|
-
spec.homepage =
|
15
|
-
spec.license =
|
9
|
+
spec.summary = 'Filters for `auto_html` gem'
|
10
|
+
spec.description = 'Filters for `auto_html` gem'
|
11
|
+
spec.homepage = 'https://github.com/dejan/auto_html-contrib'
|
12
|
+
spec.license = 'MIT'
|
16
13
|
|
17
14
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
-
spec.bindir =
|
15
|
+
spec.bindir = 'exe'
|
19
16
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
-
spec.require_paths = [
|
17
|
+
spec.require_paths = ['lib']
|
21
18
|
|
22
|
-
spec.
|
23
|
-
|
24
|
-
spec.add_development_dependency
|
19
|
+
spec.add_dependency 'tag_helper', '~> 0.5'
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.10'
|
22
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
23
|
+
spec.add_development_dependency 'rspec', '~> 3.3'
|
24
|
+
spec.add_development_dependency 'rubocop', '~> 0.33'
|
25
|
+
spec.add_development_dependency 'fakeweb', '~> 1.3'
|
25
26
|
end
|
data/bin/console
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'auto_html/contrib'
|
5
5
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +10,5 @@ require "auto_html/contrib"
|
|
10
10
|
# require "pry"
|
11
11
|
# Pry.start
|
12
12
|
|
13
|
-
require
|
13
|
+
require 'irb'
|
14
14
|
IRB.start
|
data/lib/auto_html.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
# Filters for AutoHtml
|
2
|
+
module AutoHtml
|
3
|
+
autoload :Gist, 'auto_html/gist'
|
4
|
+
autoload :GoogleMaps, 'auto_html/google_maps'
|
5
|
+
autoload :Instagram, 'auto_html/instagram'
|
6
|
+
autoload :Vimeo, 'auto_html/vimeo'
|
7
|
+
autoload :YouTube, 'auto_html/youtube'
|
8
|
+
autoload :Twitter, 'auto_html/twitter'
|
9
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'tag_helper'
|
2
|
+
|
3
|
+
module AutoHtml
|
4
|
+
# Gist filter
|
5
|
+
class Gist
|
6
|
+
include TagHelper
|
7
|
+
|
8
|
+
def call(text)
|
9
|
+
regex = %r{https?://gist\.github\.com/(\w+/)?(\d+)}
|
10
|
+
text.gsub(regex) do
|
11
|
+
gist_id = Regexp.last_match(2)
|
12
|
+
tag(:script, type: 'text/javascript', src: gist_url(gist_id)) { '' }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def gist_url(id)
|
19
|
+
"https://gist.github.com/#{id}.js"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'tag_helper'
|
2
|
+
|
3
|
+
module AutoHtml
|
4
|
+
# Google Maps filter
|
5
|
+
class GoogleMaps
|
6
|
+
include TagHelper
|
7
|
+
|
8
|
+
def initialize(width: 420, height: 315, type: :normal, zoom: 18, show_info: false)
|
9
|
+
@width = width
|
10
|
+
@height = height
|
11
|
+
@type = type
|
12
|
+
@zoom = zoom
|
13
|
+
@show_info = show_info
|
14
|
+
end
|
15
|
+
|
16
|
+
def call(text)
|
17
|
+
regex = %r{(https?)://maps\.google\.([a-z\.]+)/maps\?(.*)}
|
18
|
+
text.gsub(regex) do
|
19
|
+
country = Regexp.last_match(2)
|
20
|
+
path = "//maps.google.#{country}/maps"
|
21
|
+
query = Regexp.last_match(3)
|
22
|
+
link = link_tag(path, query)
|
23
|
+
iframe_tag(path, query) << tag(:br) << tag(:small) { link }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def iframe_tag(path, map_query)
|
30
|
+
params = ['f=q', 'source=s_q', map_query, 'output=embed'] + map_options
|
31
|
+
tag(
|
32
|
+
:iframe,
|
33
|
+
width: @width,
|
34
|
+
height: @height,
|
35
|
+
frameborder: 0,
|
36
|
+
scrolling: 'no',
|
37
|
+
marginheight: 0,
|
38
|
+
marginwidth: 0,
|
39
|
+
src: path + '?' + params.join('&')) { '' }
|
40
|
+
end
|
41
|
+
|
42
|
+
def link_tag(path, map_query)
|
43
|
+
params = ['f=q', 'source=embed', map_query]
|
44
|
+
tag(
|
45
|
+
:a,
|
46
|
+
href: path + '?' + params.join('&'),
|
47
|
+
style: 'color:#000;text-align:left') do
|
48
|
+
'View Larger Map'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def map_options
|
53
|
+
map_options = []
|
54
|
+
map_options << 'iwloc=near' if @show_info
|
55
|
+
map_options << map_types[@type]
|
56
|
+
map_options << "z=#{@zoom}"
|
57
|
+
end
|
58
|
+
|
59
|
+
def map_types
|
60
|
+
@map_types ||= {
|
61
|
+
normal: 't=m',
|
62
|
+
satellite: 't=k',
|
63
|
+
terrain: 't=p',
|
64
|
+
hibrid: 't=h'
|
65
|
+
}
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'tag_helper'
|
2
|
+
|
3
|
+
module AutoHtml
|
4
|
+
# Instagram filter
|
5
|
+
class Instagram
|
6
|
+
include TagHelper
|
7
|
+
|
8
|
+
def initialize(width: 616, height: 714)
|
9
|
+
@width = width
|
10
|
+
@height = height
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(text)
|
14
|
+
text << '/' unless text.end_with?('/')
|
15
|
+
text.gsub(instagram_pattern) do
|
16
|
+
tag(
|
17
|
+
:iframe,
|
18
|
+
src: "#{text}embed",
|
19
|
+
height: @height,
|
20
|
+
width: @width,
|
21
|
+
frameborder: 0,
|
22
|
+
scrolling: 'no') { '' }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def instagram_pattern
|
29
|
+
@instagram_pattern ||= %r{https?:\/\/(www.)?instagr(am\.com|\.am)/p/.+}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'net/http'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module AutoHtml
|
6
|
+
# Twitter filter
|
7
|
+
class Twitter
|
8
|
+
def call(text)
|
9
|
+
text.gsub(twitter_pattern) do |match|
|
10
|
+
uri = URI('https://api.twitter.com/1/statuses/oembed.json')
|
11
|
+
uri.query = URI.encode_www_form(url: match)
|
12
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
13
|
+
http.use_ssl = true
|
14
|
+
response = JSON.parse(http.get(uri.request_uri).body)
|
15
|
+
response['html']
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def twitter_pattern
|
22
|
+
@twitter_pattern ||= %r{(?<!href=")https://twitter\.com(/#!)?/[A-Za-z0-9_]{1,15}/status(es)?/\d+}
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'tag_helper'
|
2
|
+
|
3
|
+
module AutoHtml
|
4
|
+
# Vimeo filter
|
5
|
+
class Vimeo
|
6
|
+
include TagHelper
|
7
|
+
|
8
|
+
def initialize(width: 420, height: 315, allow_fullscreen: true)
|
9
|
+
@width = width
|
10
|
+
@height = height
|
11
|
+
@allow_fullscreen = allow_fullscreen
|
12
|
+
end
|
13
|
+
|
14
|
+
def call(text)
|
15
|
+
text.gsub(vimeo_pattern) do
|
16
|
+
vimeo_id = Regexp.last_match(2)
|
17
|
+
src = src_url(vimeo_id)
|
18
|
+
tag(:iframe, { src: src }.merge(iframe_attributes)) { '' }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def vimeo_pattern
|
25
|
+
@vimeo_pattern ||= %r{https?://(www.)?vimeo\.com/([A-Za-z0-9._%-]*)((\?|#)\S+)?}
|
26
|
+
end
|
27
|
+
|
28
|
+
def src_url(vimeo_id)
|
29
|
+
"//player.vimeo.com/video/#{vimeo_id}"
|
30
|
+
end
|
31
|
+
|
32
|
+
def iframe_attributes
|
33
|
+
{}.tap do |attrs|
|
34
|
+
attrs[:width] = @width
|
35
|
+
attrs[:height] = @height
|
36
|
+
attrs[:frameborder] = 0
|
37
|
+
attrs.merge!(fullscreen_attributes) if @allow_fullscreen
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def fullscreen_attributes
|
42
|
+
{
|
43
|
+
webkitallowfullscreen: 'yes',
|
44
|
+
mozallowfullscreen: 'yes',
|
45
|
+
allowfullscreen: 'yes'
|
46
|
+
}
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'tag_helper'
|
2
|
+
|
3
|
+
module AutoHtml
|
4
|
+
# YouTube filter
|
5
|
+
class YouTube
|
6
|
+
include TagHelper
|
7
|
+
|
8
|
+
def initialize(width: 420, height: 315)
|
9
|
+
@width = width
|
10
|
+
@height = height
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(text)
|
14
|
+
text.gsub(youtube_pattern) do
|
15
|
+
youtube_id = Regexp.last_match(4)
|
16
|
+
tag(:div, class: 'video youtube') do
|
17
|
+
tag(:iframe, iframe_attributes(youtube_id)) { '' }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def youtube_pattern
|
25
|
+
@youtube_pattern ||=
|
26
|
+
%r{
|
27
|
+
(https?://)?
|
28
|
+
(www.)?
|
29
|
+
(
|
30
|
+
youtube\.com/watch\?v=|
|
31
|
+
youtu\.be/|
|
32
|
+
youtube\.com/watch\?feature=player_embedded&v=
|
33
|
+
)
|
34
|
+
([A-Za-z0-9_-]*)(\&\S+)?(\?\S+)?
|
35
|
+
}x
|
36
|
+
end
|
37
|
+
|
38
|
+
def iframe_attributes(youtube_id)
|
39
|
+
src = "//www.youtube.com/embed/#{youtube_id}"
|
40
|
+
{
|
41
|
+
width: @width,
|
42
|
+
height: @height,
|
43
|
+
src: src,
|
44
|
+
frameborder: 0,
|
45
|
+
allowfullscreen: 'yes'
|
46
|
+
}
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: auto_html-contrib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dejan Simic
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: tag_helper
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.5'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.5'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -42,16 +56,44 @@ dependencies:
|
|
42
56
|
name: rspec
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
|
-
- - "
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.3'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.3'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
46
74
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
75
|
+
version: '0.33'
|
48
76
|
type: :development
|
49
77
|
prerelease: false
|
50
78
|
version_requirements: !ruby/object:Gem::Requirement
|
51
79
|
requirements:
|
52
|
-
- - "
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.33'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: fakeweb
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.3'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
53
95
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
96
|
+
version: '1.3'
|
55
97
|
description: Filters for `auto_html` gem
|
56
98
|
email:
|
57
99
|
- desimic@gmail.com
|
@@ -61,6 +103,7 @@ extra_rdoc_files: []
|
|
61
103
|
files:
|
62
104
|
- ".gitignore"
|
63
105
|
- ".rspec"
|
106
|
+
- ".rubocop.yml"
|
64
107
|
- CODE_OF_CONDUCT.md
|
65
108
|
- Gemfile
|
66
109
|
- LICENSE
|
@@ -70,8 +113,13 @@ files:
|
|
70
113
|
- auto_html-contrib.gemspec
|
71
114
|
- bin/console
|
72
115
|
- bin/setup
|
73
|
-
- lib/auto_html
|
74
|
-
- lib/auto_html/
|
116
|
+
- lib/auto_html.rb
|
117
|
+
- lib/auto_html/gist.rb
|
118
|
+
- lib/auto_html/google_maps.rb
|
119
|
+
- lib/auto_html/instagram.rb
|
120
|
+
- lib/auto_html/twitter.rb
|
121
|
+
- lib/auto_html/vimeo.rb
|
122
|
+
- lib/auto_html/youtube.rb
|
75
123
|
homepage: https://github.com/dejan/auto_html-contrib
|
76
124
|
licenses:
|
77
125
|
- MIT
|
data/lib/auto_html/contrib.rb
DELETED