Class: ViewAssets::PathInfo
- Inherits:
-
String
- Object
- String
- ViewAssets::PathInfo
- Defined in:
- lib/view_assets/path_info.rb
Instance Method Summary collapse
- #==(pi) ⇒ Object
-
#abs ⇒ Object
alter path string ‘lib.js’ => ‘/path/to/app/public/:type/file.js’.
- #abs! ⇒ Object
- #abs? ⇒ Boolean
- #app? ⇒ Boolean
- #basename ⇒ Object
-
#depth ⇒ Object
PathInfo.new(‘lib/javascripts/file.js’).depth # => 0 PathInfo.new(‘app/javascripts/controller/action/file.js’).depth # => 2 PathInfo.new(‘/path/to/my/app/public/lib/javascripts/file.js’).depth # => 0.
-
#initialize(path) ⇒ PathInfo
constructor
A new instance of PathInfo.
- #lib? ⇒ Boolean
-
#rel ⇒ Object
alter path string ‘/path/to/app/:dir/assets/:asset_type/file.js’ => ‘file.js’.
- #rel! ⇒ Object
- #root ⇒ Object
- #vendor? ⇒ Boolean
- #with_ext? ⇒ Boolean
Constructor Details
#initialize(path) ⇒ PathInfo
Returns a new instance of PathInfo.
9 10 11 |
# File 'lib/view_assets/path_info.rb', line 9 def initialize(path) replace path end |
Instance Method Details
#==(pi) ⇒ Object
3 4 5 6 7 |
# File 'lib/view_assets/path_info.rb', line 3 def ==(pi) pi = PathInfo.new(pi) unless pi.kind_of?(PathInfo) self.rel.to_s == pi.rel.to_s end |
#abs ⇒ Object
alter path string
'lib.js'
>
'/path/to/app/public/:type/file.js'
21 22 23 24 25 26 |
# File 'lib/view_assets/path_info.rb', line 21 def abs return self if abs? # PathInfo.new("#{root}/#{with_ext? ? self : "#{self}.#{ext}" }") PathInfo.new("#{root}/#{self}") end |
#abs! ⇒ Object
28 29 30 |
# File 'lib/view_assets/path_info.rb', line 28 def abs! replace abs end |
#abs? ⇒ Boolean
13 14 15 |
# File 'lib/view_assets/path_info.rb', line 13 def abs? !match(/^#{root}/).nil? end |
#app? ⇒ Boolean
67 68 69 |
# File 'lib/view_assets/path_info.rb', line 67 def app? rel.match(/^app\/(#{JS_PATH}|#{CSS_PATH})/) end |
#basename ⇒ Object
36 37 38 |
# File 'lib/view_assets/path_info.rb', line 36 def basename PathInfo.new(with_ext? ? chomp(File.extname(self)) : self) end |
#depth ⇒ Object
PathInfo.new(‘lib/javascripts/file.js’).depth # => 0 PathInfo.new(‘app/javascripts/controller/action/file.js’).depth # => 2 PathInfo.new(‘/path/to/my/app/public/lib/javascripts/file.js’).depth # => 0
74 75 76 |
# File 'lib/view_assets/path_info.rb', line 74 def depth rel.count("/") - 2 end |
#lib? ⇒ Boolean
59 60 61 |
# File 'lib/view_assets/path_info.rb', line 59 def lib? rel.match(/^lib\/(#{JS_PATH}|#{CSS_PATH})/) end |
#rel ⇒ Object
alter path string
'/path/to/app/:dir/assets/:asset_type/file.js'
=>
'file.js'
44 45 46 47 48 |
# File 'lib/view_assets/path_info.rb', line 44 def rel return self unless abs? PathInfo.new(gsub(/^#{root}\//, '')) end |
#rel! ⇒ Object
50 51 52 53 |
# File 'lib/view_assets/path_info.rb', line 50 def rel! replace rel self end |
#root ⇒ Object
55 56 57 |
# File 'lib/view_assets/path_info.rb', line 55 def root "#{Rails.public_path}" end |