Module: Papermill

Defined in:
lib/papermill/papermill.rb,
lib/papermill/papermill_options.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

MSWIN =
(Config::CONFIG['host_os'] =~ /mswin|mingw/)
BASE_OPTIONS =
{
  :class_name => "PapermillAsset",
  :through => false,
  :inline_css => true,
  :use_content_for => true,
  :images_only => false,
  :form_helper_elements => [:upload_button, :container, :browser, :mass_edit],
  :mass_edit => true,
  :mass_editable_fields => ["title", "copyright", "description"],
  :editable_fields => [
    {:title =>       {:type => "string"}}, 
    {:alt =>         {:type => "string"}}, 
    {:copyright =>   {:type => "string"}},
    {:description => {:type => "text"  }}
  ],
  :targetted_size => nil,
  :gallery => { 
    :width => nil,
    :height => nil,
    :columns => 8,
    :lines => 2,
    :vpadding => 0,
    :hpadding => 0,
    :vmargin => 1,
    :hmargin => 1,
    :border_thickness => 2
  },
  :thumbnail => {
    :width => 100,
    :height => 100, 
    :aspect_ratio => nil, 
    :style => nil
  },
  :swfupload => { 
    :flash_url => "'/swfupload/swfupload.swf'",
    :button_image_url => "'/papermill/images/upload-blank.png'",
    :button_width     => 61,
    :button_height    => 22,
    :button_text => %{'<span class="button-text">#{I18n.t("papermill.upload-button-wording")}</span>'},
    :button_text_style => %{'.button-text { font-size: 12pt; font-weight: bold; }'},
    :button_text_top_padding => 4,
    :button_text_left_padding => 4,
    :debug => false,
    :prevent_swf_caching => true,
    :file_size_limit => "'10 MB'"
  },
  :copyright => nil,
  :copyright_text_transform => Proc.new {|c| c },
  :copyright_im_command => %{\\( -font Arial-Bold -pointsize 9 -fill '#FFFFFFE0' -border 3 -bordercolor '#50550080' -background '#00000000' label:' %s ' \\) -gravity South-West -geometry +0+0 -composite},
  :watermark => "/images/rails.png",
  :watermark_im_command => %{- | composite \\( %s -resize 100% \\) - -dissolve 20% -gravity center -geometry +0+0 },
  :alias_only => false,
  :aliases => {},
  :use_url_key => false,
  :url_key_salt => "change-me-please",
  :url_key_generator => Proc.new { |style, asset| Digest::SHA512.hexdigest("#{style}#{asset.id}#{Papermill::options[:url_key_salt]}")[0..10] },
  :use_id_partition => true,
  :papermill_url_prefix => "/system/papermill",
  :papermill_path_prefix => ":rails_root/public/system/papermill"
}

Class Method Summary collapse

Class Method Details

.compute_paperclip_pathObject



8
9
10
11
12
13
14
15
# File 'lib/papermill/papermill.rb', line 8

def self.compute_paperclip_path
  path = []
  path << (options[:use_id_partition] ? ":id_partition" : ":id")
  path << (":url_key" if options[:use_url_key])
  path << ":style"
  path << ":basename.:extension"
  path.compact.join("/")
end

.included(base) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/papermill/papermill.rb', line 17

def self.included(base)
  base.extend(ClassMethods)
  base.class_eval do
    def papermill(key, through = ((po = self.class.papermill_options) && (po[key.to_sym] || po[:default]) || Papermill::options)[:through])
      PapermillAsset.papermill(self.class.base_class.name, self.id, key.to_s, through)
    end
    
    def respond_to_with_papermill?(method, *args, &block)
      respond_to_without_papermill?(method, *args, &block) || (method.to_s =~ /^papermill_.+_ids=$/) == 0
    end
    
    def method_missing_with_papermill(method, *args, &block)
      if method.to_s =~ /^papermill_.+_ids=$/
        self.class.papermill(method.to_s[10..-6])
        self.send(method, *args, &block)
      else
        method_missing_without_papermill(method, *args, &block)
      end
    end
  end
  base.send :alias_method_chain, :method_missing, :papermill
  base.send :alias_method_chain, :respond_to?, :papermill
  ActionController::Dispatcher.middleware.insert_before(ActionController::Base.session_store, FlashSessionCookieMiddleware, ActionController::Base.session_options[:key]) unless ActionController::Dispatcher.middleware.include?(FlashSessionCookieMiddleware)
end

.optionsObject



4
5
6
# File 'lib/papermill/papermill.rb', line 4

def self.options
  @options ||= BASE_OPTIONS.deep_merge(defined?(OPTIONS) ? OPTIONS : {})
end