redde 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (26) hide show
  1. checksums.yaml +4 -4
  2. data/lib/generators/redde/layout/layout_generator.rb +13 -31
  3. data/lib/generators/redde/layout/templates/base/_header.html.haml +3 -3
  4. data/lib/generators/redde/layout/templates/base/_launchbar.html.haml +4 -4
  5. data/lib/generators/redde/layout/templates/base/_sidebar.html.haml +6 -6
  6. data/lib/generators/redde/layout/templates/controllers/base_controller.rb +1 -2
  7. data/lib/generators/redde/layout/templates/helpers/admin_helper.rb +8 -8
  8. data/lib/generators/redde/layout/templates/layouts/admin.html.haml +11 -11
  9. data/lib/generators/redde/layout/templates/layouts/login.html.haml +8 -8
  10. data/lib/generators/redde/photo/photo_generator.rb +8 -8
  11. data/lib/generators/redde/photo/templates/controller.rb +6 -15
  12. data/lib/generators/redde/photo/templates/create_photos.rb +2 -1
  13. data/lib/generators/redde/photo/templates/photo.rb +1 -1
  14. data/lib/generators/redde/photo/templates/photos/_photo.haml +3 -3
  15. data/lib/generators/redde/photo/templates/photos/_photos.haml +6 -9
  16. data/lib/generators/redde/photo/templates/photos/create.js.erb +1 -1
  17. data/lib/generators/redde/photo/templates/uploader.rb +2 -3
  18. data/lib/generators/redde/scaffold/scaffold_generator.rb +42 -31
  19. data/lib/generators/redde/scaffold/templates/controllers/controller.rb +7 -9
  20. data/lib/generators/redde/scaffold/templates/edit.html.haml +6 -6
  21. data/lib/generators/redde/scaffold/templates/index.html.haml +11 -11
  22. data/lib/redde/version.rb +1 -1
  23. data/lib/redde.rb +1 -2
  24. data/lib/url_generator.rb +8 -6
  25. data/spec/dummy/config/boot.rb +1 -1
  26. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ac9b199ec5263c756a8b8c18911e9c6fd6f46fca
4
- data.tar.gz: 457f1b1a5761524a33c272d2fb726eb2718afb93
3
+ metadata.gz: fbde0641c49836754b4070b0113f4298222340cb
4
+ data.tar.gz: 5b2da2600e17118d0515351e7c105598f953c486
5
5
  SHA512:
6
- metadata.gz: 7749d1303c8d9d99a94fec6e4a4a3e42b098ba2f88ac5367a27bf40572a50e55ed413baa5b690f4be93d81d62b21f55cf38a34ad12d65e1aeaf2d88bdd7a5db6
7
- data.tar.gz: cfd98c5ecfaff7f34ebff5add7fb3db32687f349009bf2508aadc886aa3d065738da479122753da3550b3be85832c1325bd881aaaae98b2d49258b5595f92866
6
+ metadata.gz: 9b3af10712fe15ee2e2871a3ea20534af14d7c8d296e3d4a9ba62b34c19b0e43b1b6ab15618b91073efcd88cc6b9552a4c4dabad7d454c0a3aedc2753c7a6148
7
+ data.tar.gz: 6767bae525444c8e97fc53c81d416bfee50ebd673184ee154ef085dde15fcd6c0493a0e82b67124f5fff4d3e0cf327ac0fe7d97a9c70ac6bebc0bc56f08aad94
@@ -3,54 +3,36 @@ require 'rails/generators'
3
3
  module Redde
4
4
  module Generators
5
5
  class LayoutGenerator < ::Rails::Generators::Base
6
- source_root File.expand_path("../templates", __FILE__)
7
- desc "Standart redde admin generator"
6
+ source_root File.expand_path('../templates', __FILE__)
7
+ desc 'Standart redde admin generator'
8
8
 
9
9
  attr_reader :app_name
10
10
 
11
11
  def generate_layout
12
-
13
- # copy layouts
14
- %w{ admin login }.each do |layout|
12
+ %w(admin login).each do |layout|
15
13
  template "layouts/#{layout}#{ext}", "app/views/layouts/#{layout}#{ext}"
16
14
  end
17
-
18
- # copy base
19
- directory "base", "app/views/admin/base"
20
-
21
- # copy js
22
- %w{ admin.js }.each do |js|
15
+ directory 'base', 'app/views/admin/base'
16
+ %w(admin.js).each do |js|
23
17
  template "assets/javascripts/#{js}", "app/assets/javascripts/#{js}"
24
18
  end
25
- directory "assets/javascripts/admin", "app/assets/javascripts/admin"
26
-
27
- # copy css
28
- directory "assets/stylesheets/admin", "app/assets/stylesheets/admin"
29
-
30
- # copy redactor
31
- directory "assets/redactor", "app/assets"
32
-
33
- # copy helpers
34
- template "helpers/admin_helper.rb", "app/helpers/admin_helper.rb"
35
-
36
- # copy images
37
- directory "assets/images/admin", "app/assets/images/admin"
38
-
39
- # copy application controller
40
- template "controllers/base_controller.rb", "app/controllers/admin/base_controller.rb"
41
-
19
+ directory 'assets/javascripts/admin', 'app/assets/javascripts/admin'
20
+ directory 'assets/stylesheets/admin', 'app/assets/stylesheets/admin'
21
+ directory 'assets/redactor', 'app/assets'
22
+ template 'helpers/admin_helper.rb', 'app/helpers/admin_helper.rb'
23
+ directory 'assets/images/admin', 'app/assets/images/admin'
24
+ template 'controllers/base_controller.rb', 'app/controllers/admin/base_controller.rb'
42
25
  end
43
26
 
44
27
  private
45
28
 
46
29
  def ext
47
- ".html.haml"
30
+ '.html.haml'
48
31
  end
49
32
 
50
33
  def app_name
51
- Rails.application.class.to_s.split("::").first
34
+ Rails.application.class.to_s.split('::').first
52
35
  end
53
36
  end
54
-
55
37
  end
56
38
  end
@@ -1,12 +1,12 @@
1
1
  %header.header
2
2
  .header__init
3
- = link_to admin_root_path || "/admin", class: 'header__logo' do
3
+ = link_to admin_root_path || '/admin', class: 'header__logo' do
4
4
  ReddeCMS
5
5
  %br
6
6
  %span custom system
7
7
  .header__links
8
8
  - if current_manager
9
9
  = mail_to current_manager.email
10
- = link_to "Выход", destroy_manager_session_path, :method => :delete
10
+ = link_to 'Выход', destroy_manager_session_path, method: :delete
11
11
  .header__center
12
- = link_to "AppName", root_path ||= '/', :target => :_blank
12
+ = link_to 'AppName', root_path ||= '/', target: :_blank
@@ -5,7 +5,7 @@
5
5
 
6
6
  .launchbar
7
7
  %nav.launchbar__menu
8
- = link_to "Материалы", nil, class: ['launchbar__link', ('_active' if @active == :shop)]
9
- = link_to "Обратная связь", nil, class: ['launchbar__link', ('_active' if @active == :materials)]
10
- = link_to "Система", nil, class: ['launchbar__link', ('_active' if @active == :system)]
11
- %span.launchbar__time= Russian.strftime(Time.now,"%d %b, %Y %H:%M ")
8
+ = link_to 'Материалы', nil, class: ['launchbar__link', ('_active' if @active == :shop)]
9
+ = link_to 'Обратная связь', nil, class: ['launchbar__link', ('_active' if @active == :materials)]
10
+ = link_to 'Система', nil, class: ['launchbar__link', ('_active' if @active == :system)]
11
+ %span.launchbar__time= Russian.strftime(Time.now, '%d %b, %Y %H:%M ')
@@ -1,13 +1,13 @@
1
- -# add this condition to remove empty sidebar
1
+ -# add this condition to remove empty sidebar
2
2
  -# if @active
3
3
  %nav.sidebar
4
4
  - case @active
5
- - when :shop then
6
- = link_to "Товары", admin_products_path, class: 'sidebar__link'
7
- - when :materials then
8
- = link_to "Статьи", [:admin, :articles], class: 'sidebar__link'
5
+ - when :shop
6
+ = link_to 'Товары', admin_products_path, class: 'sidebar__link'
7
+ - when :materials
8
+ = link_to 'Статьи', [:admin, :articles], class: 'sidebar__link'
9
9
  - when :system
10
- = link_to "Пользователи", admin_users_path, class: 'sidebar__link'
10
+ = link_to 'Пользователи', admin_users_path, class: 'sidebar__link'
11
11
  - else
12
12
  = link_to 'Демо active', nil, class: ['sidebar__link', '_active']
13
13
  = link_to nil, class: ['sidebar__link'] do
@@ -7,5 +7,4 @@ class Admin::BaseController < ActionController::Base
7
7
 
8
8
  def welcome
9
9
  end
10
-
11
- end
10
+ end
@@ -31,16 +31,17 @@ module AdminHelper
31
31
  });
32
32
  </script>
33
33
  }.gsub(/[\n ]+/, ' ').strip.html_safe
34
- return content_for(:js,html)
34
+ content_for(:js, html)
35
35
  end
36
36
 
37
37
  def show_tree(c)
38
38
  link = link_to c.name, [:edit, :admin, c]
39
- edit = link_to "Удал",[:admin, c], data: { confirm: 'Точно удалить?' }, :method => :delete, class: "del"
39
+ edit = link_to 'Удал', [:admin, c], data: { confirm: 'Точно удалить?' },
40
+ method: :delete, class: 'del'
40
41
  html = content_tag(:div, link + content_tag(:p, edit))
41
42
  if c.children.any?
42
43
  html << content_tag(:ol) do
43
- raw c.children.map{|ch| show_tree(ch)}.join()
44
+ raw c.children.map { |ch| show_tree(ch) }.join('')
44
45
  end
45
46
  end
46
47
  content_tag :li, raw(html), id: "list_#{c.id}"
@@ -79,16 +80,15 @@ module AdminHelper
79
80
  }.gsub(/[\n ]+/, ' ').strip.html_safe
80
81
  end
81
82
 
82
- def tsingular model
83
+ def tsingular(model)
83
84
  model.model_name.human
84
85
  end
85
86
 
86
- def taccusative model_name
87
+ def taccusative(model_name)
87
88
  t("activerecord.models.#{model_name}.acc")
88
89
  end
89
90
 
90
- def tplural model
91
- model.model_name.human(:count => 'other')
91
+ def tplural(model)
92
+ model.model_name.human(count: 'other')
92
93
  end
93
-
94
94
  end
@@ -1,29 +1,29 @@
1
1
  !!!
2
- %html{lang: "en"}
2
+ %html{ lang: 'en' }
3
3
  %head
4
- %meta{:charset => "UTF-8"}/
5
- %title= @page_title || "ReddeCMS"
4
+ %meta{ charset: 'UTF-8'}/
5
+ %title= @page_title || 'ReddeCMS'
6
6
  = favicon_link_tag 'admin/favicon.png'
7
- = stylesheet_link_tag "admin"
8
- = javascript_include_tag "admin"
7
+ = stylesheet_link_tag 'admin'
8
+ = javascript_include_tag 'admin'
9
9
  = yield :js
10
10
  = csrf_meta_tag
11
11
  %body
12
- = render "launchbar"
13
- = render "header"
12
+ = render 'launchbar'
13
+ = render 'header'
14
14
  .wrapper
15
- = render "sidebar"
15
+ = render 'sidebar'
16
16
  .main
17
17
  .page-header
18
18
  = yield(:page_header)
19
19
  - if notice
20
20
  .notice= notice
21
21
  - if alert
22
- .alert= alert
23
- .page{class: "#{yield(:page_sidebar).empty? ? '_full' : '_sidebar'}"}
22
+ .alert= alert
23
+ .page{ class: "#{yield(:page_sidebar).empty? ? '_full' : '_sidebar'}" }
24
24
  #filter
25
25
  = yield(:filter)
26
26
  .page-sidebar
27
27
  = yield(:page_sidebar)
28
28
  .content
29
- = yield
29
+ = yield
@@ -1,7 +1,7 @@
1
1
  !!!
2
- %html.login{:xmlns => "http://www.w3.org/1999/xhtml", "xml:lang" => "en"}
2
+ %html.login{ 'xmlns' => 'http://www.w3.org/1999/xhtml', 'xml:lang' => 'en' }
3
3
  %head
4
- %meta{"http-equiv" => "Content-Type", :content => "text/html;charset=UTF-8"}
4
+ %meta{ 'http-equiv' => 'Content-Type', 'content' => 'text/html;charset=UTF-8' }
5
5
  %title Вход на сайт | Административная панель
6
6
  = stylesheet_link_tag 'admin'
7
7
  = javascript_include_tag "admin"
@@ -15,18 +15,18 @@
15
15
  %h1 Административная панель
16
16
  .page
17
17
  .content
18
- = form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f|
18
+ = form_for(resource, as: resource_name, url: session_path(resource_name)) do |f|
19
19
  .login__fields
20
- = f.label :email, "E-mail"
20
+ = f.label :email, 'E-mail'
21
21
  %br
22
22
  = f.text_field :email, class: 'login__inp'
23
23
  .login__fields
24
- = f.label :password, "Пароль"
24
+ = f.label :password, 'Пароль'
25
25
  %br
26
- = f.password_field :password, :size => 35, class: 'login__inp'
26
+ = f.password_field :password, size: 35, class: 'login__inp'
27
27
  - if devise_mapping.rememberable?
28
28
  .login__fields
29
29
  = f.check_box :remember_me
30
- = f.label :remember_me, "Оставаться в системе"
30
+ = f.label :remember_me, 'Оставаться в системе'
31
31
  .login__actions
32
- = f.submit "Войти"
32
+ = f.submit 'Войти'
@@ -7,28 +7,28 @@ module Redde
7
7
  include Rails::Generators::Migration
8
8
  source_root File.expand_path('../templates', __FILE__)
9
9
 
10
- def self.next_migration_number(path)
11
- Time.now.utc.strftime("%Y%m%d%H%M%S")
10
+ def self.next_migration_number(_path)
11
+ Time.now.utc.strftime('%Y%m%d%H%M%S')
12
12
  end
13
-
13
+
14
14
  def copy_controller
15
- template "controller.rb", "app/controllers/admin/photos_controller.rb"
15
+ template 'controller.rb', 'app/controllers/admin/photos_controller.rb'
16
16
  end
17
17
 
18
18
  def copy_views
19
- directory "photos", "app/views/admin/photos"
19
+ directory 'photos', 'app/views/admin/photos'
20
20
  end
21
21
 
22
22
  def copy_model
23
- template "photo.rb", "app/models/photo.rb"
23
+ template 'photo.rb', 'app/models/photo.rb'
24
24
  end
25
25
 
26
26
  def copy_uploader
27
- template "uploader.rb", "app/uploaders/photo_uploader.rb"
27
+ template 'uploader.rb', 'app/uploaders/photo_uploader.rb'
28
28
  end
29
29
 
30
30
  def copy_migration
31
- migration_template "create_photos.rb", "db/migrate/create_photos.rb"
31
+ migration_template 'create_photos.rb', 'db/migrate/create_photos.rb'
32
32
  end
33
33
  end
34
34
  end
@@ -1,29 +1,20 @@
1
1
  class Admin::PhotosController < ActionController::Base
2
-
3
2
  def sort
4
3
  params[:photo].each_with_index do |id, idx|
5
4
  p = Photo.find(id)
6
- p.position = idx
7
- p.save
5
+ p.update(position: idx)
8
6
  end
9
- render :nothing => true
7
+ render nothing: true
10
8
  end
11
9
 
12
10
  def create
13
- if params[:product_id].present?
14
- parent = Product.find(params[:product_id])
15
- end
11
+ parent = Product.find(params[:product_id]) if params[:product_id].present?
16
12
  @photo = parent.photos.build(src: params[:file])
17
- unless @photo.save
18
- render js: 'alert("Ошибка! Фото не загружено")'
19
- end
13
+ render js: 'alert("Ошибка! Фото не загружено")' unless @photo.save
20
14
  end
21
15
 
22
16
  def destroy
23
17
  @photo = Photo.find(params[:id])
24
- if @photo.destroy
25
- render 'admin/photos/destroy'
26
- end
18
+ render 'admin/photos/destroy' if @photo.destroy
27
19
  end
28
-
29
- end
20
+ end
@@ -9,5 +9,6 @@ class CreatePhotos < ActiveRecord::Migration
9
9
  t.timestamps
10
10
  end
11
11
  add_index :photos, :imageable_id
12
+ add_index :photos, :imageable_type
12
13
  end
13
- end
14
+ end
@@ -4,4 +4,4 @@ class Photo < ActiveRecord::Base
4
4
  default_scope { order(:position) }
5
5
 
6
6
  mount_uploader :src, PhotoUploader
7
- end
7
+ end
@@ -1,5 +1,5 @@
1
- %li{class: "handle", :id => "photo_#{photo.id}"}
1
+ %li{ class: 'handle', id: "photo_#{photo.id}" }
2
2
  = link_to photo.src.url do
3
3
  = image_tag photo.src.admin
4
- %em= photo.src.to_s.gsub(/.*\/(.*)\z/,'\1')
5
- = link_to "удалить", url_for([:admin, photo.imageable, photo]), :method => :delete, :confirm => "Точно удалить?", :remote => true, :title => "Удалить", :class => "del"
4
+ %em= photo.src.to_s.gsub(/.*\/(.*)\z/, '\1')
5
+ = link_to 'удалить', [:admin, photo.imageable, photo], method: :delete, data: { confirm: 'Точно удалить?'}, remote: true, title: 'Удалить', class: 'del'
@@ -1,22 +1,19 @@
1
1
  - unless parent.new_record?
2
2
  = content_for(:page_sidebar) do
3
- %h5
3
+ %h5
4
4
  Фотографии
5
5
  - if editable ||= false
6
- = link_to "ред.", [:admin, parent]
6
+ = link_to 'ред.', [:admin, parent]
7
7
  .product-photos
8
8
  %ul.photos#photo-list
9
9
  = render parent.photos
10
-
11
10
  #preview
12
- #drag-n-drop{:style => "display: none; margin-top: 5px;"}
13
- #drop-zone.b-dropzone{style: 'height: 100px;', data: {"upload-url" => url_for([:admin, parent, :photos])}}
11
+ #drag-n-drop{ style: 'display: none; margin-top: 5px;' }
12
+ #drop-zone.b-dropzone{ style: 'height: 100px;', data: { 'upload-url' => url_for([:admin, parent, :photos]) } }
14
13
  .b-dropzone__bg
15
14
  .b-dropzone__txt Перетащите файлы сюда
16
-
17
-
18
- #buttons-panel{style: 'margin-bottom: 10px;'}
15
+ #buttons-panel{ style: 'margin-bottom: 10px;' }
19
16
  .b-button.js-fileapi-wrapper
20
17
  .b-button__text Загрузить файлы
21
- %input.b-button__input.js-fileapi{:name => "files", :type => "file", :multiple => true, data: {"upload-url" => url_for([:admin, parent, :photos])}}
18
+ %input.b-button__input.js-fileapi{ name: 'files', type: 'file', multiple: true, data: { "upload-url" => url_for([:admin, parent, :photos]) } }
22
19
  = photo_sortable url_for([:sort, :admin, parent, :photos])
@@ -1 +1 @@
1
- $("ul.photos").append('<%= escape_javascript(render "admin/photos/photo", { :photo => @photo, :parent => @parent }) %>');
1
+ $('ul.photos').append('<%= escape_javascript(render "admin/photos/photo", { photo: @photo, parent: @parent }) %>');
@@ -48,7 +48,7 @@ class PhotoUploader < CarrierWave::Uploader::Base
48
48
  # end
49
49
 
50
50
  version :admin do
51
- process :resize_and_pad => [119, 119, :transparent, ::Magick::CenterGravity]
51
+ process resize_and_pad: [119, 119, :transparent, ::Magick::CenterGravity]
52
52
  end
53
53
 
54
54
  # Override the filename of the uploaded files:
@@ -56,5 +56,4 @@ class PhotoUploader < CarrierWave::Uploader::Base
56
56
  # def filename
57
57
  # "something.jpg" if original_filename
58
58
  # end
59
-
60
- end
59
+ end
@@ -5,9 +5,13 @@ module Redde
5
5
  module Generators
6
6
  class ScaffoldGenerator < ::Rails::Generators::Base
7
7
  source_root File.expand_path('../templates', __FILE__)
8
- argument :controller_path, :type => :string
9
- argument :model_name, :type => :string, :required => false
10
-
8
+ argument :controller_path, type: :string
9
+ argument :model_name, type: :string, required: false
10
+
11
+ attr_accessor :model_name, :controller_routing_path, :base_name,
12
+ :controller_class_path, :controller_file_path,
13
+ :controller_class_nesting, :controller_class_nesting_depth
14
+
11
15
  def initialize(args, *options)
12
16
  super(args, *options)
13
17
  initialize_views_variables
@@ -26,24 +30,16 @@ module Redde
26
30
  @model_name = @model_name.camelize
27
31
  end
28
32
 
29
- def controller_routing_path
30
- @controller_routing_path
31
- end
32
-
33
33
  def singular_controller_routing_path
34
- @controller_routing_path.singularize
35
- end
36
-
37
- def model_name
38
- @model_name
34
+ controller_routing_path.singularize
39
35
  end
40
36
 
41
37
  def plural_model_name
42
- @model_name.pluralize
38
+ model_name.pluralize
43
39
  end
44
40
 
45
41
  def resource_name
46
- @model_name.demodulize.underscore
42
+ model_name.demodulize.underscore
47
43
  end
48
44
 
49
45
  def plural_resource_name
@@ -55,28 +51,41 @@ module Redde
55
51
  end
56
52
 
57
53
  def index_header
58
- model_name.constantize.model_name.human(:count => 'other')
54
+ model_name.constantize.model_name.human(count: 'other')
59
55
  end
60
56
 
61
57
  def sort_priority(column_name)
62
58
  case column_name
63
- when "position" then 1
64
- when "visible" then 2
65
- when "name" then 3
66
- when "title" then 3
59
+ when 'position' then 1
60
+ when 'visible' then 2
61
+ when 'name' then 3
62
+ when 'title' then 3
67
63
  else 5
68
64
  end
69
65
  end
70
66
 
71
67
  def columns
72
- begin
73
- excluded_column_names = %w[id created_at updated_at]
74
- @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)}
75
- rescue NoMethodError
76
- @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)}
77
- end
68
+ model_name.constantize.columns.reject { |c| exclude_column?(c.name) }
69
+ .sort { |a, b| sort_priority(a.name) <=> sort_priority(b.name) }
70
+ .map { |c| convert_column(c) }
71
+ rescue NoMethodError
72
+ model_name.constantize.fields.map { |c| c[1] }
73
+ .reject { |c| exclude_column?(c.name) }
74
+ .map { |c| convert_column(c) }
75
+ end
76
+
77
+ def excluded_column_names
78
+ %w(id created_at updated_at)
78
79
  end
79
-
80
+
81
+ def convert_column(column)
82
+ ::Rails::Generators::GeneratedAttribute.new(column.name, column.type.to_s)
83
+ end
84
+
85
+ def exclude_column?(name)
86
+ excluded_column_names.include?(name) || name.index('_id')
87
+ end
88
+
80
89
  def column_names
81
90
  @model_name.constantize.column_names
82
91
  end
@@ -92,13 +101,16 @@ module Redde
92
101
 
93
102
  def generate_views
94
103
  views = {
95
- "index.html.#{ext}" => "app/views/admin/#{@controller_file_path}/index.html.#{ext}",
96
- "edit.html.#{ext}" => "app/views/admin/#{@controller_file_path}/edit.html.#{ext}"
104
+ "index.html.#{ext}" => contr_path('index'),
105
+ "edit.html.#{ext}" => contr_path('edit')
97
106
  }
98
107
  selected_views = views
99
108
  options.engine == generate_erb(selected_views)
100
109
  end
101
-
110
+
111
+ def contr_path(action)
112
+ "app/views/admin/#{controller_file_path}/#{action}.html.#{ext}"
113
+ end
102
114
 
103
115
  def generate_erb(views)
104
116
  views.each do |template_name, output_path|
@@ -112,9 +124,8 @@ module Redde
112
124
  end
113
125
 
114
126
  def generate_controller
115
- template "controllers/controller.rb", "app/controllers/admin/#{plural_resource_name}_controller.rb"
127
+ template 'controllers/controller.rb', "app/controllers/admin/#{plural_resource_name}_controller.rb"
116
128
  end
117
-
118
129
  end
119
130
  end
120
131
  end
@@ -1,19 +1,17 @@
1
- # coding: utf-8
2
1
  class Admin::<%= model_name.demodulize.pluralize -%>Controller < Admin::BaseController
3
-
4
2
  def index
5
3
  @<%= plural_resource_name %> = <%= model_name.demodulize -%>.all
6
4
  end
7
- <%- if column_names.include?("position") -%>
5
+ <%- if column_names.include?('position') -%>
8
6
  def sort
9
7
  params[:pos].each_with_index do |id, idx|
10
8
  p = <%= model_name.demodulize -%>.find(id)
11
- p.position = idx
12
- p.save
9
+ p.update(position: idx)
13
10
  end
14
- render :nothing => true
11
+ render nothing: true
15
12
  end
16
13
  <%- end -%>
14
+
17
15
  def new
18
16
  @<%= resource_name %> = <%= model_name.demodulize -%>.new
19
17
  render 'edit'
@@ -26,7 +24,7 @@ class Admin::<%= model_name.demodulize.pluralize -%>Controller < Admin::BaseCont
26
24
  def create
27
25
  @<%= resource_name %> = <%= model_name.demodulize -%>.new(<%= resource_name %>_params)
28
26
  if @<%= resource_name %>.save
29
- redirect_to params[:commit] == "Применить" ? [:edit, :admin, @<%= resource_name %>] : [:admin, :<%= plural_resource_name %>], :notice => "#{<%= model_name.demodulize -%>.model_name.human} добавлен."
27
+ redirect_to params[:commit] == 'Применить' ? [:edit, :admin, @<%= resource_name %>] : [:admin, :<%= plural_resource_name %>], notice: "#{<%= model_name.demodulize -%>.model_name.human} добавлен."
30
28
  else
31
29
  render 'edit'
32
30
  end
@@ -35,7 +33,7 @@ class Admin::<%= model_name.demodulize.pluralize -%>Controller < Admin::BaseCont
35
33
  def update
36
34
  @<%= resource_name %> = <%= model_name.demodulize -%>.find(params[:id])
37
35
  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} отредактирован."
36
+ redirect_to params[:commit] == 'Применить' ? [:edit, :admin, @<%= resource_name %>] : [:admin, :<%= plural_resource_name %>], notice: "#{<%= model_name.demodulize -%>.model_name.human} отредактирован."
39
37
  else
40
38
  render 'edit'
41
39
  end
@@ -44,7 +42,7 @@ class Admin::<%= model_name.demodulize.pluralize -%>Controller < Admin::BaseCont
44
42
  def destroy
45
43
  @<%= resource_name %> = <%= model_name.demodulize -%>.find(params[:id])
46
44
  @<%= resource_name %>.destroy
47
- redirect_to admin_<%= plural_resource_name %>_path, :notice => "#{<%= model_name.demodulize -%>.model_name.human} удален."
45
+ redirect_to admin_<%= plural_resource_name %>_path, notice: "#{<%= model_name.demodulize -%>.model_name.human} удален."
48
46
  end
49
47
 
50
48
  private
@@ -4,13 +4,13 @@
4
4
  Добавить #{taccusative(:<%= resource_name %>)}
5
5
  - else
6
6
  Редактировать #{taccusative(:<%= resource_name %>)}
7
- %p= link_to "Назад", [:admin, :<%= plural_resource_name %>]
7
+ %p= link_to 'Назад', [:admin, :<%= plural_resource_name %>]
8
8
 
9
9
  = form_for [:admin, @<%= resource_name %>] do |f|
10
- = render 'validate', {f: f}
10
+ = render 'validate', { f: f }
11
11
  %table
12
12
  <%- columns.each do |column| -%>
13
- <%- if column.field_type.to_s == "text_area" -%>
13
+ <%- if column.field_type.to_s == 'text_area' -%>
14
14
  %tr
15
15
  %td{colspan: 2}
16
16
  = f.label :<%= column.name %>
@@ -21,12 +21,12 @@
21
21
  %th{colspan: 2}
22
22
  = f.<%= column.field_type -%> :<%= column.name %>
23
23
  = f.label :<%= column.name %>
24
- <%- elsif column.name != "position" -%>
24
+ <%- elsif column.name != 'position' -%>
25
25
  %tr
26
26
  %th= f.label :<%= column.name %>
27
27
  %td= f.<%= column.field_type -%> :<%= column.name %>
28
28
  <%- end -%>
29
29
  <%- end -%>
30
30
  .actions
31
- = f.submit "Сохранить"
32
- = f.submit "Применить"
31
+ = f.submit 'Сохранить'
32
+ = f.submit 'Применить'
@@ -3,35 +3,35 @@
3
3
  %p= link_to "Добавить #{taccusative('<%= resource_name %>')}", [:new, :admin, :<%= resource_name %>]
4
4
 
5
5
  - unless @<%= plural_resource_name %>.empty?
6
- %table.list<%= ".sortable" if column_names.include?("position") %>
6
+ %table.list<%= ".sortable" if column_names.include?('position') %>
7
7
  %colgroup
8
8
  <%- columns.each do |column| -%>
9
- %col<%= ".w1" if ["position", "visible"].include? column.name %>
9
+ %col<%= '.w1' if ['position', 'visible'].include? column.name %>
10
10
  <%- end -%>
11
11
  %col.w1
12
12
  %thead
13
13
  %tr
14
14
  <%- columns.each do |column| -%>
15
- %th<%- unless ["position", "visible"].include? column.name %>= <%= model_name.demodulize %>.human_attribute_name("<%= column.name %>")<% end %>
15
+ %th<%- unless ['position', 'visible'].include? column.name %>= <%= model_name.demodulize %>.human_attribute_name('<%= column.name %>')<% end %>
16
16
  <%- end -%>
17
17
  %th
18
18
  - @<%= plural_resource_name %>.each do |<%= resource_name %>|
19
- <%- if column_names.include?("position") -%>
20
- %tr{id: "pos_#{<%= resource_name %>.id}"}
19
+ <%- if column_names.include?('position') -%>
20
+ %tr{ id: "pos_#{<%= resource_name %>.id}" }
21
21
  <%- else -%>
22
22
  %tr
23
23
  <%- end -%>
24
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'}
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
29
  <%- else -%>
30
30
  %td= link_to <%= resource_name %>.<%= column.name %>, [:edit, :admin, <%= resource_name %>]
31
31
  <%- end -%>
32
32
  <%- end -%>
33
- %td= link_to "Удалить", [:admin, <%= resource_name %>], method: :delete, data: { confirm: "Точно Удалить?" }, class: :del
33
+ %td= link_to 'Удалить', [:admin, <%= resource_name %>], method: :delete, data: { confirm: 'Точно Удалить?'' }, class: :del
34
34
 
35
- <%- if column_names.include?("position") -%>
35
+ <%- if column_names.include?('position') -%>
36
36
  = sortable sort_admin_<%= plural_resource_name %>_path
37
37
  <%- end -%>
data/lib/redde/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Redde
2
- VERSION = "0.1.7"
2
+ VERSION = '0.1.8'
3
3
  end
data/lib/redde.rb CHANGED
@@ -1,7 +1,6 @@
1
- require "redde/version"
1
+ require 'redde/version'
2
2
  module Redde
3
3
  require 'generators/redde/layout/layout_generator'
4
4
  require 'generators/redde/scaffold/scaffold_generator'
5
5
  require 'generators/redde/photo/photo_generator'
6
- # Your code goes here...
7
6
  end
data/lib/url_generator.rb CHANGED
@@ -1,21 +1,23 @@
1
1
  # coding: utf-8
2
2
 
3
3
  class UrlGenerator
4
-
5
- def initialize id, name = nil
4
+ attr_reader :id, :name
5
+ def initialize(id, name = nil)
6
6
  @id = id
7
7
  @name = name
8
8
  end
9
9
 
10
10
  def url
11
- "#{@id}#-{formatted_name}".downcase
11
+ "#{id}#-{formatted_name}".downcase
12
12
  end
13
13
 
14
14
  def translitted_name
15
- Russian.translit(@name).gsub(' ','-').gsub(/[^\x00-\x7F]+/, '').gsub(/[^\w_ \-]+/i, '').gsub(/[ \-]+/i, '-').gsub(/^\-|\-$/i, '')
15
+ Russian.translit(name).gsub(' ', '-')
16
+ .gsub(/[^\x00-\x7F]+/, '').gsub(/[^\w_ \-]+/i, '')
17
+ .gsub(/[ \-]+/i, '-').gsub(/^\-|\-$/i, '')
16
18
  end
17
19
 
18
20
  def formatted_name
19
- @name.nil? ? '' : translitted_name
21
+ name.nil? ? '' : translitted_name
20
22
  end
21
- end
23
+ end
@@ -1,5 +1,5 @@
1
1
  # Set up gems listed in the Gemfile.
2
2
  ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__)
3
3
 
4
- require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
4
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
5
5
  $LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redde
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oleg Bovykin
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-03-26 00:00:00.000000000 Z
12
+ date: 2014-05-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: jquery-rails