bizarroids_slider 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +57 -0
- data/Rakefile +34 -0
- data/app/controllers/bizarroids/slider/application_controller.rb +4 -0
- data/app/controllers/bizarroids/slider/collections_controller.rb +13 -0
- data/app/controllers/bizarroids/slider/slides_controller.rb +76 -0
- data/app/helpers/bizarroids/slider/application_helper.rb +67 -0
- data/app/helpers/bizarroids/slider/collections_helper.rb +2 -0
- data/app/helpers/bizarroids/slider/slides_helper.rb +9 -0
- data/app/models/bizarroids/slider/collection.rb +38 -0
- data/app/models/bizarroids/slider/slide.rb +17 -0
- data/app/views/bizarroids/slider/collections/index.html.erb +23 -0
- data/app/views/bizarroids/slider/slides/_form.html.erb +11 -0
- data/app/views/bizarroids/slider/slides/edit.html.erb +9 -0
- data/app/views/bizarroids/slider/slides/index.html.erb +47 -0
- data/app/views/bizarroids/slider/slides/new.html.erb +9 -0
- data/config/routes.rb +11 -0
- data/lib/bizarroids/slider/config_error.rb +2 -0
- data/lib/bizarroids/slider/engine.rb +4 -0
- data/lib/bizarroids/slider/media_uploader.rb +35 -0
- data/lib/bizarroids/slider/version.rb +5 -0
- data/lib/bizarroids/slider.rb +93 -0
- data/lib/bizarroids.rb +4 -0
- data/lib/bizarroids_slider.rb +1 -0
- data/lib/generators/bizarroids/slider/install/USAGE +14 -0
- data/lib/generators/bizarroids/slider/install/install_generator.rb +23 -0
- data/lib/generators/bizarroids/slider/install/templates/bizarroids_slider.en.yml +28 -0
- data/lib/generators/bizarroids/slider/install/templates/bizarroids_slider.ru.yml +28 -0
- data/lib/generators/bizarroids/slider/install/templates/initializer.rb +5 -0
- data/lib/generators/bizarroids/slider/install/templates/migration.rb +18 -0
- data/lib/tasks/bizarroids_slider_tasks.rake +4 -0
- data/test/bizarroids_test.rb +7 -0
- data/test/controllers/bizarroids/slider/collections_controller_test.rb +7 -0
- data/test/controllers/bizarroids/slider/slides_controller_test.rb +7 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/controllers/application_controller.rb +11 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/models/ability.rb +10 -0
- data/test/dummy/app/views/layouts/application.html.erb +15 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/config/application.rb +23 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +82 -0
- data/test/dummy/config/environments/test.rb +39 -0
- data/test/dummy/config/initializers/assets.rb +8 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/bizarroids_slider.rb +5 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/bizarroids_slider.en.yml +25 -0
- data/test/dummy/config/locales/bizarroids_slider.ru.yml +25 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +4 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/migrate/20140803134633_create_bizarroids_slider_tables.rb +18 -0
- data/test/dummy/db/schema.rb +36 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/development.log +11010 -0
- data/test/dummy/log/test.log +1624 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/test/dummy/tmp/generators/config/initializers/bizarroids_slider.rb +5 -0
- data/test/dummy/tmp/generators/config/locales/bizarroids_slider.en.yml +28 -0
- data/test/dummy/tmp/generators/config/locales/bizarroids_slider.ru.yml +28 -0
- data/test/dummy/tmp/generators/config/routes.rb +4 -0
- data/test/dummy/tmp/generators/db/migrate/20140807080544_create_bizarroids_slider_tables.rb +18 -0
- data/test/fixtures/bizarroids/slider/collections.yml +11 -0
- data/test/helpers/bizarroids/slider/collections_helper_test.rb +4 -0
- data/test/helpers/bizarroids/slider/slides_helper_test.rb +4 -0
- data/test/integration/navigation_test.rb +10 -0
- data/test/lib/bizarroids/slider_test.rb +57 -0
- data/test/lib/generators/bizarroids/slider/install_generator_test.rb +33 -0
- data/test/models/bizarroids/slider/collection_test.rb +7 -0
- data/test/test_helper.rb +30 -0
- metadata +303 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2160767c527239ed5874415dcece8deb7e13364f
|
4
|
+
data.tar.gz: e87a273adfa8f63fd2981b3c9a729a01096efe6f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4815ed3073aecb0c2099ea6bf36f428985105737dd18547ef768459473b741187fe59ed215b1613fe9ea8c5217999f8c5f72e0a8372bf7dde886f3d5dfa6f7ea
|
7
|
+
data.tar.gz: b8a7ad4bba83eeb09e440799e3939d8146d6144dd6e8cc9ca3647f593eceba274ac4681ce79ce334a1a18da11046152d60b16f1de907674a988c7e4ac1106d73
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2014 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
= Bizarroids Slider
|
2
|
+
|
3
|
+
Bizarroids Slider provides user managable collections of images Rails application. This is a part of The Bizarroids.
|
4
|
+
|
5
|
+
== Installation
|
6
|
+
|
7
|
+
Add it to your Gemfile:
|
8
|
+
|
9
|
+
gem 'bizarroids_slider'
|
10
|
+
|
11
|
+
Run the following command to install it:
|
12
|
+
|
13
|
+
bundle install
|
14
|
+
|
15
|
+
Run the generator:
|
16
|
+
|
17
|
+
rails generate bizarroids:slider:install
|
18
|
+
|
19
|
+
== Configuraton
|
20
|
+
|
21
|
+
Edit +config/initialisers/bizarroids_slider.rb+. You can create collections using folowing syntax:
|
22
|
+
|
23
|
+
config.collections :key, some: :options
|
24
|
+
|
25
|
+
Avaliable options are:
|
26
|
+
|
27
|
+
- slide_attributes: [:name, :description, :media, :link] - (default) you can add columns in migration to use them in this case. Pleas do not remove default columns from database to avoid errors.
|
28
|
+
- slide_require_attributes: [:name, :media] (default) - make attribute required (only default attributes can be marked as required)
|
29
|
+
- versions: { main: {}, thumb: {} } - config of carrierwave image versions. (See corresponging carrierwave documentation)
|
30
|
+
|
31
|
+
Some aditional options can be found in application in +config/initialisers/bizarroids_slider.rb+
|
32
|
+
|
33
|
+
== Usage
|
34
|
+
|
35
|
+
Link to admin panel
|
36
|
+
|
37
|
+
bizarroids_slider_menu_link
|
38
|
+
|
39
|
+
If you use cancancan place in your ability.rb somthing like
|
40
|
+
|
41
|
+
can :manage, Bizarroids::Slider::Option
|
42
|
+
|
43
|
+
if don't, place in +config/initialisers/bizarroids_slider.rb+
|
44
|
+
|
45
|
+
config.use_cancancan = false
|
46
|
+
|
47
|
+
To get collection for :key
|
48
|
+
|
49
|
+
Bizarroids::Slider.get(:key)
|
50
|
+
Bizarroids::Slider[:key]
|
51
|
+
|
52
|
+
Slider provides several helpers
|
53
|
+
|
54
|
+
bizarroids_slider_slides key - returns collection of slides
|
55
|
+
bizarroids_slider_each_slide key - accepts block to iterate
|
56
|
+
|
57
|
+
This project rocks and uses MIT-LICENSE.
|
data/Rakefile
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'BizarroidsSlider'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
|
18
|
+
load 'rails/tasks/engine.rake'
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
Bundler::GemHelper.install_tasks
|
23
|
+
|
24
|
+
require 'rake/testtask'
|
25
|
+
|
26
|
+
Rake::TestTask.new(:test) do |t|
|
27
|
+
t.libs << 'lib'
|
28
|
+
t.libs << 'test'
|
29
|
+
t.pattern = 'test/**/*_test.rb'
|
30
|
+
t.verbose = false
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
task default: :test
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Bizarroids::Slider
|
2
|
+
class CollectionsController < parent_controller.constantize
|
3
|
+
respond_to :html
|
4
|
+
|
5
|
+
if Bizarroids::Slider.use_cancancan
|
6
|
+
authorize_resource class: "Bizarroids::Slider::Collection", param_method: :permitted_params
|
7
|
+
end
|
8
|
+
|
9
|
+
def index
|
10
|
+
@collections = Collection.actual
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module Bizarroids::Slider
|
2
|
+
class SlidesController < parent_controller.constantize
|
3
|
+
respond_to :html
|
4
|
+
before_action :set_collection, only: %i(index new create)
|
5
|
+
before_action :set_slide, only: %i(edit update destroy up down)
|
6
|
+
|
7
|
+
if Bizarroids::Slider.use_cancancan
|
8
|
+
authorize_resource class: "Bizarroids::Slider::Slide", param_method: :slide_params
|
9
|
+
end
|
10
|
+
|
11
|
+
def index
|
12
|
+
@slides = @collection.slides
|
13
|
+
end
|
14
|
+
|
15
|
+
def new
|
16
|
+
@slide = @collection.slides.build
|
17
|
+
end
|
18
|
+
|
19
|
+
def create
|
20
|
+
# remove media from params to hack carrierwave bug
|
21
|
+
@slide = @collection.slides.build slide_params.except(:media)
|
22
|
+
@slide.media = slide_params[:media]
|
23
|
+
|
24
|
+
if @slide.save
|
25
|
+
redirect_to_collection t('bizarroids.slide.slide_created')
|
26
|
+
else
|
27
|
+
render :new
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def edit
|
32
|
+
end
|
33
|
+
|
34
|
+
def update
|
35
|
+
if @slie.update slide_params
|
36
|
+
redirect_to_collection t('bizarroids.slide.slide_updated')
|
37
|
+
else
|
38
|
+
render :edit
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def destroy
|
43
|
+
@slide.destroy
|
44
|
+
redirect_to_collection t('bizarroids.slide.slide_destroyed')
|
45
|
+
end
|
46
|
+
|
47
|
+
def up
|
48
|
+
@slide.move_higher
|
49
|
+
redirect_to_collection
|
50
|
+
end
|
51
|
+
|
52
|
+
def down
|
53
|
+
@slide.move_lower
|
54
|
+
redirect_to_collection
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def set_collection
|
60
|
+
@collection = Collection.find_by! key: params[:collection_id]
|
61
|
+
end
|
62
|
+
|
63
|
+
def set_slide
|
64
|
+
@slide = Slide.find params[:id]
|
65
|
+
@collection = @slide.collection
|
66
|
+
end
|
67
|
+
|
68
|
+
def slide_params
|
69
|
+
params.permit(bizarroids_slider_slide: @collection.slide_attributes)[:bizarroids_slider_slide]
|
70
|
+
end
|
71
|
+
|
72
|
+
def redirect_to_collection msg=''
|
73
|
+
redirect_to bizarroids_slider_engine.slider_collection_slides_path(@collection), notice: msg
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module Bizarroids::Slider
|
2
|
+
module ApplicationHelper
|
3
|
+
# TODO extract to gem
|
4
|
+
def bizarroids_t key
|
5
|
+
t key, scope: :bizarroids
|
6
|
+
end
|
7
|
+
|
8
|
+
# TODO extract to gem
|
9
|
+
def bizarroids_edit_button path
|
10
|
+
bizarroids_button path, :pencil
|
11
|
+
end
|
12
|
+
|
13
|
+
# TODO extract to gem
|
14
|
+
def bizarroids_destroy_button path, confirm_message
|
15
|
+
bizarroids_button path, :trash, method: :delete, data: { confirm: confirm_message }
|
16
|
+
end
|
17
|
+
|
18
|
+
# TODO extract to gem
|
19
|
+
def bizarroids_manage_buttons edit_path, destroy_path, destroy_confirm_message
|
20
|
+
safe_join [
|
21
|
+
bizarroids_edit_button(edit_path),
|
22
|
+
bizarroids_destroy_button(destroy_path, destroy_confirm_message)
|
23
|
+
]
|
24
|
+
end
|
25
|
+
|
26
|
+
# TODO extract to gem
|
27
|
+
def bizarroids_move_buttons up_path, down_path
|
28
|
+
safe_join [
|
29
|
+
bizarroids_button(up_path, :'arrow-up', method: :patch),
|
30
|
+
bizarroids_button(down_path, :'arrow-down', method: :patch)
|
31
|
+
]
|
32
|
+
end
|
33
|
+
|
34
|
+
def bizarroids_slider_menu_link
|
35
|
+
link_to bizarroids_t('slider.name'),
|
36
|
+
bizarroids_slider_engine.slider_collections_path,
|
37
|
+
class: [bizarroids_slider_menu_link_class, 'list-group-item']
|
38
|
+
end
|
39
|
+
|
40
|
+
def bizarroids_slider_menu_link_class
|
41
|
+
bizarroids_slider_menu_link_active? ? :active : nil
|
42
|
+
end
|
43
|
+
|
44
|
+
def bizarroids_slider_menu_link_active?
|
45
|
+
controller.class.parent == Bizarroids::Slider
|
46
|
+
end
|
47
|
+
|
48
|
+
def bizarroids_slider_slides key
|
49
|
+
Bizarroids::Slider[key]
|
50
|
+
end
|
51
|
+
|
52
|
+
def bizarroids_slider_each_slide key
|
53
|
+
Bizarroids::Slider[key].each do |slide|
|
54
|
+
yield slide
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
# TODO extract to gem
|
61
|
+
def bizarroids_button path, icon, link_to_attrs={}
|
62
|
+
link_to path, link_to_attrs, class: 'btn btn-link btn-xs text-primary' do
|
63
|
+
content_tag :span, '', class: "glyphicon glyphicon-#{icon}"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
class Bizarroids::Slider::Collection < ActiveRecord::Base
|
2
|
+
has_many :slides
|
3
|
+
|
4
|
+
validates :key, presence: true, uniqueness: true
|
5
|
+
|
6
|
+
scope :actual, -> { where key: Bizarroids::Slider.keys }
|
7
|
+
default_scope -> { order :position }
|
8
|
+
|
9
|
+
def to_param
|
10
|
+
key
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_key
|
14
|
+
key.to_sym
|
15
|
+
end
|
16
|
+
|
17
|
+
def version_options
|
18
|
+
config_options.fetch :versions, {}
|
19
|
+
end
|
20
|
+
|
21
|
+
def human_name
|
22
|
+
name || key.humanize
|
23
|
+
end
|
24
|
+
|
25
|
+
def slide_attributes
|
26
|
+
config_options.fetch :slide_attributes, Bizarroids::Slider.slide_attributes
|
27
|
+
end
|
28
|
+
|
29
|
+
def slide_require_attributes
|
30
|
+
config_options.fetch :slide_require_attributes, Bizarroids::Slider.slide_require_attributes
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def config_options
|
36
|
+
Bizarroids::Slider.collections[to_key]
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class Bizarroids::Slider::Slide < ActiveRecord::Base
|
2
|
+
belongs_to :collection
|
3
|
+
|
4
|
+
validates :collection, presence: true
|
5
|
+
|
6
|
+
delegate :version_options, to: :collection
|
7
|
+
|
8
|
+
( Bizarroids::Slider::DEFAULT_SLIDE_ATTRIBUTES-[:media] ).each do |attr_name|
|
9
|
+
validates attr_name, presence: true, if: "collection.slide_require_attributes.include? :#{attr_name}"
|
10
|
+
end
|
11
|
+
|
12
|
+
acts_as_list scope: :collection
|
13
|
+
|
14
|
+
default_scope -> { order :position }
|
15
|
+
|
16
|
+
mount_uploader :media, Bizarroids::Slider::MediaUploader
|
17
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
<%= content_for :page_header do %>
|
2
|
+
<h1><%= bizarroids_t 'slider.collections' %></h1>
|
3
|
+
<% end %>
|
4
|
+
|
5
|
+
<table class='table table-bordered table-striped'>
|
6
|
+
<thead>
|
7
|
+
<tr>
|
8
|
+
<th><%= Bizarroids::Slider::Collection.human_attribute_name(:name) %></th>
|
9
|
+
</tr>
|
10
|
+
</thead>
|
11
|
+
<tbody>
|
12
|
+
<% @collections.each do |collection| %>
|
13
|
+
<tr>
|
14
|
+
<td>
|
15
|
+
<%= link_to collection.human_name, bizarroids_slider_engine.slider_collection_slides_path(collection) %>
|
16
|
+
<% if collection.description.present? %>
|
17
|
+
<br/><small><%= collection.description %></small>
|
18
|
+
<% end %>
|
19
|
+
</td>
|
20
|
+
</tr>
|
21
|
+
<% end %>
|
22
|
+
</tbody>
|
23
|
+
</table>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<%= simple_form_for @slide, url: bizarroids_slider_form_submit_path, html: { class: 'form-horizontal' } do |f| %>
|
2
|
+
<% @collection.slide_attributes.each do |attr_name| -%>
|
3
|
+
<%= f.input attr_name, required: @collection.slide_require_attributes.include?(attr_name) %>
|
4
|
+
<% end -%>
|
5
|
+
<div class='form-group'>
|
6
|
+
<div class='col-lg-offset-2 col-lg-10'>
|
7
|
+
<%= f.submit bizarroids_t(:save), class: 'btn btn-primary' %>
|
8
|
+
<%= link_to bizarroids_t(:cancel), bizarroids_slider_engine.slider_collection_slides_path(@collection), class: 'btn btn-link' %>
|
9
|
+
</div>
|
10
|
+
</div>
|
11
|
+
<% end -%>
|
@@ -0,0 +1,47 @@
|
|
1
|
+
<%= content_for :page_header do %>
|
2
|
+
<h1>
|
3
|
+
<%= bizarroids_t 'slider.collection' %>
|
4
|
+
<%= @collection.name %>
|
5
|
+
</h1>
|
6
|
+
<% end %>
|
7
|
+
|
8
|
+
<div class='lead'>
|
9
|
+
<%= link_to bizarroids_t(:'slider.new_slide'), bizarroids_slider_engine.new_slider_collection_slide_path(@collection), class: 'btn btn-success' %>
|
10
|
+
</div>
|
11
|
+
|
12
|
+
<table class='table table-bordered table-striped'>
|
13
|
+
<thead>
|
14
|
+
<tr>
|
15
|
+
<% @collection.slide_require_attributes.each do |attr_name| %>
|
16
|
+
<th><%= Bizarroids::Slider::Slide.human_attribute_name(attr_name) %></th>
|
17
|
+
<% end %>
|
18
|
+
<th class='col-sm-2'> </th>
|
19
|
+
</tr>
|
20
|
+
</thead>
|
21
|
+
<tbody>
|
22
|
+
<% @slides.each do |slide| %>
|
23
|
+
<tr>
|
24
|
+
<% @collection.slide_require_attributes.each do |attr_name| %>
|
25
|
+
<%# TODO link to media %>
|
26
|
+
<td><%= slide.send attr_name %></td>
|
27
|
+
<% end %>
|
28
|
+
<td class='text-right'>
|
29
|
+
<%=
|
30
|
+
bizarroids_move_buttons(
|
31
|
+
bizarroids_slider_engine.up_slider_slide_path(slide),
|
32
|
+
bizarroids_slider_engine.down_slider_slide_path(slide),
|
33
|
+
)
|
34
|
+
%>
|
35
|
+
|
36
|
+
<%=
|
37
|
+
bizarroids_manage_buttons(
|
38
|
+
bizarroids_slider_engine.edit_slider_slide_path(slide),
|
39
|
+
bizarroids_slider_engine.slider_slide_path(slide),
|
40
|
+
bizarroids_t('slider.confirm_slide_destroy')
|
41
|
+
)
|
42
|
+
%>
|
43
|
+
</td>
|
44
|
+
</tr>
|
45
|
+
<% end %>
|
46
|
+
</tbody>
|
47
|
+
</table>
|
data/config/routes.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
class Bizarroids::Slider::MediaUploader < CarrierWave::Uploader::Base
|
4
|
+
include CarrierWave::MiniMagick
|
5
|
+
|
6
|
+
storage :file
|
7
|
+
|
8
|
+
def store_dir
|
9
|
+
File.join Bizarroids::Slider.files_storage_dir, model.collection.key, model.id.to_s
|
10
|
+
end
|
11
|
+
|
12
|
+
version :main do
|
13
|
+
process process_variant: :main
|
14
|
+
end
|
15
|
+
|
16
|
+
version :thumb do
|
17
|
+
process process_variant: :thumb
|
18
|
+
end
|
19
|
+
|
20
|
+
def extension_white_list
|
21
|
+
Bizarroids::Slider.extension_white_list
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def process_variant variant_name
|
27
|
+
if model && model.collection && file
|
28
|
+
processors = model.version_options.fetch variant_name, {}
|
29
|
+
|
30
|
+
processors.each do |method, args|
|
31
|
+
self.send method, *args
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'cancancan'
|
2
|
+
require 'simple_form'
|
3
|
+
require 'acts_as_list'
|
4
|
+
require 'mini_magick'
|
5
|
+
require 'carrierwave'
|
6
|
+
|
7
|
+
require 'bizarroids/slider/engine'
|
8
|
+
require 'bizarroids/slider/config_error'
|
9
|
+
require 'bizarroids/slider/media_uploader'
|
10
|
+
|
11
|
+
module Bizarroids
|
12
|
+
module Slider
|
13
|
+
# name prefix for ActiveRecord
|
14
|
+
def self.table_name_prefix
|
15
|
+
'bizarroids_slider_'
|
16
|
+
end
|
17
|
+
|
18
|
+
DEFAULT_SLIDE_ATTRIBUTES = %i(name description media link).freeze
|
19
|
+
|
20
|
+
def self.get key
|
21
|
+
Collection.actual.find_by!(key: key).slides
|
22
|
+
end
|
23
|
+
|
24
|
+
class << self
|
25
|
+
alias :[] :get
|
26
|
+
end
|
27
|
+
|
28
|
+
mattr_accessor :collections
|
29
|
+
@@collections = {}
|
30
|
+
|
31
|
+
mattr_accessor :keys
|
32
|
+
@@keys = []
|
33
|
+
|
34
|
+
mattr_accessor :slide_attributes
|
35
|
+
@@slide_attributes = %i(name description media link)
|
36
|
+
|
37
|
+
mattr_accessor :slide_require_attributes
|
38
|
+
@@slide_require_attributes = %i(name)
|
39
|
+
|
40
|
+
mattr_accessor :files_storage_dir
|
41
|
+
@@files_storage_dir = 'system/slider/'
|
42
|
+
|
43
|
+
mattr_accessor :extension_white_list
|
44
|
+
@@extension_white_list = %w(jpg jpeg gif png)
|
45
|
+
|
46
|
+
mattr_accessor :parent_controller
|
47
|
+
@@parent_controller = '::ApplicationController'
|
48
|
+
|
49
|
+
mattr_accessor :use_cancancan
|
50
|
+
@@use_cancancan = true
|
51
|
+
|
52
|
+
def self.setup
|
53
|
+
yield self
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def self.collection key, attrs={}
|
59
|
+
key = key.to_sym
|
60
|
+
attrs = attrs.dup
|
61
|
+
|
62
|
+
if keys.include? key
|
63
|
+
raise ConfigError.new "Collection ':#{key}' already exists"
|
64
|
+
end
|
65
|
+
|
66
|
+
collections[key] = attrs
|
67
|
+
keys << key
|
68
|
+
|
69
|
+
# skip creating if table is not exists
|
70
|
+
return unless ActiveRecord::Base.connection.table_exists? Collection.table_name
|
71
|
+
|
72
|
+
attrs[:position] = keys.index(key)
|
73
|
+
|
74
|
+
collection = Collection.find_by key: key
|
75
|
+
|
76
|
+
if collection.present?
|
77
|
+
collection.update_attributes attrs.slice(*update_attr_names)
|
78
|
+
else
|
79
|
+
collection = Collection.create! attrs.merge(key: key).slice(*valid_attr_names)
|
80
|
+
end
|
81
|
+
|
82
|
+
collection
|
83
|
+
end
|
84
|
+
|
85
|
+
def self.valid_attr_names
|
86
|
+
%i(key name description position)
|
87
|
+
end
|
88
|
+
|
89
|
+
def self.update_attr_names
|
90
|
+
valid_attr_names - %i(key)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
data/lib/bizarroids.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bizarroids/slider"
|
@@ -0,0 +1,14 @@
|
|
1
|
+
Description:
|
2
|
+
It will create a migration, initializer and locale files
|
3
|
+
|
4
|
+
Example:
|
5
|
+
rails generate bizarroids:slider:install
|
6
|
+
|
7
|
+
This will create:
|
8
|
+
db/migrate/create_bizarroids_slider_tables.rb
|
9
|
+
config/initialiser/bizarroids_slider.rb
|
10
|
+
config/locales/bizarroids_slider.en.yml
|
11
|
+
config/locales/bizarroids_slider.ru.yml
|
12
|
+
|
13
|
+
This will add:
|
14
|
+
routes to config/routes.rb
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rails/generators/active_record/migration'
|
2
|
+
|
3
|
+
class Bizarroids::Slider::InstallGenerator < Rails::Generators::Base
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
5
|
+
include ActiveRecord::Generators::Migration
|
6
|
+
|
7
|
+
def copy_migration
|
8
|
+
migration_template 'migration.rb', 'db/migrate/create_bizarroids_slider_tables.rb'
|
9
|
+
end
|
10
|
+
|
11
|
+
def create_initalizer
|
12
|
+
initializer 'bizarroids_slider.rb', File.read(File.join(self.class.source_root, 'initializer.rb'))
|
13
|
+
end
|
14
|
+
|
15
|
+
def add_route
|
16
|
+
route "mount Bizarroids::Slider::Engine => '/admin'"
|
17
|
+
end
|
18
|
+
|
19
|
+
def copy_translation_files
|
20
|
+
copy_file "bizarroids_slider.en.yml", "config/locales/bizarroids_slider.en.yml"
|
21
|
+
copy_file "bizarroids_slider.ru.yml", "config/locales/bizarroids_slider.ru.yml"
|
22
|
+
end
|
23
|
+
end
|