BBenezech-papermill 0.4.0 → 0.4.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/README.rdoc CHANGED
@@ -1,12 +1,32 @@
1
1
  = Papermill
2
2
 
3
- Asset management made easy.. Painfully easy.
4
- Try the demo to see for yourself.
3
+ Asset management made easy.. Painfully easy.
5
4
 
6
- See papermill_module.rb for a complete list of available options.
7
- These options can be application wide, for a class, or set at the last moment for the helper.
5
+ == Try the demo to get the idea:
6
+
7
+ rails -m http://gist.github.com/177714.txt papermill-example
8
+
9
+ == Papermill comes in 2 flavors:
10
+
11
+ === Generic catch-all declaration
12
+
13
+ papermill {my_option_hash} # in your papermilled assetable model
14
+ assets_upload(:my_key, {optional_option_hash}) # form helper call
15
+ @assetable.papermill_assets(:key => :my_key) # data access in your view
16
+
17
+ === Association specific declaration
18
+
19
+ papermill :my_association, {my_option_hash} # in your papermilled assetable model
20
+ assets_upload(my_association, {optional_option_hash}) # form helper call
21
+ @assetable.my_association # data access in your view
8
22
 
9
- You'll need something like this in your environment.rb
23
+ In both case, you can specify a PapermillAsset subclass to use with :class_name => MyPapermillAssetSubclass in the option hash
24
+
25
+ See papermill_module.rb for the complete list of options.
26
+
27
+ == Installation
28
+
29
+ === You'll need something like this in your environment.rb:
10
30
 
11
31
  config.gem 'rsl-stringex', :lib => 'stringex', :source => 'http://gems.github.com'
12
32
  config.gem 'paperclip'
@@ -15,66 +35,64 @@ You'll need something like this in your environment.rb
15
35
  config.gem 'ryanb-acts-as-list', :lib => 'acts_as_list', :source => 'http://gems.github.com'
16
36
  config.gem 'BBenezech-papermill', :lib => 'papermill', :source => 'http://gems.github.com'
17
37
 
18
- Then install the whole thing:
38
+ === Then you can the whole thing:
19
39
 
20
- sudo gem install ryanb-acts-as-list -s http://gems.github.com
21
- sudo gem install paperclip
22
- sudo rake gems:install # will install the others gem. You need to install paperclip & acts_as_list first, because of a dependency mayhem.
23
- ./script/generate papermill PapermillMigration # will also copy a couple of static assets
24
- rake db:migrate
40
+ $ sudo gem install ryanb-acts-as-list -s http://gems.github.com
41
+ $ sudo gem install paperclip
42
+ $ sudo rake gems:install
43
+ # will install the others gem.
44
+ # You need to install paperclip & acts_as_list first, because of a dependency mayhem.
45
+ # Next version of gem will use gem dependencies
46
+ $ ./script/generate papermill PapermillMigration
47
+ # will generate a migration named PapermillMigration and copy a couple of static assets
48
+ $ rake db:migrate
25
49
 
26
- In your assetable model:
27
-
28
- papermill :assets
50
+ === In your assetable model:
51
+
52
+ # You can set a catch-all papermill association :
53
+ papermill {:class_name => Asset}
29
54
 
30
- In your layout:
55
+ # or create an association for the specific :my_gallery key
56
+ papermill :my_gallery, {
57
+ :class_name => GalleryAsset,
58
+ :thumbnail => {
59
+ :width => 90,
60
+ :height => 30
61
+ }
62
+ }
63
+
64
+ === In your layout:
31
65
 
32
66
  <%= papermill_stylesheet_tag %>
33
- <%= papermill_javascript_tag :with_jquery => true %>
34
- # you don't need :with_jquery if it is already loaded, obviously.
67
+ <%= papermill_javascript_tag :with_jquery => "no_conflict" %>
68
+ # you won't need :with_jquery if you use it already, obviously.
35
69
 
36
- In your edit form:
70
+ === In your edit form:
37
71
 
38
- f.images_upload(:my_image_gallery)
39
- f.image_upload(:header_image)
72
+ f.images_upload(:my_gallery) # use specific papermill :my_gallery declaration
73
+ f.assets_upload(:my_assets) # use catch-all
74
+ f.asset_upload(:my_other_asset) # use catch-all
40
75
 
41
- Finally, in your views:
76
+ === Access them with:
42
77
 
43
- # Some template image :
44
- <%= image_tag @article.assets(:header_image).first.url("800x>") %>
45
-
46
- # Some image gallery:
47
- <ul>
48
- <% @article.assets(:my_image_gallery).each do |image| %>
49
- <li><%= link_to(image_tag(image.url("100x100>")), image.url) %></li>
50
- <% end %>
51
- </ul>
52
-
53
- Also see http://gist.github.com/177714.txt to get up-to-date installation steps.
54
- See the API here http://rdoc.info/projects/BBenezech/papermill
55
-
56
- == Word of caution:
57
-
58
- Beta.
59
-
60
- This is xNIX only (system("rm ...")).
61
-
62
- You'll need rails 2.3, since this is an engine. Anyway, copying the controller/view/routes to your project will make it work on an older version of rails.
78
+ @assetable.my_gallery.each{ |image| image.url("100x100") }
79
+ @assetable.papermill_assets(:key => :my_assets).each{ |asset| asset.url }
80
+ @assetable.papermill_assets(:key => :my_other_asset).first.url
63
81
 
64
- You'll need rails 2.2, since their are calls to I18n.t. But it shouldn't be too hard to work-around either.
82
+ Also see http://gist.github.com/177714.txt for more precises installation steps.
83
+ Have a look at the API here http://rdoc.info/projects/BBenezech/papermill
65
84
 
66
- == Usage :
85
+ === Translations:
67
86
 
68
- === Demo :
87
+ Papermill is fully I18n-able.
88
+ Copy config/locales/papermill.yml to your root config/locale folder to modify any wording in a any locale.
69
89
 
70
- You can use the custom template generator to get an example application up and running in no time.
71
-
72
- rails -m http://gist.github.com/177714.txt papermill-example
73
90
 
74
- === Translation:
91
+ == Word of caution:
75
92
 
76
- Papermill is fully Rails 2.2 I18n-able.
93
+ Beta. Wait for gem 1.0.0 for the production ready thing.
94
+ This is xNIX only (system("rm ...")).
95
+ Rails 2.3
77
96
 
78
- Copy config/locale/papermill.yml to your root config/locale folder to modify any wording in a any locale.
79
97
 
80
98
  Copyright (c) 2009 Benoit Bénézech, released under the MIT license
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.4.1
@@ -107,11 +107,11 @@ module Papermill
107
107
 
108
108
  @papermill_associations ||= {}
109
109
  begin
110
- asset_class = (class_name = options.delete(:class_name)).to_s.constantize || PapermillAsset
110
+ class_name = options.delete(:class_name)
111
+ asset_class = class_name && class_name.to_s.constantize || PapermillAsset
111
112
  rescue
112
113
  raise Exception.new("Papermill: can't find class #{class_name.to_s}.\n#{class_name.to_s} should be a subclass of PapermillAsset")
113
114
  end
114
- assoc_name ||= asset_class.to_s.pluralize.underscore.to_sym
115
115
 
116
116
  @papermill_associations.merge!({assoc_name => {:class => asset_class, :options => Papermill::PAPERMILL_DEFAULTS.deep_merge(options)}})
117
117
  before_destroy :destroy_assets
@@ -120,14 +120,19 @@ module Papermill
120
120
  define_method assoc_name do |*options|
121
121
  klass = self.class.papermill_associations[assoc_name.to_sym][:class]
122
122
  options = options.first || {}
123
+ if (options.is_a?(Symbol) || options.is_a?(String))
124
+ key = options
125
+ options = {}
126
+ else
127
+ key = nil
128
+ end
123
129
  conditions = {
124
130
  :assetable_type => self.class.sti_name,
125
131
  :assetable_id => self.id
126
132
  }.merge(options.delete(:conditions) || {})
127
- conditions.merge!({:type => klass.to_s}) unless assoc_name == PapermillAsset
128
- conditions.merge!({:assetable_key => assoc_name.to_s}) if assoc_name != :papermill_assets
129
- conditions.merge!({:assetable_key => options.delete(:key)}) if options.has_key?(:key)
130
- conditions.merge!({:type => options[:class_name]}) if options[:class_name]
133
+ key ||= (assoc_name != :papermill_assets) && assoc_name.to_s
134
+ conditions.merge!({:assetable_key => key.to_s}) if key
135
+
131
136
  hash = {
132
137
  :conditions => conditions,
133
138
  :order => options.delete(:order) || "position ASC"
data/papermill.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{papermill}
8
- s.version = "0.4.0"
8
+ s.version = "0.4.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Benoit B\303\251n\303\251zech"]
12
- s.date = %q{2009-09-01}
12
+ s.date = %q{2009-09-02}
13
13
  s.description = %q{Paperclip wrapper}
14
14
  s.email = %q{benoit.benezech@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -59,7 +59,7 @@ Gem::Specification.new do |s|
59
59
  s.homepage = %q{http://github.com/BBenezech/papermill}
60
60
  s.rdoc_options = ["--charset=UTF-8"]
61
61
  s.require_paths = ["lib"]
62
- s.rubygems_version = %q{1.3.4}
62
+ s.rubygems_version = %q{1.3.5}
63
63
  s.summary = %q{Paperclip wrapper}
64
64
  s.test_files = [
65
65
  "test/papermill_test.rb",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: BBenezech-papermill
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Benoit B\xC3\xA9n\xC3\xA9zech"
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-01 00:00:00 -07:00
12
+ date: 2009-09-02 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15