bc-htmlful 0.0.7.localtracker → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/README +1 -0
- data/VERSION +1 -1
- data/bc-htmlful.gemspec +2 -2
- data/lib/htmlful/dynamic_fields.rb +31 -61
- metadata +7 -10
data/README
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.7
|
1
|
+
0.0.7
|
data/bc-htmlful.gemspec
CHANGED
@@ -5,9 +5,9 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{bc-htmlful}
|
8
|
-
s.version = "0.0.7
|
8
|
+
s.version = "0.0.7"
|
9
9
|
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new("
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Duarte Henriques", "Vasco Andrade e Silva"]
|
12
12
|
s.date = %q{2010-06-02}
|
13
13
|
s.description = %q{Form dynamic fields}
|
@@ -1,25 +1,14 @@
|
|
1
1
|
module Htmlful
|
2
2
|
module DynamicFields
|
3
|
-
def
|
4
|
-
|
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)
|
3
|
+
def _dynamic_fields(form, resource, relationship_name, block1, block2)
|
4
|
+
relationship_i18n_name = resource.class.human_attribute_name(relationship_name).to_s
|
18
5
|
form.inputs :title => relationship_name do
|
19
6
|
unless resource.send(relationship_name).empty?
|
20
7
|
form.semantic_fields_for(relationship_name) do |sub_form|
|
21
8
|
sub_form.inputs do
|
22
9
|
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"))
|
23
12
|
end
|
24
13
|
end
|
25
14
|
end
|
@@ -31,7 +20,8 @@ module Htmlful
|
|
31
20
|
end
|
32
21
|
end
|
33
22
|
}
|
34
|
-
|
23
|
+
concat link_to(t(:remove_nested_element, :resource_name => relationship_i18n_name), '#', :class => "remove_element")
|
24
|
+
concat link_to(t(:create_nested_element, :resource_name => relationship_i18n_name), "#", :class => "create_element")
|
35
25
|
}
|
36
26
|
end
|
37
27
|
end
|
@@ -40,54 +30,38 @@ module Htmlful
|
|
40
30
|
block1 = lambda do |sub_form|
|
41
31
|
sub_object = sub_form.object
|
42
32
|
attributes.each do |attribute|
|
43
|
-
if is_date
|
33
|
+
if is_date(sub_object, attribute)
|
44
34
|
concat sub_form.input(attribute, :as => :string, :wrapper_html => {:class => 'datepick'})
|
45
|
-
|
46
|
-
elsif is_datetime?(sub_object, attribute)
|
35
|
+
elsif is_datetime(sub_object, attribute)
|
47
36
|
concat sub_form.input(attribute, :include_blank => false)
|
48
|
-
|
49
|
-
elsif is_document?(sub_object, attribute)
|
37
|
+
elsif is_document(sub_object, attribute)
|
50
38
|
if is_document_empty?(sub_object, attribute)
|
51
|
-
|
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))
|
39
|
+
concat content_tag(:li, content_tag(:p, t(:no_document)))
|
54
40
|
else
|
55
|
-
if is_image
|
56
|
-
|
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
|
41
|
+
if is_image(sub_object, attribute)
|
42
|
+
concat image_tag(sub_form.object.send(attribute).url(:thumb))
|
67
43
|
else
|
68
44
|
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))
|
70
45
|
end
|
71
46
|
end
|
72
47
|
else
|
73
48
|
concat sub_form.input(attribute)
|
74
|
-
add_remove_existing_sub_object_link_in_sub_form(sub_form, get_relationship_i18n_name(resource, relationship_name))
|
75
49
|
end
|
76
50
|
end
|
77
51
|
end
|
78
52
|
block2 = lambda do |sub_form|
|
79
53
|
sub_object = sub_form.object
|
80
54
|
attributes.each do |attribute|
|
81
|
-
if is_date
|
55
|
+
if is_date(sub_object, attribute)
|
82
56
|
concat sub_form.input(attribute, :as => :string, :wrapper_html => {:class => 'datepick ignore'})
|
83
|
-
elsif is_datetime
|
57
|
+
elsif is_datetime(sub_object, attribute)
|
84
58
|
concat sub_form.input(attribute, :include_blank => false)
|
85
59
|
else
|
86
60
|
concat sub_form.input(attribute) # takes care of everything else
|
87
61
|
end
|
88
62
|
end
|
89
63
|
end
|
90
|
-
|
64
|
+
_dynamic_fields(form, resource, relationship_name, block1, block2)
|
91
65
|
end
|
92
66
|
|
93
67
|
def show_dynamic_fields(form, resource, relationship_name, *attributes)
|
@@ -108,13 +82,13 @@ module Htmlful
|
|
108
82
|
|
109
83
|
# TODO: use concat and usage will be nicer
|
110
84
|
def show_attribute_outside_form(resource, attribute, options=nil, &block)
|
111
|
-
if is_date
|
85
|
+
if is_date(resource, attribute)
|
112
86
|
resource.send(attribute) # TODO: add the controversial abbr method here, or just use title
|
113
|
-
elsif is_document
|
87
|
+
elsif is_document(resource, attribute)
|
114
88
|
if is_document_empty?(resource, attribute)
|
115
89
|
t(:no_document)
|
116
90
|
else
|
117
|
-
if is_image
|
91
|
+
if is_image(resource, attribute)
|
118
92
|
image_style = (options.nil? || options[:image_style].nil?)? :thumb : options[:image_style]
|
119
93
|
image_tag(resource.send(attribute).url(image_style))
|
120
94
|
else
|
@@ -128,17 +102,17 @@ module Htmlful
|
|
128
102
|
|
129
103
|
# inside of a form
|
130
104
|
def show_attribute(form, resource, attribute)
|
131
|
-
if is_date
|
105
|
+
if is_date(resource, attribute)
|
132
106
|
form.input(attribute, :as => :string, :wrapper_html => {:class => 'datepick'}, :input_html => {:disabled => true})
|
133
|
-
elsif is_document
|
107
|
+
elsif is_document(resource, attribute)
|
134
108
|
content_tag(:fieldset) do
|
135
109
|
content_tag(:legend) do
|
136
110
|
content_tag(:label, I18n.t("formtastic.labels.#{resource.class.name.underscore}.#{attribute}"))
|
137
111
|
end +
|
138
|
-
|
112
|
+
if is_document_empty?(resource, attribute)
|
139
113
|
t(:no_document)
|
140
114
|
else
|
141
|
-
if is_image
|
115
|
+
if is_image(resource, attribute)
|
142
116
|
image_tag(resource.send(attribute).url(:thumb))
|
143
117
|
else
|
144
118
|
link_to(resource.send("#{attribute}_file_name"), resource.send(attribute).url)
|
@@ -155,11 +129,11 @@ module Htmlful
|
|
155
129
|
resource_name_plural = localized_attribute_string(resource, association.to_sym)#resource.class.reflect_on_association(association.to_sym).klass.human_name(:count => 2)
|
156
130
|
raise ("Translation missing #{params[:locale]}, #{resource.class.human_name}, #{association}") if resource_name_plural.nil?
|
157
131
|
content_tag(:label, resource_name_plural) +
|
158
|
-
|
132
|
+
if collection.empty?
|
159
133
|
content_tag(:p, I18n.t(:no_resource_name_plural, :resource_name_plural => resource_name_plural.mb_chars.downcase))
|
160
134
|
else
|
161
135
|
content_tag(:ul, collection.inject("") { |html, sub_resource|
|
162
|
-
|
136
|
+
html + content_tag(:li, link_to(sub_resource.send(form.send(:detect_label_method, [sub_resource])), sub_resource))
|
163
137
|
}, :class => "sub-collection")
|
164
138
|
end
|
165
139
|
end
|
@@ -174,10 +148,10 @@ module Htmlful
|
|
174
148
|
returning("") do |html|
|
175
149
|
attributes.each do |attribute|
|
176
150
|
html << form.input(attribute)
|
177
|
-
if is_document
|
151
|
+
if is_document(resource, attribute)
|
178
152
|
unless is_document_empty?(resource, attribute)
|
179
153
|
html << "<li>"
|
180
|
-
if is_image
|
154
|
+
if is_image(resource, attribute)
|
181
155
|
image_style = (options.nil? || options[:image_style].nil?)? :thumb : options[:image_style]
|
182
156
|
html << image_tag(form.object.send(attribute).url(image_style))
|
183
157
|
else
|
@@ -215,19 +189,19 @@ module Htmlful
|
|
215
189
|
i18n_value.blank? ? nil : i18n_value
|
216
190
|
end
|
217
191
|
|
218
|
-
def is_date
|
192
|
+
def is_date(resource, attribute)
|
219
193
|
col = resource.column_for_attribute(attribute)
|
220
194
|
col && col.type == :date
|
221
195
|
end
|
222
196
|
|
223
|
-
def is_datetime
|
197
|
+
def is_datetime(resource, attribute)
|
224
198
|
col = resource.column_for_attribute(attribute)
|
225
199
|
col && col.type == :datetime
|
226
200
|
end
|
227
201
|
|
228
202
|
# taken from formtastic
|
229
203
|
@@file_methods = [:file?, :public_filename]
|
230
|
-
def is_document
|
204
|
+
def is_document(resource, attribute)
|
231
205
|
file = resource.send(attribute) if resource.respond_to?(attribute)
|
232
206
|
file && @@file_methods.any? { |m| file.respond_to?(m) }
|
233
207
|
end
|
@@ -236,14 +210,10 @@ module Htmlful
|
|
236
210
|
resource.send("#{attribute}_file_name").blank?
|
237
211
|
end
|
238
212
|
|
239
|
-
def is_image_empty?(resource)
|
240
|
-
resource.new_record?
|
241
|
-
end
|
242
|
-
|
243
213
|
# XXX: if image is missing, this will return false because it queries the styles. Find out what we want
|
244
|
-
def is_image
|
214
|
+
def is_image(resource, attribute)
|
245
215
|
file = resource.send(attribute) if resource.respond_to?(attribute)
|
246
|
-
is_document
|
216
|
+
is_document(resource, attribute) && file && file.respond_to?(:styles) && !file.styles.blank?
|
247
217
|
end
|
248
218
|
end
|
249
219
|
end
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bc-htmlful
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 17
|
5
|
+
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
9
|
- 7
|
10
|
-
|
11
|
-
version: 0.0.7.localtracker
|
10
|
+
version: 0.0.7
|
12
11
|
platform: ruby
|
13
12
|
authors:
|
14
13
|
- Duarte Henriques
|
@@ -63,14 +62,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
63
62
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
63
|
none: false
|
65
64
|
requirements:
|
66
|
-
- - "
|
65
|
+
- - ">="
|
67
66
|
- !ruby/object:Gem::Version
|
68
|
-
hash:
|
67
|
+
hash: 3
|
69
68
|
segments:
|
70
|
-
-
|
71
|
-
|
72
|
-
- 1
|
73
|
-
version: 1.3.1
|
69
|
+
- 0
|
70
|
+
version: "0"
|
74
71
|
requirements: []
|
75
72
|
|
76
73
|
rubyforge_project:
|