context_help 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -169,8 +169,7 @@ module ContextHelp
169
169
  module Helpers
170
170
  def self.is_visible(options)
171
171
  return false if options[:calculated_path].nil?
172
- text = options[:text] || I18n.t(options[:calculated_path]+'.text', :default => {})
173
- return false if (text.nil? or text.is_a?(Hash)) and !(Rails.env.development? and ContextHelp::Base.config[:show_missing])
172
+ return false if self.get_text(options,false).nil?
174
173
  true
175
174
  end
176
175
  def self.get_title(options)
@@ -178,15 +177,14 @@ module ContextHelp
178
177
  if (title.nil? or title.is_a?(Hash))
179
178
  title = nil
180
179
  if options[:path][:model]
181
- model_class = model_name(options[:path][:model]).classify
182
- if const_defined?(model_class)
183
- model_class = model_class.constantize
180
+ begin
181
+ model_class = model_name(options[:path][:model]).classify.constantize
184
182
  if options[:path][:attribute] then
185
183
  title = model_class.human_attribute_name(options[:path][:attribute].to_s) rescue I18n.t(options[:calculated_path]+'.title')
186
184
  else
187
185
  title = model_class.human_name
188
186
  end
189
- else
187
+ rescue
190
188
  title = I18n.t(options[:calculated_path]+'.title')
191
189
  end
192
190
  else
@@ -201,10 +199,14 @@ module ContextHelp
201
199
  end
202
200
  title
203
201
  end
204
- def self.get_text(options)
202
+ def self.get_text(options,missing=true)
205
203
  text = options[:text] || I18n.t(options[:calculated_path]+'.text', :default => {})
206
204
  if (text.nil? or text.is_a?(Hash))
207
- nil
205
+ if missing and Rails.env.development? and ContextHelp::Base.config[:show_missing]
206
+ I18n.t(options[:calculated_path]+'.text')
207
+ else
208
+ nil
209
+ end
208
210
  else
209
211
  text
210
212
  end
@@ -227,5 +229,10 @@ module ContextHelp
227
229
  return base || added
228
230
  end
229
231
  end
232
+ def self.clean(options)
233
+ options.delete(:context_help)
234
+ options.delete('context_help')
235
+ options
236
+ end
230
237
  end
231
238
  end
@@ -10,7 +10,7 @@ module ActionView
10
10
  help_options = ContextHelp::Helpers.merge_options({:context_help => {:path => {:tag => :label, :tag_options => options}}}, options)
11
11
  text ||= name.to_s.humanize
12
12
  text = text + ContextHelp::Base.help_for(help_options)
13
- label_tag_without_context_help_label_tag name, text, help_options
13
+ label_tag_without_context_help_label_tag name, text, ContextHelp::Helpers.clean(options)
14
14
  end
15
15
 
16
16
  alias_method_chain :form_tag, :context_help_form_tag
@@ -4,14 +4,12 @@ module ActionView
4
4
  def tag_with_context_help_tag(name, options = {}, open = false, escape = true)
5
5
  help_options = ContextHelp::Helpers.merge_options({:context_help => {:path => {:tag => name.to_sym, :tag_options => options}}}, options)
6
6
  help = ContextHelp::Base.help_for(help_options)
7
- options.delete('context_help')
8
- tag_without_context_help_tag(name, options, open, escape) + help
7
+ tag_without_context_help_tag(name, ContextHelp::Helpers.clean(options), open, escape) + help
9
8
  end
10
9
  def content_tag_with_context_help_content_tag(name, content_or_options_with_block = nil, options = {}, escape = true, &block)
11
10
  help_options = ContextHelp::Helpers.merge_options({:context_help => {:path => {:tag => name.to_sym, :tag_options => options}}}, options)
12
11
  help = ContextHelp::Base.help_for(help_options)
13
- options.delete('context_help')
14
- content_tag_without_context_help_content_tag(name, content_or_options_with_block, options, escape, &block) + help
12
+ content_tag_without_context_help_content_tag(name, content_or_options_with_block, ContextHelp::Helpers.clean(options), escape, &block) + help
15
13
  end
16
14
 
17
15
  alias_method_chain :tag, :context_help_tag
@@ -1,3 +1,3 @@
1
1
  module ContextHelp
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: context_help
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-15 00:00:00.000000000 -03:00
12
+ date: 2011-08-30 00:00:00.000000000 -03:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
  description: ContextHelp is a gem that allows you to show inline or aside help about