bc-htmlful 0.0.6 → 0.0.7.localtracker
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/VERSION +1 -1
- data/bc-htmlful.gemspec +8 -7
- data/lib/htmlful/dynamic_fields.rb +69 -38
- metadata +16 -8
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.7.localtracker
|
data/bc-htmlful.gemspec
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{bc-htmlful}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.7.localtracker"
|
9
9
|
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new("
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Duarte Henriques", "Vasco Andrade e Silva"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-06-02}
|
13
13
|
s.description = %q{Form dynamic fields}
|
14
14
|
s.email = %q{info@byclosure.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -32,16 +32,17 @@ Gem::Specification.new do |s|
|
|
32
32
|
s.homepage = %q{http://github.com/Byclosure/}
|
33
33
|
s.rdoc_options = ["--charset=UTF-8"]
|
34
34
|
s.require_paths = ["lib"]
|
35
|
-
s.rubygems_version = %q{1.3.
|
35
|
+
s.rubygems_version = %q{1.3.7}
|
36
36
|
s.summary = %q{Form dynamic fields}
|
37
37
|
|
38
38
|
if s.respond_to? :specification_version then
|
39
39
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
40
40
|
s.specification_version = 3
|
41
41
|
|
42
|
-
if Gem::Version.new(Gem::
|
42
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
43
43
|
else
|
44
44
|
end
|
45
45
|
else
|
46
46
|
end
|
47
47
|
end
|
48
|
+
|
@@ -1,14 +1,25 @@
|
|
1
1
|
module Htmlful
|
2
2
|
module DynamicFields
|
3
|
-
def
|
4
|
-
|
3
|
+
def add_remove_existing_sub_object_link_in_sub_form(sub_form, relationship_i18n_name)
|
4
|
+
concat sub_form.input(:_delete, :as => :hidden, :wrapper_html => {:class => 'remove'}, :input_html => {:class => "checkbox_remove"})
|
5
|
+
concat content_tag(:li, link_to(t(:remove_nested_element, :resource_name => relationship_i18n_name), '#', :class => "remove_fieldset"))
|
6
|
+
end
|
7
|
+
|
8
|
+
def add_remove_and_create_new_nested_input_links(relationship_i18n_name)
|
9
|
+
concat link_to(t(:remove_nested_element, :resource_name => relationship_i18n_name), '#', :class => "remove_element")
|
10
|
+
concat link_to(t(:create_nested_element, :resource_name => relationship_i18n_name), "#", :class => "create_element")
|
11
|
+
end
|
12
|
+
|
13
|
+
def get_relationship_i18n_name(resource, relationship_name)
|
14
|
+
resource.class.human_attribute_name(relationship_name) #.to_s
|
15
|
+
end
|
16
|
+
|
17
|
+
def create_dynamic_fields_form(form, resource, relationship_name, block1, block2)
|
5
18
|
form.inputs :title => relationship_name do
|
6
19
|
unless resource.send(relationship_name).empty?
|
7
20
|
form.semantic_fields_for(relationship_name) do |sub_form|
|
8
21
|
sub_form.inputs do
|
9
22
|
block1.call(sub_form)
|
10
|
-
concat sub_form.input(:_delete, :as => :hidden, :wrapper_html => {:class => 'remove'}, :input_html => {:class => "checkbox_remove"})
|
11
|
-
concat content_tag(:li, link_to(t(:remove_nested_element, :resource_name => relationship_i18n_name), '#', :class => "remove_fieldset"))
|
12
23
|
end
|
13
24
|
end
|
14
25
|
end
|
@@ -20,8 +31,7 @@ module Htmlful
|
|
20
31
|
end
|
21
32
|
end
|
22
33
|
}
|
23
|
-
|
24
|
-
concat link_to(t(:create_nested_element, :resource_name => relationship_i18n_name), "#", :class => "create_element")
|
34
|
+
add_remove_and_create_new_nested_input_links(get_relationship_i18n_name(resource, relationship_name))
|
25
35
|
}
|
26
36
|
end
|
27
37
|
end
|
@@ -30,38 +40,54 @@ module Htmlful
|
|
30
40
|
block1 = lambda do |sub_form|
|
31
41
|
sub_object = sub_form.object
|
32
42
|
attributes.each do |attribute|
|
33
|
-
if is_date(sub_object, attribute)
|
43
|
+
if is_date?(sub_object, attribute)
|
34
44
|
concat sub_form.input(attribute, :as => :string, :wrapper_html => {:class => 'datepick'})
|
35
|
-
|
45
|
+
add_remove_existing_sub_object_link_in_sub_form(sub_form, get_relationship_i18n_name(resource, relationship_name))
|
46
|
+
elsif is_datetime?(sub_object, attribute)
|
36
47
|
concat sub_form.input(attribute, :include_blank => false)
|
37
|
-
|
48
|
+
add_remove_existing_sub_object_link_in_sub_form(sub_form, get_relationship_i18n_name(resource, relationship_name))
|
49
|
+
elsif is_document?(sub_object, attribute)
|
38
50
|
if is_document_empty?(sub_object, attribute)
|
39
|
-
|
51
|
+
# XXX Is this case is similar to an is_empty_image? If so it shouldn't show anything, if not remove the comments below
|
52
|
+
# concat content_tag(:li, content_tag(:p, t(:no_document)))
|
53
|
+
# add_remove_existing_sub_object_link_in_sub_form(sub_form, get_relationship_i18n_name(resource, relationship_name))
|
40
54
|
else
|
41
|
-
if is_image(sub_object, attribute)
|
42
|
-
|
55
|
+
if is_image?(sub_object, attribute)
|
56
|
+
if is_image_empty?(sub_object)
|
57
|
+
# XXX Do nohting, see is_empty_document? above
|
58
|
+
else
|
59
|
+
image_opts = if sub_object.respond_to?(:geocoded?) && sub_object.geocoded?
|
60
|
+
{ :class => "geo-photo", :"data-lat" => sub_object.latitude, :"data-lng" => sub_object.longitude }
|
61
|
+
else
|
62
|
+
{}
|
63
|
+
end
|
64
|
+
concat link_to(image_tag(sub_object.send(attribute).url(:thumb), image_opts), sub_object.send(attribute).url)
|
65
|
+
add_remove_existing_sub_object_link_in_sub_form(sub_form, get_relationship_i18n_name(resource, relationship_name))
|
66
|
+
end
|
43
67
|
else
|
44
68
|
concat content_tag(:li, content_tag(:p, link_to(sub_object.send("#{attribute}_file_name"), sub_object.send(attribute).url)))
|
69
|
+
add_remove_existing_sub_object_link_in_sub_form(sub_form, get_relationship_i18n_name(resource, relationship_name))
|
45
70
|
end
|
46
71
|
end
|
47
72
|
else
|
48
73
|
concat sub_form.input(attribute)
|
74
|
+
add_remove_existing_sub_object_link_in_sub_form(sub_form, get_relationship_i18n_name(resource, relationship_name))
|
49
75
|
end
|
50
76
|
end
|
51
77
|
end
|
52
78
|
block2 = lambda do |sub_form|
|
53
79
|
sub_object = sub_form.object
|
54
80
|
attributes.each do |attribute|
|
55
|
-
if is_date(sub_object, attribute)
|
81
|
+
if is_date?(sub_object, attribute)
|
56
82
|
concat sub_form.input(attribute, :as => :string, :wrapper_html => {:class => 'datepick ignore'})
|
57
|
-
elsif is_datetime(sub_object, attribute)
|
83
|
+
elsif is_datetime?(sub_object, attribute)
|
58
84
|
concat sub_form.input(attribute, :include_blank => false)
|
59
85
|
else
|
60
86
|
concat sub_form.input(attribute) # takes care of everything else
|
61
87
|
end
|
62
88
|
end
|
63
89
|
end
|
64
|
-
|
90
|
+
create_dynamic_fields_form(form, resource, relationship_name, block1, block2)
|
65
91
|
end
|
66
92
|
|
67
93
|
def show_dynamic_fields(form, resource, relationship_name, *attributes)
|
@@ -82,13 +108,13 @@ module Htmlful
|
|
82
108
|
|
83
109
|
# TODO: use concat and usage will be nicer
|
84
110
|
def show_attribute_outside_form(resource, attribute, options=nil, &block)
|
85
|
-
if is_date(resource, attribute)
|
111
|
+
if is_date?(resource, attribute)
|
86
112
|
resource.send(attribute) # TODO: add the controversial abbr method here, or just use title
|
87
|
-
elsif is_document(resource, attribute)
|
113
|
+
elsif is_document?(resource, attribute)
|
88
114
|
if is_document_empty?(resource, attribute)
|
89
115
|
t(:no_document)
|
90
116
|
else
|
91
|
-
if is_image(resource, attribute)
|
117
|
+
if is_image?(resource, attribute)
|
92
118
|
image_style = (options.nil? || options[:image_style].nil?)? :thumb : options[:image_style]
|
93
119
|
image_tag(resource.send(attribute).url(image_style))
|
94
120
|
else
|
@@ -102,17 +128,17 @@ module Htmlful
|
|
102
128
|
|
103
129
|
# inside of a form
|
104
130
|
def show_attribute(form, resource, attribute)
|
105
|
-
if is_date(resource, attribute)
|
131
|
+
if is_date?(resource, attribute)
|
106
132
|
form.input(attribute, :as => :string, :wrapper_html => {:class => 'datepick'}, :input_html => {:disabled => true})
|
107
|
-
elsif is_document(resource, attribute)
|
133
|
+
elsif is_document?(resource, attribute)
|
108
134
|
content_tag(:fieldset) do
|
109
135
|
content_tag(:legend) do
|
110
136
|
content_tag(:label, I18n.t("formtastic.labels.#{resource.class.name.underscore}.#{attribute}"))
|
111
137
|
end +
|
112
|
-
|
138
|
+
if is_document_empty?(resource, attribute)
|
113
139
|
t(:no_document)
|
114
140
|
else
|
115
|
-
if is_image(resource, attribute)
|
141
|
+
if is_image?(resource, attribute)
|
116
142
|
image_tag(resource.send(attribute).url(:thumb))
|
117
143
|
else
|
118
144
|
link_to(resource.send("#{attribute}_file_name"), resource.send(attribute).url)
|
@@ -127,30 +153,31 @@ module Htmlful
|
|
127
153
|
def show_subcollection(form, resource, association)
|
128
154
|
collection = resource.send(association)
|
129
155
|
resource_name_plural = localized_attribute_string(resource, association.to_sym)#resource.class.reflect_on_association(association.to_sym).klass.human_name(:count => 2)
|
156
|
+
raise ("Translation missing #{params[:locale]}, #{resource.class.human_name}, #{association}") if resource_name_plural.nil?
|
130
157
|
content_tag(:label, resource_name_plural) +
|
131
|
-
|
158
|
+
if collection.empty?
|
132
159
|
content_tag(:p, I18n.t(:no_resource_name_plural, :resource_name_plural => resource_name_plural.mb_chars.downcase))
|
133
160
|
else
|
134
161
|
content_tag(:ul, collection.inject("") { |html, sub_resource|
|
135
|
-
|
162
|
+
html + content_tag(:li, link_to(sub_resource.send(form.send(:detect_label_method, [sub_resource])), sub_resource))
|
136
163
|
}, :class => "sub-collection")
|
137
164
|
end
|
138
165
|
end
|
139
|
-
|
166
|
+
|
140
167
|
def multi_select_input(form, association, options={})
|
141
168
|
form.input(association, options) + content_tag(:li, content_tag(:div, link_to(t(:clear_selected), "#", :class => "clear_multi_select"), :class => "clear_multi_select"))
|
142
169
|
end
|
143
|
-
|
170
|
+
|
144
171
|
def form_inputs(form, *attributes)
|
145
172
|
options = attributes.extract_options!
|
146
173
|
resource = form.object
|
147
174
|
returning("") do |html|
|
148
175
|
attributes.each do |attribute|
|
149
176
|
html << form.input(attribute)
|
150
|
-
if is_document(resource, attribute)
|
177
|
+
if is_document?(resource, attribute)
|
151
178
|
unless is_document_empty?(resource, attribute)
|
152
179
|
html << "<li>"
|
153
|
-
if is_image(resource, attribute)
|
180
|
+
if is_image?(resource, attribute)
|
154
181
|
image_style = (options.nil? || options[:image_style].nil?)? :thumb : options[:image_style]
|
155
182
|
html << image_tag(form.object.send(attribute).url(image_style))
|
156
183
|
else
|
@@ -166,7 +193,7 @@ module Htmlful
|
|
166
193
|
end
|
167
194
|
|
168
195
|
protected
|
169
|
-
|
196
|
+
|
170
197
|
## copied and adapted from formtastic
|
171
198
|
def localized_attribute_string(resource, attr_name)
|
172
199
|
model_name = resource.class.name.underscore
|
@@ -187,32 +214,36 @@ module Htmlful
|
|
187
214
|
i18n_value = ::I18n.t(defaults.shift, :default => defaults, :scope => "formtastic.labels")
|
188
215
|
i18n_value.blank? ? nil : i18n_value
|
189
216
|
end
|
190
|
-
|
191
|
-
def is_date(resource, attribute)
|
217
|
+
|
218
|
+
def is_date?(resource, attribute)
|
192
219
|
col = resource.column_for_attribute(attribute)
|
193
220
|
col && col.type == :date
|
194
221
|
end
|
195
|
-
|
196
|
-
def is_datetime(resource, attribute)
|
222
|
+
|
223
|
+
def is_datetime?(resource, attribute)
|
197
224
|
col = resource.column_for_attribute(attribute)
|
198
225
|
col && col.type == :datetime
|
199
226
|
end
|
200
227
|
|
201
228
|
# taken from formtastic
|
202
229
|
@@file_methods = [:file?, :public_filename]
|
203
|
-
def is_document(resource, attribute)
|
230
|
+
def is_document?(resource, attribute)
|
204
231
|
file = resource.send(attribute) if resource.respond_to?(attribute)
|
205
232
|
file && @@file_methods.any? { |m| file.respond_to?(m) }
|
206
233
|
end
|
207
|
-
|
234
|
+
|
208
235
|
def is_document_empty?(resource, attribute)
|
209
236
|
resource.send("#{attribute}_file_name").blank?
|
210
237
|
end
|
211
|
-
|
238
|
+
|
239
|
+
def is_image_empty?(resource)
|
240
|
+
resource.new_record?
|
241
|
+
end
|
242
|
+
|
212
243
|
# XXX: if image is missing, this will return false because it queries the styles. Find out what we want
|
213
|
-
def is_image(resource, attribute)
|
244
|
+
def is_image?(resource, attribute)
|
214
245
|
file = resource.send(attribute) if resource.respond_to?(attribute)
|
215
|
-
is_document(resource, attribute) && file && file.respond_to?(:styles) && !file.styles.blank?
|
246
|
+
is_document?(resource, attribute) && file && file.respond_to?(:styles) && !file.styles.blank?
|
216
247
|
end
|
217
248
|
end
|
218
249
|
end
|
metadata
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bc-htmlful
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 1032128881
|
5
|
+
prerelease: true
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 0
|
8
|
-
-
|
9
|
-
|
9
|
+
- 7
|
10
|
+
- localtracker
|
11
|
+
version: 0.0.7.localtracker
|
10
12
|
platform: ruby
|
11
13
|
authors:
|
12
14
|
- Duarte Henriques
|
@@ -15,7 +17,7 @@ autorequire:
|
|
15
17
|
bindir: bin
|
16
18
|
cert_chain: []
|
17
19
|
|
18
|
-
date: 2010-
|
20
|
+
date: 2010-06-02 00:00:00 +01:00
|
19
21
|
default_executable:
|
20
22
|
dependencies: []
|
21
23
|
|
@@ -50,23 +52,29 @@ rdoc_options:
|
|
50
52
|
require_paths:
|
51
53
|
- lib
|
52
54
|
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
53
56
|
requirements:
|
54
57
|
- - ">="
|
55
58
|
- !ruby/object:Gem::Version
|
59
|
+
hash: 3
|
56
60
|
segments:
|
57
61
|
- 0
|
58
62
|
version: "0"
|
59
63
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
60
65
|
requirements:
|
61
|
-
- - "
|
66
|
+
- - ">"
|
62
67
|
- !ruby/object:Gem::Version
|
68
|
+
hash: 25
|
63
69
|
segments:
|
64
|
-
-
|
65
|
-
|
70
|
+
- 1
|
71
|
+
- 3
|
72
|
+
- 1
|
73
|
+
version: 1.3.1
|
66
74
|
requirements: []
|
67
75
|
|
68
76
|
rubyforge_project:
|
69
|
-
rubygems_version: 1.3.
|
77
|
+
rubygems_version: 1.3.7
|
70
78
|
signing_key:
|
71
79
|
specification_version: 3
|
72
80
|
summary: Form dynamic fields
|