configure image styles
# File lib/rich.rb, line 11 def self.image_styles @@image_styles.merge({ :rich_thumb => "100x100#" }) end
# File lib/rich.rb, line 14 def self.image_styles=(image_styles) @@image_styles = image_styles end
# File lib/rich.rb, line 176 def self.insert # manually inject into Formtastic 1. V2 is extended autmatically. if Object.const_defined?("Formtastic") if(Gem.loaded_specs["formtastic"].version.version[0,1] == "1") require 'rich/integrations/legacy_formtastic' ::Formtastic::SemanticFormBuilder.send :include, Rich::Integrations::FormtasticBuilder end end end
End configuration defaults
# File lib/rich.rb, line 81 def self.options(overrides={}, scope_type=nil, scope_id=nil) # merge in editor settings configured elsewhere if(self.allowed_styles == :all) # replace :all with a list of the actual styles that are present all_styles = Rich.image_styles.keys all_styles.push(:original) self.allowed_styles = all_styles end base = { :allowed_styles => self.allowed_styles, :default_style => self.default_style, :insert_many => self.insert_many, :allow_document_uploads => self.allow_document_uploads, :allow_embeds => self.allow_embeds, :placeholder_image => self.placeholder_image, :preview_size => self.preview_size, :hidden_input => self.hidden_input } editor_options = self.editor.merge(base) # merge in local overrides editor_options.merge!(overrides) if overrides # if the contentcss is set to :default, use the asset pipeline editor_options[:contentsCss] = ActionController::Base.helpers.stylesheet_path('rich/editor.css') if editor_options[:contentsCss] == :default # update the language to the currently selected locale editor_options[:language] = I18n.locale # remove the filebrowser if allow_document_uploads is false (the default) unless editor_options[:allow_document_uploads] editor_options[:toolbar][1].delete("richFile") end unless editor_options[:allow_embeds] editor_options[:toolbar][1].delete("MediaEmbed") end # object scoping # todo: support scoped=string to scope to collections, set id to 0 unless editor_options[:scoped] == nil # true signifies object level scoping if editor_options[:scoped] == true if(scope_type != nil && scope_id != nil) editor_options[:scope_type] = scope_type editor_options[:scope_id] = scope_id else # cannot scope new objects editor_options[:scoped] = false end else # not true (but also not nil) signifies scoping to a collection if(scope_type != nil) editor_options[:scope_type] = editor_options[:scoped] editor_options[:scope_id] = 0 editor_options[:scoped] = true else editor_options[:scoped] = false end end end editor_options end
# File lib/rich.rb, line 172 def self.setup yield self end
# File lib/rich.rb, line 155 def self.validate_mime_type(mime, simplified_type) # does the mimetype match the given simplified type? #puts "matching:" + mime + " TO " + simplified_type false # assume the worst if simplified_type == "image" if allowed_image_types.include?(mime) true end elsif simplified_type == "file" if allowed_document_types == :all || allowed_document_types.include?(mime) true end end end