radiant-images-extension 0.4.4 → 0.5.0

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
- 0.4.4
1
+ 0.5.0
@@ -0,0 +1,49 @@
1
+ require 'acts_as_list'
2
+
3
+ class Attachment < ActiveRecord::Base
4
+
5
+ default_scope :order => 'attachments.position ASC'
6
+
7
+ belongs_to :page
8
+ belongs_to :image
9
+
10
+ belongs_to :created_by, :class_name => 'User'
11
+ belongs_to :updated_by, :class_name => 'User'
12
+
13
+ acts_as_list :scope => :page
14
+
15
+ def url(*params)
16
+ image.url(*params) rescue nil
17
+ end
18
+
19
+ def title(*params)
20
+ image.title(*params) rescue nil
21
+ end
22
+
23
+ def caption(*params)
24
+ image.caption(*params) rescue nil
25
+ end
26
+
27
+ # Overloads the base to_json to return what we want
28
+ def to_json(*attrs); super self.class.params; end
29
+
30
+ class << self
31
+
32
+ # Returns attributes attached to the attachment
33
+ def attrs
34
+ [ :id, :title, :caption, :image_file_name, :image_content_type, :image_file_size ]
35
+ end
36
+
37
+ # Returns methods with usefuly information
38
+ def methds
39
+ [ :url, :title, :caption ]
40
+ end
41
+
42
+ # Returns a custom hash of attributes on the product
43
+ def params
44
+ { :only => self.attrs, :methods => self.methds }
45
+ end
46
+
47
+ end
48
+
49
+ end
@@ -0,0 +1,19 @@
1
+ class CreateAttachments < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :attachments, :force => true do |t|
4
+ t.integer :position, :default => 1
5
+ t.integer :image_id
6
+ t.integer :page_id
7
+ t.integer :created_by_id
8
+ t.integer :updated_by_id
9
+ end
10
+ add_index :attachments, ["image_id"], :name => "index_attachments_on_image_id"
11
+ add_index :attachments, ["page_id"], :name => "index_attachments_on_page_id"
12
+ add_index :attachments, ["position"], :name => "index_attachments_on_position"
13
+
14
+ end
15
+
16
+ def self.down
17
+ drop_table :attachments
18
+ end
19
+ end
data/images_extension.rb CHANGED
@@ -23,6 +23,7 @@ class ImagesExtension < Radiant::Extension
23
23
 
24
24
  Paperclip::Railtie.insert
25
25
 
26
+ Page.send :include, Images::Models::Page
26
27
  Page.send :include, Images::Tags::Core
27
28
 
28
29
  UserActionObserver.instance.send :add_observer!, Image
@@ -0,0 +1,15 @@
1
+ module Images
2
+ module Models
3
+ module Page
4
+
5
+ def self.included(base)
6
+ base.class_eval do
7
+ has_many :attachments
8
+ has_many :images, :through => :attachments
9
+ end
10
+ end
11
+
12
+ end
13
+ end
14
+ end
15
+
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{radiant-images-extension}
8
- s.version = "0.4.4"
8
+ s.version = "0.5.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Dirk Kelly", "Mario Visic"]
12
- s.date = %q{2010-12-06}
12
+ s.date = %q{2010-12-09}
13
13
  s.description = %q{Image Radiant Extension management tool, meant only to be useful to pages and extensions that need to require images.}
14
14
  s.email = %q{info@squaretalent.com}
15
15
  s.extra_rdoc_files = [
@@ -22,6 +22,7 @@ Gem::Specification.new do |s|
22
22
  "Rakefile",
23
23
  "VERSION",
24
24
  "app/controllers/admin/images_controller.rb",
25
+ "app/models/attachment.rb",
25
26
  "app/models/image.rb",
26
27
  "app/views/admin/images/_bottom.haml",
27
28
  "app/views/admin/images/_fields.haml",
@@ -38,10 +39,12 @@ Gem::Specification.new do |s|
38
39
  "db/migrate/20100601042237_create_images.rb",
39
40
  "db/migrate/20100602044124_add_position_to_images.rb",
40
41
  "db/migrate/20100929150930_change_images_to_created_by_id.rb",
42
+ "db/migrate/20101208095450_create_attachments.rb",
41
43
  "features/support/env.rb",
42
44
  "features/support/paths.rb",
43
45
  "images_extension.rb",
44
46
  "lib/images/interface/admin/images.rb",
47
+ "lib/images/models/page.rb",
45
48
  "lib/images/tags/core.rb",
46
49
  "lib/images/tags/helpers.rb",
47
50
  "lib/radiant-images-extension.rb",
@@ -54,10 +57,12 @@ Gem::Specification.new do |s|
54
57
  "public/stylesheets/sass/admin/extensions/images/index.sass",
55
58
  "radiant-images-extension.gemspec",
56
59
  "spec/controllers/admin/images_controller_spec.rb",
60
+ "spec/datasets/attachments.rb",
57
61
  "spec/datasets/images.rb",
58
62
  "spec/datasets/squaretalent.png",
59
63
  "spec/lib/images/tags/core_spec.rb",
60
64
  "spec/lib/images_extension_spec.rb",
65
+ "spec/models/attachment_spec.rb",
61
66
  "spec/models/image_spec.rb",
62
67
  "spec/spec.opts",
63
68
  "spec/spec_helper.rb"
@@ -68,9 +73,11 @@ Gem::Specification.new do |s|
68
73
  s.summary = %q{Images Extension for Radiant CMS}
69
74
  s.test_files = [
70
75
  "spec/controllers/admin/images_controller_spec.rb",
76
+ "spec/datasets/attachments.rb",
71
77
  "spec/datasets/images.rb",
72
78
  "spec/lib/images/tags/core_spec.rb",
73
79
  "spec/lib/images_extension_spec.rb",
80
+ "spec/models/attachment_spec.rb",
74
81
  "spec/models/image_spec.rb",
75
82
  "spec/spec_helper.rb"
76
83
  ]
@@ -0,0 +1,17 @@
1
+ class AttachmentsDataset < Dataset::Base
2
+
3
+ uses :images, :pages
4
+
5
+ def load
6
+
7
+ { :parent => [ :first, :second, :third ], :child => [ :fourth, :fifth, :sixth ]}.map do |page, attachments|
8
+ attachments.each_with_index do |attachment, i|
9
+ create_record :attachment, attachment,
10
+ :image => images(attachment),
11
+ :page => pages(page),
12
+ :position => i+1
13
+ end
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,52 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+
3
+ describe Attachment do
4
+
5
+ dataset :attachments
6
+
7
+ context 'attributes' do
8
+
9
+ before(:each) do
10
+ @attachment = attachments(:first)
11
+ end
12
+
13
+ it 'should have a position' do
14
+ @attachment.position.should === 1
15
+ end
16
+
17
+ it 'should have a product' do
18
+ @attachment.page.class.should == Page
19
+ end
20
+
21
+ it 'should have an image' do
22
+ @attachment.image.class.should == Image
23
+ end
24
+
25
+ end
26
+
27
+ context 'alias methods' do
28
+
29
+ before(:each) do
30
+ stub(AWS::S3::Base).establish_connection!
31
+ @attachment = attachments(:first)
32
+ end
33
+
34
+ describe '#url' do
35
+ it 'should return its assets url' do
36
+ stub(@attachment).image.stub!.url { 'url' }
37
+ @attachment.url.should === @attachment.image.url
38
+ end
39
+ end
40
+ describe '#title' do
41
+ it 'should return its assets title' do
42
+ @attachment.title.should === @attachment.image.title
43
+ end
44
+ end
45
+ describe '#caption' do
46
+ it 'should return its assets caption' do
47
+ @attachment.caption.should === @attachment.image.caption
48
+ end
49
+ end
50
+ end
51
+
52
+ end
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
2
 
3
3
  describe Image do
4
4
  dataset :images
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: radiant-images-extension
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 11
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 4
9
- - 4
10
- version: 0.4.4
8
+ - 5
9
+ - 0
10
+ version: 0.5.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Dirk Kelly
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-12-06 00:00:00 +08:00
19
+ date: 2010-12-09 00:00:00 +08:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -130,6 +130,7 @@ files:
130
130
  - Rakefile
131
131
  - VERSION
132
132
  - app/controllers/admin/images_controller.rb
133
+ - app/models/attachment.rb
133
134
  - app/models/image.rb
134
135
  - app/views/admin/images/_bottom.haml
135
136
  - app/views/admin/images/_fields.haml
@@ -146,10 +147,12 @@ files:
146
147
  - db/migrate/20100601042237_create_images.rb
147
148
  - db/migrate/20100602044124_add_position_to_images.rb
148
149
  - db/migrate/20100929150930_change_images_to_created_by_id.rb
150
+ - db/migrate/20101208095450_create_attachments.rb
149
151
  - features/support/env.rb
150
152
  - features/support/paths.rb
151
153
  - images_extension.rb
152
154
  - lib/images/interface/admin/images.rb
155
+ - lib/images/models/page.rb
153
156
  - lib/images/tags/core.rb
154
157
  - lib/images/tags/helpers.rb
155
158
  - lib/radiant-images-extension.rb
@@ -162,10 +165,12 @@ files:
162
165
  - public/stylesheets/sass/admin/extensions/images/index.sass
163
166
  - radiant-images-extension.gemspec
164
167
  - spec/controllers/admin/images_controller_spec.rb
168
+ - spec/datasets/attachments.rb
165
169
  - spec/datasets/images.rb
166
170
  - spec/datasets/squaretalent.png
167
171
  - spec/lib/images/tags/core_spec.rb
168
172
  - spec/lib/images_extension_spec.rb
173
+ - spec/models/attachment_spec.rb
169
174
  - spec/models/image_spec.rb
170
175
  - spec/spec.opts
171
176
  - spec/spec_helper.rb
@@ -205,8 +210,10 @@ specification_version: 3
205
210
  summary: Images Extension for Radiant CMS
206
211
  test_files:
207
212
  - spec/controllers/admin/images_controller_spec.rb
213
+ - spec/datasets/attachments.rb
208
214
  - spec/datasets/images.rb
209
215
  - spec/lib/images/tags/core_spec.rb
210
216
  - spec/lib/images_extension_spec.rb
217
+ - spec/models/attachment_spec.rb
211
218
  - spec/models/image_spec.rb
212
219
  - spec/spec_helper.rb