auto_html-whistlerbrk 2.0.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +123 -0
- data/Rakefile +9 -0
- data/lib/auto_html.rb +17 -0
- data/lib/auto_html/auto_html_for.rb +64 -0
- data/lib/auto_html/base.rb +21 -0
- data/lib/auto_html/builder.rb +22 -0
- data/lib/auto_html/capistrano.rb +17 -0
- data/lib/auto_html/filter.rb +22 -0
- data/lib/auto_html/filters/dailymotion.rb +6 -0
- data/lib/auto_html/filters/flickr.rb +20 -0
- data/lib/auto_html/filters/gist.rb +8 -0
- data/lib/auto_html/filters/google_map.rb +19 -0
- data/lib/auto_html/filters/hashtag.rb +7 -0
- data/lib/auto_html/filters/html_escape.rb +9 -0
- data/lib/auto_html/filters/image.rb +16 -0
- data/lib/auto_html/filters/instagram.rb +10 -0
- data/lib/auto_html/filters/link.rb +16 -0
- data/lib/auto_html/filters/liveleak.rb +19 -0
- data/lib/auto_html/filters/metacafe.rb +13 -0
- data/lib/auto_html/filters/redcarpet.rb +4 -0
- data/lib/auto_html/filters/sanitize.rb +5 -0
- data/lib/auto_html/filters/simple_format.rb +12 -0
- data/lib/auto_html/filters/soundcloud.rb +19 -0
- data/lib/auto_html/filters/ted.rb +13 -0
- data/lib/auto_html/filters/twitter.rb +19 -0
- data/lib/auto_html/filters/vimeo.rb +15 -0
- data/lib/auto_html/filters/worldstar.rb +8 -0
- data/lib/auto_html/filters/youtube.rb +19 -0
- data/lib/auto_html/filters/youtube_image.rb +17 -0
- data/lib/auto_html/filters/youtube_js_api.rb +6 -0
- data/lib/auto_html/railtie.rb +10 -0
- data/lib/auto_html/rake_tasks.rb +27 -0
- data/lib/auto_html/task.rb +9 -0
- data/test/fixture_setup.rb +13 -0
- data/test/fixtures/database.yml +5 -0
- data/test/fixtures/schema.rb +20 -0
- data/test/functional/auto_html_for_options_test.rb +26 -0
- data/test/functional/auto_html_for_test.rb +56 -0
- data/test/functional/filter_test.rb +27 -0
- data/test/test_helper.rb +16 -0
- data/test/unit/auto_html_test.rb +37 -0
- data/test/unit/filters/dailymotion_test.rb +34 -0
- data/test/unit/filters/gist_test.rb +15 -0
- data/test/unit/filters/google_map_test.rb +24 -0
- data/test/unit/filters/hashtag_test.rb +25 -0
- data/test/unit/filters/html_escape_test.rb +15 -0
- data/test/unit/filters/image_test.rb +77 -0
- data/test/unit/filters/instagram_test.rb +35 -0
- data/test/unit/filters/link_test.rb +55 -0
- data/test/unit/filters/liveleak_test.rb +17 -0
- data/test/unit/filters/metacafe_test.rb +29 -0
- data/test/unit/filters/redcarpet_test.rb +38 -0
- data/test/unit/filters/sanitize_test.rb +36 -0
- data/test/unit/filters/simple_format_test.rb +15 -0
- data/test/unit/filters/soundcloud_test.rb +52 -0
- data/test/unit/filters/ted_test.rb +18 -0
- data/test/unit/filters/twitter_test.rb +45 -0
- data/test/unit/filters/vimeo_test.rb +64 -0
- data/test/unit/filters/worldstar_test.rb +27 -0
- data/test/unit/filters/youtube_image_test.rb +59 -0
- data/test/unit/filters/youtube_js_api_test.rb +30 -0
- data/test/unit/filters/youtube_test.rb +73 -0
- data/test/unit/unit_test_helper.rb +3 -0
- metadata +134 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2220b1eb921c79b4707bb45ecb0f76fdf8006b62
|
4
|
+
data.tar.gz: 36a8fc8048d33adca21900d15613e979523c4391
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 92705cade08e1209263d509782740600f6f1eb260b45c6425337f7315ffbc819d6f43416e798da188bd52b12374b65fe9fcfce46e20b83dbe9975cb157cf690c
|
7
|
+
data.tar.gz: 7ece2134b243221e03a3204083390730db1179a773358394908e333369ae328f73547232f46ecc6c6c722ea49b003763ddcaaf85b5653dd9e2fd2fc08f9bcae7
|
data/README.md
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
auto_html [![Build Status](https://secure.travis-ci.org/dejan/auto_html.png?branch=master)](http://travis-ci.org/dejan/auto_html)
|
2
|
+
=========
|
3
|
+
|
4
|
+
|
5
|
+
auto_html is a Rails extension for transforming URLs to appropriate resource (image, link, YouTube, Vimeo video,...). It's the perfect choice if you don't want to bother visitors with rich HTML editor or markup code, but you still want to allow them to embed video, images, links and more on your site, purely by pasting URL. Check out the [live demo](http://rors.org/demos/auto_html).
|
6
|
+
|
7
|
+
|
8
|
+
## Install
|
9
|
+
|
10
|
+
Specify the gem in Gemfile of the project
|
11
|
+
|
12
|
+
gem "auto_html"
|
13
|
+
|
14
|
+
|
15
|
+
## Example usage
|
16
|
+
|
17
|
+
Transforming string with text and URLs is done with *auto_html* method:
|
18
|
+
|
19
|
+
include AutoHtml
|
20
|
+
|
21
|
+
auto_html('Hey! Checkout out: http://vukajlija.com') { simple_format; link(:target => 'blank') }
|
22
|
+
=> "<p>Hey! Checkout out: <a href='http://vukajlija.com' target='blank'>http://vukajlija.com</a></p>"
|
23
|
+
|
24
|
+
You'll probably have user input stored in model, so it's a good place to automate and even store this conversion for performance reason. This is done with *auto_html_for* method. Let's say you have model Comment with attribute body. Create another column in table Comments called body_html (again, this is optional but recommended for performance reasons). Now have something like this:
|
25
|
+
|
26
|
+
class Comment < ActiveRecord::Base
|
27
|
+
auto_html_for :body do
|
28
|
+
html_escape
|
29
|
+
image
|
30
|
+
youtube(:width => 400, :height => 250, :autoplay => true)
|
31
|
+
link :target => "_blank", :rel => "nofollow"
|
32
|
+
simple_format
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
... and you'll have this behavior:
|
37
|
+
|
38
|
+
Comment.create(:body => 'Hey check out this cool video: http://www.youtube.com/watch?v=WdsGihou8J4')
|
39
|
+
=> #<Comment id: 123, body: '<p>Hey check out this cool video: <div class="video youtube"><iframe class="youtube-player" type="text/html" width="587" height="350" src="http://www.youtube.com/embed/WdsGihou8J4" frameborder="0"> <br /></iframe></div></p>'>
|
40
|
+
|
41
|
+
Note that order of invoking filters is important, i.e. you want html_escape as first and link amongst last, so that it doesn't transform youtube URL to plain link.
|
42
|
+
|
43
|
+
|
44
|
+
Now all you have to do is to display it in template without escaping, since plugin took care of that:
|
45
|
+
|
46
|
+
<% for comment in @comments %>
|
47
|
+
<li><%= comment.body_html %></li>
|
48
|
+
<% end %>
|
49
|
+
|
50
|
+
|
51
|
+
If you need to display preview, no problem. Have something like this as action in your controller:
|
52
|
+
|
53
|
+
def preview
|
54
|
+
comment = Comment.new(params[:comment])
|
55
|
+
render :text => comment.body_html
|
56
|
+
end
|
57
|
+
|
58
|
+
AutoHtml is highly customizable, and you can easily create new filters that will transform user input any way you like. For instance, this is the image filter that comes bundled with plugin:
|
59
|
+
|
60
|
+
AutoHtml.add_filter(:image) do |text|
|
61
|
+
text.gsub(/http:\/\/.+\.(jpg|jpeg|bmp|gif|png)(\?\S+)?/i) do |match|
|
62
|
+
%|<img src="#{match}" alt=""/>|
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
## Bundled filters
|
68
|
+
|
69
|
+
For filter list and options they support check: <http://github.com/dejan/auto_html/tree/master/lib/auto_html/filters>
|
70
|
+
|
71
|
+
|
72
|
+
## Non-ActiveRecord models
|
73
|
+
|
74
|
+
AutoHtml uses standard ActiveModel API, which means that you can include AutoHtmlFor module (that automates transformation of the field) in any non-ActiveRecord model that uses ActiveModel. Here's working [mongoid](http://mongoid.org/) example:
|
75
|
+
|
76
|
+
class Post
|
77
|
+
include Mongoid::Document
|
78
|
+
include AutoHtmlFor
|
79
|
+
|
80
|
+
field :body
|
81
|
+
|
82
|
+
auto_html_for :body do
|
83
|
+
simple_format
|
84
|
+
link
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
|
89
|
+
## Rake and Capistrano tasks
|
90
|
+
|
91
|
+
AutoHtml has a Rake task for rebuilding cached in DB column values
|
92
|
+
Usage: `rake auto_html:rebuild CLASS=[your model]`
|
93
|
+
Where `[your model]` is the name of model which values you want to rebuild.
|
94
|
+
|
95
|
+
If you want to run it on remote server, just add this to your `deploy.rb`:
|
96
|
+
|
97
|
+
require 'auto_html/capistrano'
|
98
|
+
|
99
|
+
Now you can run `cap auto_html:rebuild CLASS=[your_model]`.
|
100
|
+
|
101
|
+
|
102
|
+
## Licence
|
103
|
+
|
104
|
+
Copyright (c) 2009 Dejan Simic
|
105
|
+
|
106
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
107
|
+
a copy of this software and associated documentation files (the
|
108
|
+
"Software"), to deal in the Software without restriction, including
|
109
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
110
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
111
|
+
permit persons to whom the Software is furnished to do so, subject to
|
112
|
+
the following conditions:
|
113
|
+
|
114
|
+
The above copyright notice and this permission notice shall be
|
115
|
+
included in all copies or substantial portions of the Software.
|
116
|
+
|
117
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
118
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
119
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
120
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
121
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
122
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
123
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
data/lib/auto_html.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
%w(base filter builder).each do |f|
|
2
|
+
require File.expand_path("../auto_html/#{f}", __FILE__)
|
3
|
+
end
|
4
|
+
|
5
|
+
Dir["#{File.dirname(__FILE__) + '/auto_html/filters'}/**/*"].each do |filter|
|
6
|
+
require "#{filter}"
|
7
|
+
end
|
8
|
+
|
9
|
+
# if rails
|
10
|
+
require 'auto_html/railtie' if defined?(Rails::Railtie)
|
11
|
+
if defined?(ActiveRecord::Base)
|
12
|
+
ActiveRecord::Base.send :include, AutoHtmlFor
|
13
|
+
|
14
|
+
module ActionView::Helpers::TextHelper
|
15
|
+
include AutoHtml
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'rails'
|
2
|
+
|
3
|
+
require 'active_support/core_ext/module/attribute_accessors' if Rails::VERSION::MAJOR >= 4
|
4
|
+
|
5
|
+
module AutoHtmlFor
|
6
|
+
|
7
|
+
# default options that can be overridden on the global level
|
8
|
+
@@auto_html_for_options = {
|
9
|
+
:htmlized_attribute_suffix => '_html'
|
10
|
+
}
|
11
|
+
mattr_reader :auto_html_for_options
|
12
|
+
|
13
|
+
def self.included(base)
|
14
|
+
base.extend(ClassMethods)
|
15
|
+
end
|
16
|
+
|
17
|
+
module ClassMethods
|
18
|
+
def auto_html_for(raw_attrs, &proc)
|
19
|
+
include AutoHtmlFor::InstanceMethods
|
20
|
+
|
21
|
+
if defined?(ActiveRecord) == "constant"
|
22
|
+
return unless ActiveRecord::Base.connection.table_exists? self.table_name
|
23
|
+
end
|
24
|
+
|
25
|
+
suffix = AutoHtmlFor.auto_html_for_options[:htmlized_attribute_suffix]
|
26
|
+
auto_html_for_columns = [raw_attrs].flatten.map { |a| "#{a}#{suffix}" }
|
27
|
+
|
28
|
+
# Needed for Mongoid
|
29
|
+
column_names = self.respond_to?(:column_names) ? self.column_names : fields.keys
|
30
|
+
|
31
|
+
missing_cache_columns = auto_html_for_columns - column_names
|
32
|
+
missing_cache_columns.each do |missing_cache_column|
|
33
|
+
raw_attr = missing_cache_column.gsub(suffix, '')
|
34
|
+
define_method(missing_cache_column) do
|
35
|
+
val = self[raw_attr] || self.send(raw_attr.to_sym)
|
36
|
+
auto_html(val, &proc)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
cache_columns = auto_html_for_columns - missing_cache_columns
|
41
|
+
cache_columns.each do |cache_column|
|
42
|
+
raw_attr = cache_column.gsub(suffix, '')
|
43
|
+
define_method("#{raw_attr}=") do |val|
|
44
|
+
self[raw_attr] = val
|
45
|
+
result = auto_html(val, &proc)
|
46
|
+
self.send("#{cache_column}=", result)
|
47
|
+
val
|
48
|
+
end
|
49
|
+
|
50
|
+
define_method(cache_column) do
|
51
|
+
result = self[cache_column]
|
52
|
+
result.respond_to?(:html_safe) ? result.html_safe : result
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
module InstanceMethods
|
60
|
+
include AutoHtml
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'active_support/core_ext/object/blank'
|
2
|
+
require 'active_support/core_ext/module/attribute_accessors'
|
3
|
+
|
4
|
+
module AutoHtml
|
5
|
+
extend self
|
6
|
+
|
7
|
+
def self.add_filter(name, &block)
|
8
|
+
AutoHtml::Builder.add_filter(name, &block)
|
9
|
+
end
|
10
|
+
|
11
|
+
def auto_html(raw, options = {}, &proc)
|
12
|
+
return "" if raw.blank?
|
13
|
+
builder = Builder.new(raw, options)
|
14
|
+
result = builder.instance_eval(&proc)
|
15
|
+
return raw if result.nil?
|
16
|
+
result.respond_to?(:html_safe) ?
|
17
|
+
result.html_safe :
|
18
|
+
result
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module AutoHtml
|
2
|
+
class Builder
|
3
|
+
@@filters = {}
|
4
|
+
|
5
|
+
def initialize(text, options = {})
|
6
|
+
@text = text.dup
|
7
|
+
@options = options
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.add_filter(name, &block)
|
11
|
+
filter = Filter.new(block)
|
12
|
+
@@filters.merge!(name => filter)
|
13
|
+
src = %|
|
14
|
+
def #{name}(options = {})
|
15
|
+
@text = @@filters["#{name}".to_sym].apply(@text, options)
|
16
|
+
end
|
17
|
+
|
|
18
|
+
class_eval src, __FILE__, __LINE__
|
19
|
+
filter
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'auto_html/task'
|
2
|
+
|
3
|
+
# Capistrano task for AutoHtml.
|
4
|
+
# Just add:
|
5
|
+
|
6
|
+
# require 'auto_html/capistrano'
|
7
|
+
# in your Capistrano deploy.rb, you will have AutoHtml rake task in Capistrano
|
8
|
+
|
9
|
+
Capistrano::Configuration.instance(:must_exist).load do
|
10
|
+
namespace :auto_html do
|
11
|
+
desc "Rebuild auto_html columns"
|
12
|
+
task :rebuild do
|
13
|
+
klass = AutoHtml::Task.obtain_class
|
14
|
+
run "cd #{current_path} && bundle exec rake auto_html:rebuild CLASS=#{klass} RAILS_ENV=#{rails_env}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module AutoHtml
|
2
|
+
class Filter
|
3
|
+
def initialize(block)
|
4
|
+
@block = block
|
5
|
+
@options = nil
|
6
|
+
end
|
7
|
+
|
8
|
+
def with(options, &block)
|
9
|
+
@options = options
|
10
|
+
@block = block
|
11
|
+
end
|
12
|
+
|
13
|
+
def apply(text, options = {})
|
14
|
+
_options = @options && @options.merge(options)
|
15
|
+
if _options
|
16
|
+
@block.call(text.to_s.dup, _options)
|
17
|
+
else
|
18
|
+
@block.call(text.to_s.dup)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,6 @@
|
|
1
|
+
AutoHtml.add_filter(:dailymotion).with(:width => 480, :height => 360) do |text, options|
|
2
|
+
text.gsub(/(?<!=")https?:\/\/www\.dailymotion\.com.*\/video\/(.+)_*/) do
|
3
|
+
video_id = $1
|
4
|
+
%{<div class="video-container dailymotion"><object type="application/x-shockwave-flash" data="http://www.dailymotion.com/swf/#{video_id}&related=0" width="#{options[:width]}" height="#{options[:height]}"><param name="movie" value="http://www.dailymotion.com/swf/#{video_id}&related=0"></param><param name="allowFullScreen" value="true"></param><param name="allowScriptAccess" value="always"></param><a href="http://www.dailymotion.com/video/#{video_id}?embed=1"><img src="http://www.dailymotion.com/thumbnail/video/#{video_id}" width="#{options[:width]}" height="#{options[:height]}"/></a></object></div>}
|
5
|
+
end
|
6
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
AutoHtml.add_filter(:flickr).with(:maxwidth => nil, :maxheight => nil, :link_options => {}) do |text, options|
|
2
|
+
require 'uri'
|
3
|
+
require 'net/http'
|
4
|
+
require 'rexml/document'
|
5
|
+
|
6
|
+
regex = %r{http://(www\.)?flickr\.com/photos/[^\s<]*}
|
7
|
+
|
8
|
+
text.gsub(regex) do |match|
|
9
|
+
params = { :url => match, :format => "json" }
|
10
|
+
[:maxwidth, :maxheight].each { |p| params[p] = options[p] unless options[p].nil? or not options[p] > 0 }
|
11
|
+
|
12
|
+
uri = URI("http://www.flickr.com/services/oembed")
|
13
|
+
uri.query = URI.encode_www_form(params)
|
14
|
+
|
15
|
+
response = JSON.parse(Net::HTTP.get(uri))
|
16
|
+
|
17
|
+
link_options = Array(options[:link_options]).reject { |k,v| v.nil? }.map { |k, v| %{#{k}="#{REXML::Text::normalize(v)}"} }.join(' ')
|
18
|
+
%{<a href="#{match}"#{ ' ' + link_options unless link_options.empty? }><img src="#{response["url"]}" alt="#{response["title"]}" title="#{response["title"]}" /></a>}
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
AutoHtml.add_filter(:gist).with({}) do |text, options|
|
2
|
+
# E.g. https://gist.github.com/1710276
|
3
|
+
regex = %r{https?://gist\.github\.com/(\w+/)?(\d+)}
|
4
|
+
text.gsub(regex) do
|
5
|
+
gist_id = $2
|
6
|
+
%{<script type="text/javascript" src="https://gist.github.com/#{gist_id}.js"></script>}
|
7
|
+
end
|
8
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
AutoHtml.add_filter(:google_map).with(:width => 420, :height => 315, :style => "color:#000;text-align:left", :link_text => "View Larger Map", :show_info => true, :type => :normal, :zoom => 18, :more => '') do |text, options|
|
3
|
+
map_type = { :normal => '&t=m', :satellite => '&t=k', :terrain => '&t=p', :hibrid => '&t=h' }
|
4
|
+
regex = /(https?):\/\/maps\.google\.([a-z\.]+)\/maps\?(.*)/
|
5
|
+
text.gsub(regex) do
|
6
|
+
domain_country = $2
|
7
|
+
map_query = $3
|
8
|
+
width = options[:width]
|
9
|
+
height = options[:height]
|
10
|
+
style = options[:style]
|
11
|
+
link_text = options[:link_text]
|
12
|
+
type = options[:type].to_sym
|
13
|
+
map_options = (options[:show_info] ? '' : '&iwloc=near')
|
14
|
+
map_options << map_type[type] if map_type.has_key?(type)
|
15
|
+
map_options << "&z=#{options[:zoom]}"
|
16
|
+
map_options << options[:more]
|
17
|
+
%{<iframe width="#{width}" height="#{height}" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="//maps.google.#{domain_country}/maps?f=q&source=s_q&#{map_query}&output=embed#{map_options}"></iframe><br /><small><a href="//maps.google.#{domain_country}/maps?f=q&source=embed&#{map_query}" style="#{style}">#{link_text}</a></small>}
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
AutoHtml.add_filter(:hashtag).with(:source => :twitter) do |text, options|
|
2
|
+
if options[:source] == :twitter
|
3
|
+
text.gsub(/#([^\s]+)/, '<a href="http://twitter.com/search?q=%23\1&f=realtime" class="hashtag" target="_blank">#\1</a>')
|
4
|
+
elsif options[:source] == :facebook
|
5
|
+
text.gsub(/#([^\s]+)/, '<a href="https://www.facebook.com/hashtag/\1" class="hashtag" target="_blank">#\1</a>')
|
6
|
+
end
|
7
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'redcarpet'
|
2
|
+
|
3
|
+
class NoParagraphRenderer < ::Redcarpet::Render::XHTML
|
4
|
+
def paragraph(text)
|
5
|
+
text
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
AutoHtml.add_filter(:image).with({:alt => ''}) do |text, options|
|
10
|
+
r = Redcarpet::Markdown.new(NoParagraphRenderer)
|
11
|
+
alt = options[:alt]
|
12
|
+
options[:proxy] ||= ""
|
13
|
+
text.gsub(/(?<=^|\s)https?:\/\/.+?\.(jpg|jpeg|bmp|gif|png)(\?\S+)?/i) do |match|
|
14
|
+
r.render("![#{alt}](#{options[:proxy]}#{match})")
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'net/http'
|
3
|
+
|
4
|
+
AutoHtml.add_filter(:instagram) do |text|
|
5
|
+
regex = %r{https?:\/\/(www.)?instagr(am\.com|\.am)/p/.+}
|
6
|
+
text.gsub(regex) do |match|
|
7
|
+
match << '/' unless match.end_with?('/')
|
8
|
+
%{<iframe src="#{match}embed" height="714" width="616" frameborder="0" scrolling="no"></iframe>}
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
AutoHtml.add_filter(:link).with({}) do |text, options|
|
2
|
+
require 'uri'
|
3
|
+
require 'rinku'
|
4
|
+
require 'rexml/document'
|
5
|
+
option_short_link_name = options.delete(:short_link_name)
|
6
|
+
attributes = Array(options).reject { |k,v| v.nil? }.map { |k, v| %{#{k}="#{REXML::Text::normalize(v)}"} }.join(' ')
|
7
|
+
Rinku.auto_link(text, :all, attributes) do |url|
|
8
|
+
if option_short_link_name
|
9
|
+
uri = URI.parse(URI.encode(url.strip))
|
10
|
+
uri.query = nil
|
11
|
+
uri.to_s
|
12
|
+
else
|
13
|
+
url
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
AutoHtml.add_filter(:liveleak).with(:width => 420, :height => 315, :frameborder => 0, :wmode => nil, :autoplay => false, :hide_related => false) do |text, options|
|
2
|
+
regex = %r{http://www\.liveleak\.com/(?:ll_embed|view)\?.=(\w+)}
|
3
|
+
text.gsub(regex) do
|
4
|
+
liveleak_id = $1
|
5
|
+
width = options[:width]
|
6
|
+
height = options[:height]
|
7
|
+
frameborder = options[:frameborder]
|
8
|
+
wmode = options[:wmode]
|
9
|
+
autoplay = options[:autoplay]
|
10
|
+
hide_related = options[:hide_related]
|
11
|
+
src = "http://www.liveleak.com/ll_embed?f=#{liveleak_id}"
|
12
|
+
params = []
|
13
|
+
params << "wmode=#{wmode}" if wmode
|
14
|
+
params << "autoplay=1" if autoplay
|
15
|
+
params << "rel=0" if hide_related
|
16
|
+
src += "?#{params.join '&'}" unless params.empty?
|
17
|
+
%{<div class="video-container liveleak"><iframe width="#{width}" height="#{height}" src="#{src}" frameborder="#{frameborder}" allowfullscreen></iframe></div>}
|
18
|
+
end
|
19
|
+
end
|