Sha256: 43202505a3f6c5efc7df5f66cbc4ae032fdf6f37833b08ed575ab35fee913ab0

Contents?: true

Size: 1.08 KB

Versions: 2

Compression:

Stored size: 1.08 KB

Contents

module MulberryPreview
  LANGUAGES = [:ruby, :python, :java, :js, :scss, :sass, :haml, :html, :json, :go, :sql, :yaml, :c, :coffee, :properties, :clojure]

  module ActionViewExtension
    def preview(r)
      type = r.content_type[/^[^\/]+/].to_sym
      ext = r.content_type[/(?<=\/)(x-)?(.+)/, 2].to_sym
      case type
      when :text
        if LANGUAGES.include?(ext)
          raw CodeRay.scan(r.content, ext).div(:line_numbers => :table, :css => :class)
        else
          raw %{<div class="code">#{r.content}</div>}
        end
      when :audio
        raw %{<audio src="#{preview_path(r.class, r.id)}" />}
      when :video
        raw %{<video src="#{preview_path(r.class, r.id)}" />}
      when :image
        raw %{<img src="#{preview_path(r.class, r.id)}" class="img-thumbnail" />}
      when :application
        if :pdf == ext
          raw %{<iframe src="#{preview_path(r.class, r.id)}" width='860' height='800' border='0' style='border:none'></iframe>}
        else
          "#{r.content_type} => #{r}"
        end
      else
        "Binary File [#{r}]" 
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mulberry_preview-0.0.10 lib/mulberry_preview/helper/action_view_extension.rb
mulberry_preview-0.0.9 lib/mulberry_preview/helper/action_view_extension.rb