Module: ContextHelp::Base
- Defined in:
- lib/context_help/base.rb
Class Method Summary collapse
- .config ⇒ Object
- .context_help(&block) ⇒ Object
- .flush_items ⇒ Object
- .get_option(name, options) ⇒ Object
- .help_for(options) ⇒ Object
- .help_items ⇒ Object
- .help_path_for(options, register = true) ⇒ Object
- .html_help(options) ⇒ Object
- .inline_help(options) ⇒ Object
- .link_to_help(options) ⇒ Object
- .link_to_object(options) ⇒ Object
- .register_item(options) ⇒ Object
Class Method Details
.config ⇒ Object
31 32 33 |
# File 'lib/context_help/base.rb', line 31 def self.config @config end |
.context_help(&block) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/context_help/base.rb', line 43 def self.context_help(&block) help = '' @help_items.each do |item| item[:calculated_path] = self.help_path_for(item, false) if !item[:calculated_path] if block_given? help += yield(item) elsif !item[:skip] and item[:calculated_path] help += self.html_help(item) end end help.strip end |
.flush_items ⇒ Object
34 35 36 |
# File 'lib/context_help/base.rb', line 34 def self.flush_items @help_items = [] end |
.get_option(name, options) ⇒ Object
135 136 137 138 139 140 141 142 143 |
# File 'lib/context_help/base.rb', line 135 def self.get_option(name, ) return @config[name] if [:calculated_path].nil? value = I18n.t([:calculated_path]+'.'+name.to_s, :default => {}) if value.is_a?(Hash) @config[name] else value end end |
.help_for(options) ⇒ Object
38 39 40 41 42 |
# File 'lib/context_help/base.rb', line 38 def self.help_for() = [:context_help] self.help_path_for() self.inline_help() end |
.help_items ⇒ Object
28 29 30 |
# File 'lib/context_help/base.rb', line 28 def self.help_items @help_items end |
.help_path_for(options, register = true) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/context_help/base.rb', line 65 def self.help_path_for(,register=true) path = [:path] return path if path.is_a?(String) ruta = nil if ![:skip] if path[:model] and @config[:exclude_models].index(path[:model].to_sym).nil? ruta = 'context_help.models.'+Helpers.model_name(path[:model]) [:pre_level_class] = @config[:level_classes][:model] if (path[:attribute]) ruta = ruta + '.attributes.'+ path[:attribute].to_s.underscore [:pre_level_class] = @config[:level_classes][:model_attribute] end elsif path[:custom] ruta = 'context_help.custom.'+path[:custom] [:pre_level_class] = @config[:level_classes][:custom] elsif path[:tag] and @config[:exclude_tags].index(path[:tag].to_sym).nil? ruta = 'context_help.html.'+path[:tag].to_s.downcase ruta = ruta + '.' + path[:tag_options][:id].to_s if path[:tag_options][:id] if @config[:level_classes][:html].include?(path[:tag]) [:pre_level_class] = @config[:level_classes][:html][path[:tag]] else [:pre_level_class] = @config[:level_classes][:html][:default] end end end if ruta [:calculated_path] = ruta self.register_item() if register return [:calculated_path] end nil end |
.html_help(options) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/context_help/base.rb', line 100 def self.html_help() if [:help_builder].is_a?(Proc) [:help_builder].call() elsif [:calculated_path] title = Helpers.get_title() text = Helpers.get_text() return '' if (title.nil? || text.nil?) and !(Rails.env.development? and @config[:show_missing]) html = "<#{[:title_tag]} id=\"#{[:item_id]}\" class=\"#{[:title_class]} #{[:level_class]}\">#{title}</#{[:title_tag]}> <#{[:text_tag]} class=\"#{[:text_class]} #{[:level_class]}\">#{text}</#{[:text_tag]}>" html += self.link_to_object() html end end |
.inline_help(options) ⇒ Object
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/context_help/base.rb', line 55 def self.inline_help() return '' if [:skip] or ![:calculated_path] if [:inline_help_builder].is_a?(Proc) [:inline_help_builder].call() elsif [:show_inline] self.html_help() else '' end end |
.link_to_help(options) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/context_help/base.rb', line 114 def self.link_to_help() if [:link_to_help_builder].is_a?(Proc) [:link_to_help_builder].call() elsif [:link_to_help] and [:calculated_path] title = Helpers.get_title() return '' if title.nil? "<a href=\"##{[:item_id]}\" id=\"#{[:item_id]}_object\" class=\"context_help_link_to_help\">help</a>" else '' end end |
.link_to_object(options) ⇒ Object
125 126 127 128 129 130 131 132 133 |
# File 'lib/context_help/base.rb', line 125 def self.link_to_object() if [:link_to_object_builder].is_a?(Proc) [:link_to_object_builder].call() elsif [:link_to_object] "<a href=\"#link_to_help_#{[:item_id]}\">help</a>" else '' end end |
.register_item(options) ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/context_help/base.rb', line 134 def self.register_item() def self.get_option(name, ) return @config[name] if [:calculated_path].nil? value = I18n.t([:calculated_path]+'.'+name.to_s, :default => {}) if value.is_a?(Hash) @config[name] else value end end found = false last = nil @help_items.each do |item| found = (item[:calculated_path] == [:calculated_path]) last = item break if found end if found .update(last) else [:show_inline] ||= get_option(:show_inline, ) [:title_tag] ||= get_option(:title_tag, ) [:title_class] ||= get_option(:title_class, ) [:text_tag] ||= get_option(:text_tag, ) [:text_class] ||= get_option(:text_class, ) [:link_to_object] ||= get_option(:link_to_object, ) [:link_to_help] ||= get_option(:link_to_help, ) [:level_class] ||= I18n.t([:calculated_path]+'.level_class', :default => ([:pre_level_class] || 'help_level_1')) [:link_to_help_builder] ||= @config[:link_to_help_builder] [:link_to_object_builder] ||= @config[:link_to_object_builder] [:inline_help_builder] ||= @config[:inline_help_builder] [:help_builder] ||= @config[:help_builder] [:item_id] = "context_help_item_#{(@help_items.length+1).to_s}" @help_items << end end |