Module: ThemeBandit::URLFormatter
Instance Method Summary collapse
- #cdn_to_fqd(src) ⇒ Object
-
#get_absolute_path(old_path, new_path) ⇒ Object
returns resolved path, ready for use with host.
- #path_with_leading_slash(str) ⇒ Object
- #strip_query_string(str) ⇒ Object
Instance Method Details
#cdn_to_fqd(src) ⇒ Object
7 8 9 |
# File 'lib/theme_bandit/url_formatter.rb', line 7 def cdn_to_fqd(src) src[/^\/\//] ? "http:#{src}" : src end |
#get_absolute_path(old_path, new_path) ⇒ Object
returns resolved path, ready for use with host
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/theme_bandit/url_formatter.rb', line 12 def get_absolute_path(old_path, new_path) number_of_dot_dots = new_path.split('/').select { |v| v == '..' }.length if number_of_dot_dots > 0 # TODO: should be separate method new_path = new_path.gsub('../', '') old_path = old_path.split('/') old_path.pop(number_of_dot_dots + 1) new_path = old_path.push(new_path).join('/') "#{path_with_leading_slash(new_path)}" else "#{path_with_leading_slash(new_path)}" end end |
#path_with_leading_slash(str) ⇒ Object
26 27 28 |
# File 'lib/theme_bandit/url_formatter.rb', line 26 def path_with_leading_slash(str) str[/^\//] ? str : "/#{str}" end |
#strip_query_string(str) ⇒ Object
3 4 5 |
# File 'lib/theme_bandit/url_formatter.rb', line 3 def strip_query_string(str) str.split('?').first end |