papermill 2.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.0
1
+ 2.0.1
@@ -28,7 +28,11 @@ module Papermill
28
28
  # Helper can generates inline css styling that adapt to your gallery/images placeholder. You can use it to scaffold, then copy the lines you need in your application css and set it to false.
29
29
 
30
30
  # :inline_css => true,
31
-
31
+
32
+ # If you don't want generated CSS and JS to be captured and available through @papermill_inline_css/@papermill_inline_js, and instead directly outputed in the form, set it to false
33
+
34
+ # :use_content_for => true,
35
+
32
36
  # SwfUpload will only let the user upload images.
33
37
 
34
38
  # :images_only => false,
@@ -51,16 +51,18 @@ module ActionView::Helpers::FormTagHelper
51
51
  options = association_options.deep_merge(options)
52
52
  field_name = "#{assetable_name}[papermill_#{method}_ids][]"
53
53
 
54
+ html = {}
55
+
54
56
  if ot = options[:thumbnail]
55
57
  w = ot[:width] || ot[:height] && ot[:aspect_ratio] && (ot[:height] * ot[:aspect_ratio]).to_i || nil
56
58
  h = ot[:height] || ot[:width] && ot[:aspect_ratio] && (ot[:width] / ot[:aspect_ratio]).to_i || nil
57
59
  computed_style = ot[:style] || (w || h) && "#{w}x#{h}>" || "original"
58
- set_papermill_inline_css(field_id, w, h, options)
60
+ html[:css] = set_papermill_inline_css(field_id, w, h, options)
59
61
  end
60
62
 
61
- set_papermill_inline_js(field_id, compute_papermill_url(:create, computed_style, field_name, field_id, options), options)
63
+ html[:js] = set_papermill_inline_js(field_id, compute_papermill_url(:create, computed_style, field_name, field_id, options), options)
62
64
 
63
- html = {}
65
+
64
66
  html[:upload_button] = %{\
65
67
  <div id="#{field_id}-button-wrapper" class="papermill-button-wrapper" style="height: #{options[:swfupload][:button_height]}px;">
66
68
  <span id="browse_for_#{field_id}" class="swf_button"></span>
@@ -91,7 +93,7 @@ module ActionView::Helpers::FormTagHelper
91
93
  # hidden_field needed to empty a list.
92
94
  %{<div class="papermill">
93
95
  #{@template.hidden_field("#{assetable_name}[papermill_#{method}_ids]", nil)}
94
- #{options[:form_helper_elements].map{|element| html[element] || ""}.join("\n")}
96
+ #{html[:css] + html[:js] + options[:form_helper_elements].map{|element| html[element] || ""}.join("\n")}
95
97
  </div>}
96
98
  end
97
99
 
@@ -106,36 +108,44 @@ module ActionView::Helpers::FormTagHelper
106
108
  end
107
109
 
108
110
  def set_papermill_inline_js(field_id, create_url, options)
109
- return unless options[:inline_css]
110
- @template.content_for :papermill_inline_js do
111
- %{ jQuery("##{field_id}").sortable() } if options[:gallery]
112
- end
113
- @template.content_for :papermill_inline_js do
114
- %{
115
- new SWFUpload({
116
- post_params: {
117
- "#{ ActionController::Base.session_options[:key] }": "#{ @template.cookies[ActionController::Base.session_options[:key]] }"
118
- },
119
- upload_id: "#{ field_id }",
120
- upload_url: "#{ @template.escape_javascript create_url }",
121
- file_types: "#{ options[:images_only] ? '*.jpg;*.jpeg;*.png;*.gif' : '' }",
122
- file_queue_limit: "#{ !options[:gallery] ? '1' : '0' }",
123
- file_queued_handler: Papermill.file_queued,
124
- file_dialog_complete_handler: Papermill.file_dialog_complete,
125
- upload_start_handler: Papermill.upload_start,
126
- upload_progress_handler: Papermill.upload_progress,
127
- file_queue_error_handler: Papermill.file_queue_error,
128
- upload_error_handler: Papermill.upload_error,
129
- upload_success_handler: Papermill.upload_success,
130
- upload_complete_handler: Papermill.upload_complete,
131
- button_placeholder_id: "browse_for_#{field_id}",
132
- #{ options[:swfupload].map { |key, value| "#{key}: #{value}" if value }.compact.join(",\n") }
111
+ outputed_js = (options[:gallery] ? %{ jQuery("##{field_id}").sortable() } : "") +
112
+ %{
113
+ new SWFUpload({
114
+ post_params: {
115
+ "#{ ActionController::Base.session_options[:key] }": "#{ @template.cookies[ActionController::Base.session_options[:key]] }"
116
+ },
117
+ upload_id: "#{ field_id }",
118
+ upload_url: "#{ @template.escape_javascript create_url }",
119
+ file_types: "#{ options[:images_only] ? '*.jpg;*.jpeg;*.png;*.gif' : '' }",
120
+ file_queue_limit: "#{ !options[:gallery] ? '1' : '0' }",
121
+ file_queued_handler: Papermill.file_queued,
122
+ file_dialog_complete_handler: Papermill.file_dialog_complete,
123
+ upload_start_handler: Papermill.upload_start,
124
+ upload_progress_handler: Papermill.upload_progress,
125
+ file_queue_error_handler: Papermill.file_queue_error,
126
+ upload_error_handler: Papermill.upload_error,
127
+ upload_success_handler: Papermill.upload_success,
128
+ upload_complete_handler: Papermill.upload_complete,
129
+ button_placeholder_id: "browse_for_#{field_id}",
130
+ #{ options[:swfupload].map { |key, value| "#{key}: #{value}" if value }.compact.join(",\n") }
131
+ });
132
+ }
133
+ if options[:use_content_for]
134
+ @template.content_for :papermill_inline_js do
135
+ outputed_js
136
+ end
137
+ ""
138
+ else
139
+ %{<script type="text/javascript">
140
+ $(function() {
141
+ #{outputed_js}
133
142
  });
134
- }
143
+ </script>}
135
144
  end
136
145
  end
137
146
 
138
147
  def set_papermill_inline_css(field_id, width, height, options)
148
+ return unless options[:inline_css]
139
149
  html = ["\n"]
140
150
  size = [width && "width:#{width}px", height && "height:#{height}px"].compact.join("; ")
141
151
  if og = options[:gallery]
@@ -148,8 +158,15 @@ module ActionView::Helpers::FormTagHelper
148
158
  html << %{##{field_id}, ##{field_id} .asset { #{size} }}
149
159
  end
150
160
  html << %{##{field_id} .name { width:#{width || "100"}px; }}
151
- @template.content_for :papermill_inline_css do
152
- html.join("\n")
161
+ if options[:use_content_for]
162
+ @template.content_for :papermill_inline_css do
163
+ html.join("\n")
164
+ end
165
+ ""
166
+ else
167
+ %{<style type="text/css">
168
+ #{html.join("\n")}
169
+ </style>}
153
170
  end
154
171
  end
155
172
  end
@@ -54,7 +54,7 @@ module Papermill
54
54
  return if assoc_key.to_sym == :default
55
55
  unless papermill_options[assoc_key.to_sym][:through]
56
56
  self.class_eval %{
57
- has_many :#{assoc_key}, :as => "assetable", :dependent => :delete_all, :order => :position, :class_name => "PapermillAsset", :conditions => {:assetable_key => '#{assoc_key}'}, :before_add => Proc.new{|a, asset| asset.assetable_key = '#{assoc_key}'}
57
+ has_many :#{assoc_key}, :as => "assetable", :dependent => :destroy, :order => :position, :class_name => "PapermillAsset", :conditions => {:assetable_key => '#{assoc_key}'}, :before_add => Proc.new{|a, asset| asset.assetable_key = '#{assoc_key}'}
58
58
  def papermill_#{assoc_key}_ids=(ids)
59
59
  unless (assets_ids = ids.map(&:to_i).select{|i|i>0}) == self.#{assoc_key}.map(&:id)
60
60
  assets = PapermillAsset.find(assets_ids)
@@ -3,6 +3,7 @@ module Papermill
3
3
  :class_name => "PapermillAsset",
4
4
  :through => false,
5
5
  :inline_css => true,
6
+ :use_content_for => true,
6
7
  :images_only => false,
7
8
  :form_helper_elements => [:upload_button, :container, :browser, :mass_edit],
8
9
  :mass_edit => true,
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 2
7
7
  - 0
8
- - 0
9
- version: 2.0.0
8
+ - 1
9
+ version: 2.0.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - "Benoit B\xC3\xA9n\xC3\xA9zech"
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-24 00:00:00 +01:00
17
+ date: 2010-03-31 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency