Class: UrlPlugin
Instance Attribute Summary collapse
Attributes included from Rubko::Base
#parent
Instance Method Summary
collapse
#config
#camelize, #finalize, #httpGet, #initialize, #jsonParse, #loadController, #loadFile, #loadModel, #loadPlugin, #loadView, #method_missing, #uncamelize
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Rubko::Base
Instance Attribute Details
#base ⇒ Object
Returns the value of attribute base.
32
33
34
|
# File 'lib/rubko/plugins/url.rb', line 32
def base
@base
end
|
#ending ⇒ Object
Returns the value of attribute ending.
32
33
34
|
# File 'lib/rubko/plugins/url.rb', line 32
def ending
@ending
end
|
#fileBase ⇒ Object
Returns the value of attribute fileBase.
32
33
34
|
# File 'lib/rubko/plugins/url.rb', line 32
def fileBase
@fileBase
end
|
#fileTime ⇒ Object
Returns the value of attribute fileTime.
32
33
34
|
# File 'lib/rubko/plugins/url.rb', line 32
def fileTime
@fileTime
end
|
#fullPath ⇒ Object
Returns the value of attribute fullPath.
32
33
34
|
# File 'lib/rubko/plugins/url.rb', line 32
def fullPath
@fullPath
end
|
#host ⇒ Object
33
34
35
|
# File 'lib/rubko/plugins/url.rb', line 33
def host
@host
end
|
#method ⇒ Object
33
34
35
|
# File 'lib/rubko/plugins/url.rb', line 33
def method
@method
end
|
#path ⇒ Object
33
34
35
|
# File 'lib/rubko/plugins/url.rb', line 33
def path
@path
end
|
#protocol ⇒ Object
33
34
35
|
# File 'lib/rubko/plugins/url.rb', line 33
def protocol
@protocol
end
|
Instance Method Details
#ajax? ⇒ Boolean
35
36
37
|
# File 'lib/rubko/plugins/url.rb', line 35
def ajax?
env["HTTP_X_REQUESTED_WITH"] == 'XMLHttpRequest'
end
|
#file(*path) ⇒ Object
64
65
66
67
68
|
# File 'lib/rubko/plugins/url.rb', line 64
def file(*path)
name = 'public/' + path.join('/')
time = File.mtime(name).to_i / 3 % 1000000 if File.exists? name
generate fileBase, (time.to_s if fileTime), *path
end
|
#forceSSL ⇒ Object
85
86
87
88
89
90
|
# File 'lib/rubko/plugins/url.rb', line 85
def forceSSL
if protocol != 'https://'
@protocol, @fullPath = 'https://', true
refresh
end
end
|
#generate(*path) ⇒ Object
47
48
49
50
51
52
53
54
|
# File 'lib/rubko/plugins/url.rb', line 47
def generate(*path)
path.compact!
path.map! { |seg|
seg = path[seg] if seg.kind_of? Integer
URI.escape seg
}
(protocol+host if fullPath).to_s + base + path.join('/')
end
|
#init ⇒ Object
4
5
6
7
8
9
10
|
# File 'lib/rubko/plugins/url.rb', line 4
def init
@ending = '/' @base = '/' @fileBase = 'files' @fileTime = true @fullPath = false end
|
#link(*path) ⇒ Object
56
57
58
|
# File 'lib/rubko/plugins/url.rb', line 56
def link(*path)
generate(*path) + (ending unless path.empty?).to_s
end
|
#linkSlug(*path) ⇒ Object
60
61
62
|
# File 'lib/rubko/plugins/url.rb', line 60
def linkSlug(*path)
link( *path.compact.map { |x| slug x } )
end
|
#newPath ⇒ Object
23
24
25
26
27
28
29
30
|
# File 'lib/rubko/plugins/url.rb', line 23
def newPath
unless @newPath
@newPath = path * '/'
config
@newPath = @newPath.split '/', -1
end
@newPath
end
|
#redirect(*path) ⇒ Object
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/rubko/plugins/url.rb', line 70
def redirect(*path)
self.status = 302
self.['Location'] =
if path.size == 1 && path.first =~ %r{^(https?:)?//}
path.first
else
link(*path)
end
''
end
|
#refresh ⇒ Object
81
82
83
|
# File 'lib/rubko/plugins/url.rb', line 81
def refresh
redirect(*path)
end
|
#rewrite(from, to) ⇒ Object
39
40
41
|
# File 'lib/rubko/plugins/url.rb', line 39
def rewrite(from, to)
@newPath.sub! from, to if from === @newPath
end
|
#slug(str) ⇒ Object
43
44
45
|
# File 'lib/rubko/plugins/url.rb', line 43
def slug(str)
str.strip.downcase.gsub(/[^0-9a-z]+/i, '-').gsub(/^-+|-+$/, '')
end
|