auto_html 1.6.4 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +47 -98
  3. data/Rakefile +6 -7
  4. data/lib/auto_html.rb +9 -15
  5. data/lib/auto_html/emoji.rb +57 -0
  6. data/lib/auto_html/html_escape.rb +10 -0
  7. data/lib/auto_html/image.rb +23 -0
  8. data/lib/auto_html/link.rb +31 -0
  9. data/lib/auto_html/markdown.rb +15 -0
  10. data/lib/auto_html/pipeline.rb +15 -0
  11. data/lib/auto_html/simple_format.rb +22 -0
  12. data/spec/emoji_spec.rb +9 -0
  13. data/spec/html_escape_spec.rb +8 -0
  14. data/spec/image_spec.rb +39 -0
  15. data/spec/link_spec.rb +39 -0
  16. data/spec/markdown_spec.rb +7 -0
  17. data/spec/pipeline_spec.rb +24 -0
  18. data/spec/simple_format_spec.rb +16 -0
  19. data/spec/spec_helper.rb +11 -0
  20. metadata +121 -88
  21. data/lib/auto_html/auto_html_for.rb +0 -64
  22. data/lib/auto_html/base.rb +0 -18
  23. data/lib/auto_html/builder.rb +0 -21
  24. data/lib/auto_html/capistrano.rb +0 -17
  25. data/lib/auto_html/filter.rb +0 -22
  26. data/lib/auto_html/filters/dailymotion.rb +0 -6
  27. data/lib/auto_html/filters/flickr.rb +0 -20
  28. data/lib/auto_html/filters/gist.rb +0 -8
  29. data/lib/auto_html/filters/google_map.rb +0 -19
  30. data/lib/auto_html/filters/google_video.rb +0 -6
  31. data/lib/auto_html/filters/hashtag.rb +0 -7
  32. data/lib/auto_html/filters/html_escape.rb +0 -9
  33. data/lib/auto_html/filters/image.rb +0 -16
  34. data/lib/auto_html/filters/instagram.rb +0 -10
  35. data/lib/auto_html/filters/link.rb +0 -16
  36. data/lib/auto_html/filters/liveleak.rb +0 -19
  37. data/lib/auto_html/filters/metacafe.rb +0 -13
  38. data/lib/auto_html/filters/redcarpet.rb +0 -4
  39. data/lib/auto_html/filters/sanitize.rb +0 -5
  40. data/lib/auto_html/filters/simple_format.rb +0 -12
  41. data/lib/auto_html/filters/soundcloud.rb +0 -21
  42. data/lib/auto_html/filters/ted.rb +0 -13
  43. data/lib/auto_html/filters/twitter.rb +0 -19
  44. data/lib/auto_html/filters/vimeo.rb +0 -15
  45. data/lib/auto_html/filters/worldstar.rb +0 -8
  46. data/lib/auto_html/filters/youtube.rb +0 -19
  47. data/lib/auto_html/filters/youtube_image.rb +0 -17
  48. data/lib/auto_html/filters/youtube_js_api.rb +0 -6
  49. data/lib/auto_html/railtie.rb +0 -10
  50. data/lib/auto_html/rake_tasks.rb +0 -27
  51. data/lib/auto_html/task.rb +0 -9
  52. data/test/fixture_setup.rb +0 -13
  53. data/test/fixtures/database.yml +0 -5
  54. data/test/fixtures/schema.rb +0 -20
  55. data/test/functional/auto_html_for_options_test.rb +0 -26
  56. data/test/functional/auto_html_for_test.rb +0 -56
  57. data/test/functional/filter_test.rb +0 -27
  58. data/test/test_helper.rb +0 -9
  59. data/test/unit/auto_html_test.rb +0 -37
  60. data/test/unit/filters/dailymotion_test.rb +0 -20
  61. data/test/unit/filters/gist_test.rb +0 -15
  62. data/test/unit/filters/google_map_test.rb +0 -24
  63. data/test/unit/filters/hashtag_test.rb +0 -25
  64. data/test/unit/filters/html_escape_test.rb +0 -15
  65. data/test/unit/filters/image_test.rb +0 -65
  66. data/test/unit/filters/instagram_test.rb +0 -8
  67. data/test/unit/filters/link_test.rb +0 -55
  68. data/test/unit/filters/liveleak_test.rb +0 -15
  69. data/test/unit/filters/metacafe_test.rb +0 -29
  70. data/test/unit/filters/redcarpet_test.rb +0 -38
  71. data/test/unit/filters/sanitize_test.rb +0 -36
  72. data/test/unit/filters/simple_format_test.rb +0 -15
  73. data/test/unit/filters/soundcloud_test.rb +0 -29
  74. data/test/unit/filters/ted_test.rb +0 -18
  75. data/test/unit/filters/twitter_test.rb +0 -45
  76. data/test/unit/filters/vimeo_test.rb +0 -50
  77. data/test/unit/filters/worldstar_test.rb +0 -14
  78. data/test/unit/filters/youtube_image_test.rb +0 -59
  79. data/test/unit/filters/youtube_js_api_test.rb +0 -30
  80. data/test/unit/filters/youtube_test.rb +0 -59
  81. data/test/unit/unit_test_helper.rb +0 -3
@@ -1,21 +0,0 @@
1
- module AutoHtml
2
- class Builder
3
- @@filters = {}
4
-
5
- def initialize(text)
6
- @text = text.dup
7
- end
8
-
9
- def self.add_filter(name, &block)
10
- filter = Filter.new(block)
11
- @@filters.merge!(name => filter)
12
- src = %|
13
- def #{name}(options = {})
14
- @text = @@filters["#{name}".to_sym].apply(@text, options)
15
- end
16
- |
17
- class_eval src, __FILE__, __LINE__
18
- filter
19
- end
20
- end
21
- end
@@ -1,17 +0,0 @@
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
@@ -1,22 +0,0 @@
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
@@ -1,6 +0,0 @@
1
- AutoHtml.add_filter(:dailymotion).with(:width => 480, :height => 360) do |text, options|
2
- text.gsub(/http:\/\/www\.dailymotion\.com.*\/video\/(.+)_*/) do
3
- video_id = $1
4
- %{<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>}
5
- end
6
- end
@@ -1,20 +0,0 @@
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
@@ -1,8 +0,0 @@
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
@@ -1,19 +0,0 @@
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 => '&amp;t=m', :satellite => '&amp;t=k', :terrain => '&amp;t=p', :hibrid => '&amp;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] ? '' : '&amp;iwloc=near')
14
- map_options << map_type[type] if map_type.has_key?(type)
15
- map_options << "&amp;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&amp;source=s_q&amp;#{map_query}&amp;output=embed#{map_options}"></iframe><br /><small><a href="//maps.google.#{domain_country}/maps?f=q&amp;source=embed&amp;#{map_query}" style="#{style}">#{link_text}</a></small>}
18
- end
19
- end
@@ -1,6 +0,0 @@
1
- # GoogleVideo is discontinued so don't do anything
2
- # TODO Remove this filter in auto_html v2.0
3
- AutoHtml.add_filter(:google_video) do |text, options|
4
- text
5
- end
6
-
@@ -1,7 +0,0 @@
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
@@ -1,9 +0,0 @@
1
- AutoHtml.add_filter(:html_escape).with(
2
- :map => {
3
- '&' => '&amp;',
4
- '>' => '&gt;',
5
- '<' => '&lt;',
6
- '"' => '&quot;' }) do |text, options|
7
-
8
- text.to_s.gsub(/[&"><]/) { |special| options[:map][special] }
9
- end
@@ -1,16 +0,0 @@
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(/(?<!src=")https?:\/\/.+?\.(jpg|jpeg|bmp|gif|png)(\?\S+)?/i) do |match|
14
- r.render("![#{alt}](#{options[:proxy]}#{match})")
15
- end
16
- end
@@ -1,10 +0,0 @@
1
- require 'uri'
2
- require 'net/http'
3
-
4
- AutoHtml.add_filter(:instagram) do |text|
5
- text << '/' unless text.end_with?('/')
6
- regex = %r{https?:\/\/(www.)?instagr(am\.com|\.am)/p/.+}
7
- text.gsub(regex) do
8
- %{<iframe src="#{text}embed" height="714" width="616" frameborder="0" scrolling="no"></iframe>}
9
- end
10
- end
@@ -1,16 +0,0 @@
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
@@ -1,19 +0,0 @@
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
- %{<iframe width="#{width}" height="#{height}" src="#{src}" frameborder="#{frameborder}" allowfullscreen></iframe>}
18
- end
19
- end
@@ -1,13 +0,0 @@
1
- AutoHtml.add_filter(:metacafe).with(:width => 440, :height => 272, :show_stats => false, :autoplay => false) do |text, options|
2
- text.gsub(/http:\/\/www\.metacafe\.com\/watch\/([A-Za-z0-9._%-]*)\/([A-Za-z0-9._%-]*)(\/)?/) do
3
- metacafe_id = $1
4
- metacafe_slug = $2
5
- width = options[:width]
6
- height = options[:height]
7
- show_stats = options[:show_stats] ? "showStats=yes" : "showStats=no"
8
- autoplay = options[:autoplay] ? "autoPlay=yes" : "autoPlay=no"
9
- flash_vars = [show_stats, autoplay].join("|")
10
-
11
- %{<div style="background:#000000;width:#{width}px;height:#{height}px"><embed flashVars="playerVars=#{flash_vars}" src="http://www.metacafe.com/fplayer/#{metacafe_id}/#{metacafe_slug}.swf" width="#{width}" height="#{height}" wmode="transparent" allowFullScreen="true" allowScriptAccess="always" name="Metacafe_#{metacafe_id}" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed></div>}
12
- end
13
- end
@@ -1,4 +0,0 @@
1
- require 'redcarpet'
2
- AutoHtml.add_filter(:redcarpet).with(:renderer => Redcarpet::Render::HTML, :markdown_options => {}) do |text, options|
3
- Redcarpet::Markdown.new(options[:renderer], options[:markdown_options]).render(text)
4
- end
@@ -1,5 +0,0 @@
1
- AutoHtml.add_filter(:sanitize).with({}) do |text, options|
2
- require 'action_controller'
3
- require 'cgi'
4
- HTML::WhiteListSanitizer.new.sanitize(text, options)
5
- end
@@ -1,12 +0,0 @@
1
- AutoHtml.add_filter(:simple_format).with({}) do |text, html_options|
2
- require 'action_view'
3
-
4
- args = [text, {}, {:sanitize => false}]
5
- begin
6
- ActionView::Base.new.simple_format(*args)
7
- rescue ArgumentError
8
- # Rails 2 support
9
- args.pop
10
- retry
11
- end
12
- end
@@ -1,21 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- # set these options and default values
4
- # :width => '100%', :height => 166, :auto_play => false, :theme_color => '00FF00', :color => '915f33', :show_comments => false
5
- AutoHtml.add_filter(:soundcloud).with(:width => '100%', :height => 166, :auto_play => false, :theme_color => '00FF00', :color => '915f33', :show_comments => false, :show_artwork => false) do |text, options|
6
- require 'uri'
7
- require 'net/http'
8
- text.gsub(/(https?:\/\/)?(www.)?soundcloud\.com\/\S*/) do |match|
9
- new_uri = match.to_s
10
- new_uri = (new_uri =~ /^https?\:\/\/.*/) ? URI(new_uri) : URI("http://#{new_uri}")
11
- new_uri.normalize!
12
- width = options[:width]
13
- height = options[:height]
14
- auto_play = options[:auto_play]
15
- theme_color = options[:theme_color]
16
- color = options[:color]
17
- show_artwork = options[:show_artwork]
18
- show_comments = options[:show_comments]
19
- %{<iframe width="#{width}" height="#{height}" scrolling="no" frameborder="no" src="http://w.soundcloud.com/player/?url=#{new_uri}&show_artwork=#{show_artwork}&show_comments=#{show_comments}&auto_play=#{auto_play}&color=#{color}&theme_color=#{theme_color}"></iframe>}
20
- end
21
- end
@@ -1,13 +0,0 @@
1
- # TED talks (http://www.ted.com)
2
- AutoHtml.add_filter(:ted).with(:width => 640, :height => 360, :scrolling => "no", :frameborder => 0, :allow_full_screen => false) do |text, options|
3
- text.gsub(/https?:\/\/(www.|embed.)?ted\.com\/talks\/([A-Za-z0-9._%-]*)\.html((\?|#)\S+)?/) do
4
- ted_page = $2
5
- width = options[:width]
6
- height = options[:height]
7
- scrolling = options[:scrolling]
8
- frameborder = options[:frameborder]
9
- allow_full_screen = options[:allow_full_screen]
10
-
11
- %{<iframe width="#{width}" height="#{height}" frameborder="#{frameborder}" scrolling="#{scrolling}" src="http://embed.ted.com/talks/#{ted_page}.html"#{allow_full_screen ? ' webkitAllowFullScreen mozallowfullscreen allowFullScreen' : ''}></iframe>}
12
- end
13
- end
@@ -1,19 +0,0 @@
1
- AutoHtml.add_filter(:twitter).with({}) do |text, options|
2
- require 'uri'
3
- require 'net/http'
4
-
5
- regex = %r{(?<!href=")https://twitter\.com(/#!)?/[A-Za-z0-9_]{1,15}/status(es)?/\d+(/?)}
6
-
7
- text.gsub(regex) do |match|
8
- params = { :url => match }.merge(options)
9
-
10
- uri = URI("https://api.twitter.com/1/statuses/oembed.json")
11
- uri.query = URI.encode_www_form(params)
12
-
13
- http = Net::HTTP.new(uri.host, uri.port)
14
- http.use_ssl = true
15
-
16
- response = JSON.parse(http.get(uri.request_uri).body)
17
- response["html"]
18
- end
19
- end
@@ -1,15 +0,0 @@
1
- AutoHtml.add_filter(:vimeo).with(:width => 440, :height => 248, :show_title => false, :show_byline => false, :show_portrait => false) do |text, options|
2
- text.gsub(/https?:\/\/(www.)?vimeo\.com\/([A-Za-z0-9._%-]*)((\?|#)\S+)?/) do
3
- vimeo_id = $2
4
- width = options[:width]
5
- height = options[:height]
6
- show_title = "title=0" unless options[:show_title]
7
- show_byline = "byline=0" unless options[:show_byline]
8
- show_portrait = "portrait=0" unless options[:show_portrait]
9
- frameborder = options[:frameborder] || 0
10
- query_string_variables = [show_title, show_byline, show_portrait].compact.join("&")
11
- query_string = "?" + query_string_variables unless query_string_variables.empty?
12
-
13
- %{<iframe src="//player.vimeo.com/video/#{vimeo_id}#{query_string}" width="#{width}" height="#{height}" frameborder="#{frameborder}"></iframe>}
14
- end
15
- end
@@ -1,8 +0,0 @@
1
- AutoHtml.add_filter(:worldstar).with(:width => 448, :height => 374) do |text,options|
2
- text.gsub(/http:\/\/www\.worldstarhiphop\.com\/videos\/video\.php\?v\=(wshh[A-Za-z0-9]+)/) do
3
- video_id = $1
4
- width = options[:width]
5
- height = options[:height]
6
- %{<object width="#{width}" height="#{height}"><param name="movie" value="http://www.worldstarhiphop.com/videos/e/16711680/#{video_id}"><param name="allowFullScreen" value="true"></param><embed src="http://www.worldstarhiphop.com/videos/e/16711680/#{video_id}" type="application/x-shockwave-flash" allowFullscreen="true" width="#{width}" height="#{height}"></embed></object>}
7
- end
8
- end
@@ -1,19 +0,0 @@
1
- AutoHtml.add_filter(:youtube).with(:width => 420, :height => 315, :frameborder => 0, :wmode => nil, :autoplay => false, :hide_related => false) do |text, options|
2
- regex = /(https?:\/\/)?(www.)?(youtube\.com\/watch\?v=|youtu\.be\/|youtube\.com\/watch\?feature=player_embedded&v=)([A-Za-z0-9_-]*)(\&\S+)?(\?\S+)?/
3
- text.gsub(regex) do
4
- youtube_id = $4
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 = "//www.youtube.com/embed/#{youtube_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 youtube"><iframe width="#{width}" height="#{height}" src="#{src}" frameborder="#{frameborder}" allowfullscreen></iframe></div>}
18
- end
19
- end
@@ -1,17 +0,0 @@
1
- AutoHtml.add_filter(:youtube_image).with(:width => 320, :height => 315, :style => 'medium', :target => 'blank', :border => '0') do |text, options|
2
- styles = { 'default' => 'default', 'high' => 'hqdefault',
3
- 'medium' => 'mqdefault', 'normal' => 'sddefault',
4
- 'max' => 'maxresdefault' }
5
- regex = /(https?:\/\/)?(www.)?(youtube\.com\/watch\?v=|youtu\.be\/|youtube\.com\/watch\?feature=player_embedded&v=)([A-Za-z0-9_-]*)(\&\S+)?(\?\S+)?/
6
- text.gsub(regex) do
7
- youtube_id = $4
8
- video_url = "https://www.youtube.com/watch?v=#{youtube_id}"
9
- target = options[:target]
10
- width = options[:width]
11
- height = options[:height]
12
- border = options[:border]
13
- style = styles[options[:style]] rescue styles['default']
14
- src = "//img.youtube.com/vi/#{youtube_id}/#{style}.jpg"
15
- %{<div class="thumbnail youtube"><a href="#{video_url}" target="_#{target}"><img src="#{src}" width="#{width}" height="#{height}" border="#{border}"></a></div>}
16
- end
17
- end
@@ -1,6 +0,0 @@
1
- AutoHtml.add_filter(:youtube_js_api).with(:width => 390, :height => 250) do |text, options|
2
- text.gsub(/https?:\/\/(www.)?youtube\.com\/watch\?v=([A-Za-z0-9._%-]*)(\&\S+)?/) do
3
- youtube_id = $2
4
- %{<object width="#{options[:width]}" height="#{options[:height]}"><param name="movie" value="//www.youtube.com/v/#{youtube_id}?enablejsapi=1&playerapiid=ytplayer"></param><param name="wmode" value="transparent"></param><param name="allowscriptaccess" value="always"></param><embed src="//www.youtube.com/v/#{youtube_id}?enablejsapi=1&playerapiid=ytplayer" type="application/x-shockwave-flash" wmode="transparent" width="#{options[:width]}" height="#{options[:height]}" allowscriptaccess="always"></embed></object>}
5
- end
6
- end
@@ -1,10 +0,0 @@
1
- require 'auto_html'
2
- require 'rails'
3
-
4
- module AutoHtml
5
- class Railtie < Rails::Railtie
6
- rake_tasks do
7
- require "auto_html/rake_tasks"
8
- end
9
- end
10
- end
@@ -1,27 +0,0 @@
1
- require 'auto_html/task'
2
-
3
- # Rake task for rebuilding cached in DB auto_html columns values
4
- # Usage: rake auto_html:rebuild CLASS=[your model]
5
- # Where [your model] is the name of model which contains auto_html_for columns
6
-
7
- namespace :auto_html do
8
- desc "Rebuild auto_html columns"
9
- task :rebuild => :environment do
10
-
11
- klass = AutoHtml::Task.obtain_class.constantize
12
- suffix = AutoHtmlFor.auto_html_for_options[:htmlized_attribute_suffix]
13
- column_names = klass.respond_to?(:column_names) ? klass.column_names : klass.fields.keys
14
- observed_attributes = column_names.select { |c| c=~/#{suffix}$/ }.map { |c| c.gsub(/#{suffix}$/, '')}
15
-
16
- i = 0
17
- klass.find_each do |item|
18
- observed_attributes.each do |field|
19
- item.send("#{field}=", item.send(field))
20
- end
21
- item.save
22
- i += 1
23
- end
24
-
25
- puts "Done! Processed #{i} items."
26
- end
27
- end
@@ -1,9 +0,0 @@
1
- module AutoHtml
2
- module Task
3
- def self.obtain_class
4
- class_name = ENV['CLASS'] || ENV['class']
5
- raise "Must specify CLASS" unless class_name
6
- class_name
7
- end
8
- end
9
- end