Skip to content

Commit

Permalink
Running rubocop in auto-correct mode
Browse files Browse the repository at this point in the history
  • Loading branch information
clairezed committed Jun 26, 2017
1 parent 75ac9cd commit 1c0cffa
Show file tree
Hide file tree
Showing 69 changed files with 547 additions and 467 deletions.
2 changes: 2 additions & 0 deletions .rubocop.yml
@@ -0,0 +1,2 @@
Rails:
Enabled: true
34 changes: 17 additions & 17 deletions Gemfile
@@ -1,53 +1,53 @@
# frozen_string_literal: true

source 'https://rubygems.org'

git_source(:github) do |repo_name|
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?('/')
"https://github.com/#{repo_name}.git"
end

# Core ====================================================
gem 'rails', '~> 5.0.1'
gem 'puma', '~> 3.0'
gem 'pg'
gem 'puma', '~> 3.0'
gem 'rails', '~> 5.0.1'

# DB / Model ==============================================
gem 'acts_as_list', '~> 0.7.6'
gem 'devise', '~> 4.2.0'

# Asset pipeline ==========================================
gem 'uglifier', '>= 1.3.0'
gem 'sass-rails', '~> 5.0'
gem 'coffee-rails', '~> 4.2'
gem 'jbuilder', '~> 2.5'
gem 'jquery-rails'
gem 'sass-rails', '~> 5.0'
gem 'turbolinks', '~> 5'
gem 'jbuilder', '~> 2.5'

gem 'uglifier', '>= 1.3.0'

# Views ====================================================
gem 'bootstrap', '~> 4.0.0.alpha3.1'
gem 'autoprefixer-rails', '~> 6.3.7'
gem 'will_paginate', '~> 3.1.0'
gem 'slim', '~> 3.0.7'
gem 'bootstrap', '~> 4.0.0.alpha3.1'
gem 'font-awesome-rails'
gem 'htmlentities', '~> 4.3.4'
gem "font-awesome-rails"

gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gem 'slim', '~> 3.0.7'
gem 'will_paginate', '~> 3.1.0'

gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby]

group :development do
gem 'web-console', '>= 3.3.0'
gem 'listen', '~> 3.0.5'
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
gem 'web-console', '>= 3.3.0'
end

group :test, :development do
gem 'byebug', platform: :mri
gem 'rubocop', require: false
gem 'bullet'
gem 'rspec-rails', '~> 3.0'
gem 'byebug', platform: :mri
gem 'capybara'
gem 'email_spec'
gem 'rspec-rails', '~> 3.0'
gem 'rubocop', require: false
end

group :test do
Expand Down
9 changes: 8 additions & 1 deletion README.md
Expand Up @@ -115,4 +115,11 @@ This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md

- https://github.com/mattbrictson/rails-template
- https://github.com/elastic/elasticsearch-rails/tree/master/elasticsearch-rails/lib/rails/templates
- https://github.com/spree/spree/tree/master/cmd
- https://github.com/spree/spree/tree/master/cmd


## Todo

-> Vérifier la présence de "TODO" dans le code

- remplacer will_paginate par kaminari
2 changes: 2 additions & 0 deletions Rakefile
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

Expand Down
2 changes: 2 additions & 0 deletions app/channels/application_cable/channel.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module ApplicationCable
class Channel < ActionCable::Channel::Base
end
Expand Down
2 changes: 2 additions & 0 deletions app/channels/application_cable/connection.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module ApplicationCable
class Connection < ActionCable::Connection::Base
end
Expand Down
20 changes: 9 additions & 11 deletions app/controllers/admin/admins_controller.rb
@@ -1,16 +1,17 @@
class Admin::AdminsController < Admin::BaseController
# frozen_string_literal: true

before_action :find_admin, only: [ :edit, :update, :destroy ]
class Admin::AdminsController < Admin::BaseController
before_action :find_admin, only: %i[edit update destroy]

def index
params[:sort] ||= "email ASC"
@admins = Admin.where.not(email: "technique@studio-hb.com").paginate(per_page: 20, page: params[:page])
params[:sort] ||= 'email ASC'
@admins = Admin.where.not(email: 'technique@studio-hb.com').paginate(per_page: 20, page: params[:page])
end

def new
@admin = Admin.new
end

def create
@admin = Admin.new(admin_params)
if @admin.save
Expand All @@ -21,10 +22,9 @@ def create
render :new
end
end

def edit
end


def edit; end

def update
if @admin.update_attributes(admin_params)
flash[:notice] = "L'admin a été mis à jour avec succès"
Expand All @@ -41,7 +41,6 @@ def destroy
redirect_to admin_admins_path
end


private

def find_admin
Expand All @@ -52,5 +51,4 @@ def find_admin
def admin_params
params.require(:admin).permit(:email, :password)
end

end
10 changes: 5 additions & 5 deletions app/controllers/admin/base_controller.rb
@@ -1,11 +1,11 @@
class Admin::BaseController < ApplicationController
# frozen_string_literal: true

class Admin::BaseController < ApplicationController
before_action :authenticate_admin!
layout 'administration'

rescue_from ActiveRecord::RecordNotFound do
flash[:error] = "Element non trouvé"
redirect_to admin_root_path if !request.xhr?
flash[:error] = 'Element non trouvé'
redirect_to admin_root_path unless request.xhr?
end

end
end
32 changes: 15 additions & 17 deletions app/controllers/admin/basic_pages_controller.rb
@@ -1,56 +1,55 @@
class Admin::BasicPagesController < Admin::BaseController
# frozen_string_literal: true

before_action :find_basic_page, only: [ :edit, :update, :position, :destroy ]
class Admin::BasicPagesController < Admin::BaseController
before_action :find_basic_page, only: %i[edit update position destroy]

def index
params[:sort] ||= "sort_by_position asc"
params[:sort] ||= 'sort_by_position asc'
@basic_pages = BasicPage.apply_filters(params).paginate(per_page: 20, page: params[:page])
end

def new
@basic_page = BasicPage.new
@basic_page.build_seo
end

def create
@basic_page = BasicPage.new(basic_page_params)
if @basic_page.save
flash[:notice] = "La page a été créée avec succès"
flash[:notice] = 'La page a été créée avec succès'
redirect_to params[:continue].present? ? edit_admin_basic_page_path(@basic_page) : admin_basic_pages_path
else
flash[:error] = "Une erreur s'est produite lors de la création de la page"
render :new
end
end

def edit
end


def edit; end

def update
if @basic_page.update_attributes(basic_page_params)
flash[:notice] = "La page a été mise à jour avec succès"
flash[:notice] = 'La page a été mise à jour avec succès'
redirect_to params[:continue].present? ? edit_admin_basic_page_path(@basic_page) : admin_basic_pages_path
else
flash[:error] = "Une erreur s'est produite lors de la mise à jour de la page"
render :edit
end
end

def position
if params[:position].present?
@basic_page.insert_at params[:position].to_i
flash[:notice] = "Les pages ont été réordonnées avec succès"
@basic_page.insert_at params[:position].to_i
flash[:notice] = 'Les pages ont été réordonnées avec succès'
end
redirect_to admin_basic_pages_path
end

def destroy
@basic_page.destroy
flash[:notice] = "La page a été supprimée avec succès"
flash[:notice] = 'La page a été supprimée avec succès'
redirect_to admin_basic_pages_path
end


private

def find_basic_page
Expand All @@ -59,7 +58,6 @@ def find_basic_page

# strong parameters
def basic_page_params
params.require(:basic_page).permit(:title, :content, :enabled, seo_attributes: [:slug, :title, :keywords, :description, :id])
params.require(:basic_page).permit(:title, :content, :enabled, seo_attributes: %i[slug title keywords description id])
end

end
9 changes: 4 additions & 5 deletions app/controllers/admin/dashboard_controller.rb
@@ -1,6 +1,5 @@
class Admin::DashboardController < Admin::BaseController
# frozen_string_literal: true

def index
end

end
class Admin::DashboardController < Admin::BaseController
def index; end
end
17 changes: 7 additions & 10 deletions app/controllers/admin/seos_controller.rb
@@ -1,26 +1,24 @@
class Admin::SeosController < Admin::BaseController
# frozen_string_literal: true

before_action :find_seo, only: [ :edit, :update ]
class Admin::SeosController < Admin::BaseController
before_action :find_seo, only: %i[edit update]

def index
@seos = Seo.where.not(param: nil)
end

def edit
end


def edit; end

def update
if @seo.update_attributes(seo_params)
flash[:notice] = "Les SEO ont été mis à jour avec succès"
flash[:notice] = 'Les SEO ont été mis à jour avec succès'
redirect_to params[:continue].present? ? edit_admin_seo_path(@seo) : admin_seos_path
else
flash[:error] = "Une erreur s'est produite lors de la mise à jour des SEO"
render :edit
end
end



private

def find_seo
Expand All @@ -31,5 +29,4 @@ def find_seo
def seo_params
params.require(:seo).permit(:title, :keywords, :description)
end

end
39 changes: 20 additions & 19 deletions app/controllers/application_controller.rb
@@ -1,43 +1,44 @@
# frozen_string_literal: true

class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception

before_action :set_default_seos!, :get_basic_pages
after_action :flash_to_headers, if: ->{ request.xhr? && flash.present? }
after_action :flash_to_headers, if: -> { request.xhr? && flash.present? }

protected

def get_seo_for_static_page(param)
seo = Seo.where(param: param).first
if seo
@seo_title = seo.title if !seo.title.blank?
@seo_description = seo.description if !seo.description.blank?
@seo_keywords = seo.keywords if !seo.keywords.blank?
@seo_title = seo.title if seo.title.present?
@seo_description = seo.description if seo.description.present?
@seo_keywords = seo.keywords if seo.keywords.present?
end
end

rescue_from ActionController::InvalidAuthenticityToken do
redirect_to root_path if !request.xhr?
end
redirect_to root_path unless request.xhr?
end

private

def set_default_seos!
@seo_title ||= "Title du projet"
@seo_description ||= "Description du projet"
@seo_keywords ||= "keywords du projet, projet"
@seo_title ||= 'Title du projet'
@seo_description ||= 'Description du projet'
@seo_keywords ||= 'keywords du projet, projet'
end

# Pour les requêtes ajax
def flash_to_headers
[:error, :alert, :warning, :notice].each do |type|
if flash[type].present?
content = { message: flash[type], type: ApplicationHelper::FLASH_BS_TYPES[type] }
response.headers['X-Message'] = content.to_json
flash.discard
break
end
%i[error alert warning notice].each do |type|
next if flash[type].blank?
content = { message: flash[type], type: ApplicationHelper::FLASH_BS_TYPES[type] }
response.headers['X-Message'] = content.to_json
flash.discard
break
end
end

Expand Down
6 changes: 3 additions & 3 deletions app/controllers/basic_pages_controller.rb
@@ -1,9 +1,9 @@
# frozen_string_literal: true

class BasicPagesController < ApplicationController
include SlugsAndRedirections

def show
@basic_page = get_object_from_param_or_redirect(BasicPage.enabled)
end


end
end

0 comments on commit 1c0cffa

Please sign in to comment.