ecm_products 0.0.1.pre
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +27 -0
- data/app/controllers/ecm/products/product_categories_controller.rb +9 -0
- data/app/controllers/ecm/products/products_controller.rb +9 -0
- data/app/models/ecm/products/product.rb +97 -0
- data/app/models/ecm/products/product_category.rb +71 -0
- data/app/models/ecm/products/product_link.rb +23 -0
- data/app/models/ecm/products.rb +5 -0
- data/app/views/ecm/products/product_categories/_product_category.html.erb +23 -0
- data/app/views/ecm/products/product_categories/index.html.erb +6 -0
- data/app/views/ecm/products/product_categories/show.html.erb +18 -0
- data/app/views/ecm/products/product_links/_product_link.html.erb +12 -0
- data/app/views/ecm/products/products/_product.html.erb +29 -0
- data/app/views/ecm/products/products/_product_details.html.erb +40 -0
- data/app/views/ecm/products/products/_product_preview.html.erb +18 -0
- data/app/views/ecm/products/products/index.html.erb +3 -0
- data/app/views/ecm/products/products/show.html.erb +1 -0
- data/config/locales/ecm.products.de.yml +20 -0
- data/config/locales/ecm.products.en.yml +20 -0
- data/config/locales/ecm.products.product.de.yml +38 -0
- data/config/locales/ecm.products.product.en.yml +38 -0
- data/config/locales/ecm.products.product_category.de.yml +35 -0
- data/config/locales/ecm.products.product_category.en.yml +35 -0
- data/config/locales/ecm.products.product_link.de.yml +17 -0
- data/config/locales/ecm.products.product_link.en.yml +17 -0
- data/config/locales/ecm.products.routes.de.yml +5 -0
- data/config/locales/ecm.products.routes.en.yml +5 -0
- data/db/migrate/001_create_ecm_products_product_categories.rb +40 -0
- data/db/migrate/002_create_ecm_products_products.rb +46 -0
- data/db/migrate/003_create_ecm_products_product_links.rb +18 -0
- data/lib/ecm/products/active_admin/ecm_products_product_categories.rb +75 -0
- data/lib/ecm/products/active_admin/ecm_products_product_links.rb +39 -0
- data/lib/ecm/products/active_admin/ecm_products_products.rb +74 -0
- data/lib/ecm/products/engine.rb +12 -0
- data/lib/ecm/products/routing.rb +22 -0
- data/lib/ecm/products/version.rb +5 -0
- data/lib/ecm_products.rb +13 -0
- data/lib/tasks/ecm_products_tasks.rake +77 -0
- metadata +440 -0
@@ -0,0 +1,17 @@
|
|
1
|
+
---
|
2
|
+
en:
|
3
|
+
activerecord:
|
4
|
+
models:
|
5
|
+
ecm/products/product_link:
|
6
|
+
one: product link
|
7
|
+
other: product links
|
8
|
+
attributes:
|
9
|
+
ecm/products/product_link:
|
10
|
+
name: name
|
11
|
+
position: position
|
12
|
+
created_at: created at
|
13
|
+
updated_at: updated at
|
14
|
+
ecm_products_product: product
|
15
|
+
ecm_products_product_id: product
|
16
|
+
url: url
|
17
|
+
description: description
|
@@ -0,0 +1,40 @@
|
|
1
|
+
class CreateEcmProductsProductCategories < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :ecm_products_product_categories do |t|
|
4
|
+
t.string :locale
|
5
|
+
t.string :name
|
6
|
+
t.text :short_description
|
7
|
+
t.text :long_description
|
8
|
+
|
9
|
+
# associations
|
10
|
+
t.integer :ecm_products_products_count, :default => 0, :null => false
|
11
|
+
|
12
|
+
# awesome nested set
|
13
|
+
t.integer :lft
|
14
|
+
t.integer :rgt
|
15
|
+
t.integer :parent_id
|
16
|
+
t.integer :depth
|
17
|
+
|
18
|
+
# friendly id
|
19
|
+
t.string :slug
|
20
|
+
|
21
|
+
# paperclip
|
22
|
+
# t.attachment :preview_image
|
23
|
+
t.string :preview_image_file_name
|
24
|
+
t.integer :preview_image_file_size
|
25
|
+
t.string :preview_image_content_type
|
26
|
+
t.timestamp :preview_image_updated_at
|
27
|
+
t.string :preview_image_fingerprint
|
28
|
+
|
29
|
+
# paperclip
|
30
|
+
# t.attachment :main_image
|
31
|
+
t.string :main_image_file_name
|
32
|
+
t.integer :main_image_file_size
|
33
|
+
t.string :main_image_content_type
|
34
|
+
t.timestamp :main_image_updated_at
|
35
|
+
t.string :main_image_fingerprint
|
36
|
+
|
37
|
+
t.timestamps
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
class CreateEcmProductsProducts < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :ecm_products_products do |t|
|
4
|
+
t.string :locale
|
5
|
+
t.string :name
|
6
|
+
t.text :short_description
|
7
|
+
t.text :long_description
|
8
|
+
t.boolean :price_on_application
|
9
|
+
|
10
|
+
# associations
|
11
|
+
t.integer :ecm_products_product_links_count, :default => 0, :null => false
|
12
|
+
t.references :ecm_products_product_category
|
13
|
+
|
14
|
+
# acts as list
|
15
|
+
t.integer :position
|
16
|
+
|
17
|
+
# acts as published
|
18
|
+
t.timestamp :published_at
|
19
|
+
|
20
|
+
# friendly id
|
21
|
+
t.string :slug
|
22
|
+
|
23
|
+
# money
|
24
|
+
t.integer :price_cents
|
25
|
+
t.string :price_currency
|
26
|
+
|
27
|
+
# paperclip
|
28
|
+
# t.attachment :preview_image
|
29
|
+
t.string :preview_image_file_name
|
30
|
+
t.integer :preview_image_file_size
|
31
|
+
t.string :preview_image_content_type
|
32
|
+
t.timestamp :preview_image_updated_at
|
33
|
+
t.string :preview_image_fingerprint
|
34
|
+
|
35
|
+
# paperclip
|
36
|
+
# t.attachment :main_image
|
37
|
+
t.string :main_image_file_name
|
38
|
+
t.integer :main_image_file_size
|
39
|
+
t.string :main_image_content_type
|
40
|
+
t.timestamp :main_image_updated_at
|
41
|
+
t.string :main_image_fingerprint
|
42
|
+
|
43
|
+
t.timestamps
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class CreateEcmProductsProductLinks < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :ecm_products_product_links do |t|
|
4
|
+
t.string :name
|
5
|
+
t.string :url
|
6
|
+
t.text :description
|
7
|
+
|
8
|
+
# associations
|
9
|
+
t.references :ecm_products_product
|
10
|
+
|
11
|
+
# acts as list
|
12
|
+
t.integer :position
|
13
|
+
|
14
|
+
t.timestamps
|
15
|
+
end
|
16
|
+
add_index :ecm_products_product_links, :ecm_products_product_id
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
::ActiveAdmin.register Ecm::Products::ProductCategory do
|
2
|
+
# menu entry settings
|
3
|
+
menu :parent => Proc.new { I18n.t('ecm.products.active_admin.menu') }.call
|
4
|
+
|
5
|
+
form :html => { :enctype => "multipart/form-data" } do |f|
|
6
|
+
f.inputs do
|
7
|
+
f.input :parent, :as => :select, :collection => nested_set_options(Ecm::Products::ProductCategory, f.object) { |pc| "#{'    ' * pc.level} |-- #{pc.tree_name}".html_safe }
|
8
|
+
f.input :locale, :as => :select, :collection => I18n.available_locales.map(&:to_s)
|
9
|
+
f.input :name
|
10
|
+
f.input :short_description
|
11
|
+
f.input :long_description
|
12
|
+
f.input :preview_image, :as => :file, :hint => f.template.image_tag(f.object.preview_image.url(:medium_thumb))
|
13
|
+
f.input :main_image, :as => :file, :hint => f.template.image_tag(f.object.main_image.url(:medium_thumb))
|
14
|
+
end
|
15
|
+
f.actions
|
16
|
+
end
|
17
|
+
|
18
|
+
index :as => :nested_set do
|
19
|
+
selectable_column
|
20
|
+
column :preview_image do |pc|
|
21
|
+
link_to(image_tag(pc.preview_image.url(:small_thumb)), [:admin, pc], :style => "margin-left: #{50 * pc.level}px")
|
22
|
+
end
|
23
|
+
column :locale
|
24
|
+
column :name
|
25
|
+
column :short_description
|
26
|
+
column :ecm_products_products_count
|
27
|
+
column :created_at
|
28
|
+
column :updated_at
|
29
|
+
default_actions
|
30
|
+
end
|
31
|
+
|
32
|
+
show do
|
33
|
+
panel Ecm::Products::ProductCategory.human_attribute_name(:preview_image) do
|
34
|
+
div { image_tag(ecm_products_product_category.preview_image.url) }
|
35
|
+
end
|
36
|
+
|
37
|
+
attributes_table do
|
38
|
+
row :parent
|
39
|
+
row :name
|
40
|
+
row :ecm_products_products_count
|
41
|
+
row :created_at
|
42
|
+
row :updated_at
|
43
|
+
end
|
44
|
+
|
45
|
+
panel Ecm::Products::ProductCategory.human_attribute_name(:ecm_products_products) do
|
46
|
+
table_for ecm_products_product_category.ecm_products_products, :i18n => Ecm::Products::Product do
|
47
|
+
column :preview_image do |p|
|
48
|
+
link_to(image_tag(p.preview_image.url(:medium_thumb)), [:admin, p])
|
49
|
+
end
|
50
|
+
column :ecm_products_product_category
|
51
|
+
column :locale
|
52
|
+
column :name
|
53
|
+
column :short_description
|
54
|
+
column :created_at
|
55
|
+
column :updated_at
|
56
|
+
column do |p|
|
57
|
+
link_to(I18n.t('active_admin.view'), admin_ecm_products_product_path(p), :class => "member_link view_link") +
|
58
|
+
link_to(I18n.t('active_admin.edit'), edit_admin_ecm_products_product_path(p), :class => "member_link edit_link")
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
panel Ecm::Products::ProductCategory.human_attribute_name(:main_image) do
|
64
|
+
div { image_tag(ecm_products_product_category.main_image.url) }
|
65
|
+
end
|
66
|
+
|
67
|
+
panel Ecm::Products::ProductCategory.human_attribute_name(:short_description) do
|
68
|
+
div { ecm_products_product_category.short_description }
|
69
|
+
end
|
70
|
+
|
71
|
+
panel Ecm::Products::ProductCategory.human_attribute_name(:long_description) do
|
72
|
+
div { ecm_products_product_category.long_description }
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end if defined?(::ActiveAdmin)
|
@@ -0,0 +1,39 @@
|
|
1
|
+
::ActiveAdmin.register Ecm::Products::ProductLink do
|
2
|
+
# menu entry settings
|
3
|
+
menu :parent => Proc.new { I18n.t('ecm.products.active_admin.menu') }.call
|
4
|
+
|
5
|
+
form do |f|
|
6
|
+
f.inputs do
|
7
|
+
f.input :ecm_products_product
|
8
|
+
f.input :name
|
9
|
+
f.input :url
|
10
|
+
f.input :description
|
11
|
+
end
|
12
|
+
f.actions
|
13
|
+
end
|
14
|
+
|
15
|
+
index do
|
16
|
+
selectable_column
|
17
|
+
column :ecm_products_product
|
18
|
+
column :name
|
19
|
+
column :description
|
20
|
+
column :url
|
21
|
+
default_actions
|
22
|
+
end
|
23
|
+
|
24
|
+
show do
|
25
|
+
attributes_table do
|
26
|
+
row :ecm_products_product
|
27
|
+
row :name
|
28
|
+
row :url do |pl|
|
29
|
+
link_to(pl.url, pl.url)
|
30
|
+
end
|
31
|
+
row :created_at
|
32
|
+
row :updated_at
|
33
|
+
end
|
34
|
+
|
35
|
+
panel Ecm::Products::ProductLink.human_attribute_name(:description) do
|
36
|
+
div { ecm_products_product_link.description }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end if defined?(::ActiveAdmin)
|
@@ -0,0 +1,74 @@
|
|
1
|
+
::ActiveAdmin.register Ecm::Products::Product do
|
2
|
+
# menu entry settings
|
3
|
+
menu :parent => Proc.new { I18n.t('ecm.products.active_admin.menu') }.call
|
4
|
+
|
5
|
+
form :html => { :enctype => "multipart/form-data" } do |f|
|
6
|
+
f.inputs do
|
7
|
+
f.input :ecm_products_product_category
|
8
|
+
f.input :locale, :as => :select, :collection => I18n.available_locales.map(&:to_s)
|
9
|
+
f.input :name
|
10
|
+
f.input :short_description
|
11
|
+
f.input :long_description
|
12
|
+
f.input :price
|
13
|
+
f.input :price_on_application
|
14
|
+
f.input :published_at
|
15
|
+
f.input :preview_image, :as => :file
|
16
|
+
f.input :main_image, :as => :file
|
17
|
+
end
|
18
|
+
f.actions
|
19
|
+
end
|
20
|
+
|
21
|
+
index do
|
22
|
+
selectable_column
|
23
|
+
column :preview_image do |p|
|
24
|
+
link_to(image_tag(p.preview_image.url(:medium_thumb)), [:admin, p])
|
25
|
+
end
|
26
|
+
column :ecm_products_product_category
|
27
|
+
column :locale
|
28
|
+
column :name
|
29
|
+
column :short_description
|
30
|
+
column :created_at
|
31
|
+
column :updated_at
|
32
|
+
default_actions
|
33
|
+
end
|
34
|
+
|
35
|
+
show do
|
36
|
+
panel Ecm::Products::Product.human_attribute_name(:preview_image) do
|
37
|
+
div { image_tag(ecm_products_product.preview_image.url) }
|
38
|
+
end
|
39
|
+
|
40
|
+
attributes_table do
|
41
|
+
row :ecm_products_product_category
|
42
|
+
row :name
|
43
|
+
row :price
|
44
|
+
row :price_on_application
|
45
|
+
row :published_at
|
46
|
+
row :created_at
|
47
|
+
row :updated_at
|
48
|
+
end
|
49
|
+
|
50
|
+
panel Ecm::Products::ProductLink.human_attribute_name(:ecm_products_product_links) do
|
51
|
+
table_for ecm_products_product.ecm_products_product_links, :i18n => Ecm::Products::ProductLink do
|
52
|
+
column :name
|
53
|
+
column :description
|
54
|
+
column :url
|
55
|
+
column do |pl|
|
56
|
+
link_to(I18n.t('active_admin.view'), admin_ecm_products_product_link_path(pl), :class => "member_link view_link") +
|
57
|
+
link_to(I18n.t('active_admin.edit'), edit_admin_ecm_products_product_link_path(pl), :class => "member_link edit_link")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
panel Ecm::Products::Product.human_attribute_name(:main_image) do
|
63
|
+
div { image_tag(ecm_products_product.main_image.url) }
|
64
|
+
end
|
65
|
+
|
66
|
+
panel Ecm::Products::Product.human_attribute_name(:short_description) do
|
67
|
+
div { ecm_products_product.short_description }
|
68
|
+
end
|
69
|
+
|
70
|
+
panel Ecm::Products::Product.human_attribute_name(:long_description) do
|
71
|
+
div { ecm_products_product.long_description }
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end if defined?(::ActiveAdmin)
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module ECM
|
2
|
+
module Products
|
3
|
+
class Engine < ::Rails::Engine
|
4
|
+
# active admin
|
5
|
+
initializer :ecm_products_engine do
|
6
|
+
::ActiveAdmin.setup do |active_admin_config|
|
7
|
+
active_admin_config.load_paths += Dir[File.dirname(__FILE__) + '/active_admin']
|
8
|
+
end
|
9
|
+
end if defined?(::ActiveAdmin)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Ecm
|
2
|
+
module Products
|
3
|
+
class Routing
|
4
|
+
# Creates the routes for products and categories. You can pass options to
|
5
|
+
# specify the actions for both products and/or categories.
|
6
|
+
#
|
7
|
+
# Ecm::Products::Routing.routes(self, { :product_category_actions => [ :show ]})
|
8
|
+
#
|
9
|
+
# This will only create the show action for product categories, but omit the index action.
|
10
|
+
def self.routes(router, options = {})
|
11
|
+
options.reverse_merge!(
|
12
|
+
{ :product_category_actions => [:index, :show],
|
13
|
+
:product_actions => [:index, :show]
|
14
|
+
}
|
15
|
+
)
|
16
|
+
|
17
|
+
router.resources :ecm_products_product_categories, :only => options[:product_category_actions], :controller => 'ecm/products/product_categories'
|
18
|
+
router.resources :ecm_products_products,:only => options[:product_actions], :controller => 'ecm/products/products'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/ecm_products.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'active_admin-awesome_nested_set'
|
2
|
+
require 'acts_as_list'
|
3
|
+
# require 'acts_as_published'
|
4
|
+
require 'awesome_nested_set'
|
5
|
+
require 'awesome_nested_set-tools'
|
6
|
+
require 'friendly_id'
|
7
|
+
require 'money-rails'
|
8
|
+
require 'paperclip'
|
9
|
+
require 'rails_tools-absence_validator'
|
10
|
+
|
11
|
+
require 'ecm/products/engine'
|
12
|
+
require 'ecm/products/routing'
|
13
|
+
|
@@ -0,0 +1,77 @@
|
|
1
|
+
namespace :ecm_products do
|
2
|
+
namespace :db do
|
3
|
+
desc "Purges and creates example data"
|
4
|
+
task :populate!, [] => [:environment] do |t, args|
|
5
|
+
|
6
|
+
Rake::Task["ecm_products:db:clear!"].execute
|
7
|
+
Rake::Task["ecm_products:db:populate"].execute
|
8
|
+
end
|
9
|
+
|
10
|
+
desc "Clears all data!"
|
11
|
+
task :clear!, [] => [:environment] do |t, args|
|
12
|
+
Ecm::Products::ProductCategory.delete_all
|
13
|
+
Ecm::Products::Product.delete_all
|
14
|
+
Ecm::Products::ProductLink.delete_all
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "Creates example_data"
|
18
|
+
task :populate, [] => [:environment] do |t, args|
|
19
|
+
require "ffaker"
|
20
|
+
require "forgery"
|
21
|
+
|
22
|
+
# Create example product category roots
|
23
|
+
10.times do
|
24
|
+
Ecm::Products::ProductCategory.create! do |pc|
|
25
|
+
pc.locale = I18n.available_locales.choice.to_s
|
26
|
+
pc.name = Faker::Product.brand
|
27
|
+
pc.short_description = Faker::Lorem.paragraph(2)
|
28
|
+
pc.long_description = Faker::Lorem.paragraph(10)
|
29
|
+
pc.preview_image = File.open(ECM::Products::Engine.root + "spec/fixtures/product/preview_image.gif")
|
30
|
+
pc.main_image = File.open(ECM::Products::Engine.root + "spec/fixtures/product/main_image.gif")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# Create example product categories
|
35
|
+
# roots = Ecm::Products::ProductCategory.roots.all
|
36
|
+
10.times do
|
37
|
+
Ecm::Products::ProductCategory.create! do |pc|
|
38
|
+
pc.parent = Ecm::Products::ProductCategory.all.choice
|
39
|
+
pc.name = Faker::Product.brand
|
40
|
+
pc.short_description = Faker::Lorem.paragraph(2)
|
41
|
+
pc.long_description = Faker::Lorem.paragraph(10)
|
42
|
+
pc.preview_image = File.open(ECM::Products::Engine.root + "spec/fixtures/product_category/preview_image.gif")
|
43
|
+
pc.main_image = File.open(ECM::Products::Engine.root + "spec/fixtures/product_category/main_image.gif")
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# Create example products
|
48
|
+
product_categories = Ecm::Products::ProductCategory.all
|
49
|
+
100.times do
|
50
|
+
Ecm::Products::Product.create! do |p|
|
51
|
+
p.locale = I18n.available_locales.choice.to_s
|
52
|
+
p.name = Faker::Product.product_name
|
53
|
+
p.short_description = Faker::Lorem.paragraph(rand(2))
|
54
|
+
p.long_description = Faker::Lorem.paragraph(rand(10))
|
55
|
+
p.price_on_application = [true, false].choice
|
56
|
+
p.preview_image = File.open(ECM::Products::Engine.root + "spec/fixtures/product_category/preview_image.gif")
|
57
|
+
p.main_image = File.open(ECM::Products::Engine.root + "spec/fixtures/product_category/main_image.gif")
|
58
|
+
|
59
|
+
p.ecm_products_product_category = product_categories.choice
|
60
|
+
|
61
|
+
p.price Money.new(rand(1000000 / 100), "EUR")
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# Create example links
|
66
|
+
Ecm::Products::Product.all.each do |p|
|
67
|
+
rand(10).times do
|
68
|
+
p.ecm_products_product_links.create do |pl|
|
69
|
+
pl.name = Faker::Product.product_name
|
70
|
+
pl.url = Faker::Internet.http_url
|
71
|
+
pl.description = Faker::Lorem.paragraph(rand(3))
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|