require 'action_view' require 'yaml' module Fliqz # :nodoc: module UploaderHelper # :nodoc: class ConfigFileNotFoundError < StandardError; end class FliqzConfigInfoNotDefinedError < StandardError; end include ActionView::Helpers::TagHelper def self.included(base) #:nodoc: begin @@fliqz_config_path = RAILS_ROOT + '/config/fliqz_account.yml' @@fliqz_config = YAML.load_file(@@fliqz_config_path)[RAILS_ENV].symbolize_keys rescue raise ConfigFileNotFoundError.new('File %s not found' % @@fliqz_config_path) end begin @@fliqz_account_id = @@fliqz_config[:account_id] @@fliqz_account_id.empty? rescue raise FliqzConfigInfoNotDefinedError.new('Fliqz Account ID not defined') end end # Returns a embed tag that display a Fliqz Flash Uploader within an # HTML page. # # Please make sure you already have the right account information # defined in fliqz_account.yml file. # # ==== Flash Options # * bgcolor # - the background color of the Flash player; default '#869ca7' # * width # - the width of the Flash player; default '450' # * height # - the height of the Flash player; default '345' # * name # - the name of the Flash player; default 'baseuploader' # * align # - the align of the Flash player; default 'middle' # * play # - the play option of the Flash player; default 'true' # * loop # - the loop option of the Flash player; default 'false' # * quality # - the quality option of the Flash player; default 'high' # * wmode # - the wmode option of the Flash player; default 'transparent' # * allowscriptaccess # - the allowscriptaccess option of the Flash player; default 'always' # * src # - the src option of the Flash player; # default 'http://upload.fliqz.com/base/swf/baseuploader.swf' # # ==== Fliqz Options # Please reference page source of http://upload.fliqz.com/base/ # for more detail on these options. # * errorPage # - A URL responses to unsuccessful upload; default nil # * successPage # - A URL responses to successful upload; default 'http://upload.fliqz.com/base/htm/SuccessPage.htm' # * returnEmbedAndPerma # - A Boolean parameter which determines the content of screen # displayed by the uploader after a successful upload; default nil # * hideControlButtons # - A Boolean parameter which engages a buttonless mode of operation. # * illegalFileTypes # - This parameter restricts the list of file types uploadable by the # uploader; default nil # * fontFamily # - This overides the name of the default font family used by the text # elements; default nil # * fontColor # - This overides the color of the font used by the text elements; # default nil # # ==== Examples # * fliqz_uploader_tag # - Create an embedded Fliqz Flash Uploader with all the default # options # * fliqz_uploader_tag {:bgcolor => '#fff'} # - Create an embedded Fliqz Flash Uploader with white background # color # * fliqz_uploader_tag {:bgcolor => '#fff'}, {:fontColor => '#000'} # - Create an embedded Fliqz Flash Uploader with white background # color and black font color # def fliqz_uploader_tag flash_options={}, fliqz_options = {} flash_config, fliqz_config = get_default_fliqz_uploader_config flash_options.symbolize_keys! flash_config.update(flash_options) fliqz_options.symbolize_keys! fliqz_config.update(fliqz_options) fliqz_config[:accountId] = @@fliqz_account_id flash_config[:flashVars] = fliqz_config.to_query return tag(:embed, flash_config, false, false) end def get_default_fliqz_uploader_config flash_config = { :bgcolor => '#869ca7', :width => '450', :height => '345', :name => 'baseuploader', :align => 'middle', :play => 'true', :loop => 'false', :quality => 'high', :wmode => 'transparent', :allowscriptaccess => 'always', :src => 'http://upload.fliqz.com/base/swf/baseuploader.swf', :type => 'application/x-shockwave-flash', :pluginspage => 'http://www.adobe.com/go/getflashplayer' } fliqz_config = { :errorPage => nil, :successPage => 'http://upload.fliqz.com/base/htm/SuccessPage.htm', :returnEmbedAndPerma => nil, :hideControlButtons => nil, :illegalFileTypes => nil, :fontFamily => nil, :fontColor => nil } return flash_config, fliqz_config end end end