bc-htmlful 0.0.7 → 0.0.8.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/README CHANGED
@@ -11,4 +11,3 @@ include the javascript file in your layout:
11
11
 
12
12
 
13
13
  rake htmlful:update:javascripts
14
-
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.7
1
+ 0.0.8.localtracker
data/bc-htmlful.gemspec CHANGED
@@ -5,11 +5,11 @@
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.8.localtracker"
9
9
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
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-06-02}
12
+ s.date = %q{2010-06-08}
13
13
  s.description = %q{Form dynamic fields}
14
14
  s.email = %q{info@byclosure.com}
15
15
  s.extra_rdoc_files = [
@@ -1,14 +1,25 @@
1
1
  module Htmlful
2
2
  module DynamicFields
3
- def _dynamic_fields(form, resource, relationship_name, block1, block2)
4
- relationship_i18n_name = resource.class.human_attribute_name(relationship_name).to_s
3
+ def add_remove_existing_sub_object_link_in_sub_form(sub_form, relationship_i18n_name)
4
+ concat sub_form.input(:_destroy, :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
- 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")
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
- elsif is_datetime(sub_object, attribute)
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
- elsif is_document(sub_object, attribute)
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
- concat content_tag(:li, content_tag(:p, t(:no_document)))
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
- concat image_tag(sub_form.object.send(attribute).url(:thumb))
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
- _dynamic_fields(form, resource, relationship_name, block1, block2)
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
- if is_document_empty?(resource, attribute)
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)
@@ -129,11 +155,11 @@ module Htmlful
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)
130
156
  raise ("Translation missing #{params[:locale]}, #{resource.class.human_name}, #{association}") if resource_name_plural.nil?
131
157
  content_tag(:label, resource_name_plural) +
132
- if collection.empty?
158
+ if collection.empty?
133
159
  content_tag(:p, I18n.t(:no_resource_name_plural, :resource_name_plural => resource_name_plural.mb_chars.downcase))
134
160
  else
135
161
  content_tag(:ul, collection.inject("") { |html, sub_resource|
136
- html + content_tag(:li, link_to(sub_resource.send(form.send(:detect_label_method, [sub_resource])), sub_resource))
162
+ html + content_tag(:li, link_to(sub_resource.send(form.send(:detect_label_method, [sub_resource])), sub_resource))
137
163
  }, :class => "sub-collection")
138
164
  end
139
165
  end
@@ -148,10 +174,10 @@ module Htmlful
148
174
  returning("") do |html|
149
175
  attributes.each do |attribute|
150
176
  html << form.input(attribute)
151
- if is_document(resource, attribute)
177
+ if is_document?(resource, attribute)
152
178
  unless is_document_empty?(resource, attribute)
153
179
  html << "<li>"
154
- if is_image(resource, attribute)
180
+ if is_image?(resource, attribute)
155
181
  image_style = (options.nil? || options[:image_style].nil?)? :thumb : options[:image_style]
156
182
  html << image_tag(form.object.send(attribute).url(image_style))
157
183
  else
@@ -189,19 +215,19 @@ module Htmlful
189
215
  i18n_value.blank? ? nil : i18n_value
190
216
  end
191
217
 
192
- def is_date(resource, attribute)
218
+ def is_date?(resource, attribute)
193
219
  col = resource.column_for_attribute(attribute)
194
220
  col && col.type == :date
195
221
  end
196
222
 
197
- def is_datetime(resource, attribute)
223
+ def is_datetime?(resource, attribute)
198
224
  col = resource.column_for_attribute(attribute)
199
225
  col && col.type == :datetime
200
226
  end
201
227
 
202
228
  # taken from formtastic
203
229
  @@file_methods = [:file?, :public_filename]
204
- def is_document(resource, attribute)
230
+ def is_document?(resource, attribute)
205
231
  file = resource.send(attribute) if resource.respond_to?(attribute)
206
232
  file && @@file_methods.any? { |m| file.respond_to?(m) }
207
233
  end
@@ -210,10 +236,14 @@ module Htmlful
210
236
  resource.send("#{attribute}_file_name").blank?
211
237
  end
212
238
 
239
+ def is_image_empty?(resource)
240
+ resource.new_record?
241
+ end
242
+
213
243
  # XXX: if image is missing, this will return false because it queries the styles. Find out what we want
214
- def is_image(resource, attribute)
244
+ def is_image?(resource, attribute)
215
245
  file = resource.send(attribute) if resource.respond_to?(attribute)
216
- 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?
217
247
  end
218
248
  end
219
249
  end
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bc-htmlful
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
5
- prerelease: false
4
+ hash: 1032128845
5
+ prerelease: true
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 7
10
- version: 0.0.7
9
+ - 8
10
+ - localtracker
11
+ version: 0.0.8.localtracker
11
12
  platform: ruby
12
13
  authors:
13
14
  - Duarte Henriques
@@ -16,7 +17,7 @@ autorequire:
16
17
  bindir: bin
17
18
  cert_chain: []
18
19
 
19
- date: 2010-06-02 00:00:00 +01:00
20
+ date: 2010-06-08 00:00:00 +01:00
20
21
  default_executable:
21
22
  dependencies: []
22
23
 
@@ -62,12 +63,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
62
63
  required_rubygems_version: !ruby/object:Gem::Requirement
63
64
  none: false
64
65
  requirements:
65
- - - ">="
66
+ - - ">"
66
67
  - !ruby/object:Gem::Version
67
- hash: 3
68
+ hash: 25
68
69
  segments:
69
- - 0
70
- version: "0"
70
+ - 1
71
+ - 3
72
+ - 1
73
+ version: 1.3.1
71
74
  requirements: []
72
75
 
73
76
  rubyforge_project: