ecm_sliders2 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +35 -0
  4. data/Rakefile +27 -0
  5. data/app/helpers/ecm/sliders_helper.rb +10 -0
  6. data/app/helpers/markup_helper.rb +7 -0
  7. data/app/models/ecm/sliders/item.rb +36 -0
  8. data/app/models/ecm/sliders/slider.rb +40 -0
  9. data/app/views/ecm/sliders/sliders/_slider.haml +3 -0
  10. data/config/locales/de.yml +52 -0
  11. data/config/locales/en.yml +52 -0
  12. data/config/routes.rb +6 -0
  13. data/db/migrate/001_create_ecm_sliders_sliders.rb +14 -0
  14. data/db/migrate/002_create_ecm_sliders_items.rb +14 -0
  15. data/lib/ecm/sliders/configuration.rb +23 -0
  16. data/lib/ecm/sliders/engine.rb +7 -0
  17. data/lib/ecm/sliders/routing.rb +14 -0
  18. data/lib/ecm/sliders/version.rb +6 -0
  19. data/lib/ecm_sliders2.rb +17 -0
  20. data/lib/generators/ecm/sliders/install/install_generator.rb +21 -0
  21. data/lib/generators/ecm/sliders/install/templates/initializer.rb +39 -0
  22. data/lib/generators/ecm/sliders/install/templates/routes.source +5 -0
  23. data/lib/tasks/ecm_sliders_tasks.rake +67 -0
  24. data/spec/controllers/ecm/sliders/sliders_controller_spec.rb +23 -0
  25. data/spec/dummy/README.rdoc +261 -0
  26. data/spec/dummy/Rakefile +7 -0
  27. data/spec/dummy/app/admin/admin_users.rb +20 -0
  28. data/spec/dummy/app/admin/dashboards.rb +33 -0
  29. data/spec/dummy/app/assets/javascripts/active_admin.js +1 -0
  30. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  31. data/spec/dummy/app/assets/javascripts/bootstrap.min.js +6 -0
  32. data/spec/dummy/app/assets/stylesheets/active_admin.css.scss +29 -0
  33. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  34. data/spec/dummy/app/assets/stylesheets/bootstrap.min.css +727 -0
  35. data/spec/dummy/app/assets/stylesheets/ecm.sliders.css +9 -0
  36. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  37. data/spec/dummy/app/helpers/application_helper.rb +7 -0
  38. data/spec/dummy/app/models/admin_user.rb +11 -0
  39. data/spec/dummy/app/views/layouts/application.html.erb +37 -0
  40. data/spec/dummy/config.ru +4 -0
  41. data/spec/dummy/config/application.rb +69 -0
  42. data/spec/dummy/config/boot.rb +10 -0
  43. data/spec/dummy/config/database.yml +25 -0
  44. data/spec/dummy/config/environment.rb +5 -0
  45. data/spec/dummy/config/environments/development.rb +37 -0
  46. data/spec/dummy/config/environments/production.rb +67 -0
  47. data/spec/dummy/config/environments/test.rb +37 -0
  48. data/spec/dummy/config/initializers/active_admin.rb +154 -0
  49. data/spec/dummy/config/initializers/active_admin_footer_patch.rb +12 -0
  50. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  51. data/spec/dummy/config/initializers/devise.rb +232 -0
  52. data/spec/dummy/config/initializers/ecm_sliders.rb +39 -0
  53. data/spec/dummy/config/initializers/inflections.rb +15 -0
  54. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  55. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  56. data/spec/dummy/config/initializers/session_store.rb +8 -0
  57. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  58. data/spec/dummy/config/locales/de.yml +163 -0
  59. data/spec/dummy/config/locales/devise.en.yml +58 -0
  60. data/spec/dummy/config/locales/en.yml +5 -0
  61. data/spec/dummy/config/routes.rb +65 -0
  62. data/spec/dummy/db/migrate/20120922100801_create_ecm_sliders_sliders.ecm_sliders_engine.rb +20 -0
  63. data/spec/dummy/db/migrate/20120922100802_create_ecm_sliders_items.ecm_sliders_engine.rb +25 -0
  64. data/spec/dummy/db/migrate/20120922105221_devise_create_admin_users.rb +52 -0
  65. data/spec/dummy/db/migrate/20120922105247_create_admin_notes.rb +17 -0
  66. data/spec/dummy/db/migrate/20120922105248_move_admin_notes_to_comments.rb +25 -0
  67. data/spec/dummy/db/schema.rb +75 -0
  68. data/spec/dummy/lib/locale_generator.rb +194 -0
  69. data/spec/dummy/lib/tasks/stub_locales.rake +32 -0
  70. data/spec/dummy/public/404.html +26 -0
  71. data/spec/dummy/public/422.html +26 -0
  72. data/spec/dummy/public/500.html +25 -0
  73. data/spec/dummy/public/favicon.ico +0 -0
  74. data/spec/dummy/script/rails +6 -0
  75. data/spec/factories/ecm/sliders/items.rb +14 -0
  76. data/spec/factories/ecm/sliders/sliders.rb +10 -0
  77. data/spec/features/ecm/sliders/slider_items_admin_spec.rb +172 -0
  78. data/spec/features/ecm/sliders/sliders_admin_spec.rb +170 -0
  79. data/spec/files/ecm/sliders/items/example.png +0 -0
  80. data/spec/helpers/ecm/sliders_helper_spec.rb +36 -0
  81. data/spec/models/ecm/sliders/item_spec.rb +49 -0
  82. data/spec/models/ecm/sliders/slider_spec.rb +97 -0
  83. data/spec/models/generic_spec.rb +34 -0
  84. data/spec/requests/ecm/sliders/sliders_spec.rb +28 -0
  85. data/spec/routing/ecm/sliders/routes_spec.rb +11 -0
  86. data/spec/spec_helper.rb +38 -0
  87. data/spec/support/active_admin/sign_in_helper.rb +18 -0
  88. data/spec/support/capybara.rb +1 -0
  89. data/spec/support/factory_girl.rb +6 -0
  90. data/spec/support/ffaker.rb +1 -0
  91. data/spec/support/shoulda.rb +1 -0
  92. data/spec/views/ecm/sliders/sliders/index_spec.rb +20 -0
  93. metadata +344 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1758acc71f049bedfe4b8a8d5209d0fe4b13589e
4
+ data.tar.gz: 20f3e9c9fe308139155bb2bad8e2e53b91dcfc91
5
+ SHA512:
6
+ metadata.gz: 586ad8bad0b2894c82c444306d40c0b642b21bd76a6a591fc94e9b7ecdb46ef446377b644448580d3435bc8edff67a7559a2f59750d75e3d3a3c6e82d4357617
7
+ data.tar.gz: e2016365ac263fcc1df5c4f66f26a19a57e1a2ef863785444d141fd374f5260ee0b2cd2f1c572047f77033336ef38869c8b9ca9a59899be6a56078a146aa4919
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2012 Roberto Vasquez Angel
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,35 @@
1
+ = ECM Sliders
2
+
3
+ = Installation
4
+
5
+ Add it to your bundle:
6
+
7
+ # Gemfile
8
+ gem 'ecm_sliders2'
9
+
10
+ Update your bundle:
11
+
12
+ > bundle install
13
+
14
+ Install the module:
15
+
16
+ > rails g ecm:sliders:install
17
+
18
+ Create migrations:
19
+
20
+ > rake ecm_sliders_engine:install:migrations
21
+
22
+ Migrate:
23
+
24
+ > rake db:migrate
25
+
26
+ = Usage
27
+
28
+ Use the helper to display a slider:
29
+
30
+ <%= render_slider 'My Slider' %>
31
+
32
+ = License
33
+
34
+ This project rocks and uses MIT-LICENSE.
35
+
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'ECM Sliders 2'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+
24
+
25
+
26
+ Bundler::GemHelper.install_tasks
27
+
@@ -0,0 +1,10 @@
1
+ module Ecm::SlidersHelper
2
+ def render_slider(name, options = {})
3
+ slider = Ecm::Sliders::Slider.where(name: name.to_s).for_locale(I18n.locale).first
4
+ if slider.nil?
5
+ return I18n.t('ecm.sliders.slider.warnings.not_found', name: name)
6
+ else
7
+ return render(slider)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ module MarkupHelper
2
+ def mu(object, method)
3
+ handler = object.send(method)
4
+ erb_string = ::ERB.new(object[method.to_sym].to_s, 0).result(binding)
5
+ handler.class.new(erb_string).to_html.html_safe
6
+ end
7
+ end
@@ -0,0 +1,36 @@
1
+ module Ecm
2
+ module Sliders
3
+ class Item < ActiveRecord::Base
4
+ # acts as list
5
+ acts_as_list scope: :slider_id
6
+
7
+ # acts as markup
8
+ acts_as_markup language: :variable, columns: [ :body ]
9
+
10
+ # associations
11
+ belongs_to :slider, inverse_of: :items
12
+
13
+ # callbacks
14
+ after_initialize :set_defaults, if: :new_record?
15
+
16
+ # attachments
17
+ has_one_attached :image
18
+
19
+ # validations
20
+ validates :slider, presence: true
21
+ validates :image, presence: true
22
+ validates :markup_language, :presence => true,
23
+ :inclusion => Ecm::Sliders::Configuration.markup_languages
24
+
25
+ def human
26
+ "#{slider.class.model_name.human} #{slider.human} - #{self.class.model_name.human} #{id}"
27
+ end
28
+
29
+ private
30
+
31
+ def set_defaults
32
+ self.markup_language ||= Ecm::Sliders::Configuration.default_markup_language
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,40 @@
1
+ class Ecm::Sliders::Slider < ActiveRecord::Base
2
+ # associations
3
+ has_many :items, -> { order(:position) },
4
+ dependent: :destroy,
5
+ inverse_of: :slider
6
+
7
+ accepts_nested_attributes_for :items, allow_destroy: true
8
+
9
+ # scopes
10
+ scope :for_locale, ->(locale) { where(self.arel_table[:locale].eq(locale).or(self.arel_table[:locale].eq(nil))).order(locale: :desc) }
11
+
12
+ # callbacks
13
+ after_initialize :set_defaults, if: :new_record?
14
+
15
+ # friendly id
16
+ extend FriendlyId
17
+ friendly_id :name, use: :slugged
18
+
19
+ # validations
20
+ validates :locale, inclusion: I18n.available_locales.map(&:to_s),
21
+ if: proc { |slider| slider.locale.present? }
22
+ validates :name, presence: true,
23
+ uniqueness: { scope: [:locale] }
24
+
25
+ def interval_in_milliseconds
26
+ (interval * 1000).to_i
27
+ end
28
+
29
+ def human
30
+ name
31
+ end
32
+
33
+ private
34
+
35
+ def set_defaults
36
+ self.auto_start = Ecm::Sliders::Configuration.slider_auto_start if auto_start.nil?
37
+ self.interval ||= Ecm::Sliders::Configuration.slider_interval
38
+ end
39
+ end
40
+
@@ -0,0 +1,3 @@
1
+ = bootstrap_carousel(autostart: slider.auto_start, interval: slider.interval_in_milliseconds, id: dom_id(slider)) do |c|
2
+ - slider.items.each do |item|
3
+ - c.add_item(image_source: main_app.url_for(item.image.variant(resize: Ecm::Sliders::Configuration.item_image_styles[:slider])), caption: mu(item, :body))
@@ -0,0 +1,52 @@
1
+ de:
2
+ activerecord:
3
+ models:
4
+ ecm/sliders/item:
5
+ one: Slider Item
6
+ other: Slider Items
7
+ ecm/sliders/slider:
8
+ one: Slider
9
+ other: Slider
10
+ attributes:
11
+ ecm/sliders/item:
12
+ id: ID
13
+ body: Inhalt
14
+ created_at: Erstellt am
15
+ markup_language: Markup Sprache
16
+ image: Bild
17
+ image_content_type: Dateintyp
18
+ image_file_name: Dateiname
19
+ image_file_size: Dateigrösse
20
+ image_fingerprint: Dateifingerabdruck
21
+ image_updated_at: Datei erstellt am
22
+ position: Position
23
+ slider: Slider
24
+ slider_id: Slider
25
+ slug: Freundliche ID
26
+ updated_at: Aktualisiert am
27
+ url: URL
28
+ ecm/sliders/slider:
29
+ id: ID
30
+ auto_start: Auto Start
31
+ created_at: Erstellt am
32
+ description: Beschreibung
33
+ items: Slider Items
34
+ items_count: Slider Items
35
+ locale: Sprache
36
+ name: Name
37
+ interval: Intervall
38
+ slug: Freundliche ID
39
+ updated_at: Aktualisiert am
40
+ resources:
41
+ ecm_sliders_items: slider-items
42
+ ecm_sliders_sliders: sliders
43
+ ecm:
44
+ sliders:
45
+ item:
46
+ actions:
47
+ more: Weiterlesen
48
+ slider:
49
+ warnings:
50
+ not_found: Slider %{name} nicht gefunden
51
+ routes:
52
+ ecm_sliders_engine: slider
@@ -0,0 +1,52 @@
1
+ en:
2
+ activerecord:
3
+ models:
4
+ ecm/sliders/item:
5
+ one: slider item
6
+ other: slider items
7
+ ecm/sliders/slider:
8
+ one: slider
9
+ other: sliders
10
+ attributes:
11
+ ecm/sliders/item:
12
+ id: ID
13
+ body: body
14
+ created_at: created at
15
+ markup_language: Markup language
16
+ image: Bild
17
+ image_content_type: image filetype
18
+ image_file_name: imagte filename
19
+ image_file_size: image filesize
20
+ image_fingerprint: image fingerprint
21
+ image_updated_at: image updated at
22
+ position: position
23
+ slider: Slider
24
+ slider_id: Slider
25
+ slug: Slug
26
+ updated_at: updated at
27
+ url: url
28
+ ecm/sliders/slider:
29
+ id: ID
30
+ auto_start: auto start
31
+ created_at: created at
32
+ description: description
33
+ items: slider items
34
+ items_count: slider items
35
+ locale: locale
36
+ name: name
37
+ interval: interval
38
+ slug: friendly id
39
+ updated_at: updated at
40
+ resources:
41
+ ecm_sliders_items: slider-items
42
+ ecm_sliders_sliders: sliders
43
+ ecm:
44
+ sliders:
45
+ item:
46
+ actions:
47
+ more: more
48
+ slider:
49
+ warnings:
50
+ not_found: Could not find slider %{name}
51
+ routes:
52
+ ecm_sliders_engine: sliders
data/config/routes.rb ADDED
@@ -0,0 +1,6 @@
1
+ Ecm::Sliders::Engine.routes.draw do
2
+ localized do
3
+ scope :ecm_sliders_engine do
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,14 @@
1
+ class CreateEcmSlidersSliders < ActiveRecord::Migration[4.2]
2
+ def change
3
+ create_table :ecm_sliders_sliders do |t|
4
+ t.string :locale
5
+ t.string :name
6
+ t.text :description
7
+ t.boolean :auto_start
8
+ t.decimal :interval, :precision => 8, :scale => 2
9
+ t.string :slug
10
+
11
+ t.timestamps
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ class CreateEcmSlidersItems < ActiveRecord::Migration[4.2]
2
+ def change
3
+ create_table :ecm_sliders_items do |t|
4
+ t.references :slider
5
+ t.integer :position
6
+ t.string :url
7
+ t.text :body
8
+ t.string :markup_language
9
+ t.string :slug
10
+
11
+ t.timestamps
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,23 @@
1
+ require 'active_support/core_ext/module/delegation'
2
+ require 'active_support/core_ext/module/attribute_accessors'
3
+ require 'active_support/hash_with_indifferent_access'
4
+
5
+ module Ecm
6
+ module Sliders
7
+ module Configuration
8
+ def configure
9
+ yield self
10
+ end
11
+
12
+ mattr_accessor(:slider_auto_start)
13
+
14
+ mattr_accessor(:slider_interval)
15
+
16
+ mattr_accessor(:item_image_styles) { {} }
17
+
18
+ mattr_accessor(:markup_languages) { [] }
19
+
20
+ mattr_accessor(:default_markup_language)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,7 @@
1
+ module Ecm
2
+ module Sliders
3
+ class Engine < ::Rails::Engine
4
+ isolate_namespace Ecm::Sliders
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,14 @@
1
+ module Ecm
2
+ module Sliders
3
+ class Routing
4
+ def self.routes(router, options = {})
5
+ options.reverse_merge!(
6
+ { :slider_actions => [ :index ] }
7
+ )
8
+
9
+ router.resources :ecm_sliders_sliders, :only => options[:slider_actions], :controller => 'ecm/sliders/sliders'
10
+ end
11
+ end
12
+ end
13
+ end
14
+
@@ -0,0 +1,6 @@
1
+ module Ecm
2
+ module Sliders
3
+ VERSION = "0.0.1".freeze
4
+ end
5
+ end
6
+
@@ -0,0 +1,17 @@
1
+ require 'acts_as_list'
2
+ require 'acts_as_markup'
3
+ require 'mini_magick'
4
+ require 'friendly_id'
5
+
6
+ require 'ecm/sliders/engine'
7
+ require 'ecm/sliders/configuration'
8
+
9
+ module Ecm
10
+ module Sliders
11
+ extend Configuration
12
+
13
+ def self.table_name_prefix
14
+ 'ecm_sliders_'
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,21 @@
1
+ module Ecm
2
+ module Sliders
3
+ module Generators
4
+ class InstallGenerator < Rails::Generators::Base
5
+ desc "Generates the initializer"
6
+
7
+ source_root File.expand_path('../templates', __FILE__)
8
+
9
+ def generate_intializer
10
+ copy_file "initializer.rb", "config/initializers/ecm_sliders.rb"
11
+ end
12
+
13
+ def generate_routes
14
+ inject_into_file 'config/routes.rb', before: "\nend" do
15
+ File.read(File.join(File.expand_path('../templates', __FILE__), 'routes.source'))
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end