Module: ContextHelp::Helpers
- Defined in:
- lib/context_help/base.rb
Class Method Summary collapse
- .clean(options) ⇒ Object
- .get_doc_string(path) ⇒ Object
- .get_text(options, missing = true) ⇒ Object
- .get_title(options) ⇒ Object
- .is_visible(options) ⇒ Object
- .merge_options(base, added) ⇒ Object
- .model_name(model) ⇒ Object
Class Method Details
.clean(options) ⇒ Object
253 254 255 256 257 |
# File 'lib/context_help/base.rb', line 253 def self.clean() .delete(:context_help) .delete('context_help') end |
.get_doc_string(path) ⇒ Object
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/context_help/base.rb', line 212 def self.get_doc_string(path) plugin_prefixes = [''] plugin_prefixes += Rails.plugins.select{|p| p.is_a?(Engines::Plugin) }.map{ |p| "#{p.name}." } text = '' found = false plugin_prefixes.each do |prefix| begin item = I18n.translate prefix + path, :raise => true if item.start_with?('t.') item = I18n.t item[2, item.length] elsif item.start_with?('I18n.') item = I18n.t item[5, item.length] end text = text + ' ' + item found = true rescue end end found ? text : nil end |
.get_text(options, missing = true) ⇒ Object
200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/context_help/base.rb', line 200 def self.get_text(,missing=true) text = [:text] || get_doc_string([:calculated_path]+'.text') if text.nil? if missing and Rails.env.development? and ContextHelp::Base.config[:show_missing] I18n.t([:calculated_path]+'.text') else nil end else text end end |
.get_title(options) ⇒ Object
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/context_help/base.rb', line 179 def self.get_title() title = [:title] || get_doc_string([:calculated_path]+'.title') if title.nil? title = nil if [:path][:model] begin model_class = model_name([:path][:model]).classify.constantize if [:path][:attribute] then title = model_class.human_attribute_name([:path][:attribute].to_s) rescue I18n.t([:calculated_path]+'.title') else title = model_class.human_name end rescue title = I18n.t([:calculated_path]+'.title') end else title = I18n.t([:calculated_path]+'.title') if Rails.env.development? and ContextHelp::Base.config[:show_missing] end end title end |
.is_visible(options) ⇒ Object
174 175 176 177 178 |
# File 'lib/context_help/base.rb', line 174 def self.is_visible() return false if [:calculated_path].nil? return false if self.get_text(,false).nil? true end |
.merge_options(base, added) ⇒ Object
243 244 245 246 247 248 249 250 251 252 |
# File 'lib/context_help/base.rb', line 243 def self.(base, added) if base.is_a?(Hash) and added.is_a?(Hash) added.each do |key,value| base[key.to_sym] = self.(base[key.to_sym], value) end return base else return added || base end end |
.model_name(model) ⇒ Object
235 236 237 238 239 240 241 242 |
# File 'lib/context_help/base.rb', line 235 def self.model_name(model) model = model.to_s.underscore if model =~ /^[a-z][a-z0-9_]*\[[a-z][a-z0-9_]*_attributes\]/ model.match(/^[a-z][a-z0-9_]*\[([a-z][a-z0-9_]*)_attributes\]/)[1].singularize else model end end |