refinerycms-slideshow 2.0.10.2 → 2.0.10.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md ADDED
@@ -0,0 +1,17 @@
1
+ ## 2.0.10.2 [2013-09-02]
2
+
3
+ * FIX: Locale picker not available in the back
4
+ * FIX: Duplicates didn't take into account the same slideshow in uniqueness validation
5
+ * FEATURE: Slideshows attached to objects!
6
+
7
+ ## 2.0.10.2 [2013-08-01]
8
+
9
+ * Title method not present but needed in refinery dashboard tab
10
+
11
+ ## 2.0.10.1 [2013-08-01]
12
+
13
+ * Fixed bug with locale files and routes not present in gem.
14
+
15
+ ## 2.0.10.0 [2013-07-31]
16
+
17
+ * Initial version: Slide and slideshow models + Refinery back
data/README.md CHANGED
@@ -10,9 +10,62 @@ Current status
10
10
 
11
11
  The plugin right now includes a backend that allow us to create a slideshow and attach it slides with images, videos and an html body.
12
12
 
13
+ It also includes a way to attach a slideshow to an object and add it to that object's admin.
14
+
15
+
16
+ Attaching an Slideshow to a model
17
+ ===================================
18
+
19
+ To attach an slideshow to a model you must:
20
+
21
+ 1) Generate a migration with an slideshow id field `rails g migration AddSlideshowToModel slideshow_id:integer`
22
+
23
+ 2) Include the slideshow concern into the model and attach the slideshow
24
+
25
+ ```ruby
26
+ class Model < ActiveRecord::Base
27
+
28
+ include Refinery::Slideshow::Concerns::ModelWithSlideShow
29
+
30
+ attach_slideshow :slideshow
31
+
32
+ end
33
+ ```
34
+
35
+ This will use the previously created slideshow_id field to create a `belongs_to` relationship, so if you want another name for your slideshow (e.g. `attach_slideshow :cool_slideshow`) you will have to name your id_field in a different way in the migration (e.g. `rails g migration AddSlideshowToModel cool_slideshow_id:integer`)
36
+
37
+ 3) Use the slides partial in this model's admin:
38
+
39
+ ```ruby
40
+ <%= render 'refinery/slideshow/admin/slides/index', slideshow: f.object.slideshow %>
41
+ ```
42
+
43
+ 4) Depending on your scenary you may (or may not) need to initialize your slideshow attribute. By default, every time you access to the attached slideshow we are creating it:
44
+
45
+ ```ruby
46
+ object_model.slideshow # -> Voilá! We have created one slideshow on DB
47
+ ```
48
+
49
+ But sometimes you don't want this behaviour (e.g. I only want blog posts from some category to include a slideshow). You can achieve this by overwriting a special method in the class called `needs_slideshow?`.
50
+
51
+ ```ruby
52
+
53
+ class Model < ActiveRecord::Base
54
+
55
+ include Refinery::Slideshow::Concerns::ModelWithSlideShow
56
+
57
+ attach_slideshow :slideshow
58
+
59
+ def needs_slideshow?
60
+ # Just return a boolean. True if we must create it, False if we must not
61
+ end
62
+
63
+ end
64
+ ```
65
+
66
+ Again, if you use some different slideshow name (we used previously `cool_slideshow`) this method would be named after that slideshow name (`needs_cool_slideshow?`)
67
+
13
68
  To Do
14
69
  =====
15
70
 
16
- * Attach a slideshow to an object: "This product must have an slideshow", "I want an slideshow in this refinery page"... Imagine if we just can reuse the slideshow admin!
17
-
18
71
  * Some default front helpers: This way we could have a slideshow running without any extra front effort
@@ -1,10 +1,19 @@
1
1
  class Refinery::Slideshow::Slideshow < ActiveRecord::Base
2
- attr_accessible :uid
2
+ attr_accessible :uid, :attached, :attached_type, :attached_id
3
3
 
4
4
  has_many :slides
5
+ belongs_to :attached, polymorphic: true
6
+
7
+ validate :uid_not_blank_if_not_attached
8
+
9
+ def uid_not_blank_if_not_attached
10
+ errors.add(:uid, :blank) if self.uid.blank? && self.attached.nil?
11
+ errors.add(:uid, :taken) if self.attached.nil? && !self.class.where(uid: uid).detect{|s| s != self }.nil?
12
+ end
13
+
14
+
15
+ scope :not_attached, ->() { where(attached_type: nil, attached_id: nil) }
5
16
 
6
- validates :uid, presence: true
7
- validates :uid, uniqueness: true
8
17
 
9
18
  # Needed for the dashboard's activity list
10
19
  def title
@@ -0,0 +1,11 @@
1
+ <input type='hidden' name='switch_locale' id='switch_locale' value='<%= local_assigns[:current_locale] %>' />
2
+ <% if (locales ||= Refinery::I18n.frontend_locales).present? and locales.many? %>
3
+ <ul id='switch_locale_picker' class='clearfix'>
4
+ <% locales.each do |locale| %>
5
+ <li<%= raw(" class='selected'") if locale.to_s == local_assigns[:current_locale].to_s %>>
6
+ <%= link_to refinery_icon_tag("flags/#{locale}.png", :size => "32x22"),
7
+ refinery.url_for(:switch_locale => locale) %>
8
+ </li>
9
+ <% end %>
10
+ </ul>
11
+ <% end %>
@@ -1,4 +1,9 @@
1
1
  <%= form_for [refinery, :slideshow_admin, @slideshow, object], html: {multipart: true} do |f| -%>
2
+
3
+ <%= render "refinery/slideshow/admin/shared/locale_picker",
4
+ :current_locale => Thread.current[:globalize_locale] if Refinery.i18n_enabled? %>
5
+
6
+
2
7
  <%= render '/refinery/admin/error_messages',
3
8
  :object => object,
4
9
  :include_object_name => true %>
@@ -1,7 +1,7 @@
1
1
  <section id='records'>
2
- <%= render 'refinery/slideshow/admin/slides/records', records: records %>
2
+ <%= render 'refinery/slideshow/admin/slides/records', records: slideshow.slides %>
3
3
  </section>
4
4
  <aside id='actions'>
5
- <%= render 'refinery/slideshow/admin/slides/actions', records: records, slideshow: slideshow %>
5
+ <%= render 'refinery/slideshow/admin/slides/actions', records: slideshow.slides, slideshow: slideshow %>
6
6
  </aside>
7
- <%= render '/refinery/admin/make_sortable', :tree => false, update_url: refinery.update_positions_slideshow_admin_slideshow_slides_path(slideshow) if !searching? and controller.class.sortable? and records.count > 1 %>
7
+ <%= render '/refinery/admin/make_sortable', :tree => false, update_url: refinery.update_positions_slideshow_admin_slideshow_slides_path(slideshow) if !searching? and controller.class.sortable? and slideshow.slides.count > 1 %>
@@ -1,6 +1,6 @@
1
1
  <%= render 'refinery/slideshow/admin/slideshows/form', object: @slideshow %>
2
2
 
3
3
  <h2><%= t '.slides' %></h2>
4
- <%= render 'refinery/slideshow/admin/slides/index', records: @slideshow.slides, slideshow: @slideshow %>
4
+ <%= render 'refinery/slideshow/admin/slides/index', slideshow: @slideshow %>
5
5
 
6
6
 
@@ -7,6 +7,8 @@ en:
7
7
  create_new: Create new slide
8
8
  reorder: Reorder
9
9
  reorder_done: Reorder Done
10
+ edit:
11
+ title: Edit slide in slideshow %{slideshow}
10
12
  new:
11
13
  title: "New slide in slideshow '%{slideshow}'"
12
14
  records:
@@ -7,6 +7,8 @@ es:
7
7
  create_new: Crear nueva diapositiva
8
8
  reorder: Reordenar
9
9
  reorder_done: Terminar reordenación
10
+ edit:
11
+ title: Editar diapositiva en carrusel %{slideshow}
10
12
  new:
11
13
  title: "Nueva diapositiva para el carrusel '%{slideshow}'"
12
14
  records:
@@ -0,0 +1,6 @@
1
+ class AddAttachedToSlideshow < ActiveRecord::Migration
2
+ def change
3
+ add_column Refinery::Slideshow::Slideshow.table_name, :attached_type, :string
4
+ add_column Refinery::Slideshow::Slideshow.table_name, :attached_id, :integer
5
+ end
6
+ end
@@ -4,6 +4,7 @@ module Refinery
4
4
 
5
5
  module Slideshow
6
6
  require 'refinery/slideshow/engine'
7
+ require 'refinery/slideshow/concerns'
7
8
  attr_writer :root
8
9
 
9
10
  class << self
@@ -0,0 +1,4 @@
1
+ module Refinery::Slideshow::Concerns
2
+ end
3
+
4
+ require 'refinery/slideshow/concerns/model_with_slideshow'
@@ -0,0 +1,57 @@
1
+ module Refinery::Slideshow::Concerns::ModelWithSlideShow
2
+
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+
7
+ has_many :slideshows, class_name: "Refinery::Slideshow::Slideshow", as: :attached
8
+
9
+ end
10
+
11
+ module ClassMethods
12
+
13
+ def attach_slideshow slideshow_relationship_name
14
+
15
+ # We create the relationship
16
+ belongs_to slideshow_relationship_name, class_name: "Refinery::Slideshow::Slideshow", autosave: true
17
+
18
+ # We create a method to define if this object needs an slideshow. By default it needs it.
19
+ define_method "needs_#{slideshow_relationship_name}?" do
20
+ true
21
+ end
22
+
23
+ # In slideshow accesor we check if this record has no slideshow but should have it, then we create a new slideshow
24
+ define_method "#{slideshow_relationship_name}" do
25
+
26
+ # We try to get the slideshow using the relationship
27
+ local_slideshow = self[slideshow_relationship_name.to_sym]
28
+
29
+ # If slideshow is nil, and the object has been already saved and the object needs an slideshow then we create it
30
+ if local_slideshow.nil? && !self.new_record? && self.send("needs_#{slideshow_relationship_name}?")
31
+ local_slideshow = self.send("build_#{slideshow_relationship_name}", attached: self)
32
+ self[slideshow_relationship_name.to_sym] = local_slideshow
33
+ send "#{slideshow_relationship_name}=", local_slideshow
34
+ self.save
35
+ end
36
+
37
+ local_slideshow
38
+
39
+ end
40
+
41
+ # In slideshow assignation we should attach current object to the slideshow
42
+ define_method "#{slideshow_relationship_name}=" do |slideshow|
43
+ slideshow.attached = self
44
+ super(slideshow)
45
+ end
46
+
47
+ # Before saving we must check if this new slideshow has been created and create it otherwise
48
+ after_save do |record|
49
+ if self.send("needs_#{slideshow_relationship_name}?")
50
+ record.send(slideshow_relationship_name).nil?
51
+ end
52
+ end
53
+ end
54
+
55
+ end
56
+
57
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: refinerycms-slideshow
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.10.2
4
+ version: 2.0.10.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-26 00:00:00.000000000 Z
12
+ date: 2013-09-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: refinerycms-core
@@ -60,7 +60,7 @@ dependencies:
60
60
  - !ruby/object:Gem::Version
61
61
  version: 2.0.10
62
62
  description: RefineryCMS plugin for managing slideshows
63
- email:
63
+ email: david.brenes@the-cocktail.com
64
64
  executables: []
65
65
  extensions: []
66
66
  extra_rdoc_files: []
@@ -77,6 +77,7 @@ files:
77
77
  - app/views/refinery/slideshow/admin/slideshows/_slideshow.html.erb
78
78
  - app/views/refinery/slideshow/admin/slideshows/_form.html.erb
79
79
  - app/views/refinery/slideshow/admin/slideshows/_index.html.erb
80
+ - app/views/refinery/slideshow/admin/shared/_locale_picker.html.erb
80
81
  - app/views/refinery/slideshow/admin/slides/_actions.html.erb
81
82
  - app/views/refinery/slideshow/admin/slides/new.html.erb
82
83
  - app/views/refinery/slideshow/admin/slides/_inner_form.html.erb
@@ -95,14 +96,18 @@ files:
95
96
  - config/locales/en/plugin.yml
96
97
  - config/locales/en/views/admin/slideshows.yml
97
98
  - db/migrate/20130730140608_create_slides.rb
99
+ - db/migrate/20130818180729_add_attached_to_slideshow.rb
98
100
  - db/migrate/20130731111538_add_position_to_slide.rb
99
101
  - db/migrate/20130730083202_create_slideshows.rb
100
102
  - db/migrate/20130730150101_add_translation_to_slide.rb
101
103
  - lib/refinerycms-slideshow.rb
102
104
  - lib/refinery/slideshow/engine.rb
105
+ - lib/refinery/slideshow/concerns.rb
106
+ - lib/refinery/slideshow/concerns/model_with_slideshow.rb
103
107
  - lib/refinery/slideshow.rb
104
108
  - README.md
105
- homepage:
109
+ - CHANGELOG.md
110
+ homepage: https://github.com/simplelogica/refinerycms-slideshow
106
111
  licenses: []
107
112
  post_install_message:
108
113
  rdoc_options: []