vitrage 0.0.2 → 0.0.4
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.
- checksums.yaml +5 -5
- data/README.md +108 -2
- data/Rakefile +2 -0
- data/app/assets/javascripts/vitrage/editor.js.coffee +181 -0
- data/app/assets/javascripts/vitrage/vitrage.js +4 -0
- data/app/assets/stylesheets/vitrage/editor.scss +64 -0
- data/app/assets/stylesheets/vitrage/vitrage.css +5 -0
- data/app/controllers/vitrage/pieces_controller.rb +175 -0
- data/app/views/vitrage/_edit.html.erb +15 -0
- data/app/views/vitrage/_edit_wraped_piece.html.erb +22 -0
- data/app/views/vitrage/_form_wrap.html.erb +12 -0
- data/app/views/vitrage/_show.html.erb +3 -0
- data/app/views/vitrage/pieces/create.html.erb +1 -0
- data/app/views/vitrage/pieces/create.js.erb +1 -0
- data/app/views/vitrage/pieces/edit.html.erb +1 -0
- data/app/views/vitrage/pieces/new.html.erb +19 -0
- data/app/views/vitrage/pieces/show.html.erb +1 -0
- data/config/locales/vitrage_en.yml +5 -0
- data/config/locales/vitrage_ru.yml +5 -0
- data/config/routes.rb +2 -0
- data/lib/generators/vitrage/install_generator.rb +26 -0
- data/lib/generators/vitrage/piece_generator.rb +45 -0
- data/lib/generators/vitrage/templates/migrations/create_vitrage_piece.rb +19 -0
- data/lib/generators/vitrage/templates/migrations/create_vitrage_slots.rb +16 -0
- data/lib/generators/vitrage/templates/views/piece_form_generator.html.erb +13 -0
- data/lib/generators/vitrage/templates/views/piece_show_generator.html.erb +2 -0
- data/lib/generators/vitrage/templates/vitrage_piece.rb +10 -0
- data/lib/generators/vitrage/templates/vitrage_slot.rb +23 -0
- data/lib/vitrage/acts_as_vitrage_owner.rb +15 -0
- data/lib/vitrage/engine.rb +8 -0
- data/lib/vitrage/helpers/action_view_extention.rb +24 -0
- data/lib/vitrage/router.rb +22 -0
- data/lib/vitrage/version.rb +1 -1
- data/lib/vitrage.rb +6 -0
- data/test/dummy/config/routes.rb +1 -53
- data/test/integration/navigation_test.rb +10 -0
- data/test/test_helper.rb +1 -0
- data/vendor/assets/javascript/Sortable.js +1051 -0
- metadata +123 -8
data/config/routes.rb
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
require 'rails/generators/active_record'
|
|
2
|
+
|
|
3
|
+
module Vitrage
|
|
4
|
+
module Generators
|
|
5
|
+
class InstallGenerator < ActiveRecord::Generators::Base
|
|
6
|
+
desc "Create migration, model and routes for Vitrage"
|
|
7
|
+
|
|
8
|
+
argument :name, type: :string, default: "VitragePiece" # TODO we don't needs name
|
|
9
|
+
|
|
10
|
+
source_root File.expand_path("../templates", __FILE__)
|
|
11
|
+
|
|
12
|
+
def copy_vitrage_piece_model_file
|
|
13
|
+
copy_file "vitrage_slot.rb", "app/models/vitrage_owners_pieces_slot.rb"
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def create_vitrage_piece_migration
|
|
17
|
+
migration_template "migrations/create_vitrage_slots.rb",
|
|
18
|
+
"db/migrate/create_vitrage_owners_pieces_slots.rb"
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def add_routes
|
|
22
|
+
route "Vitrage.routes(self)"
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
require 'rails/generators/active_record/model/model_generator'
|
|
2
|
+
|
|
3
|
+
# I think it isn't optimal solution for items models generation. Rethink.
|
|
4
|
+
|
|
5
|
+
module Vitrage
|
|
6
|
+
module Generators
|
|
7
|
+
class PieceGenerator < ActiveRecord::Generators::ModelGenerator
|
|
8
|
+
desc "Create vitrage piece model, migration and necessary views"
|
|
9
|
+
|
|
10
|
+
source_root File.expand_path("../templates", __FILE__)
|
|
11
|
+
|
|
12
|
+
def class_name
|
|
13
|
+
clsn = super
|
|
14
|
+
clsn[0..3] == "Vtrg" ? clsn : "Vtrg#{clsn}"
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def file_name
|
|
18
|
+
flen = super
|
|
19
|
+
flen[0..4] == "vtrg_" ? flen : "vtrg_#{flen}"
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def table_name
|
|
23
|
+
tbns = super
|
|
24
|
+
tbns[0..4] == "vtrg_" ? tbns : "vtrg_#{tbns}"
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# override ActiveRecord::Generators::ModelGenerator method
|
|
28
|
+
def create_migration_file
|
|
29
|
+
return unless options[:migration] && options[:parent].nil?
|
|
30
|
+
attributes.each { |a| a.attr_options.delete(:index) if a.reference? && !a.has_index? } if options[:indexes] == false
|
|
31
|
+
migration_template "migrations/create_vitrage_piece.rb", "db/migrate/create_#{table_name}.rb"
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# override ActiveRecord::Generators::ModelGenerator method
|
|
35
|
+
def create_model_file
|
|
36
|
+
template 'vitrage_piece.rb', File.join('app/models/vitrage_pieces/', class_path, "#{file_name}.rb")
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def create_necessary_views
|
|
40
|
+
copy_file 'views/piece_show_generator.html.erb', File.join('app/views/vitrage/', "_#{file_name}.html.erb")
|
|
41
|
+
copy_file 'views/piece_form_generator.html.erb', File.join('app/views/vitrage/', "_#{file_name}_form.html.erb")
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
class <%= migration_class_name %> < ActiveRecord::Migration
|
|
2
|
+
def change
|
|
3
|
+
create_table :<%= table_name %> do |t|
|
|
4
|
+
<% attributes.each do |attribute| -%>
|
|
5
|
+
<% if attribute.password_digest? -%>
|
|
6
|
+
t.string :password_digest<%= attribute.inject_options %>
|
|
7
|
+
<% else -%>
|
|
8
|
+
t.<%= attribute.type %> :<%= attribute.name %><%= attribute.inject_options %>
|
|
9
|
+
<% end -%>
|
|
10
|
+
<% end -%>
|
|
11
|
+
<% if options[:timestamps] %>
|
|
12
|
+
t.timestamps
|
|
13
|
+
<% end -%>
|
|
14
|
+
end
|
|
15
|
+
<% attributes_with_index.each do |attribute| -%>
|
|
16
|
+
add_index :<%= table_name %>, :<%= attribute.index_name %><%= attribute.inject_index_options %>
|
|
17
|
+
<% end -%>
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
class CreateVitrageOwnersPiecesSlots < ActiveRecord::Migration
|
|
2
|
+
def self.up
|
|
3
|
+
create_table :vitrage_owners_pieces_slots do |t|
|
|
4
|
+
t.references :owner, polymorphic: true, null: false, index: true
|
|
5
|
+
t.references :piece, polymorphic: true, index: true
|
|
6
|
+
t.integer :ordn, default: 9, null: false
|
|
7
|
+
t.timestamps
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
add_index :vitrage_owners_pieces_slots, :ordn
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def self.down
|
|
14
|
+
drop_table :vitrage_owners_pieces_slots
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<%= semantic_form_for piece, url: form_url, method: form_method, remote: true do |f| %>
|
|
2
|
+
<%= f.inputs do %>
|
|
3
|
+
<%# Add inputs of your piece model here %>
|
|
4
|
+
<%# f.input :body, input_html: { rows: 2 } %>
|
|
5
|
+
<% end -%>
|
|
6
|
+
<%= hidden_field_tag :kind, piece.class.name.demodulize, id: nil %>
|
|
7
|
+
<%= hidden_field_tag :owner_type, params[:owner_type], id: nil %>
|
|
8
|
+
<%= hidden_field_tag :owner_id, params[:owner_id], id: nil %>
|
|
9
|
+
<%= f.actions do %>
|
|
10
|
+
<%= f.action :submit, as: :button %>
|
|
11
|
+
<%= f.action :cancel, as: :link %>
|
|
12
|
+
<% end -%>
|
|
13
|
+
<% end -%>
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
class VitrageOwnersPiecesSlot < ActiveRecord::Base
|
|
2
|
+
# stored fields: :owner_type, :owner_id, :piece_type, :piece_id, :ordn
|
|
3
|
+
|
|
4
|
+
belongs_to :owner, polymorphic: true
|
|
5
|
+
belongs_to :piece, polymorphic: true, dependent: :destroy
|
|
6
|
+
|
|
7
|
+
before_create :set_correct_order_num
|
|
8
|
+
|
|
9
|
+
default_scope -> { order(ordn: :asc, id: :asc) }
|
|
10
|
+
|
|
11
|
+
PIECE_CLASSES_STRINGS = [ ] # add pieces class names strings here (demodulized)
|
|
12
|
+
|
|
13
|
+
private
|
|
14
|
+
|
|
15
|
+
# TODO wrap this becausetroubles with updating this code in the future
|
|
16
|
+
def set_correct_order_num
|
|
17
|
+
self.ordn = 1
|
|
18
|
+
if owner
|
|
19
|
+
max_ordn = owner.vitrage_slots.maximum(:ordn)
|
|
20
|
+
self.ordn = max_ordn + 1 if max_ordn
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module Vitrage
|
|
2
|
+
module ActsAsVitrageOwner
|
|
3
|
+
extend ActiveSupport::Concern
|
|
4
|
+
|
|
5
|
+
module ClassMethods
|
|
6
|
+
def acts_as_vitrage_owner
|
|
7
|
+
has_many :vitrage_slots, class_name: "VitrageOwnersPiecesSlot",
|
|
8
|
+
as: :owner,
|
|
9
|
+
dependent: :destroy
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
ActiveRecord::Base.send :include, Vitrage::ActsAsVitrageOwner
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
module Vitrage
|
|
2
|
+
# = Helpers
|
|
3
|
+
module ActionViewExtension
|
|
4
|
+
# A helper that renders the show view of vitrage
|
|
5
|
+
#
|
|
6
|
+
# <%= show_vitrage_for @page %>
|
|
7
|
+
#
|
|
8
|
+
def show_vitrage_for(owner)
|
|
9
|
+
render partial: 'vitrage/show', locals: { owner: owner }
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# A helper that renders the show view of vitrage
|
|
13
|
+
#
|
|
14
|
+
# <%= edit_vitrage_for @page %>
|
|
15
|
+
#
|
|
16
|
+
def edit_vitrage_for(owner)
|
|
17
|
+
render partial: 'vitrage/edit', locals: { owner: owner }
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
ActiveSupport.on_load(:action_view) do
|
|
23
|
+
ActionView::Base.send :include, Vitrage::ActionViewExtension
|
|
24
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
module Vitrage
|
|
2
|
+
module Router
|
|
3
|
+
|
|
4
|
+
def routes(rails_router, options = {})
|
|
5
|
+
cs = options[:controller] ? options[:controller].to_s : "pieces"
|
|
6
|
+
|
|
7
|
+
rails_router.post '/vitrage/pieces' => "#{cs}#create", as: :vitrage_pieces
|
|
8
|
+
rails_router.get '/vitrage/pieces/new' => "#{cs}#new", as: :new_vitrage_piece
|
|
9
|
+
rails_router.get '/vitrage/pieces/restore_order' => "#{cs}#restore_order", as: :restore_order_vitrage_pieces
|
|
10
|
+
rails_router.get '/vitrage/pieces/:id/edit' => "#{cs}#edit", as: :edit_vitrage_piece
|
|
11
|
+
rails_router.get '/vitrage/pieces/:id' => "#{cs}#show", as: :vitrage_piece
|
|
12
|
+
rails_router.match '/vitrage/pieces/:id' => "#{cs}#update", via: [:patch, :put]
|
|
13
|
+
rails_router.delete '/vitrage/pieces/:id' => "#{cs}#destroy"
|
|
14
|
+
rails_router.post '/vitrage/pieces/:id/reorder' => "#{cs}#reorder", as: :vitrage_piece_reoder
|
|
15
|
+
|
|
16
|
+
# rails_router.namespace :vitrage do
|
|
17
|
+
# rails_router.resources :pieces, except: [:index]
|
|
18
|
+
# end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
end
|
|
22
|
+
end
|
data/lib/vitrage/version.rb
CHANGED
data/lib/vitrage.rb
CHANGED
data/test/dummy/config/routes.rb
CHANGED
|
@@ -1,56 +1,4 @@
|
|
|
1
1
|
Rails.application.routes.draw do
|
|
2
|
-
# The priority is based upon order of creation: first created -> highest priority.
|
|
3
|
-
# See how all your routes lay out with "rake routes".
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
# root 'welcome#index'
|
|
7
|
-
|
|
8
|
-
# Example of regular route:
|
|
9
|
-
# get 'products/:id' => 'catalog#view'
|
|
10
|
-
|
|
11
|
-
# Example of named route that can be invoked with purchase_url(id: product.id)
|
|
12
|
-
# get 'products/:id/purchase' => 'catalog#purchase', as: :purchase
|
|
13
|
-
|
|
14
|
-
# Example resource route (maps HTTP verbs to controller actions automatically):
|
|
15
|
-
# resources :products
|
|
16
|
-
|
|
17
|
-
# Example resource route with options:
|
|
18
|
-
# resources :products do
|
|
19
|
-
# member do
|
|
20
|
-
# get 'short'
|
|
21
|
-
# post 'toggle'
|
|
22
|
-
# end
|
|
23
|
-
#
|
|
24
|
-
# collection do
|
|
25
|
-
# get 'sold'
|
|
26
|
-
# end
|
|
27
|
-
# end
|
|
28
|
-
|
|
29
|
-
# Example resource route with sub-resources:
|
|
30
|
-
# resources :products do
|
|
31
|
-
# resources :comments, :sales
|
|
32
|
-
# resource :seller
|
|
33
|
-
# end
|
|
34
|
-
|
|
35
|
-
# Example resource route with more complex sub-resources:
|
|
36
|
-
# resources :products do
|
|
37
|
-
# resources :comments
|
|
38
|
-
# resources :sales do
|
|
39
|
-
# get 'recent', on: :collection
|
|
40
|
-
# end
|
|
41
|
-
# end
|
|
42
|
-
|
|
43
|
-
# Example resource route with concerns:
|
|
44
|
-
# concern :toggleable do
|
|
45
|
-
# post 'toggle'
|
|
46
|
-
# end
|
|
47
|
-
# resources :posts, concerns: :toggleable
|
|
48
|
-
# resources :photos, concerns: :toggleable
|
|
49
|
-
|
|
50
|
-
# Example resource route within a namespace:
|
|
51
|
-
# namespace :admin do
|
|
52
|
-
# # Directs /admin/products/* to Admin::ProductsController
|
|
53
|
-
# # (app/controllers/admin/products_controller.rb)
|
|
54
|
-
# resources :products
|
|
55
|
-
# end
|
|
3
|
+
mount Vitrage::Engine => "/vitrage"
|
|
56
4
|
end
|
data/test/test_helper.rb
CHANGED
|
@@ -3,6 +3,7 @@ ENV["RAILS_ENV"] = "test"
|
|
|
3
3
|
|
|
4
4
|
require File.expand_path("../../test/dummy/config/environment.rb", __FILE__)
|
|
5
5
|
ActiveRecord::Migrator.migrations_paths = [File.expand_path("../../test/dummy/db/migrate", __FILE__)]
|
|
6
|
+
ActiveRecord::Migrator.migrations_paths << File.expand_path('../../db/migrate', __FILE__)
|
|
6
7
|
require "rails/test_help"
|
|
7
8
|
|
|
8
9
|
# Filter out Minitest backtrace while allowing backtrace from other libraries
|