ideyabox 0.0.6 → 0.1.0
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/README.md +32 -1
- data/app/assets/images/.DS_Store +0 -0
- data/app/assets/javascripts/default.js +35 -0
- data/app/assets/stylesheets/{admin.scss.erb → default.scss.erb} +24 -5
- data/app/helpers/admin_helper.rb +8 -2
- data/lib/generators/.DS_Store +0 -0
- data/lib/generators/ideyabox/.DS_Store +0 -0
- data/lib/generators/ideyabox/admin/.DS_Store +0 -0
- data/lib/generators/ideyabox/admin/admin_generator.rb +45 -2
- data/lib/generators/ideyabox/admin/templates/assets/admin.js +6 -0
- data/lib/generators/ideyabox/admin/templates/assets/admin.scss.erb +3 -0
- data/lib/generators/ideyabox/admin/templates/controllers/application_controller.rb +13 -0
- data/lib/generators/ideyabox/admin/templates/locales/devise.ru.yml +36 -0
- data/lib/generators/ideyabox/admin/templates/locales/en.yml +32 -0
- data/lib/generators/ideyabox/admin/templates/locales/ru.yml +31 -0
- data/lib/generators/ideyabox/admin/templates/views/admin/shared/_header.html.haml +2 -3
- data/lib/generators/ideyabox/admin/templates/views/admin/shared/_launchbar.html.haml +2 -2
- data/lib/generators/ideyabox/admin/templates/views/admin/shared/_topbar.html.haml +1 -2
- data/lib/generators/ideyabox/admin/templates/views/layouts/admin.html.haml +1 -8
- data/lib/generators/ideyabox/admin/templates/views/layouts/login.html.haml +1 -1
- data/lib/generators/ideyabox/scaffold/.DS_Store +0 -0
- data/lib/generators/ideyabox/scaffold/scaffold_generator.rb +173 -0
- data/lib/generators/ideyabox/scaffold/templates/.DS_Store +0 -0
- data/lib/generators/ideyabox/scaffold/templates/_index.html.haml +38 -0
- data/lib/generators/ideyabox/scaffold/templates/_sort_buttons.html.haml +4 -0
- data/lib/generators/ideyabox/scaffold/templates/controllers/controller.rb +67 -0
- data/lib/generators/ideyabox/scaffold/templates/edit.html.haml +38 -0
- data/lib/generators/ideyabox/scaffold/templates/index.html.haml +9 -0
- data/lib/generators/ideyabox/scaffold/templates/index.js.haml +7 -0
- data/lib/ideyabox/version.rb +1 -1
- metadata +22 -4
- data/app/assets/javascripts/admin.js +0 -13
data/README.md
CHANGED
@@ -2,6 +2,11 @@
|
|
2
2
|
|
3
3
|
TODO: Write a gem description
|
4
4
|
|
5
|
+
## Our statuses
|
6
|
+
|
7
|
+
[](https://codeclimate.com/github/I-de-ya/ideyabox)
|
8
|
+
[](https://gemnasium.com/I-de-ya/ideyabox)
|
9
|
+
|
5
10
|
## Installation
|
6
11
|
|
7
12
|
Add this line to your application's Gemfile:
|
@@ -18,7 +23,33 @@ Or install it yourself as:
|
|
18
23
|
|
19
24
|
## Usage
|
20
25
|
|
21
|
-
|
26
|
+
Hey, people!
|
27
|
+
|
28
|
+
It's simple like this:
|
29
|
+
|
30
|
+
After installation generate all administrative staff
|
31
|
+
|
32
|
+
$ rails g ideyabox:admin -f
|
33
|
+
|
34
|
+
Generate some model or scaffold for your project
|
35
|
+
|
36
|
+
Add */admin* route in your *config/routes.rb* in :admin namespace
|
37
|
+
|
38
|
+
namespace :admin do
|
39
|
+
root :to => "your_controller#your_action"
|
40
|
+
end
|
41
|
+
|
42
|
+
like this
|
43
|
+
|
44
|
+
namespace :admin do
|
45
|
+
root :to => "guests#index"
|
46
|
+
end
|
47
|
+
|
48
|
+
## TODO
|
49
|
+
|
50
|
+
1. Add search engine
|
51
|
+
2. Add scopes to models
|
52
|
+
2. Use it
|
22
53
|
|
23
54
|
## Contributing
|
24
55
|
|
data/app/assets/images/.DS_Store
CHANGED
Binary file
|
@@ -0,0 +1,35 @@
|
|
1
|
+
//= require modernizr.js
|
2
|
+
//= require jquery
|
3
|
+
//= require jquery-ui
|
4
|
+
//= require jquery_ujs
|
5
|
+
//= require swfobject.js
|
6
|
+
//= require jquery.uploadify.min
|
7
|
+
//= require jquery-ui.min.js
|
8
|
+
//= require jquery.ui.nestedSortable
|
9
|
+
//= require chosen.jquery.js
|
10
|
+
|
11
|
+
$(document).ready(function(){
|
12
|
+
$(".chosen_select").chosen();
|
13
|
+
$('.pagination').hide();
|
14
|
+
|
15
|
+
$('.zebra th a').live('click', function () {
|
16
|
+
$.getScript(this.href);
|
17
|
+
return false;
|
18
|
+
});
|
19
|
+
|
20
|
+
$('.visibility a').live('click', function(e){
|
21
|
+
e.preventDefault();
|
22
|
+
$(this).find('i').toggleClass('icon-eye-open').toggleClass('icon-eye-close not-work');
|
23
|
+
|
24
|
+
});
|
25
|
+
|
26
|
+
$('#sort_button').on('click', function (e) {
|
27
|
+
$.ajax( {
|
28
|
+
type: 'post',
|
29
|
+
data: $('#sort-list tbody').sortable('serialize') + '&authenticity_token=#{u(form_authenticity_token)}',
|
30
|
+
dataType: 'script',
|
31
|
+
url: $(this).attr('href')
|
32
|
+
});
|
33
|
+
e.preventDefault();
|
34
|
+
});
|
35
|
+
});
|
@@ -33,6 +33,9 @@ a.del {
|
|
33
33
|
&:hover {color:#FF0000;}
|
34
34
|
}
|
35
35
|
.icon-large{font-size:1.5em;}
|
36
|
+
.horizontal_items {
|
37
|
+
display:none;
|
38
|
+
}
|
36
39
|
.bright_link {
|
37
40
|
background:$deepgreen;
|
38
41
|
color:#fff;
|
@@ -63,8 +66,10 @@ table {
|
|
63
66
|
width:100%;
|
64
67
|
border-collapse:collapse;
|
65
68
|
margin-bottom:10px;
|
69
|
+
|
66
70
|
tr {
|
67
|
-
|
71
|
+
//&:first-child {border-top:1px solid $border_color;}
|
72
|
+
border-top:1px solid $border_color;
|
68
73
|
border-bottom:1px solid $border_color;
|
69
74
|
}
|
70
75
|
td {
|
@@ -75,10 +80,20 @@ table {
|
|
75
80
|
.right {text-align:right;vertical-align:middle;}
|
76
81
|
td.icon a {width:15px;}
|
77
82
|
td.handle {color:$deepgreen;cursor: move;}
|
83
|
+
td.icon {width:22px;}
|
84
|
+
}
|
85
|
+
.not-work {
|
86
|
+
color:$border_color;
|
78
87
|
}
|
79
|
-
|
80
88
|
|
81
89
|
table.zebra {
|
90
|
+
th {
|
91
|
+
font-size:1.2em;
|
92
|
+
background:$deepgreen;
|
93
|
+
color:$border_color;
|
94
|
+
a {color:$border_color;&:hover{color:#fff;}}
|
95
|
+
padding:0.5em 7px;
|
96
|
+
}
|
82
97
|
border-right:solid 1px $border_color;
|
83
98
|
border-left:solid 1px $border_color;
|
84
99
|
tr:nth-child(2n+1) {
|
@@ -88,7 +103,6 @@ table.zebra {
|
|
88
103
|
background:#fff;
|
89
104
|
}
|
90
105
|
}
|
91
|
-
th {text-align:left;}
|
92
106
|
li {list-style: none;}
|
93
107
|
|
94
108
|
h1,h2,h3,h4,ul {margin:0;padding:0;}
|
@@ -261,6 +275,9 @@ ul.photos {
|
|
261
275
|
a.del {text-indent:-9999px;position:absolute;right:0;bottom:0;}
|
262
276
|
}
|
263
277
|
}
|
278
|
+
#index_wr {
|
279
|
+
margin-top:10px;
|
280
|
+
}
|
264
281
|
@mixin black_button {
|
265
282
|
font:1em Helvetica, Arial, sans-serif;
|
266
283
|
margin-bottom:10px;
|
@@ -271,7 +288,7 @@ ul.photos {
|
|
271
288
|
border-radius: 3px;
|
272
289
|
-webkit-border-radius: 3px;
|
273
290
|
-moz-border-radius: 3px;
|
274
|
-
text-shadow:none;
|
291
|
+
text-shadow:none;
|
275
292
|
&:hover {
|
276
293
|
color:#fff;
|
277
294
|
border:none;
|
@@ -350,7 +367,9 @@ input[type=submit] {
|
|
350
367
|
z-index:1000;
|
351
368
|
position:relative;
|
352
369
|
}
|
353
|
-
|
370
|
+
.alert {
|
371
|
+
background-color:$deepgreen;
|
372
|
+
}
|
354
373
|
.notice {
|
355
374
|
background-color:#57A957;
|
356
375
|
background-image: -khtml-gradient(linear, left top, left bottom, from(#62c462), to(#57a957));
|
data/app/helpers/admin_helper.rb
CHANGED
@@ -4,7 +4,7 @@ module AdminHelper
|
|
4
4
|
%Q{
|
5
5
|
<script type="text/javascript">
|
6
6
|
$(document).ready(function() {
|
7
|
-
$('#sort-list').sortable( {
|
7
|
+
$('#sort-list tbody').sortable( {
|
8
8
|
dropOnEmpty: false,
|
9
9
|
cursor: 'crosshair',
|
10
10
|
opacity: 0.75,
|
@@ -14,7 +14,7 @@ module AdminHelper
|
|
14
14
|
update: function() {
|
15
15
|
$.ajax( {
|
16
16
|
type: 'post',
|
17
|
-
data: $('#sort-list').sortable('serialize') + '&authenticity_token=#{u(form_authenticity_token)}',
|
17
|
+
data: $('#sort-list tbody').sortable('serialize') + '&authenticity_token=#{u(form_authenticity_token)}',
|
18
18
|
dataType: 'script',
|
19
19
|
url: '#{url}'
|
20
20
|
})
|
@@ -26,6 +26,12 @@ module AdminHelper
|
|
26
26
|
end
|
27
27
|
|
28
28
|
|
29
|
+
def sortable_columns(column, title = nil)
|
30
|
+
title ||= column.titleize
|
31
|
+
css_class = column == sort_column ? "current #{sort_direction}" : nil
|
32
|
+
direction = column == sort_column && sort_direction == "asc" ? "desc" : "asc"
|
33
|
+
link_to title, {:sort => column, :direction => direction}, {:class => css_class}
|
34
|
+
end
|
29
35
|
|
30
36
|
def current_url(overwrite={})
|
31
37
|
url_for :only_path => false, :params => params.merge(overwrite)
|
Binary file
|
Binary file
|
Binary file
|
@@ -5,14 +5,57 @@ module Ideyabox
|
|
5
5
|
source_root File.expand_path('../templates', __FILE__)
|
6
6
|
|
7
7
|
def generate_admin_layout
|
8
|
-
directory "controllers
|
8
|
+
directory "controllers", "app/controllers"
|
9
9
|
directory "views/admin", "app/views/admin"
|
10
10
|
directory "views/layouts", "app/views/layouts"
|
11
|
+
directory "locales", "config/locales"
|
12
|
+
copy_file "assets/admin.scss.erb", "app/assets/stylesheets/admin.scss.erb"
|
13
|
+
copy_file "assets/admin.js", "app/assets/javascripts/admin.js"
|
11
14
|
copy_file "tasks/seeds.rb", "db/seeds.rb"
|
12
15
|
end
|
13
16
|
|
14
17
|
def setup_routes
|
15
|
-
route("namespace :admin do
|
18
|
+
route("namespace :admin do\n\n end")
|
19
|
+
end
|
20
|
+
|
21
|
+
def add_gems_for_admin_workflow
|
22
|
+
gem 'devise'
|
23
|
+
gem 'kaminari'
|
24
|
+
gem 'russian'
|
25
|
+
gem 'redactor-rails'
|
26
|
+
gem 'haml'
|
27
|
+
gem 'carrierwave'
|
28
|
+
gem 'mini_magick'
|
29
|
+
gem 'squeel'
|
30
|
+
gem 'sexy_validators'
|
31
|
+
gem_group :development do
|
32
|
+
gem 'haml-rails'
|
33
|
+
end
|
34
|
+
|
35
|
+
inside Rails.root do
|
36
|
+
run "bundle install"
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
def rake_tasks_for_admin
|
42
|
+
generate("devise:install")
|
43
|
+
generate("devise", "User")
|
44
|
+
generate("redactor:install")
|
45
|
+
# Next 4 lines for test purposes only
|
46
|
+
# generate("scaffold", "Ghost name:string desc:text position:integer visible:boolean --skip-stylesheets")
|
47
|
+
# generate("scaffold", "Guest name:string desc:text visible:boolean --skip-stylesheets")
|
48
|
+
# generate("scaffold", "Host name:string desc:text position:integer --skip-stylesheets")
|
49
|
+
# generate("scaffold", "Post name:string desc:text --skip-stylesheets")
|
50
|
+
rake("db:migrate")
|
51
|
+
rake("db:seed")
|
52
|
+
end
|
53
|
+
|
54
|
+
def initialize_git_repo
|
55
|
+
git :init
|
56
|
+
git :add => "."
|
57
|
+
git :add => "-u"
|
58
|
+
git :commit => "-m \"First commit!\""
|
16
59
|
end
|
17
60
|
|
18
61
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# Другие переводы на https://github.com/plataformatec/devise/wiki/I18n
|
2
|
+
|
3
|
+
ru:
|
4
|
+
devise:
|
5
|
+
sessions:
|
6
|
+
link: 'Войти'
|
7
|
+
signed_in: 'Вы вошли.'
|
8
|
+
signed_out: 'Вы вышли.'
|
9
|
+
unauthenticated: 'Вы должны войти или зарегистрироваться, прежде чем сможете продолжить.'
|
10
|
+
unconfirmed: 'Вы должны подтвердить Ваш аккаунт, прежде чем сможете продолжить.'
|
11
|
+
locked: 'Ваш аккаунт заблокирован.'
|
12
|
+
invalid: 'Неверный пароль или email.'
|
13
|
+
invalid_token: 'Неверный ключ аутентификации.'
|
14
|
+
timeout: 'Ваша сессия закончена, пожалуйста, войдите еще раз, чтобы продолжить.'
|
15
|
+
inactive: 'Ваш аккаунт еще не активирован.'
|
16
|
+
passwords:
|
17
|
+
link: 'Забыли пароль?'
|
18
|
+
send_instructions: 'Вы получите email с инструкциями о том, как сбросить Ваш пароль, через несколько минут.'
|
19
|
+
updated: 'Ваш пароль изменен. Сейчас Вы можете войти.'
|
20
|
+
confirmations:
|
21
|
+
link: "Не получили иструкции для подтверждения аккаунта?"
|
22
|
+
send_instructions: 'Вы получите письмо с инструкциями о том, как подтвердить Ваш аккаунт.'
|
23
|
+
confirmed: 'Ваш аккаунт успешно подтвержден. Вы вошли.'
|
24
|
+
registrations:
|
25
|
+
link: 'Регистрация'
|
26
|
+
signed_up: 'Вы успешно зарегистрировались.'
|
27
|
+
updated: 'Ваш аккаунт изменен.'
|
28
|
+
destroyed: 'До свидания! Ваш аккаунт удален. Мы надеемся вскоре снова Вас увидеть.'
|
29
|
+
unlocks:
|
30
|
+
link: "Не получили инструкции для разблокировки аккаунта?"
|
31
|
+
send_instructions: 'Вы получите письмо с инструкциями о том, как разблокировать Ваш аккаунт, через несколько минут.'
|
32
|
+
unlocked: 'Ваш аккаунт разблокирован. Вы вошли.'
|
33
|
+
mailer:
|
34
|
+
confirmation_instructions: 'Инструкции для подтверждения'
|
35
|
+
reset_password_instructions: 'Инструкции для сброса пароля'
|
36
|
+
unlock_instructions: 'Инструкции для разблокировки'
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# Sample localization file for English. Add more files in this directory for other locales.
|
2
|
+
# See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
|
3
|
+
|
4
|
+
en:
|
5
|
+
hello: "Hello world"
|
6
|
+
flash:
|
7
|
+
notice:
|
8
|
+
was_added: "was added"
|
9
|
+
was_updated: "was updated"
|
10
|
+
was_deleted: "was deleted"
|
11
|
+
confirm:
|
12
|
+
delete: "Are you sure?"
|
13
|
+
sort:
|
14
|
+
make_default: "Sorting will change order of records on site. Are you sure?"
|
15
|
+
sort:
|
16
|
+
by_position: "Sort by position"
|
17
|
+
make_default: "Make this sort default"
|
18
|
+
back: "Back"
|
19
|
+
add: "Add"
|
20
|
+
edit: "Edit"
|
21
|
+
save: "Save"
|
22
|
+
save_errors: "Errors"
|
23
|
+
sign_out: "Sign out"
|
24
|
+
activerecord:
|
25
|
+
# Model names translations. Using in Model.human_name().
|
26
|
+
models:
|
27
|
+
# user: "User"
|
28
|
+
# Model attribute names translations. Using in Model.human_attribute_name(attribute).
|
29
|
+
attributes:
|
30
|
+
# user:
|
31
|
+
# name: "Name"
|
32
|
+
# desc: "Description"
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# Файл локалиации на русский. Добавьте другие файлики для добавки других локалей.
|
2
|
+
# Гляньте https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale чтобы найти что-нибудь для себя.
|
3
|
+
|
4
|
+
ru:
|
5
|
+
hello: "Здравствуйте!"
|
6
|
+
flash:
|
7
|
+
notice:
|
8
|
+
was_added: "добавлен"
|
9
|
+
was_edited: "обновлен"
|
10
|
+
was_deleted: "удален"
|
11
|
+
confirm:
|
12
|
+
delete: "Точно удалить?"
|
13
|
+
sort:
|
14
|
+
make_default: "Сортировка изменит текущий порядок отображения записей на сайте. Вы точно уверены?"
|
15
|
+
sort:
|
16
|
+
by_position: "Сортировка по позициям"
|
17
|
+
make_default: "Сделать сортировкой по умолчанию"
|
18
|
+
back: "Назад"
|
19
|
+
add: "Добавить"
|
20
|
+
edit: "Редактировать"
|
21
|
+
save: "Сохранить"
|
22
|
+
save_errors: "Ошибки при сохранении"
|
23
|
+
sign_out: "Выход"
|
24
|
+
activerecord:
|
25
|
+
# Перевод названий моделей. Используется в Model.human_name().
|
26
|
+
models:
|
27
|
+
# user: "Пользователь"
|
28
|
+
# Перевод названий атрибутов моделей. Используется в Model.human_attribute_name(attribute).
|
29
|
+
attributes:
|
30
|
+
# user:
|
31
|
+
# name: "Имя"
|
@@ -2,9 +2,8 @@
|
|
2
2
|
#header_wrapper
|
3
3
|
|
4
4
|
#center
|
5
|
-
= link_to "
|
6
|
-
= '
|
7
|
-
= t(@active)
|
5
|
+
= link_to image_tag("admin/rdws_cat.png"), admin_root_path, :id => 'logo'
|
6
|
+
= link_to Rails.application.class.parent_name, root_path, :target => :_blank, :id=>'application_link'
|
8
7
|
#search
|
9
8
|
= form_tag "/", :id => :subscription do
|
10
9
|
= text_field_tag :search, nil, :placeholder => "search"
|
@@ -1,4 +1,4 @@
|
|
1
|
-
- @active = :section if
|
1
|
+
- @active = :section if %w{}.include? controller.controller_name
|
2
2
|
|
3
3
|
#launchbar
|
4
4
|
%li.arrow= link_to raw("↓"), "#"
|
@@ -7,4 +7,4 @@
|
|
7
7
|
|
8
8
|
%ul.user_panel
|
9
9
|
%li= link_to current_user.email, "#"
|
10
|
-
%li= link_to
|
10
|
+
%li= link_to t('sign_out'), destroy_user_session_path, :method => :delete
|
@@ -2,15 +2,11 @@
|
|
2
2
|
%html{:xmlns => "http://www.w3.org/1999/xhtml", "xml:lang" => "en"}
|
3
3
|
%head
|
4
4
|
%title
|
5
|
-
Хиконикс
|
6
|
-
|
|
7
5
|
= @page_title
|
8
6
|
= stylesheet_link_tag "admin"
|
9
7
|
= javascript_include_tag "admin"
|
10
8
|
|
11
9
|
= redactor_lang("ru")
|
12
|
-
/= include_imperavi_stylesheet
|
13
|
-
/= include_imperavi_javascript
|
14
10
|
= yield :js
|
15
11
|
= csrf_meta_tag
|
16
12
|
%body
|
@@ -33,7 +29,4 @@
|
|
33
29
|
= yield
|
34
30
|
#previews
|
35
31
|
= yield(:preview)
|
36
|
-
= debug(params) if Rails.env == "development"
|
37
|
-
-#= request.ip
|
38
|
-
-#= request.location.city
|
39
|
-
-#= request.location.country
|
32
|
+
= debug(params) if Rails.env == "development"
|
@@ -2,7 +2,7 @@
|
|
2
2
|
%html.login{:xmlns => "http://www.w3.org/1999/xhtml", "xml:lang" => "en"}
|
3
3
|
%head
|
4
4
|
%meta{"http-equiv" => "Content-Type", :content => "text/html;charset=UTF-8"}
|
5
|
-
%title
|
5
|
+
%title Вход на сайт
|
6
6
|
= stylesheet_link_tag 'admin'
|
7
7
|
= javascript_include_tag "admin"
|
8
8
|
= csrf_meta_tag
|
Binary file
|
@@ -0,0 +1,173 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/generated_attribute'
|
3
|
+
|
4
|
+
module Ideyabox
|
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
|
+
def add_locale_templates
|
23
|
+
add_to_locales
|
24
|
+
end
|
25
|
+
|
26
|
+
def add_resources_and_root
|
27
|
+
add_resource_route
|
28
|
+
end
|
29
|
+
|
30
|
+
def updated_admin_layout
|
31
|
+
add_to_launchbar_items
|
32
|
+
add_to_topbar_items
|
33
|
+
end
|
34
|
+
|
35
|
+
protected
|
36
|
+
|
37
|
+
def initialize_views_variables
|
38
|
+
@base_name, @controller_class_path, @controller_file_path, @controller_class_nesting, @controller_class_nesting_depth = extract_modules(controller_path)
|
39
|
+
@controller_routing_path = @controller_file_path.gsub(/\//, '_')
|
40
|
+
@model_name = @controller_class_nesting + "::#{@base_name.singularize.camelize}" unless @model_name
|
41
|
+
@model_name = @model_name.camelize
|
42
|
+
end
|
43
|
+
|
44
|
+
def controller_routing_path
|
45
|
+
@controller_routing_path
|
46
|
+
end
|
47
|
+
|
48
|
+
def singular_controller_routing_path
|
49
|
+
@controller_routing_path.singularize
|
50
|
+
end
|
51
|
+
|
52
|
+
def model_name
|
53
|
+
@model_name
|
54
|
+
end
|
55
|
+
|
56
|
+
def plural_model_name
|
57
|
+
@model_name.pluralize
|
58
|
+
end
|
59
|
+
|
60
|
+
def resource_name
|
61
|
+
@model_name.demodulize.underscore
|
62
|
+
end
|
63
|
+
|
64
|
+
def plural_resource_name
|
65
|
+
resource_name.pluralize
|
66
|
+
end
|
67
|
+
|
68
|
+
def sort_priority(column_name)
|
69
|
+
case column_name
|
70
|
+
when "position" then 1
|
71
|
+
when "visible" then 2
|
72
|
+
when "name" then 3
|
73
|
+
when "title" then 3
|
74
|
+
else 5
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def columns
|
79
|
+
begin
|
80
|
+
excluded_column_names = %w[id created_at updated_at]
|
81
|
+
@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)}
|
82
|
+
rescue NoMethodError
|
83
|
+
@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)}
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def column_names
|
88
|
+
@model_name.constantize.column_names
|
89
|
+
end
|
90
|
+
|
91
|
+
def extract_modules(name)
|
92
|
+
modules = name.include?('/') ? name.split('/') : name.split('::')
|
93
|
+
name = modules.pop
|
94
|
+
path = modules.map { |m| m.underscore }
|
95
|
+
file_path = (path + [name.underscore]).join('/')
|
96
|
+
nesting = modules.map { |m| m.camelize }.join('::')
|
97
|
+
[name, path, file_path, nesting, modules.size]
|
98
|
+
end
|
99
|
+
|
100
|
+
def generate_views
|
101
|
+
views = {
|
102
|
+
"index.html.#{ext}" => "app/views/admin/#{@controller_file_path}/index.html.#{ext}",
|
103
|
+
"edit.html.#{ext}" => "app/views/admin/#{@controller_file_path}/edit.html.#{ext}",
|
104
|
+
"index.js.#{ext}" => "app/views/admin/#{@controller_file_path}/index.js.#{ext}",
|
105
|
+
"_index.html.#{ext}" => "app/views/admin/#{@controller_file_path}/_index.html.#{ext}",
|
106
|
+
"_sort_buttons.html.#{ext}" => "app/views/admin/#{@controller_file_path}/_sort_buttons.html.#{ext}"
|
107
|
+
}
|
108
|
+
views.delete("_sort_buttons.html.#{ext}") unless column_names.include?("position")
|
109
|
+
selected_views = views
|
110
|
+
options.engine == generate_erb(selected_views)
|
111
|
+
end
|
112
|
+
|
113
|
+
def generate_erb(views)
|
114
|
+
views.each do |template_name, output_path|
|
115
|
+
template template_name, output_path
|
116
|
+
end
|
117
|
+
generate_controller
|
118
|
+
end
|
119
|
+
|
120
|
+
def ext
|
121
|
+
:haml
|
122
|
+
end
|
123
|
+
|
124
|
+
def generate_controller
|
125
|
+
template "controllers/controller.rb", "app/controllers/admin/#{plural_resource_name}_controller.rb"
|
126
|
+
end
|
127
|
+
|
128
|
+
def add_resource_route
|
129
|
+
resources_string = "\n resources :#{plural_resource_name} do\n"
|
130
|
+
sort_string = " post \"sort\", :on => :collection\n"
|
131
|
+
toggleshow_string = " get \"toggleshow\", :on => :member\n"
|
132
|
+
|
133
|
+
if column_names.include?("visible") && column_names.include?("position")
|
134
|
+
final_string = "#{resources_string}#{sort_string}#{toggleshow_string} end\n"
|
135
|
+
elsif column_names.include?("visible")
|
136
|
+
final_string = "#{resources_string}#{toggleshow_string} end\n"
|
137
|
+
elsif column_names.include?("position")
|
138
|
+
final_string = "#{resources_string}#{sort_string} end\n"
|
139
|
+
else
|
140
|
+
final_string = "\n resources :#{plural_resource_name}\n"
|
141
|
+
end
|
142
|
+
|
143
|
+
inject_into_file "config/routes.rb", final_string, :after => "\n namespace :admin do\n"
|
144
|
+
end
|
145
|
+
|
146
|
+
def add_to_launchbar_items
|
147
|
+
final_string = "#{plural_resource_name} "
|
148
|
+
|
149
|
+
inject_into_file "app/views/admin/shared/_launchbar.html.haml", final_string, :after => "- @active = :section if %w{"
|
150
|
+
end
|
151
|
+
|
152
|
+
def add_to_topbar_items
|
153
|
+
final_string = "\n %li{:class => \"\#\{\'active\' if c == \'#{plural_resource_name}\'}\"\}= link_to \'#{plural_resource_name}\', admin_#{plural_resource_name}_path"
|
154
|
+
|
155
|
+
inject_into_file "app/views/admin/shared/_topbar.html.haml", final_string, :after => "-when :section"
|
156
|
+
end
|
157
|
+
|
158
|
+
def add_to_locales
|
159
|
+
locales = [:ru, :en]
|
160
|
+
|
161
|
+
attributes = column_names.collect {|column| " #{column}: \"#{column}\"\n"}
|
162
|
+
|
163
|
+
attributes_string = " #{resource_name}:\n#{attributes.join}"
|
164
|
+
|
165
|
+
locales.each do |locale|
|
166
|
+
inject_into_file "config/locales/#{locale}.yml", " #{resource_name}: \"#{resource_name}\"\n", :after => "models:\n"
|
167
|
+
inject_into_file "config/locales/#{locale}.yml", attributes_string, :after => "attributes:\n"
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
Binary file
|
@@ -0,0 +1,38 @@
|
|
1
|
+
%table.zebra<%= "#sort-list" if column_names.include?("position") %>
|
2
|
+
%thead
|
3
|
+
%tr
|
4
|
+
<%- columns.each do |column| -%>
|
5
|
+
<%- if column.name=='position' || column.name=='visible'-%>
|
6
|
+
%th{:class => <%= (column.name=='position') ? "\'position\'" : "\'visibility\'" %>}
|
7
|
+
<%- else -%>
|
8
|
+
<%= "%th= sortable_columns \"#{column.name}\", #{resource_name.capitalize}.human_attribute_name(\"#{column.name}\")" %>
|
9
|
+
<%- end -%>
|
10
|
+
<%- end -%>
|
11
|
+
%th
|
12
|
+
|
13
|
+
%tbody
|
14
|
+
- @<%= plural_resource_name %>.each do |<%= resource_name %>|
|
15
|
+
<%- if column_names.include?("position") -%>
|
16
|
+
%tr{:id => "<%= resource_name %>_#{<%= resource_name %>.id}"}
|
17
|
+
<%- else -%>
|
18
|
+
%tr
|
19
|
+
<%- end -%>
|
20
|
+
<%- columns.each do |column| -%>
|
21
|
+
<%- if column.name == "position" -%>
|
22
|
+
%td.icon.handle
|
23
|
+
%i{:class => "icon-move icon-large"}
|
24
|
+
<%- elsif column.name == "visible" -%>
|
25
|
+
%td.icon.visibility
|
26
|
+
= link_to [:toggleshow, :admin, <%= resource_name %>], :remote => true do
|
27
|
+
%i{:class => (<%= resource_name %>.visible? ? "icon-eye-open icon-large" : "icon-eye-close icon-large not-work")}
|
28
|
+
<%- else -%>
|
29
|
+
%td= link_to <%= resource_name %>.<%= column.name %>, [:edit, :admin, <%= resource_name %>]
|
30
|
+
<%- end -%>
|
31
|
+
<%- end -%>
|
32
|
+
%td.right
|
33
|
+
= link_to [:admin, <%= resource_name %>], :method => :delete, :confirm => "#{t 'confirm.delete'}", class: :del do
|
34
|
+
%span Удалить
|
35
|
+
%i{:class => "icon-trash icon-large"}
|
36
|
+
<%- if column_names.include?("position") -%>
|
37
|
+
= sortable sort_admin_<%= plural_resource_name %>_path
|
38
|
+
<%- end -%>
|
@@ -0,0 +1,4 @@
|
|
1
|
+
- unless @<%= plural_resource_name %>.empty?
|
2
|
+
%ul.horizontal_items
|
3
|
+
%li= link_to t('sort.by_position'), admin_<%= plural_resource_name %>_path, :class => "bright_link"
|
4
|
+
%li= link_to t('sort.make_default'), sort_admin_<%= plural_resource_name %>_path, :id => 'sort_button', :confirm => t('confirm.sort.make_default'), :class => "bright_link"
|
@@ -0,0 +1,67 @@
|
|
1
|
+
#coding: utf-8
|
2
|
+
class Admin::<%= plural_resource_name.capitalize -%>Controller < Admin::ApplicationController
|
3
|
+
helper_method :sort_column, :sort_direction
|
4
|
+
<%- if column_names.include?("visible") -%>
|
5
|
+
def toggleshow
|
6
|
+
@<%= plural_resource_name %> = <%= resource_name.capitalize -%>.find(params[:id])
|
7
|
+
@<%= plural_resource_name %>.toggle(:visible)
|
8
|
+
@<%= plural_resource_name %>.save
|
9
|
+
render :nothing => true
|
10
|
+
end
|
11
|
+
<%- end -%><%- if column_names.include?("position") -%>
|
12
|
+
def sort
|
13
|
+
params[:<%= resource_name %>].each_with_index do |id, idx|
|
14
|
+
@<%= resource_name %> = <%= resource_name.capitalize -%>.find(id)
|
15
|
+
@<%= resource_name %>.position = idx
|
16
|
+
@<%= resource_name %>.save
|
17
|
+
end
|
18
|
+
render :nothing => true
|
19
|
+
end
|
20
|
+
<%- end -%>
|
21
|
+
def index
|
22
|
+
@<%= plural_resource_name %> = <%= resource_name.capitalize -%>.order(sort_column + " " + sort_direction)
|
23
|
+
end
|
24
|
+
|
25
|
+
def new
|
26
|
+
@<%= resource_name %> = <%= resource_name.capitalize -%>.new
|
27
|
+
render 'edit'
|
28
|
+
end
|
29
|
+
|
30
|
+
def edit
|
31
|
+
@<%= resource_name %> = <%= resource_name.capitalize -%>.find(params[:id])
|
32
|
+
end
|
33
|
+
|
34
|
+
def create
|
35
|
+
@<%= resource_name %> = <%= resource_name.capitalize -%>.new(params[:<%= resource_name %>])
|
36
|
+
if @<%= resource_name %>.save
|
37
|
+
redirect_to admin_<%= plural_resource_name %>_path, :notice => "#{<%= resource_name.capitalize %>.model_name.human} #{t 'flash.notice.was_added'}"
|
38
|
+
else
|
39
|
+
render 'edit'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def update
|
44
|
+
@<%= resource_name %> = <%= resource_name.capitalize -%>.find(params[:id])
|
45
|
+
if @<%= resource_name %>.update_attributes(params[:<%= resource_name %>])
|
46
|
+
redirect_to admin_<%= plural_resource_name %>_path, :notice => "#{<%= resource_name.capitalize %>.model_name.human} #{t 'flash.notice.was_updated'}"
|
47
|
+
else
|
48
|
+
render 'edit'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def destroy
|
53
|
+
@<%= resource_name %> = <%= resource_name.capitalize -%>.find(params[:id])
|
54
|
+
@<%= resource_name %>.destroy
|
55
|
+
redirect_to admin_<%= plural_resource_name %>_path, :alert => "#{<%= resource_name.capitalize %>.model_name.human} #{t 'flash.notice.was_deleted'}"
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def sort_column
|
61
|
+
<%= resource_name.capitalize -%>.column_names.include?(params[:sort]) ? params[:sort] : <%= column_names.include?("position") ? "\'position\'" : "\'created_at\'" %>
|
62
|
+
end
|
63
|
+
|
64
|
+
def sort_direction
|
65
|
+
%w[asc desc].include?(params[:direction]) ? params[:direction] : "asc"
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
- content_for :page_header do
|
2
|
+
%p= link_to t('back'), admin_<%= controller_routing_path %>_path, :class => "bright_link"
|
3
|
+
%h1
|
4
|
+
- if @<%= resource_name %>.new_record?
|
5
|
+
= "#{t 'add'} #{<%= resource_name.capitalize %>.model_name.human}"
|
6
|
+
- else
|
7
|
+
= "#{t 'edit'} #{<%= resource_name.capitalize %>.model_name.human}"
|
8
|
+
|
9
|
+
= form_for [:admin, @<%= resource_name %>] do |f|
|
10
|
+
- if @<%= resource_name %>.errors.any?
|
11
|
+
#error_explanation
|
12
|
+
%h2= "#{t 'save_errors'}: #{@<%= resource_name %>.errors.count}"
|
13
|
+
%ul
|
14
|
+
- @<%= resource_name %>.errors.full_messages.each do |msg|
|
15
|
+
%li= msg
|
16
|
+
%table
|
17
|
+
<%- columns.each do |column| -%>
|
18
|
+
<%- unless column.name == "position" %>
|
19
|
+
<%- if column.field_type.to_s == "text_area" -%>
|
20
|
+
%tr
|
21
|
+
%td{colspan: 2}
|
22
|
+
= f.label :<%= column.name %>
|
23
|
+
%br
|
24
|
+
= f.<%= column.field_type -%> :<%= column.name %>
|
25
|
+
<%- elsif column.field_type.to_s == "check_box" -%>
|
26
|
+
%tr
|
27
|
+
%th{colspan: 2}
|
28
|
+
= f.<%= column.field_type -%> :<%= column.name %>
|
29
|
+
= f.label :<%= column.name %>
|
30
|
+
<%- else -%>
|
31
|
+
%tr
|
32
|
+
%th= f.label :<%= column.name %>
|
33
|
+
%td= f.<%= column.field_type -%> :<%= column.name %>
|
34
|
+
<%- end -%>
|
35
|
+
<%- end -%>
|
36
|
+
<%- end -%>
|
37
|
+
.actions
|
38
|
+
= f.submit t('save')
|
@@ -0,0 +1,9 @@
|
|
1
|
+
- content_for(:page_header) do
|
2
|
+
%p= link_to "#{t 'add'} #{<%= resource_name.capitalize %>.model_name.human}", new_admin_<%= singular_controller_routing_path %>_path, :class => "bright_link"
|
3
|
+
%h1= link_to '<%= plural_resource_name %>', admin_<%= plural_resource_name %>_path
|
4
|
+
-#= paginate @<%= plural_resource_name %>
|
5
|
+
<%= if column_names.include?("position")
|
6
|
+
"= render 'sort_buttons' "
|
7
|
+
end %>
|
8
|
+
#index_wr
|
9
|
+
<%= "= render 'index' " %>
|
data/lib/ideyabox/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ideyabox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-11-
|
13
|
+
date: 2012-11-15 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: russian
|
@@ -185,15 +185,15 @@ files:
|
|
185
185
|
- app/assets/images/admin/uploadify/uploadify.css
|
186
186
|
- app/assets/images/admin/uploadify/uploadify.swf
|
187
187
|
- app/assets/javascripts/.DS_Store
|
188
|
-
- app/assets/javascripts/admin.js
|
189
188
|
- app/assets/javascripts/chosen.jquery.js
|
189
|
+
- app/assets/javascripts/default.js
|
190
190
|
- app/assets/javascripts/jquery.ui.nestedSortable.js
|
191
191
|
- app/assets/javascripts/jquery.uploadify.min.js
|
192
192
|
- app/assets/javascripts/modernizr.js
|
193
193
|
- app/assets/javascripts/swfobject.js
|
194
194
|
- app/assets/stylesheets/.DS_Store
|
195
|
-
- app/assets/stylesheets/admin.scss.erb
|
196
195
|
- app/assets/stylesheets/chosen.scss.erb
|
196
|
+
- app/assets/stylesheets/default.scss.erb
|
197
197
|
- app/assets/stylesheets/font-awesome.css
|
198
198
|
- app/assets/stylesheets/font_awesome/.gitignore
|
199
199
|
- app/assets/stylesheets/font_awesome/font/fontawesome-webfont.eot
|
@@ -205,11 +205,20 @@ files:
|
|
205
205
|
- app/helpers/admin_helper.rb
|
206
206
|
- app/tasks/reset_db.rake
|
207
207
|
- ideyabox.gemspec
|
208
|
+
- lib/generators/.DS_Store
|
209
|
+
- lib/generators/ideyabox/.DS_Store
|
210
|
+
- lib/generators/ideyabox/admin/.DS_Store
|
208
211
|
- lib/generators/ideyabox/admin/admin_generator.rb
|
209
212
|
- lib/generators/ideyabox/admin/templates/.DS_Store
|
213
|
+
- lib/generators/ideyabox/admin/templates/assets/admin.js
|
214
|
+
- lib/generators/ideyabox/admin/templates/assets/admin.scss.erb
|
210
215
|
- lib/generators/ideyabox/admin/templates/controllers/.DS_Store
|
211
216
|
- lib/generators/ideyabox/admin/templates/controllers/admin/.DS_Store
|
212
217
|
- lib/generators/ideyabox/admin/templates/controllers/admin/application_controller.rb
|
218
|
+
- lib/generators/ideyabox/admin/templates/controllers/application_controller.rb
|
219
|
+
- lib/generators/ideyabox/admin/templates/locales/devise.ru.yml
|
220
|
+
- lib/generators/ideyabox/admin/templates/locales/en.yml
|
221
|
+
- lib/generators/ideyabox/admin/templates/locales/ru.yml
|
213
222
|
- lib/generators/ideyabox/admin/templates/tasks/seeds.rb
|
214
223
|
- lib/generators/ideyabox/admin/templates/views/.DS_Store
|
215
224
|
- lib/generators/ideyabox/admin/templates/views/admin/.DS_Store
|
@@ -219,6 +228,15 @@ files:
|
|
219
228
|
- lib/generators/ideyabox/admin/templates/views/layouts/admin.html.haml
|
220
229
|
- lib/generators/ideyabox/admin/templates/views/layouts/login.html.haml
|
221
230
|
- lib/generators/ideyabox/assets/assets_generator.rb
|
231
|
+
- lib/generators/ideyabox/scaffold/.DS_Store
|
232
|
+
- lib/generators/ideyabox/scaffold/scaffold_generator.rb
|
233
|
+
- lib/generators/ideyabox/scaffold/templates/.DS_Store
|
234
|
+
- lib/generators/ideyabox/scaffold/templates/_index.html.haml
|
235
|
+
- lib/generators/ideyabox/scaffold/templates/_sort_buttons.html.haml
|
236
|
+
- lib/generators/ideyabox/scaffold/templates/controllers/controller.rb
|
237
|
+
- lib/generators/ideyabox/scaffold/templates/edit.html.haml
|
238
|
+
- lib/generators/ideyabox/scaffold/templates/index.html.haml
|
239
|
+
- lib/generators/ideyabox/scaffold/templates/index.js.haml
|
222
240
|
- lib/ideyabox.rb
|
223
241
|
- lib/ideyabox/engine.rb
|
224
242
|
- lib/ideyabox/version.rb
|
@@ -1,13 +0,0 @@
|
|
1
|
-
//= require modernizr.js
|
2
|
-
//= require jquery
|
3
|
-
//= require jquery-ui
|
4
|
-
//= require jquery_ujs
|
5
|
-
//= require swfobject.js
|
6
|
-
//= require jquery.uploadify.min
|
7
|
-
//= require jquery-ui.min.js
|
8
|
-
//= require jquery.ui.nestedSortable
|
9
|
-
//= require chosen.jquery.js
|
10
|
-
|
11
|
-
$(document).ready(function(){
|
12
|
-
|
13
|
-
});
|