lib/ascii_binder/helpers.rb in ascii_binder-0.1.10.1 vs lib/ascii_binder/helpers.rb in ascii_binder-0.1.11

- old
+ new

@@ -8,10 +8,11 @@ STYLESHEET_DIRNAME = '_stylesheets' JAVASCRIPT_DIRNAME = '_javascripts' IMAGE_DIRNAME = '_images' BLANK_STRING_RE = Regexp.new('^\s*$') ID_STRING_RE = Regexp.new('^[A-Za-z0-9\-\_]+$') + URL_STRING_RE = Regexp.new('^https?:\/\/[\S]+$') def valid_id?(check_id) return false unless check_id.is_a?(String) return false unless check_id.match ID_STRING_RE return true @@ -22,10 +23,16 @@ return false unless check_string.length > 0 return false if check_string.match BLANK_STRING_RE return true end + def valid_url?(check_string) + return false unless valid_string?(check_string) + return false unless check_string.match URL_STRING_RE + return true + end + def camelize(text) text.gsub(/[^0-9a-zA-Z ]/i, '').split(' ').map{ |t| t.capitalize }.join end def git_root_dir @@ -80,8 +87,12 @@ @javascript_dir ||= File.join(docs_root_dir,JAVASCRIPT_DIRNAME) end def image_dir @image_dir ||= File.join(docs_root_dir,IMAGE_DIRNAME) + end + + def alias_text(target) + "<!DOCTYPE html><html><head><title>#{target}</title><link rel=\"canonical\" href=\"#{target}\"/><meta name=\"robots\" content=\"noindex\"><meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" /><meta http-equiv=\"refresh\" content=\"0; url=#{target}\" /></head></html>" end end end