refinerycms-image_rotators 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. data/app/controllers/admin/image_rotator_images_controller.rb +26 -0
  2. data/app/controllers/admin/image_rotators_controller.rb +7 -0
  3. data/app/models/image_rotator.rb +13 -0
  4. data/app/models/image_rotator_image.rb +13 -0
  5. data/app/views/admin/image_rotator_images/_form.html.erb +33 -0
  6. data/app/views/admin/image_rotator_images/_image_rotator_image.html.erb +15 -0
  7. data/app/views/admin/image_rotator_images/_sortable_list.html.erb +4 -0
  8. data/app/views/admin/image_rotator_images/edit.html.erb +1 -0
  9. data/app/views/admin/image_rotator_images/new.html.erb +1 -0
  10. data/app/views/admin/image_rotators/_form.html.erb +29 -0
  11. data/app/views/admin/image_rotators/_image_rotator.html.erb +15 -0
  12. data/app/views/admin/image_rotators/_sortable_list.html.erb +4 -0
  13. data/app/views/admin/image_rotators/edit.html.erb +57 -0
  14. data/app/views/admin/image_rotators/index.html.erb +47 -0
  15. data/app/views/admin/image_rotators/new.html.erb +1 -0
  16. data/config/locales/en.yml +34 -0
  17. data/config/locales/nb.yml +19 -0
  18. data/config/locales/nl.yml +19 -0
  19. data/config/routes.rb +11 -0
  20. data/lib/gemspec.rb +27 -0
  21. data/lib/generators/refinerycms_image_rotators_generator.rb +71 -0
  22. data/lib/generators/templates/db/migrate/create_image_rotators.rb +35 -0
  23. data/lib/generators/templates/db/seeds/image_rotators.rb +4 -0
  24. data/lib/generators/templates/public/images/arrows.png +0 -0
  25. data/lib/generators/templates/public/images/bullets.png +0 -0
  26. data/lib/generators/templates/public/images/loading.gif +0 -0
  27. data/lib/generators/templates/public/javascripts/jquery.image-rotators.js +12 -0
  28. data/lib/generators/templates/public/javascripts/refinery/admin.js +1011 -0
  29. data/lib/generators/templates/public/stylesheets/image-rotators.css +138 -0
  30. data/lib/image_rotators.rb +7 -0
  31. data/lib/refinerycms-image_rotators.rb +20 -0
  32. data/lib/tasks/image_rotators.rake +13 -0
  33. data/readme.md +10 -0
  34. metadata +99 -0
@@ -0,0 +1,26 @@
1
+ class Admin::ImageRotatorImagesController < Admin::BaseController
2
+
3
+ before_filter :find_image_rotator
4
+
5
+ crudify :image_rotator_image,
6
+ :title_attribute => 'image.title',
7
+ :sortable => false,
8
+ :redirect_to_url => 'admin_image_rotators_path'
9
+
10
+ def update_positions
11
+ 0.upto((newlist ||= params[:ul]).length - 1) do |index|
12
+ hash = newlist[index.to_s]
13
+ moved_item_id = hash['id'].split(/image_rotator_image_/)
14
+ image = ImageRotatorImage.find_by_id(moved_item_id)
15
+ image.insert_at(index + 1)
16
+ end
17
+
18
+ render :nothing => true
19
+ end
20
+
21
+ def find_image_rotator
22
+ @image_rotator = ImageRotator.find(params[:image_rotator_id])
23
+ end
24
+ private :find_image_rotator
25
+
26
+ end
@@ -0,0 +1,7 @@
1
+ class Admin::ImageRotatorsController < Admin::BaseController
2
+
3
+ before_filter :store_location, :only => [:edit]
4
+
5
+ crudify :image_rotator, :order => 'title ASC'
6
+
7
+ end
@@ -0,0 +1,13 @@
1
+ class ImageRotator < ActiveRecord::Base
2
+
3
+ has_many :images, :class_name => 'ImageRotatorImage'
4
+
5
+ validates :title, :presence => true
6
+ validates :height, :presence => true
7
+ validates :width, :presence => true
8
+
9
+ has_friendly_id :title, :use_slug => true
10
+
11
+ alias_attribute :to_s, :title
12
+
13
+ end
@@ -0,0 +1,13 @@
1
+ class ImageRotatorImage < ActiveRecord::Base
2
+
3
+ belongs_to :image_rotator
4
+ belongs_to :image
5
+
6
+ validates :url, :presence => true
7
+
8
+ acts_as_indexed :fields => [:url]
9
+ acts_as_list
10
+
11
+ default_scope order('position ASC')
12
+
13
+ end
@@ -0,0 +1,33 @@
1
+ <% form_for [:admin, @image_rotator, @image_rotator_image] do |f| -%>
2
+ <%= render :partial => "/shared/admin/error_messages", :locals => {
3
+ :object => @image_rotator_image,
4
+ :include_object_name => true
5
+ } %>
6
+
7
+ <%= f.hidden_field :image_rotator_id, :value => @image_rotator.id %>
8
+
9
+ <div class='field'>
10
+ <%= f.label :image -%>
11
+ <%= render :partial => "/shared/admin/image_picker", :locals => {
12
+ :f => f,
13
+ :field => :image_id,
14
+ :image => @image_rotator_image.image,
15
+ :toggle_image_display => false
16
+ } %>
17
+ </div>
18
+
19
+ <div class='field'>
20
+ <%= f.label :url -%>
21
+ <%= f.text_field :url %>
22
+ </div>
23
+
24
+ <%= render :partial => "/shared/admin/form_actions",
25
+ :locals => {
26
+ :f => f,
27
+ :cancel_url => [:edit, :admin, @image_rotator],
28
+ :delete_url => [:admin, @image_rotator, @image_rotator_image],
29
+ :continue_editing => false,
30
+ :delete_title => t('admin.image_rotators.image_rotator_image.delete'),
31
+ :delete_confirmation => t('shared.admin.delete.message', :title => @image_rotator_image.image.try(:title))
32
+ } %>
33
+ <% end -%>
@@ -0,0 +1,15 @@
1
+ <li class='clearfix record <%= cycle("on", "on-hover") %>' id="<%= dom_id(image_rotator_image) -%>">
2
+ <span class='title'>
3
+ <%= image_fu image_rotator_image.image, '225x255>', :class => "brown_border" %>
4
+ <span class="preview">&nbsp;</span>
5
+ </span>
6
+ <span class='actions'>
7
+ <%= link_to refinery_icon_tag("application_edit.png"), [:edit, :admin, @image_rotator, image_rotator_image],
8
+ :title => t('.edit') %>
9
+ <%= link_to refinery_icon_tag("delete.png"), admin_image_rotator_image_rotator_image_path(image_rotator_image.image_rotator, image_rotator_image),
10
+ :class => "cancel confirm-delete",
11
+ :title => t('.delete'),
12
+ :'data-confirm' => t('shared.admin.delete.message', :title => image_rotator_image.image.title),
13
+ :'data-method' => :delete %>
14
+ </span>
15
+ </li>
@@ -0,0 +1,4 @@
1
+ <ul id='sortable_list'>
2
+ <%= render :partial => '/admin/image_rotator_images/image_rotator_image', :collection => @image_rotator.images %>
3
+ </ul>
4
+ <%= render :partial => "/shared/admin/sortable_list", :locals => {:continue_reordering => (defined?(continue_reordering) ? continue_reordering : true)} %>
@@ -0,0 +1 @@
1
+ <%= render :partial => "form" %>
@@ -0,0 +1 @@
1
+ <%= render :partial => "form" %>
@@ -0,0 +1,29 @@
1
+ <% form_for [:admin, @image_rotator] do |f| -%>
2
+ <%= render :partial => "/shared/admin/error_messages", :locals => {
3
+ :object => @image_rotator,
4
+ :include_object_name => true
5
+ } %>
6
+
7
+ <div class='field'>
8
+ <%= f.label :title -%>
9
+ <%= f.text_field :title -%>
10
+ </div>
11
+
12
+ <div class='field'>
13
+ <%= f.label :height, 'Height of all images' -%>
14
+ <%= f.text_field :height, :value => '240px' -%>
15
+ </div>
16
+
17
+ <div class='field'>
18
+ <%= f.label :width, 'Width of all images' -%>
19
+ <%= f.text_field :width, :value => '725px' -%>
20
+ </div>
21
+
22
+ <%= render :partial => "/shared/admin/form_actions",
23
+ :locals => {
24
+ :f => f,
25
+ :continue_editing => false,
26
+ :delete_title => t('admin.image_rotators.image_rotator.delete'),
27
+ :delete_confirmation => t('shared.admin.delete.message')
28
+ } %>
29
+ <% end -%>
@@ -0,0 +1,15 @@
1
+ <li class='clearfix record <%= cycle("on", "on-hover") %>' id="<%= dom_id(image_rotator) -%>">
2
+ <span class='title'>
3
+ <%= image_rotator %>
4
+ <span class="preview">&nbsp;</span>
5
+ </span>
6
+ <span class='actions'>
7
+ <%= link_to refinery_icon_tag("application_edit.png"), edit_admin_image_rotator_path(image_rotator),
8
+ :title => t('.edit') %>
9
+ <%= link_to refinery_icon_tag("delete.png"), admin_image_rotator_path(image_rotator),
10
+ :class => "cancel confirm-delete",
11
+ :title => t('.delete'),
12
+ :'data-confirm' => t('shared.admin.delete.message'),
13
+ :'data-method' => :delete %>
14
+ </span>
15
+ </li>
@@ -0,0 +1,4 @@
1
+ <ul id='sortable_list'>
2
+ <%= render :partial => 'image_rotator', :collection => @image_rotators %>
3
+ </ul>
4
+ <%= render :partial => "/shared/admin/sortable_list", :locals => {:continue_reordering => (defined?(continue_reordering) ? continue_reordering : true)} %>
@@ -0,0 +1,57 @@
1
+ <%= render :partial => "form" %>
2
+
3
+ <div id="actions">
4
+ <ul>
5
+ <li>
6
+ <%= link_to t('.add_image'), new_admin_image_rotator_image_rotator_image_url(@image_rotator),
7
+ :class => "add_icon" %>
8
+ </li>
9
+ <% if @image_rotator.images.count > 1 %>
10
+ <li>
11
+ <%= link_to t('.reorder', :what => "Image Rotators"),
12
+ [:admin, @image_rotator, :image_rotator_images],
13
+ :id => "reorder_action",
14
+ :class => "reorder_icon" %>
15
+
16
+ <%= link_to t('.reorder_done', :what => "Image Rotators"),
17
+ [:admin, @image_rotator, :image_rotator_images],
18
+ :id => "reorder_action_done",
19
+ :style => "display: none;",
20
+ :class => "reorder_icon" %>
21
+ </li>
22
+ <% end %>
23
+ </div>
24
+
25
+ <div id='records'>
26
+ <% if @image_rotator.images.any? %>
27
+ <%= render :partial => "/admin/image_rotator_images/sortable_list" %>
28
+ <label>To use this image rotator, embed the following code into the desired page:</label>
29
+ <pre style="overflow-x: auto;"><code>
30
+ &lt;div class="image-rotator" style="height:<%= @image_rotator.height %>;width:<%= @image_rotator.width %>;"&gt;
31
+ <% @image_rotator.images.each do |image| %>
32
+ &lt;a href="<%= image.url %>"&gt;&lt;img src="<%= image.image.url %>" alt="<%= image.image.title %>" /&gt;
33
+ <% end %>
34
+ &lt;/div&gt;
35
+ </code></pre>
36
+ <% else %>
37
+ <p>
38
+ <strong>
39
+ <%= t('.no_items_yet') %>
40
+ </strong>
41
+ </p>
42
+ <% end %>
43
+ </div>
44
+ <% if @image_rotator.images.count > 1 %>
45
+ <% content_for :head_after_javascript_libraries,
46
+ javascript_include_tag('refinery/serializelist.js') -%>
47
+ <% content_for :head do %>
48
+ <script type='text/javascript'>
49
+ $(document).ready(function(){
50
+ list_reorder.update_url = '<%= update_positions_admin_image_rotator_image_rotator_images_path(@image_rotator) %>';
51
+ list_reorder.sortable_list = $('#sortable_list');
52
+ list_reorder.tree = false;
53
+ list_reorder.init();
54
+ });
55
+ </script>
56
+ <% end %>
57
+ <% end %>
@@ -0,0 +1,47 @@
1
+ <div id='actions'>
2
+ <ul>
3
+ <li>
4
+ <%= render :partial => "/shared/admin/search",
5
+ :locals => {
6
+ :url => admin_image_rotators_url
7
+ } %>
8
+ </li>
9
+ <li>
10
+ <%= link_to t('.create_new'), new_admin_image_rotator_url,
11
+ :class => "add_icon" %>
12
+ </li>
13
+ </ul>
14
+ </div>
15
+ <div id='records'>
16
+ <% if searching? %>
17
+ <h2><%= t('shared.admin.search.results_for', :query => params[:search]) %></h2>
18
+ <% if @image_rotators.any? %>
19
+ <%= will_paginate @image_rotators, :previous_label => '&laquo;', :next_label => '&raquo;' %>
20
+ <ul>
21
+ <%= render :partial => "image_rotator",
22
+ :collection => @image_rotators %>
23
+ </ul>
24
+ <%= will_paginate @image_rotators, :previous_label => '&laquo;', :next_label => '&raquo;' %>
25
+ <% else %>
26
+ <p><%= t('shared.admin.search.no_results') %></p>
27
+ <% end %>
28
+ <% else %>
29
+ <% if @image_rotators.any? %>
30
+ <%= will_paginate @image_rotators,
31
+ :previous_label => '&laquo;',
32
+ :next_label => '&raquo;' %>
33
+
34
+ <%= render :partial => "sortable_list" %>
35
+
36
+ <%= will_paginate @image_rotators,
37
+ :previous_label => '&laquo;',
38
+ :next_label => '&raquo;' %>
39
+ <% else %>
40
+ <p>
41
+ <strong>
42
+ <%= t('.no_items_yet') %>
43
+ </strong>
44
+ </p>
45
+ <% end %>
46
+ <% end %>
47
+ </div>
@@ -0,0 +1 @@
1
+ <%= render :partial => "form" %>
@@ -0,0 +1,34 @@
1
+ en:
2
+ shared:
3
+ admin:
4
+ image_picker:
5
+ image: image
6
+ plugins:
7
+ image_rotators:
8
+ title: Image Rotators
9
+ admin:
10
+ image_rotators:
11
+ index:
12
+ create_new: Create a new Image Rotator
13
+ reorder: Reorder Image Rotators
14
+ reorder_done: Done Reordering Image Rotators
15
+ sorry_no_results: Sorry! There are no results found.
16
+ no_items_yet: There are no Image Rotators yet. Click "Create a new Image Rotator" to add your first image rotator.
17
+ edit:
18
+ add_image: Add a new Image
19
+ reorder: Reorder Images
20
+ reorder_done: Done Reordering Images
21
+ no_items_yet: There are no Images yet. Click "Add a new Image" to add your first image.
22
+ image_rotator:
23
+ view_live: View this image rotator live <br/><em>(opens in a new window)</em>
24
+ edit: Edit this image rotator
25
+ delete: Remove this image rotator forever
26
+ image_rotator_image:
27
+ delete: Remove this image forever
28
+ image_rotator_images:
29
+ image_rotator_image:
30
+ edit: Edit this image
31
+ delete: Remove this image forever
32
+ image_rotators:
33
+ show:
34
+ other: Other Image Rotators
@@ -0,0 +1,19 @@
1
+ nb:
2
+ plugins:
3
+ image_rotators:
4
+ title: Image Rotators
5
+ admin:
6
+ image_rotators:
7
+ index:
8
+ create_new: Lag en ny Image Rotator
9
+ reorder: Endre rekkefølgen på Image Rotators
10
+ reorder_done: Ferdig å endre rekkefølgen Image Rotators
11
+ sorry_no_results: Beklager! Vi fant ikke noen resultater.
12
+ no_items_yet: Det er ingen Image Rotators enda. Klikk på "Lag en ny Image Rotator" for å legge til din første image rotator.
13
+ image_rotator:
14
+ view_live: Vis hvordan denne image rotator ser ut offentlig <br/><em>(åpner i et nytt vindu)</em>
15
+ edit: Rediger denne image rotator
16
+ delete: Fjern denne image rotator permanent
17
+ image_rotators:
18
+ show:
19
+ other: Andre Image Rotators
@@ -0,0 +1,19 @@
1
+ nl:
2
+ plugins:
3
+ image_rotators:
4
+ title: Image Rotators
5
+ admin:
6
+ image_rotators:
7
+ index:
8
+ create_new: Maak een nieuwe Image Rotator
9
+ reorder: Wijzig de volgorde van de Image Rotators
10
+ reorder_done: Klaar met het wijzingen van de volgorde van de Image Rotators
11
+ sorry_no_results: Helaas! Er zijn geen resultaten gevonden.
12
+ no_items_yet: Er zijn nog geen Image Rotators. Druk op 'Maak een nieuwe Image Rotator' om de eerste aan te maken.
13
+ image_rotator:
14
+ view_live: Bekijk deze image rotator op de website <br/><em>(opent een nieuw venster)</em>
15
+ edit: Bewerk deze image rotator
16
+ delete: Verwijder deze image rotator voor eeuwig
17
+ image_rotators:
18
+ show:
19
+ other: Andere Image Rotators
data/config/routes.rb ADDED
@@ -0,0 +1,11 @@
1
+ Refinery::Application.routes.draw do
2
+ scope(:path => 'refinery', :as => 'admin', :module => 'admin') do
3
+ resources :image_rotators do
4
+ resources :image_rotator_images, :only => %w(new create edit update destroy) do
5
+ collection do
6
+ post :update_positions
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
data/lib/gemspec.rb ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../image_rotators', __FILE__)
3
+ version = ::Refinery::ImageRotators.version
4
+ raise "Could not get version so gemspec can not be built" if version.nil?
5
+ files = Dir.glob("**/*").flatten.reject do |file|
6
+ file =~ /\.gem(spec)?$/
7
+ end
8
+
9
+ gemspec = <<EOF
10
+ Gem::Specification.new do |s|
11
+ s.name = %q{refinerycms-image_rotators}
12
+ s.version = %q{#{version}}
13
+ s.description = %q{An open source Ruby on Rails image rotator engine designed for integration with RefineryCMS.}
14
+ s.date = %q{#{Time.now.strftime('%Y-%m-%d')}}
15
+ s.summary = %q{Ruby on Rails image rotator engine for RefineryCMS.}
16
+ s.email = %q{jacob@envylabs.com}
17
+ s.homepage = %q{http://envylabs.com}
18
+ s.authors = %w(Jacob\\ Swanner)
19
+ s.require_paths = %w(lib)
20
+
21
+ s.files = [
22
+ '#{files.join("',\n '")}'
23
+ ]
24
+ end
25
+ EOF
26
+
27
+ File.open(File.expand_path("../../refinerycms-image_rotators.gemspec", __FILE__), 'w').puts(gemspec)
@@ -0,0 +1,71 @@
1
+ require 'rails/generators/migration'
2
+
3
+ class RefinerycmsImageRotatorsGenerator < Rails::Generators::NamedBase
4
+ include Rails::Generators::Migration
5
+
6
+ source_root File.expand_path('../templates/', __FILE__)
7
+ argument :name, :type => :string, :default => 'image_rotators', :banner => ''
8
+ argument :attributes, :type => :array, :default => ["name:string"]
9
+
10
+ def generate
11
+ migration_template('db/migrate/create_image_rotators.rb', 'db/migrate/create_image_rotators.rb')
12
+ %w(
13
+ db/seeds/image_rotators.rb
14
+ public/images/arrows.png
15
+ public/images/bullets.png
16
+ public/images/loading.gif
17
+ public/javascripts/jquery.image-rotators.js
18
+ public/javascripts/refinery/admin.js
19
+ public/stylesheets/image-rotators.css
20
+ ).each { |path| copy_file path, Rails.root.join(path) }
21
+
22
+ puts <<-EOS
23
+ ------------------------
24
+ Now run:
25
+ rake db:migrate
26
+ ------------------------
27
+ Put the following in your layout:
28
+ stylesheet_link_tag 'image-rotators.css'
29
+ javascript_include_tag 'jquery.image-rotators.js'
30
+ ------------------------
31
+ EOS
32
+ end
33
+
34
+ # Implement the required interface for Rails::Generators::Migration.
35
+ def self.next_migration_number(dirname) #:nodoc:
36
+ next_migration_number = current_migration_number(dirname) + 1
37
+ if ActiveRecord::Base.timestamped_migrations
38
+ [Time.now.utc.strftime("%Y%m%d%H%M%S"), "%.14d" % next_migration_number].max
39
+ else
40
+ "%.3d" % next_migration_number
41
+ end
42
+ end
43
+
44
+ end
45
+
46
+ # Below is a hack until this issue:
47
+ # https://rails.lighthouseapp.com/projects/8994/tickets/3820-make-railsgeneratorsmigrationnext_migration_number-method-a-class-method-so-it-possible-to-use-it-in-custom-generators
48
+ # is fixed on the Rails project.
49
+
50
+ require 'rails/generators/named_base'
51
+ require 'rails/generators/migration'
52
+ require 'rails/generators/active_model'
53
+ require 'active_record'
54
+
55
+ module ActiveRecord
56
+ module Generators
57
+ class Rails::Generators::NamedBase #:nodoc:
58
+ include Rails::Generators::Migration
59
+
60
+ # Implement the required interface for Rails::Generators::Migration.
61
+ def self.next_migration_number(dirname) #:nodoc:
62
+ next_migration_number = current_migration_number(dirname) + 1
63
+ if ActiveRecord::Base.timestamped_migrations
64
+ [Time.now.utc.strftime("%Y%m%d%H%M%S"), "%.14d" % next_migration_number].max
65
+ else
66
+ "%.3d" % next_migration_number
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end