class Ruhoh::Resources::Stylesheets::CollectionView
Attributes
_cache[RW]
Public Class Methods
new(collection)
click to toggle source
Calls superclass method
# File lib/ruhoh/resources/stylesheets/collection_view.rb, line 5 def initialize(collection) super(collection) @_cache = {} end
Public Instance Methods
load(sub_context)
click to toggle source
Load Stylesheets
as defined within the given sub_context
Example:
{{# stylesheets.load }} global.css custom.css {{/ stylesheets.load }} (stylesheets are separated by newlines)
This is a convenience method that will automatically create link tags with respect to ruhoh’s internal URL generation mechanism; e.g. base_path
@returns HTML link tags for given stylesheets
# File lib/ruhoh/resources/stylesheets/collection_view.rb, line 23 def load(sub_context) stylesheets = sub_context.split("\n").map{ |s| s.gsub(/\s/, '') }.delete_if(&:empty?) stylesheets.map { |name| "<link href='#{make_url(name)}' type='text/css' rel='stylesheet' media='all'>" }.join("\n") end
Protected Instance Methods
make_url(name)
click to toggle source
# File lib/ruhoh/resources/stylesheets/collection_view.rb, line 32 def make_url(name) return name if name =~ /^(http:|https:)?\/\//i path = if @_cache[name] @_cache[name] else @_cache[name] = name "#{name}?#{rand()}" end ruhoh.to_url(url_endpoint, path) end