Module: InlineStylesheetTag::ViewHelpers

Defined in:
lib/inline_stylesheet_tag/view_helper.rb

Overview

Fixme: Remove Rails coupling

Instance Method Summary collapse

Instance Method Details

#fetch_inline_stylesheet_tag(url) ⇒ Object



3
4
5
6
# File 'lib/inline_stylesheet_tag/view_helper.rb', line 3

def fetch_inline_stylesheet_tag(url)
  response = Faraday.get(url)
  response.body if response.status == 200
end

#inline_stylesheet_tag(url, *more) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/inline_stylesheet_tag/view_helper.rb', line 8

def inline_stylesheet_tag(url, *more)
  Rails.cache.fetch("inline-css-#{Digest::MD5.hexdigest(url)}", expires_in: 1.hour) do
    content = fetch_inline_stylesheet_tag(url) rescue nil
    if content.present?
      (:style, content.html_safe)
    else
      stylesheet_link_tag url, *more
    end
  end
end