Module: AsciiBinderGabrielRH::Helpers
- Defined in:
- lib/ascii_binder_gabriel_rh/helpers.rb
Constant Summary collapse
- BUILD_FILENAME =
'_build_cfg.yml'
- TOPIC_MAP_FOLDER =
'_topic_maps'
- TOPIC_MAP_FILENAME =
'_topic_map.yml'
- DISTRO_MAP_FILENAME =
'_distro_map.yml'
- PREVIEW_DIRNAME =
'_preview'
- PACKAGE_DIRNAME =
'_package'
- 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]+$')
Instance Method Summary collapse
- #alias_text(target) ⇒ Object
- #camelize(text) ⇒ Object
- #docs_root_dir ⇒ Object
- #gem_root_dir ⇒ Object
- #git_root_dir ⇒ Object
- #image_dir ⇒ Object
- #javascript_dir ⇒ Object
- #log_debug(text) ⇒ Object
- #log_error(text) ⇒ Object
- #log_fatal(text) ⇒ Object
- #log_info(text) ⇒ Object
- #log_levels ⇒ Object
- #log_unknown(text) ⇒ Object
- #log_warn(text) ⇒ Object
- #logerr ⇒ Object
- #logstd ⇒ Object
- #package_dir ⇒ Object
- #preview_dir ⇒ Object
- #set_depth(user_depth) ⇒ Object
- #set_docs_root_dir(docs_root_dir) ⇒ Object
- #set_log_level(user_log_level) ⇒ Object
- #stylesheet_dir ⇒ Object
- #template_dir ⇒ Object
- #template_renderer ⇒ Object
- #valid_id?(check_id) ⇒ Boolean
- #valid_string?(check_string) ⇒ Boolean
- #valid_url?(check_string) ⇒ Boolean
- #without_warnings ⇒ Object
Instance Method Details
#alias_text(target) ⇒ Object
168 169 170 |
# File 'lib/ascii_binder_gabriel_rh/helpers.rb', line 168 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) ⇒ Object
38 39 40 |
# File 'lib/ascii_binder_gabriel_rh/helpers.rb', line 38 def camelize(text) text.gsub(/[^0-9a-zA-Z ]/i, '').split(' ').map{ |t| t.capitalize }.join end |
#docs_root_dir ⇒ Object
54 55 56 |
# File 'lib/ascii_binder_gabriel_rh/helpers.rb', line 54 def docs_root_dir AsciiBinderGabrielRH::DOCS_ROOT_DIR end |
#gem_root_dir ⇒ Object
46 47 48 |
# File 'lib/ascii_binder_gabriel_rh/helpers.rb', line 46 def gem_root_dir @gem_root_dir ||= File.("../../../", __FILE__) end |
#git_root_dir ⇒ Object
42 43 44 |
# File 'lib/ascii_binder_gabriel_rh/helpers.rb', line 42 def git_root_dir @git_root_dir ||= `git rev-parse --show-toplevel`.chomp end |
#image_dir ⇒ Object
164 165 166 |
# File 'lib/ascii_binder_gabriel_rh/helpers.rb', line 164 def image_dir @image_dir ||= File.join(docs_root_dir,IMAGE_DIRNAME) end |
#javascript_dir ⇒ Object
160 161 162 |
# File 'lib/ascii_binder_gabriel_rh/helpers.rb', line 160 def javascript_dir @javascript_dir ||= File.join(docs_root_dir,JAVASCRIPT_DIRNAME) end |
#log_debug(text) ⇒ Object
112 113 114 |
# File 'lib/ascii_binder_gabriel_rh/helpers.rb', line 112 def log_debug(text) logstd.debug(text) end |
#log_error(text) ⇒ Object
104 105 106 |
# File 'lib/ascii_binder_gabriel_rh/helpers.rb', line 104 def log_error(text) logerr.error(text) end |
#log_fatal(text) ⇒ Object
108 109 110 |
# File 'lib/ascii_binder_gabriel_rh/helpers.rb', line 108 def log_fatal(text) logerr.fatal(text) end |
#log_info(text) ⇒ Object
96 97 98 |
# File 'lib/ascii_binder_gabriel_rh/helpers.rb', line 96 def log_info(text) logstd.info(text) end |
#log_levels ⇒ Object
66 67 68 69 70 71 72 73 74 |
# File 'lib/ascii_binder_gabriel_rh/helpers.rb', line 66 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) ⇒ Object
116 117 118 |
# File 'lib/ascii_binder_gabriel_rh/helpers.rb', line 116 def log_unknown(text) logstd.unknown(text) end |
#log_warn(text) ⇒ Object
100 101 102 |
# File 'lib/ascii_binder_gabriel_rh/helpers.rb', line 100 def log_warn(text) logstd.warn(text) end |
#logerr ⇒ Object
76 77 78 79 80 81 82 83 84 |
# File 'lib/ascii_binder_gabriel_rh/helpers.rb', line 76 def logerr @logerr ||= begin logger = Logger.new(STDERR, level: AsciiBinderGabrielRH::LOG_LEVEL) logger.formatter = proc do |severity, datetime, progname, msg| "#{severity}: #{msg}\n" end logger end end |
#logstd ⇒ Object
86 87 88 89 90 91 92 93 94 |
# File 'lib/ascii_binder_gabriel_rh/helpers.rb', line 86 def logstd @logstd ||= begin logger = Logger.new(STDOUT, level: AsciiBinderGabrielRH::LOG_LEVEL) logger.formatter = proc do |severity, datetime, progname, msg| severity == 'ANY' ? "#{msg}\n" : "#{severity}: #{msg}\n" end logger end end |
#package_dir ⇒ Object
146 147 148 149 150 151 152 153 154 |
# File 'lib/ascii_binder_gabriel_rh/helpers.rb', line 146 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 ⇒ Object
136 137 138 139 140 141 142 143 144 |
# File 'lib/ascii_binder_gabriel_rh/helpers.rb', line 136 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_depth(user_depth) ⇒ Object
58 59 60 |
# File 'lib/ascii_binder_gabriel_rh/helpers.rb', line 58 def set_depth(user_depth) AsciiBinderGabrielRH.const_set("DEPTH", user_depth) end |
#set_docs_root_dir(docs_root_dir) ⇒ Object
50 51 52 |
# File 'lib/ascii_binder_gabriel_rh/helpers.rb', line 50 def set_docs_root_dir(docs_root_dir) AsciiBinderGabrielRH.const_set("DOCS_ROOT_DIR", docs_root_dir) end |
#set_log_level(user_log_level) ⇒ Object
62 63 64 |
# File 'lib/ascii_binder_gabriel_rh/helpers.rb', line 62 def set_log_level(user_log_level) AsciiBinderGabrielRH.const_set("LOG_LEVEL", log_levels[user_log_level]) end |
#stylesheet_dir ⇒ Object
156 157 158 |
# File 'lib/ascii_binder_gabriel_rh/helpers.rb', line 156 def stylesheet_dir @stylesheet_dir ||= File.join(docs_root_dir,STYLESHEET_DIRNAME) end |
#template_dir ⇒ Object
132 133 134 |
# File 'lib/ascii_binder_gabriel_rh/helpers.rb', line 132 def template_dir @template_dir ||= File.join(docs_root_dir,'_templates') end |
#template_renderer ⇒ Object
128 129 130 |
# File 'lib/ascii_binder_gabriel_rh/helpers.rb', line 128 def template_renderer @template_renderer ||= TemplateRenderer.new(docs_root_dir, template_dir) end |
#valid_id?(check_id) ⇒ Boolean
19 20 21 22 23 |
# File 'lib/ascii_binder_gabriel_rh/helpers.rb', line 19 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) ⇒ Boolean
25 26 27 28 29 30 |
# File 'lib/ascii_binder_gabriel_rh/helpers.rb', line 25 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) ⇒ Boolean
32 33 34 35 36 |
# File 'lib/ascii_binder_gabriel_rh/helpers.rb', line 32 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 ⇒ Object
120 121 122 123 124 125 126 |
# File 'lib/ascii_binder_gabriel_rh/helpers.rb', line 120 def without_warnings verboseness_level = $VERBOSE $VERBOSE = nil yield ensure $VERBOSE = verboseness_level end |