furatto 1.1.5 → 1.2.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cb7536e61f899bdbcfe9a770f524c46d16050949
4
- data.tar.gz: 6f334d0a2b80f5df604548507bbe3013d4c9b348
3
+ metadata.gz: ca419e7970fabaabdcfa98d4ebbc40732938619d
4
+ data.tar.gz: f4815b048d9093671c937604655aa661c58ec380
5
5
  SHA512:
6
- metadata.gz: 9235d7cf14f68ae131f15af8e4dbaca402dbf341bfc200c9366c4fdbbd7ca1aa60cc962b2c6c5ebd6e4338230a357deb49152a0c0c384cf62973c8e0e2fec9a4
7
- data.tar.gz: 797112c06df7ba87cb9b221560c91d6c90e95332f7eb0a8c019004383d5a8d103d83c923edd0d54b2685cdd5242c054eedd731a04db451597a8fd035a9d9ca65
6
+ metadata.gz: f21732ad188b5e5944cbdad193a5f0566e513f4aa48a3e3bb0bba649a7541526c2cb0f7571c30c612a7fbac6f3be1fa1d088ed7809401677a7c738868f99f16f
7
+ data.tar.gz: 29b10ab8b665503b5d7c9c618be60978daa1af95fd2cd575dbb1104c006f23e495645526411b754929f3b5e4fd863d05f737c6bf6e125fe9de1249d38d9fda84
data/lib/furatto.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  require "furatto/version"
2
+ require "furatto_rails_helpers/form_builder"
3
+ require "furatto_rails_helpers/action_view_form_builder_extension"
2
4
  require "furatto_rails_helpers/furatto_helpers"
3
5
 
4
6
  module Furatto
@@ -1,3 +1,3 @@
1
1
  module Furatto
2
- VERSION = "1.1.5"
2
+ VERSION = "1.2.5"
3
3
  end
@@ -0,0 +1,27 @@
1
+ module ActionView
2
+ module Helpers
3
+ module FormHelper
4
+ def form_for_with_furatto(record, options = {}, &block)
5
+ options[:builder] ||= Furatto::FormBuilder
6
+ options[:html] ||= {}
7
+ options[:auto_labels] = true unless options.has_key? :auto_labels
8
+ form_for_without_furatto(record, options, &block)
9
+ end
10
+
11
+ def fields_for_with_furatto(record_name, record_object = nil, options = {}, &block)
12
+ options[:builder] ||= Furatto::FormBuilder
13
+ options[:html] ||= {}
14
+ options[:html][:attached_labels] = options[:attached_labels]
15
+ options[:auto_labels] = true unless options.has_key? :auto_labels
16
+ fields_for_without_furatto(record_name, record_object, options, &block)
17
+ end
18
+
19
+ alias_method_chain :form_for, :furatto
20
+ alias_method_chain :fields_for, :furatto
21
+ end
22
+ end
23
+ end
24
+
25
+ ActionView::Base.field_error_proc = Proc.new do |html_tag, instance_tag|
26
+ html_tag
27
+ end
@@ -0,0 +1,52 @@
1
+ require 'action_view/helpers'
2
+
3
+ module Furatto
4
+ class FormBuilder < ActionView::Helpers::FormBuilder
5
+ include ActionView::Helpers::TagHelper
6
+
7
+ %w(file_field email_field text_field text_area telephone_field phone_field
8
+ url_field number_field date_field datetime_field datetime_local_field
9
+ month_field week_field time_field range_field search_field color_field ).each do |method_name|
10
+ define_method(method_name) do |*args|
11
+ attribute = args[0]
12
+ options = args[1] || {}
13
+ field(attribute, options) do |options|
14
+ super(attribute, options)
15
+ end
16
+ end
17
+ end
18
+
19
+ def label(attribute, text = nil, options = {})
20
+ options[:class] ||= ""
21
+ options[:class] += " error" if has_error?(attribute)
22
+ super(attribute, (text || "").html_safe, options)
23
+ end
24
+
25
+ private
26
+
27
+ def has_error?(attribute)
28
+ object.respond_to?(:errors) && !object.errors[attribute].blank?
29
+ end
30
+
31
+ def error_for(attribute, options = {})
32
+ if has_error?(attribute)
33
+ error_messages = object.errors[attribute].join(', ')
34
+ error_messages = error_messages.html_safe if options[:html_safe_errors]
35
+ content_tag(:span, error_messages, :class => "error help-hint")
36
+ end
37
+ end
38
+
39
+ def error_and_hint(attribute, options = {})
40
+ html = ""
41
+ html += error_for(attribute, options) || ""
42
+ html.html_safe
43
+ end
44
+
45
+ def field(attribute, options, &block)
46
+ html = ''.html_safe
47
+ options[:class] = " error" if has_error?(attribute)
48
+ html += yield(options)
49
+ html += error_and_hint(attribute, options)
50
+ end
51
+ end
52
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: furatto
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.5
4
+ version: 1.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Abraham Kuri Vargas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-20 00:00:00.000000000 Z
11
+ date: 2014-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -68,6 +68,8 @@ files:
68
68
  - lib/furatto.rb
69
69
  - lib/furatto/engine.rb
70
70
  - lib/furatto/version.rb
71
+ - lib/furatto_rails_helpers/action_view_form_builder_extension.rb
72
+ - lib/furatto_rails_helpers/form_builder.rb
71
73
  - lib/furatto_rails_helpers/furatto_helpers.rb
72
74
  - lib/generators/furatto/install_generator.rb
73
75
  - lib/generators/furatto/templates/application.html.erb