redde 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +20 -0
- data/.rspec +1 -0
- data/Gemfile +4 -0
- data/Guardfile +24 -0
- data/LICENSE +22 -0
- data/README.md +57 -0
- data/Rakefile +2 -0
- data/lib/generators/redde/deploy/deploy_generator.rb +34 -0
- data/lib/generators/redde/deploy/templates/Capfile +4 -0
- data/lib/generators/redde/deploy/templates/deploy.rb +33 -0
- data/lib/generators/redde/deploy/templates/recipes/base.rb +16 -0
- data/lib/generators/redde/deploy/templates/recipes/check.rb +13 -0
- data/lib/generators/redde/deploy/templates/recipes/database.rb +66 -0
- data/lib/generators/redde/deploy/templates/recipes/imagemagick.rb +8 -0
- data/lib/generators/redde/deploy/templates/recipes/memcached.rb +10 -0
- data/lib/generators/redde/deploy/templates/recipes/monit.rb +35 -0
- data/lib/generators/redde/deploy/templates/recipes/nginx.rb +26 -0
- data/lib/generators/redde/deploy/templates/recipes/nodejs.rb +10 -0
- data/lib/generators/redde/deploy/templates/recipes/postfix.rb +37 -0
- data/lib/generators/redde/deploy/templates/recipes/rbenv.rb +17 -0
- data/lib/generators/redde/deploy/templates/recipes/templates/database.yml.erb +8 -0
- data/lib/generators/redde/deploy/templates/recipes/templates/dkim-filter.conf.erb +57 -0
- data/lib/generators/redde/deploy/templates/recipes/templates/dkim-filter.defaults.erb +11 -0
- data/lib/generators/redde/deploy/templates/recipes/templates/dkim-keys.conf.erb +2 -0
- data/lib/generators/redde/deploy/templates/recipes/templates/gemrc.erb +1 -0
- data/lib/generators/redde/deploy/templates/recipes/templates/main.cf.erb +43 -0
- data/lib/generators/redde/deploy/templates/recipes/templates/memcached.erb +47 -0
- data/lib/generators/redde/deploy/templates/recipes/templates/monit_monitrc.erb +21 -0
- data/lib/generators/redde/deploy/templates/recipes/templates/monit_nginx.erb +5 -0
- data/lib/generators/redde/deploy/templates/recipes/templates/monit_unicorn.erb +14 -0
- data/lib/generators/redde/deploy/templates/recipes/templates/nginx_unicorn.erb +28 -0
- data/lib/generators/redde/deploy/templates/recipes/templates/unicorn.rb.erb +36 -0
- data/lib/generators/redde/deploy/templates/recipes/templates/unicorn_init.erb +84 -0
- data/lib/generators/redde/deploy/templates/recipes/unicorn.rb +27 -0
- data/lib/generators/redde/layout/layout_generator.rb +57 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/addphoto.png +0 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/ajaxloader2.gif +0 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/arrow_down.png +0 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/arrow_enter.png +0 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/arrow_right.png +0 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/coins.png +0 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/confirm.png +0 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/del.png +0 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/delete.png +0 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/email.png +0 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/error.png +0 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/fio.png +0 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/folder.png +0 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/folder_.png +0 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/icon_eye.gif +0 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/lightbox/css/jquery.lightbox-0.5.css +101 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/lightbox/images/lightbox-blank.gif +0 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/lightbox/images/lightbox-btn-close.gif +0 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/lightbox/images/lightbox-btn-next.gif +0 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/lightbox/images/lightbox-btn-prev.gif +0 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/lightbox/images/lightbox-ico-loading.gif +0 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/lightbox/js/jquery.js +32 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/lightbox/js/jquery.lightbox-0.5.js +477 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/lightbox/js/jquery.lightbox-0.5.min.js +42 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/lightbox/js/jquery.lightbox-0.5.pack.js +14 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/logo.png +0 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/logo_reddeshop.png +0 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/move_handler.png +0 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/phone.png +0 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/photo_ico.png +0 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/print.png +0 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/redactor/css/docstyle.css +123 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/redactor/css/redactor.css +369 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/redactor/css/style.css +119 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/redactor/css/wym.css +136 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/redactor/img/icons.png +0 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/redactor/langs/by.js +72 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/redactor/langs/de.js +75 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/redactor/langs/en.js +76 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/redactor/langs/es.js +76 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/redactor/langs/fr.js +74 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/redactor/langs/hu.js +76 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/redactor/langs/it.js +76 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/redactor/langs/ja.js +76 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/redactor/langs/lv.js +74 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/redactor/langs/nl.js +76 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/redactor/langs/pl.js +75 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/redactor/langs/pt_br.js +81 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/redactor/langs/ru.js +75 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/redactor/langs/sq.js +76 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/redactor/langs/tr.js +76 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/redactor/langs/ua.js +75 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/redactor/langs/zh_cn.js +77 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/redactor/plugins/file.html +3 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/redactor/plugins/image.html +39 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/redactor/plugins/image_edit.html +35 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/redactor/plugins/link.html +74 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/redactor/plugins/table.html +25 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/redactor/plugins/video.html +15 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/redactor/redactor.js.erb +2260 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/redactor/redactor.min.js +1 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/redactor/toolbars/default.js +219 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/redactor/toolbars/mini.js +103 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/reddebox/_jquery.reddebox.js.erb +214 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/reddebox/close.png +0 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/reddebox/jquery.reddebox.js.erb +246 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/reddebox/jquery.reddebox.scss +31 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/reddebox/next.png +0 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/reddebox/prev.png +0 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/refresh.png +0 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/submit.png +0 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/submit_hover.png +0 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/uploadifive/change-log.txt +19 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/uploadifive/check-exists.php +15 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/uploadifive/index.php +50 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/uploadifive/jquery.uploadifive.js +888 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/uploadifive/jquery.uploadifive.min.js +6 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/uploadifive/license-standard.txt +71 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/uploadifive/uploadifive-cancel.png +0 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/uploadifive/uploadifive-image-only.php +66 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/uploadifive/uploadifive.css +100 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/uploadifive/uploadifive.php +33 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/uploadify/#swfobject.js +4 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/uploadify/cancel.png +0 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/uploadify/jquery.uploadify.min.js +315 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/uploadify/uploadify-cancel.png +0 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/uploadify/uploadify.css +66 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/uploadify/uploadify.swf +0 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/view.png +0 -0
- data/lib/generators/redde/layout/templates/assets/images/admin/view_mk.png +0 -0
- data/lib/generators/redde/layout/templates/assets/javascripts/admin/jquery.ui.nestedSortable.js +390 -0
- data/lib/generators/redde/layout/templates/assets/javascripts/admin/swfobject.js +4 -0
- data/lib/generators/redde/layout/templates/assets/javascripts/admin/zen_textarea.min.js +17 -0
- data/lib/generators/redde/layout/templates/assets/javascripts/admin.js +88 -0
- data/lib/generators/redde/layout/templates/assets/stylesheets/admin/_reset.scss +32 -0
- data/lib/generators/redde/layout/templates/assets/stylesheets/admin/blocks/_list.scss +22 -0
- data/lib/generators/redde/layout/templates/assets/stylesheets/admin/blocks/_notice.scss +39 -0
- data/lib/generators/redde/layout/templates/assets/stylesheets/admin/blocks/_orders.scss +22 -0
- data/lib/generators/redde/layout/templates/assets/stylesheets/admin/blocks/_partners.scss +15 -0
- data/lib/generators/redde/layout/templates/assets/stylesheets/admin/blocks/_photos.scss +31 -0
- data/lib/generators/redde/layout/templates/assets/stylesheets/admin/blocks/_sortable.scss +17 -0
- data/lib/generators/redde/layout/templates/assets/stylesheets/admin/default.scss +127 -0
- data/lib/generators/redde/layout/templates/assets/stylesheets/admin/defaults/_input.scss +43 -0
- data/lib/generators/redde/layout/templates/assets/stylesheets/admin/defaults/_table.scss +24 -0
- data/lib/generators/redde/layout/templates/assets/stylesheets/admin/layouts/_header.scss +57 -0
- data/lib/generators/redde/layout/templates/assets/stylesheets/admin/layouts/_launchbar.scss +35 -0
- data/lib/generators/redde/layout/templates/assets/stylesheets/admin/layouts/_login.scss +10 -0
- data/lib/generators/redde/layout/templates/assets/stylesheets/admin/layouts/_main.scss +59 -0
- data/lib/generators/redde/layout/templates/assets/stylesheets/admin/layouts/_sidebar.scss +35 -0
- data/lib/generators/redde/layout/templates/assets/stylesheets/admin/shop/_filter.scss +16 -0
- data/lib/generators/redde/layout/templates/assets/stylesheets/admin/shop/_order-sh.scss +59 -0
- data/lib/generators/redde/layout/templates/assets/stylesheets/admin/shop/_pe.scss +43 -0
- data/lib/generators/redde/layout/templates/assets/stylesheets/admin.scss +12 -0
- data/lib/generators/redde/layout/templates/controllers/base_controller.rb +6 -0
- data/lib/generators/redde/layout/templates/helpers/admin_helper.rb +37 -0
- data/lib/generators/redde/layout/templates/layouts/admin.html.haml +30 -0
- data/lib/generators/redde/layout/templates/layouts/login.html.haml +32 -0
- data/lib/generators/redde/layout/templates/shared/_header.html.haml +13 -0
- data/lib/generators/redde/layout/templates/shared/_launchbar.html.haml +9 -0
- data/lib/generators/redde/layout/templates/shared/_sidebar.html.haml +23 -0
- data/lib/generators/redde/scaffold/scaffold_generator.rb +114 -0
- data/lib/generators/redde/scaffold/templates/controllers/controller.rb +55 -0
- data/lib/generators/redde/scaffold/templates/edit.html.haml +36 -0
- data/lib/generators/redde/scaffold/templates/index.html.haml +37 -0
- data/lib/redde/version.rb +3 -0
- data/lib/redde.rb +4 -0
- data/redde.gemspec +26 -0
- data/spec/deploy_generator_spec.rb +29 -0
- data/spec/layout_generator_spec.rb +41 -0
- data/spec/scaffold_generator_spec.rb +25 -0
- data/spec/spec_helper.rb +10 -0
- metadata +327 -0
@@ -0,0 +1,23 @@
|
|
1
|
+
- a = controller.controller_name
|
2
|
+
%ul#nav
|
3
|
+
-case @active
|
4
|
+
-when :shop then
|
5
|
+
%li{:class => "#{'active' if a == 'products'}"}= link_to "Товары", admin_products_path
|
6
|
+
%li{:class => "#{'active' if a == 'categories'}"}= link_to "Категории", admin_categories_path
|
7
|
+
%li{:class => "#{'active' if a == 'countries'}"}= link_to "Страны", admin_countries_path
|
8
|
+
%li{:class => "#{'active' if a == 'regions'}"}= link_to "Регионы", admin_regions_path
|
9
|
+
%li{:class => "#{'active' if a == 'brands'}"}= link_to "Производители", [:admin, :brands]
|
10
|
+
%li{:class => "#{'active' if a == 'sliders' && params[:slider_block] == "1"}"}= link_to "Слайдер", admin_sliders_path(slider_block: 1)
|
11
|
+
%li{:class => "#{'active' if a == 'sliders' && params[:slider_block] == "3"}"}= link_to "Баннеры (маленькие)", admin_sliders_path(slider_block: 3)
|
12
|
+
%li{:class => "#{'active' if a == 'orders'}"}= link_to "Заказы", [:admin, :orders]
|
13
|
+
|
14
|
+
|
15
|
+
-when :materials then
|
16
|
+
%li{:class => "#{'active' if a == 'articles'}"}= link_to "Статьи", [:admin, :articles]
|
17
|
+
%li{:class => "#{'active' if a == 'categories'}"}= link_to "Категории", [:admin, :categories]
|
18
|
+
%li{:class => "#{'active' if a == 'works'}"}= link_to "Портфолио", [:admin, :works]
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
-when :system
|
23
|
+
%li{:class => "#{'active' if a == 'users'}"}= link_to "Пользователи", admin_users_path
|
@@ -0,0 +1,114 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/generated_attribute'
|
3
|
+
|
4
|
+
module Redde
|
5
|
+
module Generators
|
6
|
+
class ScaffoldGenerator < ::Rails::Generators::Base
|
7
|
+
source_root File.expand_path('../templates', __FILE__)
|
8
|
+
argument :controller_path, :type => :string
|
9
|
+
argument :model_name, :type => :string, :required => false
|
10
|
+
argument :layout, :type => :string, :default => "application",
|
11
|
+
:banner => "Specify application layout"
|
12
|
+
|
13
|
+
def initialize(args, *options)
|
14
|
+
super(args, *options)
|
15
|
+
initialize_views_variables
|
16
|
+
end
|
17
|
+
|
18
|
+
def copy_views
|
19
|
+
generate_views
|
20
|
+
end
|
21
|
+
|
22
|
+
protected
|
23
|
+
|
24
|
+
def initialize_views_variables
|
25
|
+
@base_name, @controller_class_path, @controller_file_path, @controller_class_nesting, @controller_class_nesting_depth = extract_modules(controller_path)
|
26
|
+
@controller_routing_path = @controller_file_path.gsub(/\//, '_')
|
27
|
+
@model_name = @controller_class_nesting + "::#{@base_name.singularize.camelize}" unless @model_name
|
28
|
+
@model_name = @model_name.camelize
|
29
|
+
end
|
30
|
+
|
31
|
+
def controller_routing_path
|
32
|
+
@controller_routing_path
|
33
|
+
end
|
34
|
+
|
35
|
+
def singular_controller_routing_path
|
36
|
+
@controller_routing_path.singularize
|
37
|
+
end
|
38
|
+
|
39
|
+
def model_name
|
40
|
+
@model_name
|
41
|
+
end
|
42
|
+
|
43
|
+
def plural_model_name
|
44
|
+
@model_name.pluralize
|
45
|
+
end
|
46
|
+
|
47
|
+
def resource_name
|
48
|
+
@model_name.demodulize.underscore
|
49
|
+
end
|
50
|
+
|
51
|
+
def plural_resource_name
|
52
|
+
resource_name.pluralize
|
53
|
+
end
|
54
|
+
|
55
|
+
def sort_priority(column_name)
|
56
|
+
case column_name
|
57
|
+
when "position" then 1
|
58
|
+
when "visible" then 2
|
59
|
+
when "name" then 3
|
60
|
+
when "title" then 3
|
61
|
+
else 5
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def columns
|
66
|
+
begin
|
67
|
+
excluded_column_names = %w[id created_at updated_at]
|
68
|
+
@model_name.constantize.columns.reject{|c| excluded_column_names.include?(c.name) || c.name.index("_id") }.sort{|a, b| sort_priority(a.name) <=> sort_priority(b.name)}.collect{|c| ::Rails::Generators::GeneratedAttribute.new(c.name, c.type)}
|
69
|
+
rescue NoMethodError
|
70
|
+
@model_name.constantize.fields.collect{|c| c[1]}.reject{|c| excluded_column_names.include?(c.name) || c.name.index("_id") }.collect{|c| ::Rails::Generators::GeneratedAttribute.new(c.name, c.type.to_s)}
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def column_names
|
75
|
+
@model_name.constantize.column_names
|
76
|
+
end
|
77
|
+
|
78
|
+
def extract_modules(name)
|
79
|
+
modules = name.include?('/') ? name.split('/') : name.split('::')
|
80
|
+
name = modules.pop
|
81
|
+
path = modules.map { |m| m.underscore }
|
82
|
+
file_path = (path + [name.underscore]).join('/')
|
83
|
+
nesting = modules.map { |m| m.camelize }.join('::')
|
84
|
+
[name, path, file_path, nesting, modules.size]
|
85
|
+
end
|
86
|
+
|
87
|
+
def generate_views
|
88
|
+
views = {
|
89
|
+
"index.html.#{ext}" => "app/views/admin/#{@controller_file_path}/index.html.#{ext}",
|
90
|
+
"edit.html.#{ext}" => "app/views/admin/#{@controller_file_path}/edit.html.#{ext}"
|
91
|
+
}
|
92
|
+
selected_views = views
|
93
|
+
options.engine == generate_erb(selected_views)
|
94
|
+
end
|
95
|
+
|
96
|
+
|
97
|
+
def generate_erb(views)
|
98
|
+
views.each do |template_name, output_path|
|
99
|
+
template template_name, output_path
|
100
|
+
end
|
101
|
+
generate_controller
|
102
|
+
end
|
103
|
+
|
104
|
+
def ext
|
105
|
+
:haml
|
106
|
+
end
|
107
|
+
|
108
|
+
def generate_controller
|
109
|
+
template "controllers/controller.rb", "app/controllers/admin/#{plural_resource_name}_controller.rb"
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
class Admin::<%= plural_resource_name.capitalize -%>Controller < Admin::BaseController
|
3
|
+
|
4
|
+
def index
|
5
|
+
@<%= plural_resource_name %> = <%= model_name.demodulize -%>.all
|
6
|
+
end
|
7
|
+
<%- if column_names.include?("position") -%>
|
8
|
+
def sort
|
9
|
+
params[:pos].each_with_index do |id, idx|
|
10
|
+
p = <%= model_name.demodulize -%>.find(id)
|
11
|
+
p.position = idx
|
12
|
+
p.save
|
13
|
+
end
|
14
|
+
render :nothing => true
|
15
|
+
end
|
16
|
+
<%- end -%>
|
17
|
+
def new
|
18
|
+
@<%= resource_name %> = <%= model_name.demodulize -%>.new
|
19
|
+
render 'edit'
|
20
|
+
end
|
21
|
+
|
22
|
+
def edit
|
23
|
+
@<%= resource_name %> = <%= model_name.demodulize -%>.find(params[:id])
|
24
|
+
end
|
25
|
+
|
26
|
+
def create
|
27
|
+
@<%= resource_name %> = <%= model_name.demodulize -%>.new(<%= resource_name %>_params)
|
28
|
+
if @<%= resource_name %>.save
|
29
|
+
redirect_to params[:commit] == "Применить" ? [:edit, :admin, @<%= resource_name %>] : [:admin, :<%= plural_resource_name %>], :notice => "#{<%= model_name.demodulize -%>.model_name.human} добавлен."
|
30
|
+
else
|
31
|
+
render 'edit'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def update
|
36
|
+
@<%= resource_name %> = <%= model_name.demodulize -%>.find(params[:id])
|
37
|
+
if @<%= resource_name %>.update_attributes(<%= resource_name %>_params)
|
38
|
+
redirect_to params[:commit] == "Применить" ? [:edit, :admin, @<%= resource_name %>] : [:admin, :<%= plural_resource_name %>], :notice => "#{<%= model_name.demodulize -%>.model_name.human} отредактирован."
|
39
|
+
else
|
40
|
+
render 'edit'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def destroy
|
45
|
+
@<%= resource_name %> = <%= model_name.demodulize -%>.find(params[:id])
|
46
|
+
@<%= resource_name %>.destroy
|
47
|
+
redirect_to admin_<%= plural_resource_name %>_path, :notice => "#{<%= model_name.demodulize -%>.model_name.human} удален."
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
def <%= resource_name %>_params
|
52
|
+
params.require(:<%= resource_name %>).permit(<%= column_names.select {|c| !(['id', 'updated_at', 'created_at'].include? c) }.map {|c| ":#{c}"}.join(', ') %>)
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
- content_for :page_header do
|
2
|
+
%h1
|
3
|
+
- if @<%= resource_name %>.new_record?
|
4
|
+
Добавить #{tgenetive(:<%= resource_name %>)}
|
5
|
+
- else
|
6
|
+
Редактировать #{tgenetive(:<%= resource_name %>)}
|
7
|
+
|
8
|
+
= form_for [:admin, @<%= resource_name %>] do |f|
|
9
|
+
- if @<%= resource_name %>.errors.any?
|
10
|
+
#error_explanation
|
11
|
+
%h2= "Ошибки при сохранении: #{@<%= resource_name %>.errors.count}"
|
12
|
+
%ul
|
13
|
+
- @<%= resource_name %>.errors.full_messages.each do |msg|
|
14
|
+
%li= msg
|
15
|
+
%table
|
16
|
+
<%- columns.each do |column| -%>
|
17
|
+
<%- if column.field_type.to_s == "text_area" -%>
|
18
|
+
%tr
|
19
|
+
%td{colspan: 2}
|
20
|
+
= f.label :<%= column.name %>
|
21
|
+
%br
|
22
|
+
= f.<%= column.field_type -%> :<%= column.name %>
|
23
|
+
<%- elsif column.field_type.to_s == "check_box" -%>
|
24
|
+
%tr
|
25
|
+
%th{colspan: 2}
|
26
|
+
= f.<%= column.field_type -%> :<%= column.name %>
|
27
|
+
= f.label :<%= column.name %>
|
28
|
+
<%- elsif column.name != "position" -%>
|
29
|
+
%tr
|
30
|
+
%th= f.label :<%= column.name %>
|
31
|
+
%td= f.<%= column.field_type -%> :<%= column.name %>
|
32
|
+
<%- end -%>
|
33
|
+
<%- end -%>
|
34
|
+
.actions
|
35
|
+
= f.submit "Сохранить"
|
36
|
+
= f.submit "Применить"
|
@@ -0,0 +1,37 @@
|
|
1
|
+
- content_for(:page_header) do
|
2
|
+
%h1= tplural(<%= resource_name.capitalize %>)
|
3
|
+
%p= link_to "Добавить #{tgenetive('<%= resource_name %>')}", [:new, :admin, :<%= resource_name %>]
|
4
|
+
|
5
|
+
- unless @<%= plural_resource_name %>.empty?
|
6
|
+
%table.list<%= ".sortable" if column_names.include?("position") %>
|
7
|
+
%colgroup
|
8
|
+
<%- columns.each do |column| -%>
|
9
|
+
%col<%= ".w1" if ["position", "visible"].include? column.name %>
|
10
|
+
<%- end -%>
|
11
|
+
%col.w1
|
12
|
+
%thead
|
13
|
+
%tr
|
14
|
+
<%- columns.each do |column| -%>
|
15
|
+
%th<%- unless ["position", "visible"].include? column.name %>= <%= resource_name.capitalize %>.human_attribute_name("<%= column.name %>")<% end %>
|
16
|
+
<%- end -%>
|
17
|
+
%th
|
18
|
+
- @<%= plural_resource_name %>.each do |<%= resource_name %>|
|
19
|
+
<%- if column_names.include?("position") -%>
|
20
|
+
%tr{id: "pos_#{<%= resource_name %>.id}"}
|
21
|
+
<%- else -%>
|
22
|
+
%tr
|
23
|
+
<%- end -%>
|
24
|
+
<%- columns.each do |column| -%>
|
25
|
+
<%- if column.name == "position" -%>
|
26
|
+
%td.handle= image_tag asset_path("admin/move_handler.png")
|
27
|
+
<%- elsif column.name == "visible" -%>
|
28
|
+
%td.show= link_to "", admin_<%= singular_controller_routing_path %>_path(<%= resource_name %>, <%= resource_name %>: {visible: !<%= resource_name %>.visible}), :class => <%= resource_name %>.visible ? nil : "not-show", data: {method: 'put'}
|
29
|
+
<%- else -%>
|
30
|
+
%td= link_to <%= resource_name %>.<%= column.name %>, [:edit, :admin, <%= resource_name %>]
|
31
|
+
<%- end -%>
|
32
|
+
<%- end -%>
|
33
|
+
%td= link_to "Удалить", [:admin, <%= resource_name %>], :method => :delete, :confirm => "Удалить?", class: :del
|
34
|
+
|
35
|
+
<%- if column_names.include?("position") -%>
|
36
|
+
= sortable sort_admin_<%= plural_resource_name %>_path
|
37
|
+
<%- end -%>
|
data/lib/redde.rb
ADDED
data/redde.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require File.expand_path('../lib/redde/version', __FILE__)
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.authors = ["Oleg Bovykin"]
|
7
|
+
gem.email = ["oleg.bovykin@gmail.com"]
|
8
|
+
gem.description = %q{Simple admin scaffold generator}
|
9
|
+
gem.summary = %q{Admin scaffold generator for redde shop engine}
|
10
|
+
gem.homepage = "http://github.com/redde/redde"
|
11
|
+
|
12
|
+
gem.files = `git ls-files`.split($\)
|
13
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
14
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
15
|
+
gem.name = "redde"
|
16
|
+
gem.require_paths = ["lib"]
|
17
|
+
gem.version = Redde::VERSION
|
18
|
+
|
19
|
+
gem.add_runtime_dependency 'russian', '>= 0.6.0'
|
20
|
+
gem.add_runtime_dependency 'haml-rails'
|
21
|
+
gem.add_runtime_dependency 'compass-rails'
|
22
|
+
gem.add_development_dependency 'rails', '>= 3.1'
|
23
|
+
gem.add_development_dependency 'rspec-rails', '>= 2.7'
|
24
|
+
gem.add_development_dependency 'guard-rspec'
|
25
|
+
gem.add_development_dependency 'generator_spec'
|
26
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Redde::Generators::DeployGenerator do
|
4
|
+
include GeneratorSpec::TestCase
|
5
|
+
destination File.expand_path("../../tmp", __FILE__)
|
6
|
+
arguments %w(127.0.0.1 redde.ru)
|
7
|
+
|
8
|
+
before(:all) do
|
9
|
+
prepare_destination
|
10
|
+
run_generator
|
11
|
+
end
|
12
|
+
|
13
|
+
after(:all) do
|
14
|
+
FileUtils.rm_rf 'tmp'
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "deploy" do
|
18
|
+
|
19
|
+
it "creates a test initializer" do
|
20
|
+
# check capfile and deploy.rb
|
21
|
+
assert_file "Capfile"
|
22
|
+
assert_file "config/deploy.rb"
|
23
|
+
|
24
|
+
assert_directory "config/recipes"
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Redde::Generators::LayoutGenerator do
|
4
|
+
include GeneratorSpec::TestCase
|
5
|
+
destination File.expand_path("../../tmp", __FILE__)
|
6
|
+
arguments %w(something)
|
7
|
+
|
8
|
+
before(:all) do
|
9
|
+
prepare_destination
|
10
|
+
run_generator
|
11
|
+
end
|
12
|
+
|
13
|
+
after(:all) do
|
14
|
+
FileUtils.rm_rf 'tmp'
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "layout" do
|
18
|
+
|
19
|
+
it "creates a test initializer" do
|
20
|
+
# check layouts
|
21
|
+
assert_file "app/views/layouts/admin.html.haml"
|
22
|
+
assert_file "app/views/layouts/login.html.haml"
|
23
|
+
|
24
|
+
# check shared
|
25
|
+
assert_file "app/views/admin/shared/_launchbar.html.haml"
|
26
|
+
assert_file "app/views/admin/shared/_sidebar.html.haml"
|
27
|
+
assert_file "app/views/admin/shared/_header.html.haml"
|
28
|
+
|
29
|
+
# check js and css
|
30
|
+
assert_file "app/assets/javascripts/admin.js"
|
31
|
+
assert_file "app/assets/stylesheets/admin.scss"
|
32
|
+
|
33
|
+
#check images
|
34
|
+
assert_directory "app/assets/images/admin"
|
35
|
+
assert_directory "app/assets/javascripts/admin"
|
36
|
+
assert_directory "app/assets/stylesheets/admin"
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Redde::Generators::ScaffoldGenerator do
|
4
|
+
include GeneratorSpec::TestCase
|
5
|
+
destination File.expand_path("../../tmp", __FILE__)
|
6
|
+
# arguments 'CategoryValues'
|
7
|
+
|
8
|
+
before(:all) do
|
9
|
+
prepare_destination
|
10
|
+
run_generator
|
11
|
+
end
|
12
|
+
|
13
|
+
after(:all) do
|
14
|
+
FileUtils.rm_rf 'tmp'
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "scaffold" do
|
18
|
+
|
19
|
+
it "Test scaffold generator" do
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'rails/all'
|
3
|
+
require 'active_record'
|
4
|
+
require 'rspec'
|
5
|
+
require 'generator_spec/test_case'
|
6
|
+
require 'generators/redde/layout/layout_generator'
|
7
|
+
require 'generators/redde/scaffold/scaffold_generator'
|
8
|
+
require 'generators/redde/deploy/deploy_generator'
|
9
|
+
Dir[Pathname.new(File.expand_path('../', __FILE__)).join('support/**/*.rb')].each {|f| require f}
|
10
|
+
|