ecm_references2 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +47 -0
  4. data/Rakefile +25 -0
  5. data/app/admin/ecm_references_categories.rb +92 -0
  6. data/app/admin/ecm_references_references.rb +78 -0
  7. data/app/assets/stylesheets/ecm_references.css.less +7 -0
  8. data/app/controllers/ecm/references/categories_controller.rb +11 -0
  9. data/app/controllers/ecm/references/references_controller.rb +11 -0
  10. data/app/models/ecm/references.rb +5 -0
  11. data/app/models/ecm/references/category.rb +102 -0
  12. data/app/models/ecm/references/reference.rb +83 -0
  13. data/app/views/ecm/references/categories/_category.html.haml +13 -0
  14. data/app/views/ecm/references/categories/_category_in_table.html.haml +6 -0
  15. data/app/views/ecm/references/categories/_table.html.haml +4 -0
  16. data/app/views/ecm/references/categories/index.html.haml +9 -0
  17. data/app/views/ecm/references/categories/show.html.haml +9 -0
  18. data/app/views/ecm/references/references/_reference.html.haml +7 -0
  19. data/app/views/ecm/references/references/_reference_in_list.html.haml +11 -0
  20. data/app/views/ecm/references/references/_reference_in_table.html.haml +3 -0
  21. data/app/views/ecm/references/references/_references_in_category.html.haml +3 -0
  22. data/app/views/ecm/references/references/index.html.haml +11 -0
  23. data/app/views/ecm/references/references/show.html.haml +6 -0
  24. data/config/locales/de.yml +55 -0
  25. data/config/locales/en.yml +54 -0
  26. data/db/migrate/001_create_ecm_references_categories.rb +24 -0
  27. data/db/migrate/002_create_ecm_references_references.rb +25 -0
  28. data/lib/ecm/references/configuration.rb +49 -0
  29. data/lib/ecm/references/engine.rb +11 -0
  30. data/lib/ecm/references/routing.rb +10 -0
  31. data/lib/ecm/references/version.rb +5 -0
  32. data/lib/ecm_references2.rb +22 -0
  33. data/lib/generators/ecm/references/install/install_generator.rb +15 -0
  34. data/lib/generators/ecm/references/install/templates/ecm_references.rb +56 -0
  35. data/lib/generators/ecm/references/locales/locales_generator.rb +16 -0
  36. data/lib/tasks/ecm_references_tasks.rake +4 -0
  37. metadata +560 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b0eec12851cb4a8cc1568d3cd8b91b9cf9d47cd7
4
+ data.tar.gz: 5ef621a651dbbc89498d513e28279461fc0e8298
5
+ SHA512:
6
+ metadata.gz: 78478ab24ab14599ed662a892f5ebd2cee1d23e3595201a84a797c946372929b07c48c4610a0df1c1640d0cfbb23cb89c465c1efb96b4e1947d71e60b4574d41
7
+ data.tar.gz: e38a50bbc36a352de7faf6c3c25b97658f23f720ac0ef374af125f3d3a2f91934b69984c15549c15a582e45d2b16f652400874a9de536ea820b850927e0f2af3
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2015 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,47 @@
1
+ = ECM References 2 Module
2
+
3
+ This project rocks and uses MIT-LICENSE.
4
+
5
+ = Installation
6
+
7
+ Add it to your Gemfile:
8
+
9
+ # Gemfile
10
+ gem 'ecm_references2'
11
+
12
+ Add the initializer:
13
+
14
+ rails g ecm:references:install
15
+
16
+ Add the migrations:
17
+
18
+ rake ecm_references_engine:install:migrations
19
+ rake db:migrate
20
+
21
+ Add the routes:
22
+
23
+ # config/routes.rb
24
+ Ecm::References::Routing.routes(self)
25
+
26
+
27
+ = Running tests
28
+
29
+ gem install bundler
30
+ bundle
31
+ cd spec/dummy && rake db:migrate RAILS_ENV=test && cd ../..
32
+ guard
33
+
34
+ = FAQ
35
+
36
+ Q: Bundling fails installing RedCloth with message "Failed to build native extension..../home/vagrant/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/mkmf.rb:456:in `try_do': The compiler failed to generate an executable file. (RuntimeError) You have to install development tools first.". What can I do?
37
+
38
+ A: Install libgmp-dev:
39
+
40
+ sudo apt-get install -y libgmp-dev
41
+
42
+
43
+ Q: Tests fail with message "Paperclip::Errors::CommandNotFoundError: Could not run the `identify` command. Please install ImageMagick.". What can I do?
44
+
45
+ A: Install imagemagick:
46
+
47
+ sudo apt-get install -y imagemagick
data/Rakefile ADDED
@@ -0,0 +1,25 @@
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 References 2'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ Bundler::GemHelper.install_tasks
24
+
25
+ require 'rails/dummy/tasks'
@@ -0,0 +1,92 @@
1
+ ActiveAdmin.register Ecm::References::Category do
2
+ menu parent: proc { I18n.t('ecm.references.active_admin.menu') }.call
3
+
4
+ permit_params :description,
5
+ :locale,
6
+ :markup_language,
7
+ :name,
8
+ :parent_id,
9
+ :slug
10
+
11
+ # Nested set settings
12
+ config.sort_order = 'lft_asc'
13
+ sortable_tree_member_actions
14
+
15
+ form do |f|
16
+ f.inputs do
17
+ f.input :parent, as: :select, collection: nested_set_options(Ecm::References::Category, f.object) { |c| "#{'&#160;&#160;&#160;&#160;' * c.depth}&bull; #{c}".html_safe }
18
+ end # f.inputs
19
+
20
+ f.inputs do
21
+ f.input :locale, as: :select, collection: I18n.available_locales.map(&:to_s)
22
+ f.input :name
23
+ f.input :description
24
+ end # f.inputs
25
+
26
+ f.inputs do
27
+ f.input :markup_language, as: :select, collection: Ecm::References::Configuration.markup_languages.map(&:to_s)
28
+ end # f.inputs
29
+
30
+ f.actions
31
+ end # form
32
+
33
+ index as: :nested_set do
34
+ selectable_column
35
+ sortable_tree_columns
36
+ sortable_tree_indented_column :name
37
+ column :locale
38
+ column :reference_count
39
+ column :created_at
40
+ column :updated_at
41
+ actions
42
+ end # index
43
+
44
+ show title: :to_s do
45
+ panel Ecm::References::Category.human_attribute_name(:description) do
46
+ ecm_references_category.description
47
+ end # panel
48
+
49
+ panel Ecm::References::Category.human_attribute_name(:children) do
50
+ table_for ecm_references_category.descendants, i18n: Ecm::References::Category do
51
+ sortable_tree_columns
52
+ sortable_tree_indented_column :name
53
+ column :locale
54
+ column :reference_count
55
+ column :created_at
56
+ column :updated_at
57
+ column do |child|
58
+ link_to(I18n.t('active_admin.view'), [:admin, child], class: 'member_link view_link') +
59
+ link_to(I18n.t('active_admin.edit'), [:edit, :admin, child], class: 'member_link edit_link')
60
+ end
61
+ end # table_for
62
+ end # panel
63
+
64
+ panel Ecm::References::Category.human_attribute_name(:references) do
65
+ table_for ecm_references_category.references, i18n: Ecm::References::Reference do
66
+ sortable_columns
67
+ column :preview_picture do |reference|
68
+ image_tag(reference.preview_picture_image_url(:small_thumb)) unless reference.preview_picture_image_url(:small_thumb).nil?
69
+ end
70
+ column :name
71
+ column :published
72
+ column :created_at
73
+ column :updated_at
74
+ column do |child|
75
+ link_to(I18n.t('active_admin.view'), [:admin, child], class: 'member_link view_link') +
76
+ link_to(I18n.t('active_admin.edit'), [:edit, :admin, child], class: 'member_link edit_link')
77
+ end
78
+ end # table_for
79
+ end # panel
80
+ end # show
81
+
82
+ sidebar Ecm::References::Category.human_attribute_name(:details), only: :show do
83
+ attributes_table_for ecm_references_category do
84
+ row :parent
85
+ row :name
86
+ row :locale
87
+ row :reference_count
88
+ row :created_at
89
+ row :updated_at
90
+ end
91
+ end # sidebar
92
+ end # ActiveAdmin.register Ecm::References::Category
@@ -0,0 +1,78 @@
1
+ ActiveAdmin.register Ecm::References::Reference do
2
+ menu parent: proc { I18n.t('ecm.references.active_admin.menu') }.call
3
+
4
+ permit_params :attached_pictures_attributes,
5
+ :category,
6
+ :ecm_categories_category_id,
7
+ :description,
8
+ :markup_language,
9
+ :name,
10
+ :published,
11
+ pictures_attributes: [
12
+ :description,
13
+ :image,
14
+ :markup_language,
15
+ :name
16
+ ]
17
+
18
+ # List settings
19
+ sortable_member_actions
20
+
21
+ form do |f|
22
+ f.inputs do
23
+ f.input :category, as: :select,
24
+ collection: nested_set_options(Ecm::References::Category) { |c| "#{'&#160;&#160;&#160;&#160;' * c.depth}&bull; #{c}".html_safe },
25
+ prompt: ''
26
+ end # f.inputs
27
+
28
+ f.inputs do
29
+ f.input :name
30
+ f.input :description
31
+ f.input :published, as: :boolean
32
+ end # f.inputs
33
+
34
+ f.inputs do
35
+ f.input :markup_language, as: :select, collection: Ecm::References::Configuration.markup_languages.map(&:to_s)
36
+ end # f.inputs
37
+
38
+ form_inputs_for_pictureable(f)
39
+
40
+ f.actions
41
+
42
+ # f.inputs do
43
+ # span do f.object.errors.inspect end
44
+ # end
45
+ end # form
46
+
47
+ index do
48
+ selectable_column
49
+ column :preview_picture do |reference|
50
+ image_tag(reference.preview_picture_image_url(:small_thumb)) unless reference.preview_picture_image_url(:small_thumb).nil?
51
+ end
52
+ column :category
53
+ column :name
54
+ column :published
55
+ column :created_at
56
+ column :updated_at
57
+ actions
58
+ end # index
59
+
60
+ show title: :to_s do
61
+ panel Ecm::References::Reference.human_attribute_name(:description) do
62
+ ecm_references_reference.description
63
+ end # panel
64
+
65
+ panel_for_pictureable
66
+ end # show
67
+
68
+ sidebar Ecm::References::Reference.human_attribute_name(:details), only: :show do
69
+ attributes_table_for ecm_references_reference do
70
+ row :category
71
+ row :name
72
+ row :published
73
+ row :markup_language
74
+ row :created_at
75
+ row :updated_at
76
+ end
77
+ end # sidebar
78
+ end # ActiveAdmin.register Ecm::References::Reference
@@ -0,0 +1,7 @@
1
+ /*
2
+ *= require ecm_pictures
3
+ */
4
+
5
+ .reference-preview {
6
+ margin-bottom: 20px;
7
+ }
@@ -0,0 +1,11 @@
1
+ module Ecm::References
2
+ class CategoriesController < Configuration.base_controller.constantize
3
+ def index
4
+ @categories = Category.with_public_visibility.page(params[:page]).per(5)
5
+ end
6
+
7
+ def show
8
+ @category = Category.with_public_visibility.find(params[:id])
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Ecm::References
2
+ class ReferencesController < Configuration.base_controller.constantize
3
+ def index
4
+ @references = Reference.with_public_visibility.page(params[:page]).per(5)
5
+ end
6
+
7
+ def show
8
+ @reference = Reference.with_public_visibility.find(params[:id])
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ module Ecm::References
2
+ def self.table_name_prefix
3
+ 'ecm_references_'
4
+ end
5
+ end
@@ -0,0 +1,102 @@
1
+ module Ecm::References
2
+ class Category < ActiveRecord::Base
3
+ self.table_name = 'ecm_references_categories'
4
+
5
+ # associations
6
+ has_many :references, foreign_key: :ecm_categories_category_id,
7
+ dependent: :destroy
8
+
9
+ # attributes
10
+ # attr_accessible :description,
11
+ # :locale,
12
+ # :markup_language,
13
+ # :name,
14
+ # :parent_id,
15
+ # :slug
16
+
17
+ # callbacks
18
+ after_initialize :set_defaults
19
+ before_validation :set_locale_from_parent
20
+ before_save :update_locale_on_children!, if: proc { |category| category.locale_changed? }
21
+
22
+ # default scope
23
+ default_scope { order(:lft) }
24
+
25
+ # friendly id support
26
+ extend FriendlyId
27
+ friendly_id :name, use: [:slugged, :finders]
28
+
29
+ # markup support
30
+ acts_as_markup language: :variable, columns: [:description]
31
+
32
+ # nested set support
33
+ acts_as_nested_set
34
+
35
+ # validations
36
+ validates :locale, inclusion: I18n.available_locales.map(&:to_s), allow_blank: true
37
+ validate :equality_of_locale_and_parent_locale, if: proc { |category| category.parent.respond_to?(:locale) }
38
+ validates :markup_language, presence: true,
39
+ inclusion: Ecm::References::Configuration.markup_languages.map(&:to_s)
40
+ validates :name, presence: true,
41
+ uniqueness: { scope: [:parent_id] }
42
+
43
+ def self.localized
44
+ where(locale: I18n.locale)
45
+ end
46
+
47
+ def self.with_public_visibility
48
+ localized
49
+ end
50
+
51
+ def human
52
+ name
53
+ end
54
+
55
+ def locale=(locale)
56
+ write_attribute(:locale, locale.to_s) if locale.respond_to?(:to_s)
57
+ end
58
+
59
+ def locale_label(view)
60
+ view.content_tag(:span, locale, class: 'label label-default')
61
+ end
62
+
63
+ def references_count
64
+ references.count
65
+ end
66
+
67
+ def references_count_label(view)
68
+ view.content_tag(:span, references_count, class: 'badge')
69
+ end
70
+
71
+ def to_s
72
+ name
73
+ end
74
+
75
+ def tree_name
76
+ name
77
+ end
78
+
79
+ private
80
+
81
+ def equality_of_locale_and_parent_locale
82
+ locale == parent.locale
83
+ end # def
84
+
85
+ def set_defaults
86
+ if self.new_record?
87
+ self.markup_language ||= Ecm::References::Configuration.default_markup_language
88
+ end
89
+ end # def
90
+
91
+ def set_locale_from_parent
92
+ self.locale = parent.locale if parent.respond_to?(:locale)
93
+ end # def
94
+
95
+ def update_locale_on_children!
96
+ children.each do |child|
97
+ child.locale = locale
98
+ child.save!
99
+ end
100
+ end # def
101
+ end # class Category < ActiveRecord::Base
102
+ end # module Ecm::References
@@ -0,0 +1,83 @@
1
+ module Ecm::References
2
+ class Reference < ActiveRecord::Base
3
+ self.table_name = 'ecm_references_references'
4
+
5
+ # acts as list
6
+ acts_as_list scope: :ecm_categories_category
7
+ default_scope { order('ecm_categories_category_id ASC, position ASC') }
8
+
9
+ # acts as published
10
+ include ActsAsPublished::ActiveRecord
11
+ acts_as_published
12
+
13
+ # associations
14
+ belongs_to :category,
15
+ foreign_key: :ecm_categories_category_id
16
+ has_many :attached_pictures, as: :pictureable,
17
+ class_name: Ecm::Pictures::AttachedPicture,
18
+ inverse_of: :pictureable
19
+ has_many :pictures, through: :attached_pictures,
20
+ class_name: Ecm::Pictures::Picture
21
+
22
+ accepts_nested_attributes_for :attached_pictures, allow_destroy: true
23
+ accepts_nested_attributes_for :pictures, allow_destroy: true
24
+
25
+ # attributes
26
+ # attr_accessible :attached_pictures_attributes,
27
+ # :category,
28
+ # :ecm_categories_category_id,
29
+ # :description,
30
+ # :markup_language,
31
+ # :name,
32
+ # :pictures_attributes
33
+
34
+ # callbacks
35
+ after_initialize :set_defaults
36
+ # before_validation do
37
+ # self.published = ["published"] # if @attributes.has_key?("published")
38
+ # end
39
+
40
+ # friendly id support
41
+ extend FriendlyId
42
+ friendly_id :name, use: [:slugged, :finders]
43
+
44
+ # markup support
45
+ acts_as_markup language: :variable, columns: [:description]
46
+
47
+ # validations
48
+ validates :ecm_categories_category_id, presence: true
49
+ validates :markup_language, presence: true,
50
+ inclusion: Ecm::References::Configuration.markup_languages.map(&:to_s)
51
+ validates :name, presence: true,
52
+ uniqueness: { scope: [:ecm_categories_category_id] }
53
+
54
+ def self.localized
55
+ joins(:category).where(ecm_references_categories: { locale: I18n.locale })
56
+ end
57
+
58
+ def self.with_public_visibility
59
+ published.localized
60
+ end
61
+
62
+ def preview_picture
63
+ pictures.first
64
+ end
65
+
66
+ def preview_picture_image_url(style = nil)
67
+ preview_picture.image.url(style) if preview_picture.respond_to?(:image) && preview_picture.image.respond_to?(:url)
68
+ end
69
+
70
+ def to_s
71
+ name
72
+ end # def
73
+
74
+ private
75
+
76
+ def set_defaults
77
+ if self.new_record?
78
+ self.markup_language ||= Ecm::References::Configuration.default_markup_language
79
+ self.published = Ecm::References::Configuration.new_references_published_by_default if published_at.nil?
80
+ end
81
+ end # def
82
+ end # class Reference < ActiveRecord::Base
83
+ end # module Ecm::References