diff --git a/app/controllers/styles_controller.rb b/app/controllers/styles_controller.rb new file mode 100644 index 00000000..98d4dd69 --- /dev/null +++ b/app/controllers/styles_controller.rb @@ -0,0 +1,18 @@ +# Foodcoop-specific styling +class StylesController < ApplicationController + skip_before_filter :authenticate + + # renders foodcoop css, or 404 if not configured + # + # When requested with the parameter +md5+, the result is returned + # with an expiry time of a week, to leverage caching. + def foodcoop + css = FoodsoftConfig[:custom_css] + if css.blank? + render text: nil, content_type: 'text/css', status: 404 + else + expires_in 1.week, public:true if params[:md5].present? + render text: css, content_type: 'text/css' + end + end +end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 1df214fd..ad1112e6 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -218,5 +218,18 @@ module ApplicationHelper text_truncated end end + + # @return [String] path to foodcoop CSS style (with MD5 parameter for caching) + def foodcoop_css_path(options={}) + super(options.merge({md5: Digest::MD5.hexdigest(FoodsoftConfig[:custom_css])})) + end + + # @return [String] stylesheet tag for foodcoop CSS style (+custom_css+ foodcoop config) + # @see #foodcoop_css_path + def foodcoop_css_tag(options={}) + unless FoodsoftConfig[:custom_css].blank? + stylesheet_link_tag foodcoop_css_path, media: 'all' + end + end end diff --git a/app/views/layouts/_header.html.haml b/app/views/layouts/_header.html.haml index 06920588..d84a4f47 100644 --- a/app/views/layouts/_header.html.haml +++ b/app/views/layouts/_header.html.haml @@ -10,6 +10,7 @@ //%link(href="images/favicon.ico" rel="shortcut icon") = yield(:head) + = foodcoop_css_tag %body = yield diff --git a/config/app_config.yml.SAMPLE b/config/app_config.yml.SAMPLE index fd4af4d4..fbb4731e 100644 --- a/config/app_config.yml.SAMPLE +++ b/config/app_config.yml.SAMPLE @@ -86,6 +86,9 @@ default: &defaults # Page footer (html allowed). Default is a Foodsoft footer. Set to `blank` for no footer. #page_footer: FC Test is supported by Hoster. + # Custom css for the foodcoop + #custom_css: 'body { background-color: #fcffba; }' + # email address to be used as sender email_sender: foodsoft@foodcoop.test diff --git a/config/routes.rb b/config/routes.rb index 3af42129..42921214 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -24,6 +24,8 @@ Foodsoft::Application.routes.draw do match '/login/accept_invitation/:token' => 'login#accept_invitation', as: :accept_invitation, via: [:get, :post] resources :sessions, :only => [:new, :create, :destroy] + get '/foodcoop.css' => 'styles#foodcoop', :as => 'foodcoop_css' + ########### User specific get '/home/profile', :as => 'my_profile'