class Ruhoh::Resources::Javascripts::CollectionView
Attributes
_cache[RW]
Public Class Methods
new(collection)
click to toggle source
Calls superclass method
# File lib/ruhoh/resources/javascripts/collection_view.rb, line 5 def initialize(collection) super(collection) @_cache = {} end
Public Instance Methods
all()
click to toggle source
# File lib/ruhoh/resources/javascripts/collection_view.rb, line 30 def all() files.values.map { |pointer| load_model_view(pointer) } end
load(sub_context)
click to toggle source
Load javascripts as defined within the given sub_context
Example:
{{# javascripts.load }} app.js scroll.js {{/ javascripts.load }} (scripts are separated by newlines)
This is a convenience method that will automatically create script tags with respect to ruhoh’s internal URL generation mechanism; e.g. base_path.
@returns HTML script tags for given javascripts.
# File lib/ruhoh/resources/javascripts/collection_view.rb, line 23 def load(sub_context) javascripts = sub_context.split("\n").map{ |s| s.gsub(/\s/, '') }.delete_if(&:empty?) javascripts.map { |name| "<script src='#{make_url(name)}'></script>" }.join("\n") end
make_url(name)
click to toggle source
# File lib/ruhoh/resources/javascripts/collection_view.rb, line 36 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