class EL::AssetsMapper
Attributes
baseurl[R]
wd[R]
Public Class Methods
new(baseurl, opts = {})
click to toggle source
@example
assets_mapper :vendor do js_tag :jquery chdir 'jquery-ui' js_tag 'js/jquery-ui.min' css_tag 'css/jquery-ui.min' cd '../bootstrap' js_tag 'js/bootstrap.min' css_tag 'css/bootstrap' end #=> <script src="/vendor/jquery.js" ... #=> <script src="/vendor/jquery-ui/js/jquery-ui.min.js" ... #=> <link href="/vendor/jquery-ui/css/jquery-ui.min.css" ... #=> <script src="/vendor/bootstrap/js/bootstrap.min.js" ... #=> <link href="/vendor/bootstrap/css/bootstrap.css" ...
# File lib/el/assets.rb, line 28 def initialize baseurl, opts = {}, &proc @opts = Hash[opts] @suffix = @opts.delete(:suffix) || '' baseurl = baseurl.to_s.dup.strip baseurl.empty? ? baseurl = nil : (baseurl =~ /\/\Z/ || baseurl << '/') @baseurl, @wd = baseurl.freeze, nil proc && self.instance_exec(&proc) end
Public Instance Methods
chdir(path = nil)
click to toggle source
# File lib/el/assets.rb, line 43 def chdir path = nil return @wd = nil unless path wd = [] if (path = path.to_s) =~ /\A\// path = path.sub(/\A\/+/, '') path = path.empty? ? [] : [path] else dirs_back, path = path.split(/\/+/).partition { |c| c == '..' } if @wd wd_chunks = @wd.split(/\/+/) wd = wd_chunks[0, wd_chunks.size - dirs_back.size] || [] end end @wd = (wd + path << '').compact.join('/').freeze end
Also aliased as: cd
Private Instance Methods
assets_url(path = nil)
click to toggle source
# File lib/el/assets.rb, line 61 def assets_url path = nil chunks = [baseurl, wd, path] # assigning array to a variable chunks.select! {|c| c && c.size > 0} # and work on it File.join(*chunks) # is 2x faster than array#select {...} end