radiant-images-extension 0.1.1 → 0.3.2

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.
@@ -0,0 +1,64 @@
1
+ module Images
2
+ module Tags
3
+ class Helpers
4
+
5
+ class TagError < StandardError; end
6
+
7
+ class << self
8
+
9
+ def current_images(tag)
10
+ result = nil
11
+
12
+ if tag.locals.images.present?
13
+ result = tag.locals.images
14
+ elsif tag.attr['key'] and tag.attr['value']
15
+ result = Image.find(:all, :conditions => { tag.attr['key'].to_sym => tag.attr['value'].to_s }) rescue nil
16
+ else
17
+ result = Image.all
18
+ end
19
+
20
+ result
21
+ end
22
+
23
+ def current_image(tag)
24
+ result = nil
25
+
26
+ if tag.locals.image.present?
27
+ result = tag.locals.image
28
+ elsif tag.attr['id']
29
+ result = Image.find(tag.attr['id'])
30
+ elsif tag.attr['title']
31
+ result = Image.find_by_title(tag.attr['title'])
32
+ elsif tag.attr['position']
33
+ begin
34
+ result = tag.locals.images[(tag.attr['position']-1).to_i]
35
+ rescue
36
+ result = Image.find_by_position(tag.attr['position'].to_i)
37
+ end
38
+ end
39
+
40
+ result
41
+ end
42
+
43
+ def image_options(tag)
44
+ attr = tag.attr.symbolize_keys
45
+ by = attr[:by] || 'position'
46
+ order = attr[:order] || 'asc'
47
+
48
+ options = {
49
+ :order => "#{by} #{order}",
50
+ :limit => attr[:limit] || nil,
51
+ :offset => attr[:offset] || nil
52
+ }
53
+ end
54
+
55
+ def image_and_options(tag)
56
+ options = tag.attr.dup
57
+ [find_image(tag, options), options]
58
+ end
59
+
60
+ end
61
+
62
+ end
63
+ end
64
+ end
@@ -20,6 +20,7 @@ namespace :radiant do
20
20
  if asset.asset_type.name == :image
21
21
  Image.create({
22
22
  :title => asset.title,
23
+ :caption => asset.caption,
23
24
  :asset_file_name => asset.asset_file_name,
24
25
  :asset_content_type => asset.asset_content_type,
25
26
  :asset_file_size => asset.asset_file_size
@@ -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.1.1"
8
+ s.version = "0.3.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["squaretalent"]
12
- s.date = %q{2010-09-16}
12
+ s.date = %q{2010-10-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 = [
@@ -18,6 +18,7 @@ Gem::Specification.new do |s|
18
18
  ]
19
19
  s.files = [
20
20
  ".gitignore",
21
+ "CHANGELOG",
21
22
  "LICENSE",
22
23
  "README.md",
23
24
  "Rakefile",
@@ -38,12 +39,15 @@ Gem::Specification.new do |s|
38
39
  "cucumber.yml",
39
40
  "db/migrate/20100601042237_create_images.rb",
40
41
  "db/migrate/20100602044124_add_position_to_images.rb",
42
+ "db/migrate/20100929150930_change_images_to_created_by_id.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",
45
- "lib/images/tags/image.rb",
47
+ "lib/images/tags/core.rb",
48
+ "lib/images/tags/helpers.rb",
46
49
  "lib/tasks/images_extension_tasks.rake",
50
+ "public/images/admin/extensions/images/sort.png",
47
51
  "public/images/extensions/images/missing_icon.png",
48
52
  "public/images/extensions/images/missing_normal.png",
49
53
  "public/images/extensions/images/missing_preview.png",
@@ -53,7 +57,7 @@ Gem::Specification.new do |s|
53
57
  "radiant-images-extension.gemspec",
54
58
  "spec/controllers/admin/images_controller_spec.rb",
55
59
  "spec/datasets/images.rb",
56
- "spec/lib/images/tags/image_spec.rb",
60
+ "spec/lib/images/tags/core_spec.rb",
57
61
  "spec/models/image_spec.rb",
58
62
  "spec/spec.opts",
59
63
  "spec/spec_helper.rb"
@@ -66,7 +70,7 @@ Gem::Specification.new do |s|
66
70
  s.test_files = [
67
71
  "spec/controllers/admin/images_controller_spec.rb",
68
72
  "spec/datasets/images.rb",
69
- "spec/lib/images/tags/image_spec.rb",
73
+ "spec/lib/images/tags/core_spec.rb",
70
74
  "spec/models/image_spec.rb",
71
75
  "spec/spec_helper.rb"
72
76
  ]
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Admin::ImagesController do
4
4
  dataset :users
@@ -9,7 +9,6 @@ describe Admin::ImagesController do
9
9
  @images = Image.all
10
10
  end
11
11
 
12
-
13
12
  context 'user not logged in' do
14
13
 
15
14
  it 'should redirect to login path' do
@@ -20,7 +19,6 @@ describe Admin::ImagesController do
20
19
  end
21
20
 
22
21
  context 'user logged in' do
23
-
24
22
  before :each do
25
23
  login_as :admin
26
24
  stub(AWS::S3::Base).establish_connection!
@@ -37,98 +35,36 @@ describe Admin::ImagesController do
37
35
  get :index
38
36
  assigns(:images).should == @images
39
37
  end
40
-
41
- end
42
-
43
- context 'show action' do
44
38
 
45
- it 'should redirect to the edit action' do
46
- get :show, :id => @image.id
47
- response.should redirect_to edit_admin_image_url(@image)
39
+ it 'should use pagination' do
40
+ get :index
41
+ assigns(:images).class.should == WillPaginate::Collection
48
42
  end
49
-
50
- end
51
43
 
52
- context 'edit action' do
53
-
54
- it 'should render the edit template' do
55
- get :edit, :id => @image.id
56
- response.should render_template(:edit)
57
- end
58
-
59
- it 'should redirect to the index on invalid image id' do
60
- get :edit, :id => 999999
61
- response.should redirect_to admin_images_url
62
- end
63
-
64
- end
44
+ end
65
45
 
66
- context 'new action' do
46
+ context 'search action' do
67
47
 
68
- it 'should render the new template' do
69
- get :new
70
- response.should render_template(:new)
48
+ before :each do
49
+ login_as :admin
50
+ stub(AWS::S3::Base).establish_connection!
71
51
  end
72
52
 
73
- end
74
-
75
- context 'update action' do
76
-
77
- it 'should redirect to the index on valid image' do
78
- put :update, :id => @image.id
79
- response.should redirect_to admin_images_url
53
+ it 'should render the search template on search action' do
54
+ get :search
55
+ response.should render_template(:search)
80
56
  end
81
57
 
82
- it 'should render the edit template on invalid model' do
83
- any_instance_of(Image, :valid? => false)
84
- put :update, :id => @image.id
85
- response.should render_template(:edit)
86
- end
58
+ it 'should return valid search results'
87
59
 
88
- end
89
-
90
- context 'create action' do
91
-
92
- it "create action should render new template when model is invalid" do
93
- stub.instance_of(Image).valid? {false}
94
- post :create
95
- response.should render_template(:new)
96
- end
97
-
98
- it "create action should redirect when model is valid" do
99
- stub.instance_of(Image).valid? {true}
100
- post :create
101
- response.should redirect_to admin_images_url
102
- end
60
+ it 'should respond to JS requests correctly'
103
61
 
62
+ it 'should respond to xml requests correctly'
104
63
 
64
+ it 'should respond to json requests correctly'
65
+
105
66
  end
106
67
 
107
- context 'remove action' do
108
-
109
- it 'should render the remove template' do
110
- get :remove, :id => @image.id
111
- response.should render_template(:remove)
112
-
113
- end
114
-
115
- end
116
-
117
- context 'destroy action' do
118
-
119
- it 'should redirect to the index' do
120
- # we need to stop destroy_attached_files running (as it'll error with no S3 details)
121
- mock(@images[1]).destroy_attached_files
122
-
123
- @images[1].destroy
124
- delete :destroy, :id => @images[1].id
125
- response.should redirect_to admin_images_url
126
- Image.exists?(@images[1].id).should be_false
127
- end
128
-
129
- end
130
-
131
-
132
68
  end
133
69
 
134
70
 
@@ -5,7 +5,7 @@ class ImagesDataset < Dataset::Base
5
5
  images.each_with_index do |image, i|
6
6
  create_record :image, image.to_sym,
7
7
  :title => image.to_s,
8
- :caption => 'brief description',
8
+ :caption => "caption for #{image.to_s}",
9
9
  :asset_file_name => "#{image.to_s}.png",
10
10
  :asset_content_type => "image/png",
11
11
  :asset_file_size => i+1*1000,
@@ -0,0 +1,110 @@
1
+ require 'spec_helper'
2
+
3
+ describe Images::Tags::Core do
4
+ dataset :pages, :images
5
+
6
+ it 'should describe these tags' do
7
+ Images::Tags::Core.tags.sort.should == [
8
+ 'images',
9
+ 'images:if_images',
10
+ 'images:unless_images',
11
+ 'images:each',
12
+ 'images:first',
13
+ 'image',
14
+ 'image:if_first',
15
+ 'image:unless_first',
16
+ 'image:url',
17
+ 'image:id',
18
+ 'image:title'].sort
19
+ end
20
+
21
+ before(:all) do
22
+ @images = [ images(:first), images(:second) ]
23
+ end
24
+
25
+ before(:each) do
26
+ stub(AWS::S3::Base).establish_connection!
27
+ end
28
+
29
+ describe '<r:images>' do
30
+
31
+ it 'should render' do
32
+ tag = '<r:images>success</r:images>'
33
+ exp = 'success'
34
+
35
+ pages(:home).should render(tag).as(exp)
36
+ end
37
+
38
+ end
39
+
40
+ describe '<r:images:if_images>' do
41
+
42
+ context 'success' do
43
+ it 'should render' do
44
+ tag = '<r:images><r:if_images>success</r:if_images></r:images>'
45
+ exp = 'success'
46
+
47
+ pages(:home).should render(tag).as(exp)
48
+ end
49
+ it 'should render' do
50
+ tag = '<r:images key="title" value="first"><r:if_images>success</r:if_images></r:images>'
51
+ exp = 'success'
52
+
53
+ pages(:home).should render(tag).as(exp)
54
+ end
55
+ end
56
+
57
+ context 'failure' do
58
+ it 'should not render' do
59
+ mock(Image).all { [] }
60
+ tag = '<r:images><r:if_images>failure</r:if_images></r:images>'
61
+ exp = ''
62
+
63
+ pages(:home).should render(tag).as(exp)
64
+ end
65
+ it 'should not render' do
66
+ tag = '<r:images key="title" value="notme"><r:if_images>failure</r:if_images></r:images>'
67
+ exp = ''
68
+
69
+ pages(:home).should render(tag).as(exp)
70
+ end
71
+ end
72
+
73
+ end
74
+
75
+ describe '<r:images:unless_images>' do
76
+
77
+ context 'success' do
78
+ it 'should render' do
79
+ mock(Image).all { [] }
80
+ tag = '<r:images><r:unless_images>success</r:unless_images></r:images>'
81
+ exp = 'success'
82
+
83
+ pages(:home).should render(tag).as(exp)
84
+ end
85
+ it 'should render' do
86
+ tag = '<r:images key="title" value="notme"><r:unless_images>success</r:unless_images></r:images>'
87
+ exp = 'success'
88
+
89
+ pages(:home).should render(tag).as(exp)
90
+ end
91
+ end
92
+
93
+ context 'failure' do
94
+ it 'should not render' do
95
+ tag = '<r:images><r:unless_images>failure</r:unless_images></r:images>'
96
+ exp = ''
97
+
98
+ pages(:home).should render(tag).as(exp)
99
+ end
100
+ it 'should not render' do
101
+ tag = '<r:images key="title" value="first"><r:unless_images>failure</r:unless_images></r:images>'
102
+ exp = ''
103
+
104
+ pages(:home).should render(tag).as(exp)
105
+ end
106
+ end
107
+
108
+ end
109
+
110
+ end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Image do
4
4
  dataset :images
@@ -13,7 +13,7 @@ describe Image do
13
13
  end
14
14
 
15
15
  it 'should have a caption' do
16
- @image.caption.should == 'brief description'
16
+ @image.caption.should == "caption for #{@image.title.to_s}"
17
17
  end
18
18
 
19
19
  it 'should require a unique title' do
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: 25
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 1
10
- version: 0.1.1
8
+ - 3
9
+ - 2
10
+ version: 0.3.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - squaretalent
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-16 00:00:00 +08:00
18
+ date: 2010-10-09 00:00:00 +08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -110,6 +110,7 @@ extra_rdoc_files:
110
110
  - README.md
111
111
  files:
112
112
  - .gitignore
113
+ - CHANGELOG
113
114
  - LICENSE
114
115
  - README.md
115
116
  - Rakefile
@@ -130,12 +131,15 @@ files:
130
131
  - cucumber.yml
131
132
  - db/migrate/20100601042237_create_images.rb
132
133
  - db/migrate/20100602044124_add_position_to_images.rb
134
+ - db/migrate/20100929150930_change_images_to_created_by_id.rb
133
135
  - features/support/env.rb
134
136
  - features/support/paths.rb
135
137
  - images_extension.rb
136
138
  - lib/images/interface/admin/images.rb
137
- - lib/images/tags/image.rb
139
+ - lib/images/tags/core.rb
140
+ - lib/images/tags/helpers.rb
138
141
  - lib/tasks/images_extension_tasks.rake
142
+ - public/images/admin/extensions/images/sort.png
139
143
  - public/images/extensions/images/missing_icon.png
140
144
  - public/images/extensions/images/missing_normal.png
141
145
  - public/images/extensions/images/missing_preview.png
@@ -145,7 +149,7 @@ files:
145
149
  - radiant-images-extension.gemspec
146
150
  - spec/controllers/admin/images_controller_spec.rb
147
151
  - spec/datasets/images.rb
148
- - spec/lib/images/tags/image_spec.rb
152
+ - spec/lib/images/tags/core_spec.rb
149
153
  - spec/models/image_spec.rb
150
154
  - spec/spec.opts
151
155
  - spec/spec_helper.rb
@@ -186,6 +190,6 @@ summary: Images Extension for Radiant CMS
186
190
  test_files:
187
191
  - spec/controllers/admin/images_controller_spec.rb
188
192
  - spec/datasets/images.rb
189
- - spec/lib/images/tags/image_spec.rb
193
+ - spec/lib/images/tags/core_spec.rb
190
194
  - spec/models/image_spec.rb
191
195
  - spec/spec_helper.rb