Class: EL::AssetsMapper
Instance Attribute Summary collapse
-
#baseurl ⇒ Object
readonly
Returns the value of attribute baseurl.
-
#wd ⇒ Object
readonly
Returns the value of attribute wd.
Instance Method Summary collapse
- #chdir(path = nil) ⇒ Object (also: #cd)
-
#initialize(baseurl, opts = {}, &proc) ⇒ AssetsMapper
constructor
A new instance of AssetsMapper.
Methods included from TagFactory
#comment_tag, #comment_tag!, #css_tag, #doctype_tag, #js_tag
Constructor Details
#initialize(baseurl, opts = {}, &proc) ⇒ AssetsMapper
Returns a new instance of AssetsMapper.
28 29 30 31 32 33 34 35 |
# 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 |
Instance Attribute Details
#baseurl ⇒ Object (readonly)
Returns the value of attribute baseurl.
5 6 7 |
# File 'lib/el/assets.rb', line 5 def baseurl @baseurl end |
#wd ⇒ Object (readonly)
Returns the value of attribute wd.
5 6 7 |
# File 'lib/el/assets.rb', line 5 def wd @wd end |
Instance Method Details
#chdir(path = nil) ⇒ Object Also known as: cd
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# 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 |