Merge pull request #306 from wvengen/feature-styling

allow foodcoops to add custom css
This commit is contained in:
wvengen 2014-09-02 13:59:18 +02:00
commit 97dc090e4d
5 changed files with 37 additions and 0 deletions

View file

@ -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

View file

@ -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

View file

@ -10,6 +10,7 @@
//%link(href="images/favicon.ico" rel="shortcut icon")
= yield(:head)
= foodcoop_css_tag
%body
= yield