comfy_carousel 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -22,6 +22,8 @@ This gem comes bundled with [slides.jquery.js](http://slidesjs.com/) that you ca
22
22
 
23
23
  ## Usage
24
24
 
25
+ You'll notice that carousels have `dimensions` field. You can force-resize uploaded images via ImageMagic values. For example: `300x200#` will resize any image to be 300px wide and 200px in height. Also it will crop image if necessary.
26
+
25
27
  There's nothing on the front-end really. You have access to `Carousel::Carousel` objects that in turn can be used to access their slides. Like so:
26
28
 
27
29
  @carousel = Carousel::Carousel.find_by_identifier('my_carousel')
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
@@ -50,7 +50,8 @@ class Admin::Carousel::SlidesController < Admin::Carousel::BaseController
50
50
  protected
51
51
 
52
52
  def build_slide
53
- @slide = @carousel.slides.new(params[:slide])
53
+ # Yes, this is terrible. Thank paperclip for that.
54
+ @slide = Carousel::Slide.new({:carousel => @carousel}.merge(params[:slide] || {}))
54
55
  end
55
56
 
56
57
  def load_slide
@@ -1,8 +1,20 @@
1
1
  class Carousel::Slide < ActiveRecord::Base
2
2
 
3
+ IMAGE_MIMETYPES = %w(gif jpeg pjpeg png svg+xml tiff).collect{|subtype| "image/#{subtype}"}
4
+
3
5
  self.table_name = :carousel_slides
4
6
 
5
- has_attached_file :file
7
+ upload_options = (ComfyCarousel.config.upload_options || {}).merge(
8
+ :styles => lambda { |slide|
9
+ if c = slide.instance.carousel && dimentions = c.try(:dimentions)
10
+ { :original => dimentions }
11
+ else
12
+ { }
13
+ end
14
+ }
15
+ )
16
+ has_attached_file :file, upload_options
17
+ before_post_process :is_image?
6
18
 
7
19
  # -- Relationships --------------------------------------------------------
8
20
  belongs_to :carousel
@@ -17,6 +29,11 @@ class Carousel::Slide < ActiveRecord::Base
17
29
  # -- Scopes ---------------------------------------------------------------
18
30
  default_scope order('carousel_slides.position')
19
31
 
32
+ # -- Instance Methods -----------------------------------------------------
33
+ def is_image?
34
+ IMAGE_MIMETYPES.include?(file_content_type)
35
+ end
36
+
20
37
  protected
21
38
 
22
39
  def assign_position
@@ -1,4 +1,5 @@
1
1
  <%= form.text_field :label, :id => (@carousel.new_record?? 'slugify' : nil) %>
2
2
  <%= form.text_field :identifier, :id => 'slug' %>
3
+ <%= form.text_field :dimensions %>
3
4
 
4
- <%= form.submit (@carousel.new_record? ? 'Create Carousel' : 'Update Carousel') %>
5
+ <%= form.submit @carousel.new_record?? 'Create Carousel' : 'Update Carousel' %>
@@ -1,6 +1,12 @@
1
1
  <%= form.text_field :label %>
2
2
  <%= form.text_area :content %>
3
3
  <%= form.text_field :url %>
4
+
5
+ <% if @slide.file? && !@slide.new_record? %>
6
+ <%= form.simple_field 'Current Image' do %>
7
+ <%= image_tag @slide.file.url %>
8
+ <% end %>
9
+ <% end %>
4
10
  <%= form.file_field :file %>
5
11
 
6
12
  <% if defined?(ComfortableMexicanSofa) %>
@@ -10,4 +16,4 @@
10
16
  <%= cms_hook :carousel_slide, :locals => { :form => form } %>
11
17
  <% end %>
12
18
 
13
- <%= form.submit (@slide.new_record? ? 'Create Slide' : 'Update Slide') %>
19
+ <%= form.submit @slide.new_record?? 'Create Slide' : 'Update Slide' %>
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "comfy_carousel"
8
- s.version = "0.0.1"
8
+ s.version = "0.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Oleg Khabarov", "The Working Group Inc."]
@@ -4,6 +4,7 @@ class CreateComfyCarousel < ActiveRecord::Migration
4
4
  create_table :carousel_carousels do |t|
5
5
  t.string :label, :null => false
6
6
  t.string :identifier, :null => false
7
+ t.string :dimensions
7
8
  t.timestamps
8
9
  end
9
10
  add_index :carousel_carousels, :identifier
@@ -16,6 +16,7 @@ ActiveRecord::Schema.define(:version => 1) do
16
16
  create_table "carousel_carousels", :force => true do |t|
17
17
  t.string "label", :null => false
18
18
  t.string "identifier", :null => false
19
+ t.string "dimensions"
19
20
  t.datetime "created_at", :null => false
20
21
  t.datetime "updated_at", :null => false
21
22
  end
@@ -11,11 +11,15 @@ module ComfyCarousel
11
11
  # Form builder
12
12
  attr_accessor :form_builder
13
13
 
14
+ # Paperclip upload settings for photos
15
+ attr_accessor :upload_options
16
+
14
17
  # Configuration defaults
15
18
  def initialize
16
- @admin_route_prefix = 'admin'
17
- @admin_controller = 'ApplicationController'
18
- @form_builder = 'ComfyCarousel::FormBuilder'
19
+ @admin_route_prefix = 'admin'
20
+ @admin_controller = 'ApplicationController'
21
+ @form_builder = 'ComfyCarousel::FormBuilder'
22
+ @upload_options = { }
19
23
  end
20
24
 
21
25
  end
@@ -10,6 +10,7 @@ module ComfyCarousel
10
10
  conf.admin_route_prefix = ComfortableMexicanSofa.config.admin_route_prefix
11
11
  conf.admin_controller = 'CmsAdmin::BaseController'
12
12
  conf.form_builder = 'ComfortableMexicanSofa::FormBuilder'
13
+ conf.upload_options = ComfortableMexicanSofa.config.upload_file_options
13
14
  end
14
15
  # Adding view hooks
15
16
  ComfortableMexicanSofa::ViewHooks.add(:navigation, '/admin/carousel/navigation')
@@ -1,3 +1,4 @@
1
1
  default:
2
2
  label: Default
3
- identifier: default
3
+ identifier: default
4
+ dimensions:
@@ -15,9 +15,10 @@ class ActiveSupport::TestCase
15
15
  # resetting default configuration
16
16
  def reset_config
17
17
  ComfyCarousel.configure do |config|
18
- config.admin_route_prefix = 'admin'
19
- config.admin_controller = 'ApplicationController'
20
- config.form_builder = 'ComfyCarousel::FormBuilder'
18
+ config.admin_route_prefix = 'admin'
19
+ config.admin_controller = 'ApplicationController'
20
+ config.form_builder = 'ComfyCarousel::FormBuilder'
21
+ config.upload_options = { }
21
22
  end
22
23
  end
23
24
 
@@ -4,9 +4,10 @@ class ConfigurationTest < ActiveSupport::TestCase
4
4
 
5
5
  def test_configuration
6
6
  assert config = ComfyCarousel.configuration
7
- assert_equal 'admin', config.admin_route_prefix
8
- assert_equal 'ApplicationController', config.admin_controller
7
+ assert_equal 'admin', config.admin_route_prefix
8
+ assert_equal 'ApplicationController', config.admin_controller
9
9
  assert_equal 'ComfyCarousel::FormBuilder', config.form_builder
10
+ assert_equal ({}), config.upload_options
10
11
  end
11
12
 
12
13
  def test_initialization_overrides
@@ -15,15 +15,25 @@ class SlideTest < ActiveSupport::TestCase
15
15
  end
16
16
 
17
17
  def test_creation
18
+ carousel = carousel_carousels(:default)
18
19
  assert_difference 'Carousel::Slide.count' do
19
- slide = carousel_carousels(:default).slides.create(
20
+ slide = carousel.slides.create(
20
21
  :label => 'Test',
21
22
  :content => 'Test Content',
22
23
  :url => 'http://google.com',
23
24
  :file => fixture_file_upload('files/image.jpg', 'image/jpeg')
24
25
  )
25
26
  assert_equal 1, slide.position
27
+ assert_equal carousel, slide.carousel
26
28
  end
27
29
  end
28
30
 
31
+ def test_is_image?
32
+ slide = carousel_slides(:default)
33
+ assert slide.is_image?
34
+
35
+ slide.update_attribute(:file_content_type, 'application/pdf')
36
+ assert !slide.is_image?
37
+ end
38
+
29
39
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: comfy_carousel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -14,7 +14,7 @@ date: 2012-02-07 00:00:00.000000000Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
17
- requirement: &70348692094640 !ruby/object:Gem::Requirement
17
+ requirement: &70281782162840 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 3.1.0
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70348692094640
25
+ version_requirements: *70281782162840
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: jquery-rails
28
- requirement: &70348692091400 !ruby/object:Gem::Requirement
28
+ requirement: &70281782162080 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: 1.0.0
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *70348692091400
36
+ version_requirements: *70281782162080
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: paperclip
39
- requirement: &70348692083860 !ruby/object:Gem::Requirement
39
+ requirement: &70281782161380 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,7 +44,7 @@ dependencies:
44
44
  version: 2.3.0
45
45
  type: :runtime
46
46
  prerelease: false
47
- version_requirements: *70348692083860
47
+ version_requirements: *70281782161380
48
48
  description: ''
49
49
  email: oleg@twg.ca
50
50
  executables: []
@@ -135,7 +135,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
135
135
  version: '0'
136
136
  segments:
137
137
  - 0
138
- hash: -1820114394021651927
138
+ hash: -4170429523828767881
139
139
  required_rubygems_version: !ruby/object:Gem::Requirement
140
140
  none: false
141
141
  requirements: