Skip to content

Commit

Permalink
tweak code so that locomotive.works (hosting) could handle smoothly t…
Browse files Browse the repository at this point in the history
…he white label feature
  • Loading branch information
did committed Mar 8, 2017
1 parent d5c959e commit fde99c4
Show file tree
Hide file tree
Showing 18 changed files with 66 additions and 27 deletions.
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module RedirectToMainHostController
private private


def redirect_to_main_host def redirect_to_main_host
return if Locomotive.config.host.blank? return if Locomotive.config.host.blank? || request.env['locomotive.default_host'].present?


if request.host != Locomotive.config.host if request.host != Locomotive.config.host
options = { host: Locomotive.config.host } options = { host: Locomotive.config.host }
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/locomotive/errors_controller.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ class ErrorsController < ApplicationController


layout '/locomotive/layouts/error' layout '/locomotive/layouts/error'


helper Locomotive::BaseHelper

def error_404 def error_404
render '404', status: :not_found render '404', status: :not_found
end end
Expand Down
6 changes: 5 additions & 1 deletion app/controllers/locomotive/passwords_controller.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ def after_sending_reset_password_instructions_path_for(resource_name)
end end


def set_locale def set_locale
I18n.locale = current_site? ? current_site.accounts.first.locale : Locomotive.config.default_locale I18n.locale = current_site? ? current_site.accounts.first.locale : default_locale
end

def default_locale
Locomotive.config.default_locale
end end


end end
Expand Down
6 changes: 6 additions & 0 deletions app/controllers/locomotive/registrations_controller.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class RegistrationsController < ::Devise::RegistrationsController


helper Locomotive::BaseHelper helper Locomotive::BaseHelper


before_filter :set_locale

private private


def after_sign_up_path_for(resource) def after_sign_up_path_for(resource)
Expand All @@ -20,5 +22,9 @@ def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) << :name devise_parameter_sanitizer.for(:sign_up) << :name
end end


def set_locale
I18n.locale = Locomotive.config.default_locale
end

end end
end end
6 changes: 5 additions & 1 deletion app/controllers/locomotive/sessions_controller.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ def after_sign_out_path_for(resource)
end end


def set_locale def set_locale
I18n.locale = current_site? ? current_site.accounts.first.locale : Locomotive.config.default_locale I18n.locale = current_site? ? current_site.accounts.first.locale : default_locale
end

def default_locale
Locomotive.config.default_locale
end end


end end
Expand Down
18 changes: 18 additions & 0 deletions app/helpers/locomotive/base_helper.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ def body_class
[self.controller.controller_name, action].map(&:dasherize).join(' ') [self.controller.controller_name, action].map(&:dasherize).join(' ')
end end


def application_name
Locomotive.config.name
end

def title(title = nil) def title(title = nil)
if title.nil? if title.nil?
@content_for_title @content_for_title
Expand All @@ -33,6 +37,12 @@ def help(text)
end end
end end


#= Sessions

def enable_registration?
current_site.nil? && Locomotive.config.enable_registration
end

#= Sidebar #= Sidebar


def sidebar_current_section_class def sidebar_current_section_class
Expand Down Expand Up @@ -72,6 +82,14 @@ def form_tab_pane(name, first = false, &block)


## Tag helpers ## ## Tag helpers ##


def account_logo_tag
image_tag 'locomotive/logo-white.png'
end

def sidebar_logo_tag
image_tag 'locomotive/logo.png'
end

def icon_tag(name) def icon_tag(name)
content_tag :i, '', class: ['fa', name].join(' ') content_tag :i, '', class: ['fa', name].join(' ')
end end
Expand Down
2 changes: 1 addition & 1 deletion app/views/locomotive/layouts/account.html.slim
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ html xmlns='http://www.w3.org/1999/xhtml' lang=I18n.locale
meta charset="utf-8" meta charset="utf-8"
meta http-equiv="x-ua-compatible" content="ie=edge" meta http-equiv="x-ua-compatible" content="ie=edge"


title= escape_once(strip_tags(title) + " | #{Locomotive.config.name}") title= escape_once(strip_tags(title) + " | #{application_name}")


meta name="viewport" content="width=device-width, initial-scale=1" meta name="viewport" content="width=device-width, initial-scale=1"


Expand Down
4 changes: 2 additions & 2 deletions app/views/locomotive/layouts/error.html.slim
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ html xmlns='http://www.w3.org/1999/xhtml' lang=I18n.locale
meta charset="utf-8" meta charset="utf-8"
meta http-equiv="x-ua-compatible" content="ie=edge" meta http-equiv="x-ua-compatible" content="ie=edge"


title= escape_once(strip_tags(error_title) + " | Locomotive") title= escape_once(strip_tags(error_title) + " | #{application_name}")


meta name="viewport" content="width=device-width, initial-scale=1" meta name="viewport" content="width=device-width, initial-scale=1"


Expand All @@ -19,6 +19,6 @@ html xmlns='http://www.w3.org/1999/xhtml' lang=I18n.locale
.public-container .public-container
.public-wrapper .public-wrapper
= link_to root_path, class: 'brand-logo' do = link_to root_path, class: 'brand-logo' do
= image_tag 'locomotive/logo-white.png' = account_logo_tag


= yield = yield
2 changes: 1 addition & 1 deletion app/views/locomotive/passwords/edit.html.slim
Original file line number Original file line Diff line number Diff line change
@@ -1,7 +1,7 @@
- title t('locomotive.passwords.edit.title') - title t('locomotive.passwords.edit.title')


= link_to root_path, class: 'brand-logo' do = link_to root_path, class: 'brand-logo' do
= image_tag 'locomotive/logo-white.png' = account_logo_tag


.public-box .public-box
.public-intro .public-intro
Expand Down
2 changes: 1 addition & 1 deletion app/views/locomotive/passwords/new.html.slim
Original file line number Original file line Diff line number Diff line change
@@ -1,7 +1,7 @@
- title t('locomotive.passwords.new.title') - title t('locomotive.passwords.new.title')


= link_to root_path, class: 'brand-logo' do = link_to root_path, class: 'brand-logo' do
= image_tag 'locomotive/logo-white.png' = account_logo_tag


.public-box .public-box
.public-intro .public-intro
Expand Down
2 changes: 1 addition & 1 deletion app/views/locomotive/registrations/new.html.slim
Original file line number Original file line Diff line number Diff line change
@@ -1,7 +1,7 @@
- title t('locomotive.registrations.new.title') - title t('locomotive.registrations.new.title')


= link_to root_path, class: 'brand-logo' do = link_to root_path, class: 'brand-logo' do
= image_tag 'locomotive/logo-white.png' = account_logo_tag


.public-box .public-box
.public-intro .public-intro
Expand Down
4 changes: 2 additions & 2 deletions app/views/locomotive/sessions/new.html.slim
Original file line number Original file line Diff line number Diff line change
@@ -1,7 +1,7 @@
- title t('locomotive.sessions.new.title') - title t('locomotive.sessions.new.title')


= link_to root_path, class: 'brand-logo' do = link_to root_path, class: 'brand-logo' do
= image_tag 'locomotive/logo-white.png' = account_logo_tag


.public-box .public-box
.public-intro .public-intro
Expand All @@ -20,5 +20,5 @@
= f.actions do = f.actions do
= f.button :submit, t('.submit'), class: 'btn btn-primary' = f.button :submit, t('.submit'), class: 'btn btn-primary'


- if current_site.nil? && Locomotive.config.enable_registration - if enable_registration?
= link_to t('.sign_up').html_safe, sign_up_path, class: 'public-link' = link_to t('.sign_up').html_safe, sign_up_path, class: 'public-link'
2 changes: 1 addition & 1 deletion app/views/locomotive/shared/_account_navigation.slim
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,5 @@
nav.navigation class="#{class_name rescue ''}" nav.navigation class="#{class_name rescue ''}"
= link_to root_path, class: 'brand-logo' do = link_to root_path, class: 'brand-logo' do
= image_tag 'locomotive/logo-white.png' = account_logo_tag


= render 'locomotive/shared/account/navigation' = render 'locomotive/shared/account/navigation'
2 changes: 1 addition & 1 deletion app/views/locomotive/shared/_sidebar.html.slim
Original file line number Original file line Diff line number Diff line change
@@ -1,6 +1,6 @@
.sidebar role="tablist" aria-multiselectable="false" data-current-section=sidebar_current_section_class .sidebar role="tablist" aria-multiselectable="false" data-current-section=sidebar_current_section_class
= link_to root_path, class: 'sidebar-logo' do = link_to root_path, class: 'sidebar-logo' do
= image_tag 'locomotive/logo.png' = sidebar_logo_tag


- cache(cache_key_for_sidebar) do - cache(cache_key_for_sidebar) do
= link_to dashboard_path(current_site), class: sidebar_link_class(:dashboard) do = link_to dashboard_path(current_site), class: sidebar_link_class(:dashboard) do
Expand Down
11 changes: 6 additions & 5 deletions config/locales/devise.en.yml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@ en:
send_instructions: 'You will receive an email with instructions about how to unlock your account in a few minutes.' send_instructions: 'You will receive an email with instructions about how to unlock your account in a few minutes.'
unlocked: 'Your account was successfully unlocked. You are now signed in.' unlocked: 'Your account was successfully unlocked. You are now signed in.'
mailer: mailer:
locomotive_account: confirmation_instructions:
confirmation_instructions: 'Confirmation instructions' locomotive_account_subject: 'Confirmation instructions'
reset_password_instructions: 'Reset password instructions' reset_password_instructions:
unlock_instructions: 'Unlock Instructions' locomotive_account_subject: 'Reset password instructions'

unlock_instructions:
locomotive_account_subject: 'Unlock Instructions'


locomotive: locomotive:
devise_mailer: devise_mailer:
Expand Down
10 changes: 6 additions & 4 deletions config/locales/devise.fr.yml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ fr:
send_instructions: 'Vous allez recevoir un email avec les instructions nécessaires pour dé-vérouiller votre compte dans quelques minutes' send_instructions: 'Vous allez recevoir un email avec les instructions nécessaires pour dé-vérouiller votre compte dans quelques minutes'
unlocked: 'Votre compte à été dé-verouillé. Vous êtes connecté!' unlocked: 'Votre compte à été dé-verouillé. Vous êtes connecté!'
mailer: mailer:
locomotive_account: confirmation_instructions:
confirmation_instructions: 'Instructions de validation' locomotive_account_subject: 'Instructions de validation'
reset_password_instructions: 'Instructions de rétablissement du mot de passe' reset_password_instructions:
unlock_instructions: 'Instructions de déverrouillage.' locomotive_account_subject: 'Instructions de rétablissement du mot de passe'
unlock_instructions:
locomotive_account_subject: 'Instructions de déverrouillage.'
locomotive: locomotive:
devise_mailer: devise_mailer:
common: common:
Expand Down
4 changes: 3 additions & 1 deletion lib/locomotive/middlewares/site.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ def request_for_the_back_office_and_default_host?(request)
end end


def default_host?(request) def default_host?(request)
(default_host && request.host == default_host) || localhost?(request) request.env['locomotive.default_host'].present? ||
(default_host && request.host == default_host) ||
localhost?(request)
end end


def localhost?(request) def localhost?(request)
Expand Down
8 changes: 4 additions & 4 deletions spec/models/locomotive/content_entry_spec.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -388,12 +388,12 @@


end end


# it_should_behave_like 'model scoped by a site' do it_should_behave_like 'model scoped by a site' do


# let(:model) { build_content_entry } let(:model) { build_content_entry }
# let(:attribute) { :content_version } let(:attribute) { :content_version }


# end end


def localize_content_type(content_type) def localize_content_type(content_type)
content_type.entries_custom_fields.first.localized = true content_type.entries_custom_fields.first.localized = true
Expand Down

0 comments on commit fde99c4

Please sign in to comment.