context_help 0.0.1 → 0.0.2
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.
- data/lib/context_help/base.rb +68 -18
- data/lib/context_help/patches/form_helper_patch.rb +17 -10
- data/lib/context_help/patches/form_tag_helper_patch.rb +20 -0
- data/lib/context_help/patches/formtastic_patch.rb +9 -5
- data/lib/context_help/patches/tag_helper_patch.rb +5 -3
- data/lib/context_help/version.rb +1 -1
- data/lib/context_help.rb +1 -0
- metadata +3 -2
data/lib/context_help/base.rb
CHANGED
@@ -25,6 +25,16 @@ module ContextHelp
|
|
25
25
|
:link_to_help => false
|
26
26
|
}
|
27
27
|
|
28
|
+
def self.help_items
|
29
|
+
@help_items
|
30
|
+
end
|
31
|
+
def self.config
|
32
|
+
@config
|
33
|
+
end
|
34
|
+
def self.flush_items
|
35
|
+
@help_items = []
|
36
|
+
end
|
37
|
+
|
28
38
|
def self.help_for(options)
|
29
39
|
help_options = options[:context_help]
|
30
40
|
self.help_path_for(help_options)
|
@@ -42,15 +52,6 @@ module ContextHelp
|
|
42
52
|
end
|
43
53
|
help.strip
|
44
54
|
end
|
45
|
-
def self.help_items
|
46
|
-
@help_items
|
47
|
-
end
|
48
|
-
def self.config
|
49
|
-
@config
|
50
|
-
end
|
51
|
-
def self.flush_items
|
52
|
-
@help_items = []
|
53
|
-
end
|
54
55
|
def self.inline_help(options)
|
55
56
|
return '' if options[:skip] or !options[:calculated_path]
|
56
57
|
if options[:inline_help_builder].is_a?(Proc)
|
@@ -68,13 +69,16 @@ module ContextHelp
|
|
68
69
|
ruta = nil
|
69
70
|
if !options[:skip]
|
70
71
|
if path[:model] and @config[:exclude_models].index(path[:model].to_sym).nil?
|
71
|
-
ruta = 'context_help.models.'+model_name(path[:model])
|
72
|
+
ruta = 'context_help.models.'+Helpers.model_name(path[:model])
|
72
73
|
options[:pre_level_class] = @config[:level_classes][:model]
|
73
74
|
|
74
75
|
if (path[:attribute])
|
75
76
|
ruta = ruta + '.attributes.'+ path[:attribute].to_s.underscore
|
76
77
|
options[:pre_level_class] = @config[:level_classes][:model_attribute]
|
77
78
|
end
|
79
|
+
elsif path[:custom]
|
80
|
+
ruta = 'context_help.custom.'+path[:custom]
|
81
|
+
options[:pre_level_class] = @config[:level_classes][:custom]
|
78
82
|
elsif path[:tag] and @config[:exclude_tags].index(path[:tag].to_sym).nil?
|
79
83
|
ruta = 'context_help.html.'+path[:tag].to_s.downcase
|
80
84
|
ruta = ruta + '.' + path[:tag_options][:id].to_s if path[:tag_options][:id]
|
@@ -84,13 +88,10 @@ module ContextHelp
|
|
84
88
|
else
|
85
89
|
options[:pre_level_class] = @config[:level_classes][:html][:default]
|
86
90
|
end
|
87
|
-
elsif path[:custom]
|
88
|
-
ruta = 'context_help.custom.'+path[:custom]
|
89
|
-
options[:pre_level_class] = @config[:level_classes][:custom]
|
90
91
|
end
|
91
92
|
end
|
92
93
|
if ruta
|
93
|
-
options[:calculated_path] = ruta
|
94
|
+
options[:calculated_path] = ruta
|
94
95
|
self.register_item(options) if register
|
95
96
|
return options[:calculated_path]
|
96
97
|
end
|
@@ -100,8 +101,10 @@ module ContextHelp
|
|
100
101
|
if options[:help_builder].is_a?(Proc)
|
101
102
|
options[:help_builder].call(options)
|
102
103
|
elsif options[:calculated_path]
|
103
|
-
title =
|
104
|
-
text =
|
104
|
+
title = Helpers.get_title(options)
|
105
|
+
text = Helpers.get_text(options)
|
106
|
+
return '' if (title.nil? || text.nil?) and !(Rails.env.development? and @config[:show_missing])
|
107
|
+
|
105
108
|
html = "<#{options[:title_tag]} id=\"#{options[:item_id]}\" class=\"#{options[:title_class]} #{options[:level_class]}\">#{title}</#{options[:title_tag]}>
|
106
109
|
<#{options[:text_tag]} class=\"#{options[:text_class]} #{options[:level_class]}\">#{text}</#{options[:text_tag]}>"
|
107
110
|
html += self.link_to_object(options)
|
@@ -111,7 +114,9 @@ module ContextHelp
|
|
111
114
|
def self.link_to_help(options)
|
112
115
|
if options[:link_to_help_builder].is_a?(Proc)
|
113
116
|
options[:link_to_help_builder].call(options)
|
114
|
-
elsif options[:link_to_help] and
|
117
|
+
elsif options[:link_to_help] and options[:calculated_path]
|
118
|
+
title = Helpers.get_title(options)
|
119
|
+
return '' if title.nil?
|
115
120
|
"<a href=\"##{options[:item_id]}\" id=\"#{options[:item_id]}_object\" class=\"context_help_link_to_help\">help</a>"
|
116
121
|
else
|
117
122
|
''
|
@@ -159,6 +164,51 @@ module ContextHelp
|
|
159
164
|
@help_items << options
|
160
165
|
end
|
161
166
|
end
|
167
|
+
end
|
168
|
+
|
169
|
+
module Helpers
|
170
|
+
def self.is_visible(options)
|
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])
|
174
|
+
true
|
175
|
+
end
|
176
|
+
def self.get_title(options)
|
177
|
+
title = options[:title] || I18n.t(options[:calculated_path]+'.title', :default => {})
|
178
|
+
if (title.nil? or title.is_a?(Hash))
|
179
|
+
title = nil
|
180
|
+
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
|
184
|
+
if options[:path][:attribute] then
|
185
|
+
title = model_class.human_attribute_name(options[:path][:attribute].to_s) rescue I18n.t(options[:calculated_path]+'.title')
|
186
|
+
else
|
187
|
+
title = model_class.human_name
|
188
|
+
end
|
189
|
+
else
|
190
|
+
title = I18n.t(options[:calculated_path]+'.title')
|
191
|
+
end
|
192
|
+
else
|
193
|
+
title = I18n.t(options[:calculated_path]+'.title') if Rails.env.development? and ContextHelp::Base.config[:show_missing]
|
194
|
+
end
|
195
|
+
else
|
196
|
+
if title.start_with?('t.')
|
197
|
+
title = I18n.t title[2, title.length]
|
198
|
+
elsif title.start_with?('I18n.')
|
199
|
+
title = I18n.t title[5, title.length]
|
200
|
+
end
|
201
|
+
end
|
202
|
+
title
|
203
|
+
end
|
204
|
+
def self.get_text(options)
|
205
|
+
text = options[:text] || I18n.t(options[:calculated_path]+'.text', :default => {})
|
206
|
+
if (text.nil? or text.is_a?(Hash))
|
207
|
+
nil
|
208
|
+
else
|
209
|
+
text
|
210
|
+
end
|
211
|
+
end
|
162
212
|
def self.model_name(model)
|
163
213
|
model = model.to_s.underscore
|
164
214
|
if model =~ /^[a-z][a-z0-9_]*\[[a-z][a-z0-9_]*_attributes\]/
|
@@ -170,7 +220,7 @@ module ContextHelp
|
|
170
220
|
def self.merge_options(base, added)
|
171
221
|
if base.is_a?(Hash) and added.is_a?(Hash)
|
172
222
|
added.each do |key,value|
|
173
|
-
base[key] = self.merge_options(base[key], value)
|
223
|
+
base[key.to_sym] = self.merge_options(base[key.to_sym], value)
|
174
224
|
end
|
175
225
|
return base
|
176
226
|
else
|
@@ -9,48 +9,55 @@ module ActionView
|
|
9
9
|
object_name = ActionController::RecordIdentifier.singular_class_name(record_or_name_or_array)
|
10
10
|
end
|
11
11
|
|
12
|
-
options = ContextHelp::
|
12
|
+
options = ContextHelp::Helpers.merge_options({:context_help => {:path => {:model => object_name.to_sym} } }, args.last.is_a?(::Hash)? args.last : {})
|
13
13
|
help = ContextHelp::Base.help_for(options)
|
14
14
|
help + fields_for_without_context_help_fields_for(record_or_name_or_array, *args, &block)
|
15
15
|
end
|
16
16
|
def label_with_context_help_label(object_name, method, text = nil, options = {})
|
17
|
-
help_options = ContextHelp::
|
17
|
+
help_options = ContextHelp::Helpers.merge_options({:context_help => {:path => {:model => object_name.to_sym, :attribute=> method.to_sym}}}, options)
|
18
18
|
ContextHelp::Base.help_for(help_options)
|
19
19
|
link_to_help = ContextHelp::Base.link_to_help(help_options[:context_help])
|
20
|
-
|
20
|
+
text = if text.blank?
|
21
|
+
i18n_label = I18n.t("helpers.label.#{object_name}.#{method}", :default => "")
|
22
|
+
i18n_label if i18n_label.present?
|
23
|
+
else
|
24
|
+
text.to_s
|
25
|
+
end
|
26
|
+
text ||= method.to_s.humanize
|
27
|
+
label_without_context_help_label(object_name, method, text.to_s + link_to_help, help_options)
|
21
28
|
end
|
22
29
|
def text_field_with_context_help_text_field(object_name, method, options = {})
|
23
|
-
help_options = ContextHelp::
|
30
|
+
help_options = ContextHelp::Helpers.merge_options({:context_help => {:path => {:model => object_name.to_sym, :attribute=> method.to_sym}}}, options)
|
24
31
|
help = ContextHelp::Base.help_for(help_options)
|
25
32
|
text_field_without_context_help_text_field(object_name, method, options) + help
|
26
33
|
end
|
27
34
|
def password_field_with_context_help_password_field(object_name, method, options = {})
|
28
|
-
help_options = ContextHelp::
|
35
|
+
help_options = ContextHelp::Helpers.merge_options({:context_help => {:path => {:model => object_name.to_sym, :attribute=> method.to_sym}}}, options)
|
29
36
|
help = ContextHelp::Base.help_for(help_options)
|
30
37
|
password_field_without_context_help_password_field(object_name, method, options) + help
|
31
38
|
end
|
32
39
|
def hidden_field_with_context_help_hidden_field(object_name, method, options = {})
|
33
|
-
help_options = ContextHelp::
|
40
|
+
help_options = ContextHelp::Helpers.merge_options({:context_help => {:path => {:model => object_name.to_sym, :attribute=> method.to_sym}}}, options)
|
34
41
|
help = ContextHelp::Base.help_for(help_options)
|
35
42
|
hidden_field_without_context_help_hidden_field(object_name, method, options) + help
|
36
43
|
end
|
37
44
|
def file_field_with_context_help_file_field(object_name, method, options = {})
|
38
|
-
help_options = ContextHelp::
|
45
|
+
help_options = ContextHelp::Helpers.merge_options({:context_help => {:path => {:model => object_name.to_sym, :attribute=> method.to_sym}}}, options)
|
39
46
|
help = ContextHelp::Base.help_for(help_options)
|
40
47
|
file_field_without_context_help_file_field(object_name, method, options) + help
|
41
48
|
end
|
42
49
|
def text_area_with_context_help_text_area(object_name, method, options = {})
|
43
|
-
help_options = ContextHelp::
|
50
|
+
help_options = ContextHelp::Helpers.merge_options({:context_help => {:path => {:model => object_name.to_sym, :attribute=> method.to_sym}}}, options)
|
44
51
|
help = ContextHelp::Base.help_for(help_options)
|
45
52
|
text_area_without_context_help_text_area(object_name, method, options) + help
|
46
53
|
end
|
47
54
|
def check_box_with_context_help_check_box(object_name, method, options = {}, checked_value = "1", unchecked_value = "0")
|
48
|
-
help_options = ContextHelp::
|
55
|
+
help_options = ContextHelp::Helpers.merge_options({:context_help => {:path => {:model => object_name.to_sym, :attribute=> method.to_sym}}}, options)
|
49
56
|
help = ContextHelp::Base.help_for(help_options)
|
50
57
|
check_box_without_context_help_check_box(object_name, method, options, checked_value, unchecked_value) + help
|
51
58
|
end
|
52
59
|
def radio_button_with_context_help_radio_button(object_name, method, tag_value, options = {})
|
53
|
-
help_options = ContextHelp::
|
60
|
+
help_options = ContextHelp::Helpers.merge_options({:context_help => {:path => {:model => object_name.to_sym, :attribute=> method.to_sym}}}, options)
|
54
61
|
help = ContextHelp::Base.help_for(help_options)
|
55
62
|
radio_button_without_context_help_radio_button(object_name, method, tag_value, options) +help
|
56
63
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module ActionView
|
2
|
+
module Helpers
|
3
|
+
module FormTagHelper
|
4
|
+
def form_tag_with_context_help_form_tag(url_for_options = {}, options = {}, *parameters_for_url, &block)
|
5
|
+
help_options = ContextHelp::Helpers.merge_options({:context_help => {:path => {:tag => :form, :tag_options => options}}}, options)
|
6
|
+
ContextHelp::Base.help_for(help_options)
|
7
|
+
form_tag_without_context_help_form_tag(url_for_options, options, *parameters_for_url, &block)
|
8
|
+
end
|
9
|
+
def label_tag_with_context_help_label_tag(name, text = nil, options = {})
|
10
|
+
help_options = ContextHelp::Helpers.merge_options({:context_help => {:path => {:tag => :label, :tag_options => options}}}, options)
|
11
|
+
text ||= name.to_s.humanize
|
12
|
+
text = text + ContextHelp::Base.help_for(help_options)
|
13
|
+
label_tag_without_context_help_label_tag name, text, help_options
|
14
|
+
end
|
15
|
+
|
16
|
+
alias_method_chain :form_tag, :context_help_form_tag
|
17
|
+
alias_method_chain :label_tag, :context_help_label_tag
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -3,14 +3,19 @@ module ContextHelp
|
|
3
3
|
def inputs(*args, &block)
|
4
4
|
title = field_set_title_from_args(*args)
|
5
5
|
html_options = args.extract_options!
|
6
|
-
help_options = ContextHelp::
|
6
|
+
help_options = ContextHelp::Helpers.merge_options({:context_help => {:path => {:tag => 'fieldset', :tag_options => html_options}}}, html_options)
|
7
7
|
help_options[:context_help][:title] = title if help_options[:context_help][:path][:tag]
|
8
8
|
help = ContextHelp::Base.help_for(help_options)
|
9
9
|
super *(args<<help_options), &block
|
10
10
|
end
|
11
11
|
def input(method, options = {})
|
12
|
-
options = ContextHelp::
|
13
|
-
|
12
|
+
options = ContextHelp::Helpers.merge_options({:context_help => {:path => {:model => model_name.to_sym, :attribute=> method.to_sym}}}, options || {})
|
13
|
+
super
|
14
|
+
end
|
15
|
+
def radio_input(method, options)
|
16
|
+
options[:label] = localized_string(method, options[:label], :label) || humanized_attribute_name(method)
|
17
|
+
ContextHelp::Base.help_for(options)
|
18
|
+
super
|
14
19
|
end
|
15
20
|
def legend_tag(method, options = {})
|
16
21
|
if options[:label] == false
|
@@ -19,8 +24,7 @@ module ContextHelp
|
|
19
24
|
text = localized_string(method, options[:label], :label) || humanized_attribute_name(method)
|
20
25
|
text += required_or_optional_string(options.delete(:required))
|
21
26
|
text = Formtastic::Util.html_safe(text)
|
22
|
-
|
23
|
-
template.content_tag :legend, template.label_tag(nil, text, :for => nil), :class => :label
|
27
|
+
template.content_tag :legend, template.label_tag(nil, text, options), :class => :label
|
24
28
|
end
|
25
29
|
end
|
26
30
|
end
|
@@ -2,14 +2,16 @@ module ActionView
|
|
2
2
|
module Helpers
|
3
3
|
module TagHelper
|
4
4
|
def tag_with_context_help_tag(name, options = {}, open = false, escape = true)
|
5
|
-
help_options = ContextHelp::
|
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')
|
7
8
|
tag_without_context_help_tag(name, options, open, escape) + help
|
8
9
|
end
|
9
10
|
def content_tag_with_context_help_content_tag(name, content_or_options_with_block = nil, options = {}, escape = true, &block)
|
10
|
-
help_options = ContextHelp::
|
11
|
+
help_options = ContextHelp::Helpers.merge_options({:context_help => {:path => {:tag => name.to_sym, :tag_options => options}}}, options)
|
11
12
|
help = ContextHelp::Base.help_for(help_options)
|
12
|
-
|
13
|
+
options.delete('context_help')
|
14
|
+
content_tag_without_context_help_content_tag(name, content_or_options_with_block, options, escape, &block) + help
|
13
15
|
end
|
14
16
|
|
15
17
|
alias_method_chain :tag, :context_help_tag
|
data/lib/context_help/version.rb
CHANGED
data/lib/context_help.rb
CHANGED
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.
|
4
|
+
version: 0.0.2
|
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-
|
12
|
+
date: 2011-08-15 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
|
@@ -29,6 +29,7 @@ files:
|
|
29
29
|
- lib/context_help.rb
|
30
30
|
- lib/context_help/base.rb
|
31
31
|
- lib/context_help/patches/form_helper_patch.rb
|
32
|
+
- lib/context_help/patches/form_tag_helper_patch.rb
|
32
33
|
- lib/context_help/patches/formtastic_patch.rb
|
33
34
|
- lib/context_help/patches/tag_helper_patch.rb
|
34
35
|
- lib/context_help/version.rb
|