Module: Rich

Defined in:
lib/rich.rb,
lib/rich/engine.rb,
lib/rich/version.rb,
lib/rich/authorize.rb,
app/models/rich/rich_file.rb,
app/helpers/rich/files_helper.rb,
app/helpers/rich/application_helper.rb,
app/controllers/rich/files_controller.rb,
lib/rich/integrations/legacy_formtastic.rb,
lib/generators/rich/install/install_generator.rb

Defined Under Namespace

Modules: ApplicationHelper, Authorize, FilesHelper, Generators, Integrations Classes: Engine, FilesController, RichFile

Constant Summary collapse

VERSION =
"1.4.6"
@@image_styles =
{
  :thumb => "100x100#"
}
@@convert_options =
{}
@@allowed_styles =
:all
@@default_style =
:thumb
@@authentication_method =
:none
@@insert_many =
false
@@allow_document_uploads =
false
@@allow_embeds =
false
@@allowed_image_types =
['image/jpeg', 'image/png', 'image/gif', 'image/jpg']
@@allowed_document_types =
:all
@@placeholder_image =

a transparent pixel

"data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="
@@preview_size =
"100px"
@@hidden_input =
false
@@editor =
{
  :height => 400,
  :stylesSet  =>  [],
  :extraPlugins => 'stylesheetparser,richfile,MediaEmbed',
  :removePlugins => 'scayt,menubutton,image,forms',
  :contentsCss => :default,
  :removeDialogTabs => 'link:advanced;link:target',
  :startupOutlineBlocks => true,
  :forcePasteAsPlainText => true,
  :format_tags => 'h3;p;pre',
  :toolbar => [['Format','Styles'],['Bold', 'Italic', '-','NumberedList', 'BulletedList', 'Blockquote', '-', 'richImage', 'richFile','MediaEmbed', '-', 'Link', 'Unlink'],['Source', 'ShowBlocks']],
  :language => I18n.default_locale,
  :richBrowserUrl => '/rich/files/',
  :uiColor => '#f4f4f4'
}

Class Method Summary collapse

Class Method Details

.image_stylesObject

configure image styles



11
12
13
# File 'lib/rich.rb', line 11

def self.image_styles
    @@image_styles.merge({ :rich_thumb => "100x100#" })
end

.image_styles=(image_styles) ⇒ Object



14
15
16
# File 'lib/rich.rb', line 14

def self.image_styles=(image_styles)
  @@image_styles = image_styles
end

.insertObject



176
177
178
179
180
181
182
183
184
# 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

.options(overrides = {}, scope_type = nil, scope_id = nil) ⇒ Object

End configuration defaults



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# 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

.setup {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (Rich)

    the object that the method was called on



172
173
174
# File 'lib/rich.rb', line 172

def self.setup
  yield self
end

.validate_mime_type(mime, simplified_type) ⇒ Object



155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# 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