module AsciiBinder::Helpers
Constants
- BLANK_STRING_RE
- BUILD_FILENAME
- DISTRO_MAP_FILENAME
- ID_STRING_RE
- IMAGE_DIRNAME
- JAVASCRIPT_DIRNAME
- PACKAGE_DIRNAME
- PREVIEW_DIRNAME
- STYLESHEET_DIRNAME
- TOPIC_MAP_FILENAME
- URL_STRING_RE
Public Instance Methods
alias_text(target)
click to toggle source
# File lib/ascii_binder/helpers.rb, line 163 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
camelize(text)
click to toggle source
# File lib/ascii_binder/helpers.rb, line 37 def camelize(text) text.gsub(/[^0-9a-zA-Z ]/i, '').split(' ').map{ |t| t.capitalize }.join end
docs_root_dir()
click to toggle source
# File lib/ascii_binder/helpers.rb, line 53 def docs_root_dir AsciiBinder::DOCS_ROOT_DIR end
gem_root_dir()
click to toggle source
# File lib/ascii_binder/helpers.rb, line 45 def gem_root_dir @gem_root_dir ||= File.expand_path("../../../", __FILE__) end
git_root_dir()
click to toggle source
# File lib/ascii_binder/helpers.rb, line 41 def git_root_dir @git_root_dir ||= `git rev-parse --show-toplevel`.chomp end
image_dir()
click to toggle source
# File lib/ascii_binder/helpers.rb, line 159 def image_dir @image_dir ||= File.join(docs_root_dir,IMAGE_DIRNAME) end
javascript_dir()
click to toggle source
# File lib/ascii_binder/helpers.rb, line 155 def javascript_dir @javascript_dir ||= File.join(docs_root_dir,JAVASCRIPT_DIRNAME) end
log_debug(text)
click to toggle source
# File lib/ascii_binder/helpers.rb, line 107 def log_debug(text) logstd.debug(text) end
log_error(text)
click to toggle source
# File lib/ascii_binder/helpers.rb, line 99 def log_error(text) logerr.error(text) end
log_fatal(text)
click to toggle source
# File lib/ascii_binder/helpers.rb, line 103 def log_fatal(text) logerr.fatal(text) end
log_info(text)
click to toggle source
# File lib/ascii_binder/helpers.rb, line 91 def log_info(text) logstd.info(text) end
log_levels()
click to toggle source
# File lib/ascii_binder/helpers.rb, line 61 def log_levels @log_levels ||= { :debug => Logger::DEBUG.to_i, :error => Logger::ERROR.to_i, :fatal => Logger::FATAL.to_i, :info => Logger::INFO.to_i, :warn => Logger::WARN.to_i, } end
log_unknown(text)
click to toggle source
# File lib/ascii_binder/helpers.rb, line 111 def log_unknown(text) logstd.unknown(text) end
log_warn(text)
click to toggle source
# File lib/ascii_binder/helpers.rb, line 95 def log_warn(text) logstd.warn(text) end
logerr()
click to toggle source
# File lib/ascii_binder/helpers.rb, line 71 def logerr @logerr ||= begin logger = Logger.new(STDERR, level: AsciiBinder::LOG_LEVEL) logger.formatter = proc do |severity, datetime, progname, msg| "#{severity}: #{msg}\n" end logger end end
logstd()
click to toggle source
# File lib/ascii_binder/helpers.rb, line 81 def logstd @logstd ||= begin logger = Logger.new(STDOUT, level: AsciiBinder::LOG_LEVEL) logger.formatter = proc do |severity, datetime, progname, msg| severity == 'ANY' ? "#{msg}\n" : "#{severity}: #{msg}\n" end logger end end
package_dir()
click to toggle source
# File lib/ascii_binder/helpers.rb, line 141 def package_dir @package_dir ||= begin lpackage_dir = File.join(docs_root_dir,PACKAGE_DIRNAME) if not File.exists?(lpackage_dir) Dir.mkdir(lpackage_dir) end lpackage_dir end end
preview_dir()
click to toggle source
# File lib/ascii_binder/helpers.rb, line 131 def preview_dir @preview_dir ||= begin lpreview_dir = File.join(docs_root_dir,PREVIEW_DIRNAME) if not File.exists?(lpreview_dir) Dir.mkdir(lpreview_dir) end lpreview_dir end end
set_docs_root_dir(docs_root_dir)
click to toggle source
# File lib/ascii_binder/helpers.rb, line 49 def set_docs_root_dir(docs_root_dir) AsciiBinder.const_set("DOCS_ROOT_DIR", docs_root_dir) end
set_log_level(user_log_level)
click to toggle source
# File lib/ascii_binder/helpers.rb, line 57 def set_log_level(user_log_level) AsciiBinder.const_set("LOG_LEVEL", log_levels[user_log_level]) end
stylesheet_dir()
click to toggle source
# File lib/ascii_binder/helpers.rb, line 151 def stylesheet_dir @stylesheet_dir ||= File.join(docs_root_dir,STYLESHEET_DIRNAME) end
template_dir()
click to toggle source
# File lib/ascii_binder/helpers.rb, line 127 def template_dir @template_dir ||= File.join(docs_root_dir,'_templates') end
template_renderer()
click to toggle source
# File lib/ascii_binder/helpers.rb, line 123 def template_renderer @template_renderer ||= TemplateRenderer.new(docs_root_dir, template_dir) end
valid_id?(check_id)
click to toggle source
# File lib/ascii_binder/helpers.rb, line 18 def valid_id?(check_id) return false unless check_id.is_a?(String) return false unless check_id.match ID_STRING_RE return true end
valid_string?(check_string)
click to toggle source
# File lib/ascii_binder/helpers.rb, line 24 def valid_string?(check_string) return false unless check_string.is_a?(String) return false unless check_string.length > 0 return false if check_string.match BLANK_STRING_RE return true end
valid_url?(check_string)
click to toggle source
# File lib/ascii_binder/helpers.rb, line 31 def valid_url?(check_string) return false unless valid_string?(check_string) return false unless check_string.match URL_STRING_RE return true end
without_warnings() { || ... }
click to toggle source
# File lib/ascii_binder/helpers.rb, line 115 def without_warnings verboseness_level = $VERBOSE $VERBOSE = nil yield ensure $VERBOSE = verboseness_level end