Class: Slick::Web::File
Instance Attribute Summary collapse
Attributes inherited from Node
#name, #parent
Instance Method Summary
collapse
Methods inherited from Node
#dir?, #file?, #relative_path, #root
Constructor Details
#initialize(*args) ⇒ File
Returns a new instance of File.
8
9
10
11
|
# File 'lib/slick/web/file.rb', line 8
def initialize(*args)
super
@paths = []
end
|
Instance Attribute Details
Returns the value of attribute paths.
6
7
8
|
# File 'lib/slick/web/file.rb', line 6
def paths
@paths
end
|
Instance Method Details
#extension ⇒ Object
17
18
19
20
21
22
23
|
# File 'lib/slick/web/file.rb', line 17
def extension
@extension ||= if matches = name.match(/\.(.+)\z/i)
matches[1].downcase
else
""
end
end
|
#grab(params = {}, &block) ⇒ Object
36
37
38
39
40
41
|
# File 'lib/slick/web/file.rb', line 36
def grab(params = {}, &block)
_self = self
Slick::Workspace.new.instance_eval do
grab{_self.render(params, &block)}
end
end
|
62
63
64
|
# File 'lib/slick/web/file.rb', line 62
def inspect
relative_path
end
|
13
14
15
|
# File 'lib/slick/web/file.rb', line 13
def path
paths.last
end
|
#render(params = {}, &block) ⇒ Object
#url(params = {}) ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/slick/web/file.rb', line 43
def url(params = {})
path = relative_path
candidate_path = path.sub(/\.[^\/]+\z/, '')
if root.find_file(candidate_path) == self
path = candidate_path
candidate_path = path.sub(/\/[^\/]*\z/, '')
candidate_path = '/' if candidate_path == ''
path = candidate_path if root.find_file(candidate_path) == self
end
out = [path]
if params.count > 0
out << '?'
out << params.url_encode
end
out.join
end
|