Skip to content

Commit

Permalink
[#1551] Use Current.theme in place of Theme.name (#1621)
Browse files Browse the repository at this point in the history
* Rename method set_locale_from_subdomain to set_current_locale

* Set Current.theme before each request

* Use Current.theme in Theme.name

* s/Theme.name/Current.theme

* Delete unused Theme model
  • Loading branch information
veganstraightedge authored May 25, 2020
1 parent 9ffe1c8 commit 57ad4c6
Show file tree
Hide file tree
Showing 27 changed files with 58 additions and 59 deletions.
10 changes: 8 additions & 2 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception

before_action :set_locale_from_subdomain
before_action :set_current_locale
before_action :set_current_theme

before_action :set_site_locale
before_action :check_for_redirection
before_action :strip_file_extension
Expand Down Expand Up @@ -44,7 +46,7 @@ def authorize
redirect_to [:signin], alert: 'You need to sign in to view that page.' unless signed_in?
end

def set_locale_from_subdomain
def set_current_locale
locale = request.subdomain
I18n.locale = locale if I18n.available_locales.include?(locale.to_sym)

Expand All @@ -59,6 +61,10 @@ def set_locale_from_subdomain
end
end

def set_current_theme
Current.theme = ENV.fetch('THEME') { '2017' }
end

def check_for_redirection
redirect = Redirect.where(source_path: request.path.downcase).last
redirect = Redirect.where(source_path: "#{request.path.downcase}/").last if redirect.blank?
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/article_archives_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def index
if path.present?
redirect_to path
else
render "#{Theme.name}/article_archives/index"
render "#{Current.theme}/article_archives/index"
end
end
end
4 changes: 2 additions & 2 deletions app/controllers/articles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class ArticlesController < ApplicationController
def index
@articles = Article.includes(:tags, :categories).live.published.root.page(params[:page]).per(10)

render "#{Theme.name}/articles/index"
render "#{Current.theme}/articles/index"
end

def show
Expand Down Expand Up @@ -53,7 +53,7 @@ def show
if @article.content_in_html?
render html: @article.content.html_safe, layout: false
else
render "#{Theme.name}/articles/show"
render "#{Current.theme}/articles/show"
end
end
end
10 changes: 5 additions & 5 deletions app/controllers/books_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def index

@books = Book.english.for_index

render "#{Theme.name}/books/index"
render "#{Current.theme}/books/index"
end

def show
Expand All @@ -20,31 +20,31 @@ def show
@title = PageTitle.new title_for(:books, @book.slug.underscore)
@tool = @book

render "#{Theme.name}/books/show"
render "#{Current.theme}/books/show"
end

def extras
@html_id = 'page'
@body_id = 'tools'
@title = PageTitle.new title_for(:books, @book.slug.underscore, :extras)

render "#{Theme.name}/books/extras"
render "#{Current.theme}/books/extras"
end

def lit_kit
@html_id = 'page'
@body_id = 'tools'
@title = PageTitle.new title_for(:books, :lit_kit)

render "#{Theme.name}/books/lit_kit"
render "#{Current.theme}/books/lit_kit"
end

def into_libraries
@html_id = 'page'
@body_id = 'tools'
@title = PageTitle.new title_for(:books, :into_libraries)

render "#{Theme.name}/books/into_libraries"
render "#{Current.theme}/books/into_libraries"
end

private
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/categories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def show
@html_id = 'page'
@body_id = 'category'

render "#{Theme.name}/categories/show"
render "#{Current.theme}/categories/show"
end

def index
Expand All @@ -17,11 +17,11 @@ def index
@categories = Category.all
@title = PageTitle.new title_for(:categories)

render "#{Theme.name}/categories/index"
render "#{Current.theme}/categories/index"
end

def feed
render "#{Theme.name}/articles/index"
render "#{Current.theme}/articles/index"
end

private
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/episodes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def show
@editable = @episode
@title = PageTitle.new title_for :podcasts, @episode.name

render "#{Theme.name}/episodes/show"
render "#{Current.theme}/episodes/show"
end

def transcript
Expand All @@ -17,7 +17,7 @@ def transcript
@editable = @episode
@title = PageTitle.new title_for :podcasts, @episode.name, :transcript

render "#{Theme.name}/episodes/show"
render "#{Current.theme}/episodes/show"
end

private
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def index
# Homepage featured article
@latest_article = articles_for_current_page.first if first_page?

if Theme.name == '2020'
if Current.theme == '2020'
# Feed artciles, needed for pagination
@articles = articles_for_current_page.page(params[:page]).per(14).padding(1)

Expand Down Expand Up @@ -44,7 +44,7 @@ def index
@articles = articles_for_current_page.page(params[:page]).per(6).padding(1)
end

render "#{Theme.name}/home/index"
render "#{Current.theme}/home/index"
end

private
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/issues_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ def show
@editable = @issue

@title = PageTitle.new title_for :journals, journal.name, @issue.issue
render "#{Theme.name}/books/show"
render "#{Current.theme}/books/show"
end
end
4 changes: 2 additions & 2 deletions app/controllers/journals_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ class JournalsController < ToolsController
# See tools_controller.rb for inherited behavior
def index
@journals = Journal.includes(:issues)
render "#{Theme.name}/journals/index"
render "#{Current.theme}/journals/index"
end

def show
@journal = Journal.find_by(slug: params[:id])
render "#{Theme.name}/journals/show"
render "#{Current.theme}/journals/show"
end
end
4 changes: 2 additions & 2 deletions app/controllers/languages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def index
@locales = Locale.live
@title = PageTitle.new t 'header.languages'

render "#{Theme.name}/languages/index"
render "#{Current.theme}/languages/index"
end

def show
Expand All @@ -16,7 +16,7 @@ def show
@locale = Locale.find_by(slug: canonical_locale.canonical)
@title = PageTitle.new "#{@locale.name} / #{@locale.name_in_english} (#{@locale.slug})"

render "#{Theme.name}/languages/show"
render "#{Current.theme}/languages/show"
end

private
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/logos_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def index
@tools = Logo.live.published.page(params[:page]).per(100)
@title = PageTitle.new title_for :logos

render "#{Theme.name}/logos/index"
render "#{Current.theme}/logos/index"
end

def show
Expand All @@ -18,6 +18,6 @@ def show
@editable = @tool
@title = PageTitle.new title_for :logos, @tool.name

render "#{Theme.name}/logos/show"
render "#{Current.theme}/logos/show"
end
end
10 changes: 5 additions & 5 deletions app/controllers/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,34 @@ def about
@editable = @page
@title = PageTitle.new I18n.t('page_titles.about.about')

render "#{Theme.name}/pages/about"
render "#{Current.theme}/pages/about"
end

def contact
@editable = @page
@title = PageTitle.new I18n.t('page_titles.about.contact')

render "#{Theme.name}/pages/contact"
render "#{Current.theme}/pages/contact"
end

def library
@title = PageTitle.new I18n.t('page_titles.about.library')

render "#{Theme.name}/pages/library"
render "#{Current.theme}/pages/library"
end

def post_order_success
@title = PageTitle.new title_for I18n.t('page_titles.about.store'), I18n.t('page_titles.about.post_order_success')
@order_id = params[:ordernum]

render "#{Theme.name}/pages/post_order_success"
render "#{Current.theme}/pages/post_order_success"
end

# TODO: make this view localizable
def submission_guidelines
@title = PageTitle.new I18n.t('page_titles.about.submission_guidelines')

render "#{Theme.name}/pages/submission_guidelines"
render "#{Current.theme}/pages/submission_guidelines"
end

def pgp_public_key
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/podcasts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def index
@editable = @podcasts.first
@title = PageTitle.new title_for :podcasts

render "#{Theme.name}/podcasts/index"
render "#{Current.theme}/podcasts/index"
end

def show
Expand All @@ -15,7 +15,7 @@ def show
@podcast = Podcast.find_by(slug: params[:slug])
@title = PageTitle.new title_for @podcast.name

render "#{Theme.name}/podcasts/show"
render "#{Current.theme}/podcasts/show"
end

def feed; end
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/search_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def index

@title = PageTitle.new title_for :search, :results, "“#{@query}”"

render "#{Theme.name}/search/index"
render "#{Current.theme}/search/index"
end

def advanced
Expand All @@ -24,7 +24,7 @@ def advanced

@advanced_search = AdvancedSearch.new(params[:q])

render "#{Theme.name}/search/advanced"
render "#{Current.theme}/search/advanced"
end

def advanced_search
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/support_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def new
@body_id = 'support'
@title = PageTitle.new t('views.support.new.heading')

render "#{Theme.name}/support/new"
render "#{Current.theme}/support/new"
end

def create
Expand All @@ -28,7 +28,7 @@ def thanks
@body_id = 'support'
@title = PageTitle.new t('views.support.thanks.heading')

render "#{Theme.name}/support/thanks"
render "#{Current.theme}/support/thanks"
end

def create_session
Expand Down Expand Up @@ -76,7 +76,7 @@ def edit
@next_invoice = Stripe::Invoice.upcoming(customer: @customer.id)
end

render "#{Theme.name}/support/edit"
render "#{Current.theme}/support/edit"
end

def update_subscription
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/tags_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ def show
@html_id = 'page'
@body_id = 'tag'

render "#{Theme.name}/tags/show"
render "#{Current.theme}/tags/show"
end

def feed
render "#{Theme.name}/articles/index"
render "#{Current.theme}/articles/index"
end

private
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/tools_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ class ToolsController < ApplicationController

# GET /tools
def about
render "#{Theme.name}/tools/about"
render "#{Current.theme}/tools/about"
end

def index
render "#{Theme.name}/tools/index"
render "#{Current.theme}/tools/index"
end

def show
render "#{Theme.name}/tools/show"
render "#{Current.theme}/tools/show"
end

private
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/videos_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def index
@title = PageTitle.new title_for :videos
@videos = Video.live.published.page(params[:page]).per(20)

render "#{Theme.name}/videos/index"
render "#{Current.theme}/videos/index"
end

def show
Expand All @@ -17,6 +17,6 @@ def show
@body_id = 'video'
@title = PageTitle.new title_for :videos, @video.title

render "#{Theme.name}/videos/show"
render "#{Current.theme}/videos/show"
end
end
2 changes: 1 addition & 1 deletion app/controllers/zines_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class ZinesController < ToolsController
# See tools_controller.rb for inherited behavior
def show
render "#{Theme.name}/books/show"
render "#{Current.theme}/books/show"
end
end
4 changes: 2 additions & 2 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ def largest_touch_icon_url
end

def render_themed path, options = {}
render "#{Theme.name}/#{path}", options
render "#{Current.theme}/#{path}", options
end

def tt path, options = {}
t "#{Theme.name}.#{path}", options
t "#{Current.theme}.#{path}", options
end
end
2 changes: 1 addition & 1 deletion app/models/current.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
class Current < ActiveSupport::CurrentAttributes
attribute :user
attribute :user, :theme
end
Loading

0 comments on commit 57ad4c6

Please sign in to comment.