+
diff --git a/lib/file_presenter.rb b/lib/file_presenter.rb
new file mode 100644
index 0000000..1554a8f
--- /dev/null
+++ b/lib/file_presenter.rb
@@ -0,0 +1,90 @@
+# All file presenters must extends `FilePresenter` not only to ensure the
+# same interface, but also to make `FilePresenter.for(file)` to work.
+class FilePresenter
+
+ # Will return a encapsulated `UploadedFile` or the same object if no
+ # one accepts it. That behave allow to give any model to this class,
+ # like a Article and have no trouble with that.
+ def self.for(f)
+ return f if f.is_a? FilePresenter
+ klass = FilePresenter.subclasses.sort_by {|class_name|
+ class_name.constantize.accepts?(f) || 0
+ }.last.constantize
+ klass.accepts?(f) ? klass.new(f) : f
+ end
+
+ def initialize(f)
+ @file = f
+ end
+
+ # Allows to use the original `UploadedFile` reference.
+ def encapsulated_file
+ @file
+ end
+
+ # This method must be overridden in subclasses.
+ #
+ # If the class accepts the file, return a number that represents the
+ # priority the class should be given to handle that file. Higher numbers
+ # mean higher priority.
+ #
+ # If the class does not accept the file, return false.
+ def self.accepts?(f)
+ nil
+ end
+
+ # Define the css classes to style the page fragment with the file related
+ # content. If you want other classes to identify this area to your
+ # customized presenter, so do this:
+ # def css_class_list
+ # [super, 'myclass'].flatten
+ # end
+ def css_class_list
+ [ @file.css_class_list,
+ 'file-' + self.class.to_s.split(/:+/).map(&:underscore)[1..-1].join('-'),
+ 'content-type_' + self.content_type.split('/')[0],
+ 'content-type_' + self.content_type.gsub(/[^a-z0-9]/i,'-')
+ ].flatten
+ end
+
+ # Enable file presenter to customize the css classes on view_page.rhtml
+ # You may not overwrite this method on your customized presenter.
+ def css_class_name
+ [css_class_list].flatten.compact.join(' ')
+ end
+
+ # The generic icon class-name or the specific file path.
+ # You may replace this method on your custom FilePresenter.
+ # See the current used icons class-names in public/designs/icons/tango/style.css
+ def icon_name
+ if mime_type
+ [ mime_type.split('/')[0], mime_type.gsub(/[^a-z0-9]/i, '-') ]
+ else
+ 'upload-file'
+ end
+ end
+
+ # Automatic render `file_presenter/.html.erb` to display your
+ # custom presenter html content.
+ # You may not overwrite this method on your customized presenter.
+ # A variable with the same presenter name will be created to refer
+ # to the file object.
+ # Example:
+ # The `FilePresenter::Image` render `file_presenter/image.html.erb`
+ # inside the `file_presenter/image.html.erb` you can access the
+ # required `FilePresenter::Image` instance in the `image` variable.
+ def to_html(options = {})
+ file = self
+ lambda do
+ render :partial => file.class.to_s.underscore,
+ :locals => { :options => options },
+ :object => file
+ end
+ end
+
+ # That makes the presenter to works like any other `UploadedFile` instance.
+ def method_missing(m, *args)
+ @file.send(m, *args)
+ end
+
+end
diff --git a/lib/file_presenter/generic.rb b/lib/file_presenter/generic.rb
new file mode 100644
index 0000000..5a81690
--- /dev/null
+++ b/lib/file_presenter/generic.rb
@@ -0,0 +1,11 @@
+# Made to encapsulate any UploadedFile
+class FilePresenter::Generic < FilePresenter
+ def initialize(f)
+ @file = f
+ end
+
+ # if returns low priority, because it is generic.
+ def self.accepts?(f)
+ 1 if f.is_a? UploadedFile
+ end
+end
diff --git a/lib/file_presenter/image.rb b/lib/file_presenter/image.rb
new file mode 100644
index 0000000..1192715
--- /dev/null
+++ b/lib/file_presenter/image.rb
@@ -0,0 +1,13 @@
+class FilePresenter::Image < FilePresenter
+ def initialize(f)
+ @file = f
+ end
+
+ def self.accepts?(f)
+ f.image? ? 10 : nil
+ end
+
+ def icon_name
+ article.public_filename :icon
+ end
+end
diff --git a/plugins/html5_video/lib/file_presenter/video.rb b/plugins/html5_video/lib/file_presenter/video.rb
new file mode 100644
index 0000000..53ad7d8
--- /dev/null
+++ b/plugins/html5_video/lib/file_presenter/video.rb
@@ -0,0 +1,10 @@
+class FilePresenter::Video < FilePresenter
+ def initialize(f)
+ @file = f
+ end
+
+ def self.accepts?(f)
+ return nil if f.content_type.nil?
+ ( f.content_type[0..4] == 'video' ) ? 10 : nil
+ end
+end
diff --git a/plugins/html5_video/lib/html5_video_plugin.rb b/plugins/html5_video/lib/html5_video_plugin.rb
new file mode 100644
index 0000000..953e511
--- /dev/null
+++ b/plugins/html5_video/lib/html5_video_plugin.rb
@@ -0,0 +1,13 @@
+class Html5VideoPlugin < Noosfero::Plugin
+
+ FilePresenter::Video
+
+ def self.plugin_name
+ "HTML5 Video"
+ end
+
+ def self.plugin_description
+ _("A plugin to enable the video suport, with auto conversion for the web.")
+ end
+
+end
diff --git a/plugins/html5_video/views/file_presenter/_video.html.erb b/plugins/html5_video/views/file_presenter/_video.html.erb
new file mode 100644
index 0000000..abf9b0c
--- /dev/null
+++ b/plugins/html5_video/views/file_presenter/_video.html.erb
@@ -0,0 +1,8 @@
+
+
+