Class: Ro::Asset
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#node ⇒ Object
readonly
Returns the value of attribute node.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#relative_path ⇒ Object
readonly
Returns the value of attribute relative_path.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #img ⇒ Object
-
#initialize(arg, *args) ⇒ Asset
constructor
A new instance of Asset.
- #is_img? ⇒ Boolean (also: #is_img)
- #is_src? ⇒ Boolean (also: #is_src)
- #size ⇒ Object
- #src ⇒ Object
- #stat ⇒ Object
Methods included from Klass
Methods inherited from String
Constructor Details
#initialize(arg, *args) ⇒ Asset
Returns a new instance of Asset.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/ro/asset.rb', line 7 def initialize(arg, *args) = args.last.is_a?(Hash) ? args.pop : {} @path = Path.for(arg, *args) @node = .fetch(:node) { Node.for(@path.split('/assets/').first) } @relative_path = @path.relative_to(@node.path) @name = @relative_path @url = @node.url_for(@relative_path) super(@path) end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/ro/asset.rb', line 5 def name @name end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
5 6 7 |
# File 'lib/ro/asset.rb', line 5 def node @node end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
5 6 7 |
# File 'lib/ro/asset.rb', line 5 def path @path end |
#relative_path ⇒ Object (readonly)
Returns the value of attribute relative_path.
5 6 7 |
# File 'lib/ro/asset.rb', line 5 def relative_path @relative_path end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
5 6 7 |
# File 'lib/ro/asset.rb', line 5 def url @url end |
Instance Method Details
#img ⇒ Object
29 30 31 32 |
# File 'lib/ro/asset.rb', line 29 def img return unless is_img? Ro.image_info(path.to_s) end |
#is_img? ⇒ Boolean Also known as: is_img
23 24 25 |
# File 'lib/ro/asset.rb', line 23 def is_img? @path.file? && Ro.is_image?(@path.basename) end |
#is_src? ⇒ Boolean Also known as: is_src
34 35 36 37 38 |
# File 'lib/ro/asset.rb', line 34 def is_src? key = relative_path.parts subdir = key.size > 2 ? key[1] : nil !!(subdir == 'src') end |
#size ⇒ Object
51 52 53 |
# File 'lib/ro/asset.rb', line 51 def size stat.size end |
#src ⇒ Object
42 43 44 45 |
# File 'lib/ro/asset.rb', line 42 def src return unless is_src? Ro.render_src(path, node) end |
#stat ⇒ Object
47 48 49 |
# File 'lib/ro/asset.rb', line 47 def stat @path.stat.size end |