Skip to content

Commit

Permalink
KBP-175 KBP-181 #time 10h code refactor for project template
Browse files Browse the repository at this point in the history
  • Loading branch information
İsmail Akbudak committed Jan 8, 2018
1 parent 48c2607 commit e164182
Show file tree
Hide file tree
Showing 44 changed files with 338 additions and 115 deletions.
14 changes: 7 additions & 7 deletions bin/build_app
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
echo "Build cybele gem"
./bin/build_gem

# Remove dummy_app_2
echo "Remove dummy_app_2"
rm -rf tmp/dummy_app_2
# Remove dummy_app_3
echo "Remove dummy_app_3"
rm -rf tmp/dummy_app_3

# Disable spring
export DISABLE_SPRING=1
# or you can run this command
# ps ax | grep spring | grep dummy_app_2 | cut -f1 -d' ' | xargs kill
# ps ax | grep spring | grep dummy_app_3 | cut -f1 -d' ' | xargs kill

# Create dummy_app_2
echo "Create dummy_app_2"
cybele tmp/dummy_app_2 --skip-create-database
# Create dummy_app_3
echo "Create dummy_app_3"
cybele tmp/dummy_app_3 --skip-create-database
24 changes: 14 additions & 10 deletions lib/cybele/helpers/app_files/view_files.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,7 @@ def customize_view_files_with_option
'app_files/app/views/welcome' => 'app/views/welcome',
'app_files/public' => 'public'
)
template_files = %w[
app/views/welcome/index.html.haml.erb
app/views/layouts/mailer.html.haml.erb
app/views/layouts/application.html.haml.erb
app/views/layouts/partials/_navbar.html.haml.erb
app/views/layouts/hq/application.html.haml.erb
app/views/layouts/hq/login.html.haml.erb
]
replace_erb_with_haml(template_files)
replace_erb_with_haml
end

def customize_default_view_files
Expand All @@ -41,7 +33,17 @@ def remove_erb_files(template_files)
remove_files(template_files)
end

def replace_erb_with_haml(template_files)
# rubocop:disable Metrics/MethodLength
# rubocop:disable Metrics/LineLength
def replace_erb_with_haml
template_files = %w[
app/views/welcome/index.html.haml.erb
app/views/layouts/mailer.html.haml.erb
app/views/layouts/application.html.haml.erb
app/views/layouts/partials/_navbar.html.haml.erb
app/views/layouts/hq/application.html.haml.erb
app/views/layouts/hq/login.html.haml.erb
]
remove_erb_files(template_files)
files_to_template(
'app_files/app/views/welcome/index.html.haml.erb' => 'app/views/welcome/index.html.haml',
Expand All @@ -52,6 +54,8 @@ def replace_erb_with_haml(template_files)
'app_files/app/views/layouts/hq/login.html.haml.erb' => 'app/views/layouts/hq/login.html.haml'
)
end
# rubocop:enable Metrics/MethodLength
# rubocop:enable Metrics/LineLength
end
end
end
Expand Down
1 change: 0 additions & 1 deletion lib/cybele/helpers/app_files/view_gems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ module ViewGems
def add_required_view_gems
files = %w[
app_files/bootstrap_Gemfile.erb
app_files/blankable_Gemfile.erb
app_files/breadcrumb_Gemfile.erb
app_files/jquery_Gemfile.erb
]
Expand Down
7 changes: 7 additions & 0 deletions lib/cybele/helpers/devise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ def generate_devise_models
remove_file 'config/locales/devise.en.yml', force: true
copy_file 'config/locales/devise.en.yml', 'config/locales/devise.en.yml'
copy_file 'config/locales/devise.tr.yml', 'config/locales/devise.tr.yml'
inject_into_file 'db/seeds.rb', after: "# Character.create(name: 'Luke', movie: movies.first)\n" do
template_content('devise/seeds.rb.erb')
end
configure_app_name(%w[db/seeds.rb])
Dir.glob('db/migrate/*devise_create*.rb') do |f|
replace_in_file f, 't.boolean :is_active', 't.boolean :is_active, default: true'
end
end

def generate_devise_views
Expand Down
3 changes: 3 additions & 0 deletions lib/cybele/helpers/locale_language.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ def configure_locale_language
'config/locales/models.en.yml' => 'config/locales/models.en.yml',
'config/locales/view.en.yml' => 'config/locales/view.en.yml'
)
inject_into_file 'config/application.rb',
template_content('config/config_application.rb.erb'),
after: 'class Application < Rails::Application'
end
end
end
Expand Down
3 changes: 2 additions & 1 deletion lib/cybele/helpers/responders.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ def replace_responders_file_contents
'require "application_responder"',
"require 'application_responder'"
# Remove comments in locale/responders.yml
uncomment_lines 'config/locales/responders.en.yml', /alert:/
remove_file 'config/locales/responders.en.yml', force: true
copy_file 'config/locales/responders.tr.yml', 'config/locales/responders.tr.yml'
copy_file 'config/locales/responders.en.yml', 'config/locales/responders.en.yml'
end
end
end
Expand Down
3 changes: 3 additions & 0 deletions lib/cybele/helpers/sidekiq.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ def configure_sidekiq
inject_into_file 'config/routes.rb',
template_content('sidekiq/sidekiq_routes_mount.erb'),
after: 'Rails.application.routes.draw do'
inject_into_file 'config/application.rb',
template_content('sidekiq/sidekiq_application.rb.erb'),
after: 'class Application < Rails::Application'
end

private
Expand Down
15 changes: 15 additions & 0 deletions templates/app_files/app/assets/stylesheets/application.css.sass
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
@import "bootstrap"

/* from vendor
@import "nprogress"
@import "trix"
@import "jquery.datetimepicker"

/* Custom container
body
Expand Down Expand Up @@ -45,6 +50,16 @@ body
color: #777
border-top: .05rem solid #e5e5e5

.simple_form
.form-actions
text-align: right

.form-group
.checkbox
label
input[type="checkbox"]
margin: 0 10px 0 0

/* Supporting marketing content
.about-contact
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
@import "sidebar"
@import "footable.bootstrap.min"

/* from vendor
@import "nprogress"
@import "trix"
@import "jquery.datetimepicker"

body
main
@media (max-width: 767px)
Expand All @@ -38,14 +43,32 @@ body
min-width: 115px

#toolbar
text-align: right
a
margin-bottom: 12px

#admin-devise-page
.card
margin-top: 70px
margin-top: 50px
width: 30rem

.simple_form
.form-actions
text-align: right

.form-group
.checkbox
label
input[type="checkbox"]
margin: 0 10px 0 0

.audit.form-inline
.form-group
margin: 0px 10px

label
padding: 0 5px

.alert.message
.far.fa-smile
padding: 0 5px
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Activatable

def activation_toggle(resource)
if resource.update(is_active: !resource.is_active)
i18n_key = `flash.actions.toggle_is_active.#{resource.is_active ? 'active' : 'passive'}`
i18n_key = "flash.actions.toggle_is_active.#{resource.is_active ? 'active' : 'passive'}"
flash[:info] = I18n.t(i18n_key, resource_name: resource.class.model_name.human)
else
flash[:danger] = I18n.t('flash.messages.error_occurred')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Hq::PasswordsController < Devise::PasswordsController

private

def after_resetting_password_path_for
def after_resetting_password_path_for(_resource)
hq_root_path
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class User::PasswordsController < Devise::PasswordsController
private

def after_resetting_password_path_for
def after_resetting_password_path_for(_resource)
user_root_path
end
end
17 changes: 15 additions & 2 deletions templates/app_files/app/helpers/application_helper.rb.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module ApplicationHelper
end

def blankable(contents, search)
render partial: contents.size == 0 ? 'blank' : 'list', contents: contents, search: search
render partial: contents.size == 0 ? 'blank' : 'list', locals: { contents: contents, search: search }
end

def auditable_types_collection(auditable_types)
Expand All @@ -33,11 +33,24 @@ module ApplicationHelper

def query_present?(array)
q = params[:q]
return false unless params[:q].present?
return false unless q.present?
q = q.permit!.to_h
q.any? {|k,v| k.to_s.in?(array) && v.present? }
end

def actions_collection
%w(create update destroy).map {|a| [t("actions.#{a}"), a] }
end

def css_class(paths, exist: '', not_exist: '')
if paths.is_a? Array
p = request.path
paths.each do |path|
return exist if p.include? path
end
return not_exist
end
return request.path == paths ? exist : not_exist if paths.is_a? String
raise NotImplementedError
end
end
8 changes: 6 additions & 2 deletions templates/app_files/app/models/concerns/password_creatable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ module PasswordCreatable

included do
# Virtual attributes
attr_accessor :is_generated_password

attr_reader :is_generated_password
# Callbacks
after_commit :send_login_info, on: :create
before_validation :create_password, on: :create
Expand All @@ -15,6 +14,11 @@ module PasswordCreatable
end
end

protected

# Virtual attributes
attr_writer :is_generated_password

private

def create_password
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
%h2= t('mailer.hello')

%p= t('mailer.admin.login_info.first_info')
%p= `#{t('mailer.admin.login_info.second_info')} :`
%p= "#{t('mailer.admin.login_info.second_info')} :"
%p
%strong= `#{t('activerecord.attributes.admin.email')} :`
%strong= "#{t('activerecord.attributes.admin.email')} :"
= @admin.email
%p
%strong= `#{t('activerecord.attributes.admin.password')} :`
%strong= "#{t('activerecord.attributes.admin.password')} :"
= @password
%p= link_to t('mailer.admin.login_info.btn_login'), new_admin_session_url

Expand Down
43 changes: 22 additions & 21 deletions templates/app_files/app/views/hq/audits/_filters.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,42 @@
.col-lg-10
= search_form_for(search,
builder: SimpleForm::FormBuilder,
html: { class: 'form-inline', data: { turboform: true } },
html: { class: 'audit form-inline', data: { turboform: true } },
url: hq_audits_path) do |f|
.form-group
= f.label :user_type, label: t('activerecord.attributes.audits.user_type')
%label
= "#{ t('activerecord.attributes.audits.user_type') }: "
= f.input_field :user_type_eq, label: false, class: 'form-control chosen-select',
placeholder: t('activerecord.attributes.audits.user'),
collection: audit_users, include_blank: t('view.select')

- if params[:q].present? && params[:q][:user_type_eq].present?
- type = params[:q][:user_type_eq]
- if type == 'Admin'
= f.label :user, label: t('activerecord.attributes.audits.user')
%label
= "#{ t('activerecord.attributes.audits.user') }: "
= f.input_field :user_id_eq, label: false, class: 'form-control chosen-select',
placeholder: t('activerecord.attributes.audits.user'),
collection: admins, include_blank: t('view.select')
- elsif type == 'User'
= f.label :user, label: t('activerecord.attributes.audits.user')
= f.input_field :user_id_eq, label: false, class: 'form-control chosen-select',
placeholder: t('activerecord.attributes.audits.user'),
collection: users, include_blank: t('view.select')

= f.label :auditable_type, label: t('activerecord.attributes.audits.auditable_type')
= f.input_field :auditable_type_eq, label: false, class: 'form-control chosen-select',
placeholder: t('activerecord.attributes.audits.auditable_type'),
collection: auditable_types_collection(auditable_types),
include_blank: t('view.select')
.form-group
= f.label :user, label: t('activerecord.attributes.audits.auditable_id')
= f.input_field :auditable_id_eq, label: false, class: 'form-control',
placeholder: t('activerecord.attributes.audits.auditable_id')

= f.label :user, label: t('activerecord.attributes.audits.action')
%label
= "#{ t('activerecord.attributes.audits.action') }: "
= f.input_field :action_eq, label: false, class: 'form-control chosen-select',
placeholder: t('activerecord.attributes.audits.action'),
collection: actions_collection,
include_blank: t('view.select')
= button_tag(class: 'btn btn-success btn-group') do
%i.fas.fa-search
.form-group
.input-group
%label
= "#{ t('activerecord.attributes.audits.auditable_type') }: "
= f.input_field :auditable_type_eq, label: false, class: 'form-control chosen-select',
placeholder: t('activerecord.attributes.audits.auditable_type'),
collection: auditable_types_collection(auditable_types),
include_blank: t('view.select')
= f.input_field :auditable_id_eq,
label: false,
class: 'form-control',
placeholder: t('activerecord.attributes.audits.auditable_id')
%span.input-group-btn
= button_tag(class: 'btn btn-primary') do
%i.fas.fa-search
8 changes: 4 additions & 4 deletions templates/app_files/app/views/hq/audits/_list.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@
%td= audit.id
%td
- if audit.try(:user_type).present?
= t(`activerecord.models.#{audit.try(:user_type).try(:downcase)}`)
%td= `#{audit.try(:user).try(:full_name)} - #{audit.try(:user).try(:email)}`
= t("activerecord.models.#{audit.try(:user_type).try(:downcase)}")
%td= "#{audit.try(:user).try(:full_name)} - #{audit.try(:user).try(:email)}"
%td
- if audit.try(:auditable_type).present?
= t(`activerecord.models.#{audit.try(:auditable_type).try(:underscore)}`)
= t("activerecord.models.#{audit.try(:auditable_type).try(:underscore)}")
%td= audit.auditable_id
%td= l audit.created_at
%td= t(`actions.#{audit.action}`)
%td= t("actions.#{audit.action}")
%td.actions
= link_to(hq_audit_path(id: audit),
class: 'btn btn-success btn-sm',
Expand Down
2 changes: 1 addition & 1 deletion templates/app_files/app/views/hq/audits/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
%p
%strong
- if @audit.try(:auditable_type).present?
= t(`activerecord.attributes.#{@audit.try(:auditable_type).try(:underscore)}.#{key}`)
= t("activerecord.attributes.#{@audit.try(:auditable_type).try(:underscore)}.#{key}")
= @audit.audited_changes[key]
Loading

0 comments on commit e164182

Please sign in to comment.