formize 0.0.14 → 0.0.17

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. data/VERSION +1 -1
  2. data/lib/assets/javascripts/formize.js +100 -21
  3. data/lib/assets/javascripts/jquery.ui.formize.js +292 -231
  4. data/lib/assets/javascripts/jquery.ui.timepicker.js +1060 -0
  5. data/lib/assets/javascripts/locales/jquery.ui.datepicker-ar.js +18 -18
  6. data/lib/assets/javascripts/locales/jquery.ui.datepicker-fa.js +18 -18
  7. data/lib/assets/javascripts/locales/jquery.ui.datepicker-fr-CH.js +6 -6
  8. data/lib/assets/javascripts/locales/jquery.ui.datepicker-fr.js +1 -1
  9. data/lib/assets/javascripts/locales/jquery.ui.timepicker-cs.js +17 -0
  10. data/lib/assets/javascripts/locales/jquery.ui.timepicker-de.js +17 -0
  11. data/lib/assets/javascripts/locales/jquery.ui.timepicker-el.js +17 -0
  12. data/lib/assets/javascripts/locales/jquery.ui.timepicker-es.js +17 -0
  13. data/lib/assets/javascripts/locales/jquery.ui.timepicker-et.js +17 -0
  14. data/lib/assets/javascripts/locales/jquery.ui.timepicker-fr.js +17 -0
  15. data/lib/assets/javascripts/locales/jquery.ui.timepicker-hu.js +17 -0
  16. data/lib/assets/javascripts/locales/jquery.ui.timepicker-id.js +17 -0
  17. data/lib/assets/javascripts/locales/jquery.ui.timepicker-it.js +17 -0
  18. data/lib/assets/javascripts/locales/jquery.ui.timepicker-lt.js +17 -0
  19. data/lib/assets/javascripts/locales/jquery.ui.timepicker-nl.js +17 -0
  20. data/lib/assets/javascripts/locales/jquery.ui.timepicker-ru.js +17 -0
  21. data/lib/assets/javascripts/locales/jquery.ui.timepicker-tr.js +17 -0
  22. data/lib/assets/javascripts/locales/jquery.ui.timepicker-vi.js +17 -0
  23. data/lib/assets/stylesheets/jquery-ui.css +19 -1
  24. data/lib/formize.rb +63 -0
  25. data/lib/formize/helpers.rb +21 -0
  26. data/lib/formize/helpers/asset_tag_helper.rb +11 -7
  27. data/lib/formize/helpers/form_helper.rb +6 -19
  28. data/lib/formize/helpers/form_tag_helper.rb +31 -0
  29. data/lib/formize/railtie.rb +1 -0
  30. data/lib/generators/formize/install/install_generator.rb +5 -5
  31. data/lib/tasks/formize.rake +27 -0
  32. metadata +34 -14
@@ -1,8 +1,29 @@
1
1
  module Formize
2
+ DATE_FORMAT_TOKENS = {
3
+ 'dd' => '%d',
4
+ 'oo' => '%j',
5
+ 'D' => '%a',
6
+ 'DD' => '%A',
7
+ 'mm' => '%m',
8
+ 'M' => '%b',
9
+ 'MM' => '%B',
10
+ 'y' => '%y',
11
+ 'yy' => '%Y'
12
+ }.freeze
13
+ TIME_FORMAT_TOKENS = {
14
+ 'hh' => '%H',
15
+ 'mm' => '%M',
16
+ 'ss' => '%S',
17
+ 'tt' => '%p',
18
+ 'TT' => '%P'
19
+ }.freeze
20
+
21
+
2
22
  # @private
3
23
  module Helpers
4
24
  autoload :AssetTagHelper, 'formize/helpers/asset_tag_helper'
5
25
  autoload :TagHelper, 'formize/helpers/tag_helper'
6
26
  autoload :FormHelper, 'formize/helpers/form_helper'
27
+ autoload :FormTagHelper, 'formize/helpers/form_tag_helper'
7
28
  end
8
29
  end
@@ -19,16 +19,21 @@ module Formize
19
19
  # @option options [TrueClass, FalseClass] :skip_stylesheet
20
20
  # Skip the inclusion of default stylesheet: formize.css
21
21
  #
22
- # @option options [TrueClass, FalseClass] :with_formize
23
- # Include main javascript formize.js
22
+ # @option options [TrueClass, FalseClass] :monolithic
23
+ # If +true+ includes a monolithic javascript formize.js else include
24
+ # choosen specific javascripts with little weight.
24
25
  #
25
- # @deprecated
26
+ # @deprecated Will be removed when rails <= 3.0 support won't be effective in
27
+ # versions >= 0.1.0
26
28
  def formize_include_tag(options={})
27
29
  options[:locale] ||= ::I18n.locale
28
30
  html = ""
29
- html << javascript_include_tag('jquery.ui.formize') if options[:special_ui]
30
- html << javascript_include_tag('locales/jquery.ui.datepicker-' + locale.to_s)
31
- html << javascript_include_tag('formize') if options[:with_formize]
31
+ if options[:monolithic]
32
+ html << javascript_include_tag('formize')
33
+ else
34
+ html << javascript_include_tag('jquery.ui.formize')
35
+ html << javascript_include_tag('locales/jquery.ui.datepicker-' + locale.to_s)
36
+ end
32
37
  unless options[:skip_stylesheet]
33
38
  html << stylesheet_link_tag('jquery-ui')
34
39
  html << stylesheet_link_tag('formize')
@@ -36,7 +41,6 @@ module Formize
36
41
  return html.html_safe
37
42
  end
38
43
 
39
-
40
44
  end
41
45
  end
42
46
  end
@@ -88,18 +88,7 @@ module Formize
88
88
  localized_value = I18n.localize(localized_value, :format=>format)
89
89
  end
90
90
  format = I18n.translate('date.formats.'+format.to_s)
91
- conv = {
92
- 'dd' => '%d',
93
- 'oo' => '%j',
94
- 'D' => '%a',
95
- 'DD' => '%A',
96
- 'mm' => '%m',
97
- 'M' => '%b',
98
- 'MM' => '%B',
99
- 'y' => '%y',
100
- 'yy' => '%Y'
101
- }
102
- conv.each{|js, rb| format.gsub!(rb, js)}
91
+ Formize::DATE_FORMAT_TOKENS.each{|js, rb| format.gsub!(rb, js)}
103
92
  html = ""
104
93
  html << hidden_field(object_name, method)
105
94
  html << tag(:input, :type=>:text, "data-datepicker"=>"#{object_name}_#{method}", "data-date-format"=>format, :value=>localized_value, "data-locale"=>::I18n.locale, :size=>options.delete(:size)||10)
@@ -107,14 +96,12 @@ module Formize
107
96
  end
108
97
 
109
98
 
110
- # Returns a text field for selecting a Date with hour
111
- # with a hidden field containing the well formatted datetime
99
+ # Returns a text field with a default placeholder for timestamp
112
100
  def datetime_field(object_name, method, options = {})
113
- object = instance_variable_get("@#{object_name}")
114
- html = ""
115
- html << hidden_field(object_name, method)
116
- html << tag(:input, :type=>:text, "data-datepicker"=>"#{object_name}_#{method}", :size=>options.delete(:size)||10)
117
- return html
101
+ default = {}
102
+ default[:placeholder] = I18n.translate!('time.placeholder') rescue nil
103
+ default[:size] ||= 24
104
+ return text_field(object_name, method, default.merge(options))
118
105
  end
119
106
 
120
107
 
@@ -0,0 +1,31 @@
1
+ module Formize
2
+ module Helpers
3
+ module FormTagHelper
4
+
5
+
6
+ def date_field_tag(name, value=nil, options={})
7
+ format = options[:format]||:default
8
+ raise ArgumentError.new("Option :format must be a Symbol referencing a translation 'date.formats.<format>'")unless format.is_a?(Symbol)
9
+ unless (localized_value = value).nil?
10
+ localized_value = I18n.localize(localized_value, :format=>format)
11
+ end
12
+ format = I18n.translate('date.formats.'+format.to_s)
13
+ Formize::DATE_FORMAT_TOKENS.each{|js, rb| format.gsub!(rb, js)}
14
+ html = ""
15
+ html << hidden_field_tag(name, value.to_s(:db))
16
+ html << tag(:input, :type=>:text, "data-datepicker"=>name, "data-date-format"=>format, :value=>localized_value, "data-locale"=>::I18n.locale, :size=>options.delete(:size)||10)
17
+ return html.html_safe
18
+ end
19
+
20
+ # Returns a text field with a default placeholder for timestamp
21
+ def datetime_field_tag(name, value=nil, options={})
22
+ default = {}
23
+ default[:placeholder] = I18n.translate!('time.placeholder') rescue nil
24
+ default[:size] ||= 24
25
+ return text_field_tag(name, value, default.merge(options))
26
+ end
27
+
28
+
29
+ end
30
+ end
31
+ end
@@ -8,6 +8,7 @@ module Formize
8
8
  include Formize::Helpers::AssetTagHelper
9
9
  include Formize::Helpers::TagHelper
10
10
  include Formize::Helpers::FormHelper
11
+ include Formize::Helpers::FormTagHelper
11
12
  end
12
13
  ActiveSupport.on_load(:action_controller) do
13
14
  include Formize::ActionController
@@ -4,7 +4,7 @@ module Formize
4
4
 
5
5
  class InstallGenerator < ::Rails::Generators::Base
6
6
  source_root File.expand_path('../templates', __FILE__)
7
- class_option :no_ui, :type => :boolean, :default => false, :desc => "Do not include special jQuery-UI JavaScripts"
7
+ # class_option :no_ui, :type => :boolean, :default => false, :desc => "Do not include special jQuery-UI JavaScripts"
8
8
  class_option :no_locales, :type => :boolean, :default => false, :desc => "Do not include locales for jQuery-UI date picker"
9
9
  class_option :no_stylesheet, :type => :boolean, :default => false, :desc => "Do not include stylesheet of jQuery-UI"
10
10
 
@@ -12,12 +12,12 @@ module Formize
12
12
  def copy_assets
13
13
  copy_file '../../../../assets/javascripts/formize.js', 'public/javascripts/formize.js'
14
14
 
15
- unless options[:no_ui]
16
- copy_file '../../../../assets/javascripts/jquery.ui.formize.js', 'public/javascripts/jquery.ui.formize.js'
17
- end
15
+ # unless options[:no_ui]
16
+ copy_file '../../../../assets/javascripts/jquery.ui.formize.js', 'public/javascripts/jquery.ui.formize.js'
17
+ # end
18
18
 
19
19
  unless options[:no_locales]
20
- for locale in Dir.glob(File.expand_path('../../../../assets/javascripts/locales/*.js', __FILE__))
20
+ for locale in Dir.glob(File.expand_path('../../../../assets/javascripts/locales/*datepicker*.js', __FILE__))
21
21
  file = locale.split(/[\\\/]+/)[-1]
22
22
  copy_file "../../../../assets/javascripts/locales/#{file}", "public/javascripts/locales/#{file}"
23
23
  end
@@ -0,0 +1,27 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+
11
+ require 'active_support'
12
+ require 'action_pack'
13
+ require 'action_view'
14
+ require 'action_controller'
15
+ require 'action_dispatch'
16
+
17
+ # $LOAD_PATH.unshift(File.dirname(__FILE__))
18
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
19
+
20
+ require 'formize'
21
+
22
+ namespace :formize do
23
+ desc "Generate formize.js"
24
+ task :compile do
25
+ Formize.compile!
26
+ end
27
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: formize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.14
4
+ version: 0.0.17
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-15 00:00:00.000000000Z
12
+ date: 2011-09-16 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &17846020 !ruby/object:Gem::Requirement
16
+ requirement: &19944640 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '3'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *17846020
24
+ version_requirements: *19944640
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: jquery-rails
27
- requirement: &17844600 !ruby/object:Gem::Requirement
27
+ requirement: &19942320 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *17844600
35
+ version_requirements: *19942320
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: fastercsv
38
- requirement: &17843480 !ruby/object:Gem::Requirement
38
+ requirement: &19940700 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *17843480
46
+ version_requirements: *19940700
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: jeweler
49
- requirement: &17841520 !ruby/object:Gem::Requirement
49
+ requirement: &19939820 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.6.4
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *17841520
57
+ version_requirements: *19939820
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rcov
60
- requirement: &17839740 !ruby/object:Gem::Requirement
60
+ requirement: &19939180 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *17839740
68
+ version_requirements: *19939180
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rdoc
71
- requirement: &17826960 !ruby/object:Gem::Requirement
71
+ requirement: &19938520 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: 2.4.2
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *17826960
79
+ version_requirements: *19938520
80
80
  description: Like simple_form or formtastic, it aims to handle easily forms but taking
81
81
  in account AJAX and HTML5 on depending fields mainly.
82
82
  email: brice.texier@ekylibre.org
@@ -104,6 +104,7 @@ files:
104
104
  - lib/assets/images/ui-icons_cd0a0a_256x240.png
105
105
  - lib/assets/javascripts/formize.js
106
106
  - lib/assets/javascripts/jquery.ui.formize.js
107
+ - lib/assets/javascripts/jquery.ui.timepicker.js
107
108
  - lib/assets/javascripts/locales/jquery.ui.datepicker-af.js
108
109
  - lib/assets/javascripts/locales/jquery.ui.datepicker-ar.js
109
110
  - lib/assets/javascripts/locales/jquery.ui.datepicker-az.js
@@ -158,6 +159,20 @@ files:
158
159
  - lib/assets/javascripts/locales/jquery.ui.datepicker-zh-CN.js
159
160
  - lib/assets/javascripts/locales/jquery.ui.datepicker-zh-HK.js
160
161
  - lib/assets/javascripts/locales/jquery.ui.datepicker-zh-TW.js
162
+ - lib/assets/javascripts/locales/jquery.ui.timepicker-cs.js
163
+ - lib/assets/javascripts/locales/jquery.ui.timepicker-de.js
164
+ - lib/assets/javascripts/locales/jquery.ui.timepicker-el.js
165
+ - lib/assets/javascripts/locales/jquery.ui.timepicker-es.js
166
+ - lib/assets/javascripts/locales/jquery.ui.timepicker-et.js
167
+ - lib/assets/javascripts/locales/jquery.ui.timepicker-fr.js
168
+ - lib/assets/javascripts/locales/jquery.ui.timepicker-hu.js
169
+ - lib/assets/javascripts/locales/jquery.ui.timepicker-id.js
170
+ - lib/assets/javascripts/locales/jquery.ui.timepicker-it.js
171
+ - lib/assets/javascripts/locales/jquery.ui.timepicker-lt.js
172
+ - lib/assets/javascripts/locales/jquery.ui.timepicker-nl.js
173
+ - lib/assets/javascripts/locales/jquery.ui.timepicker-ru.js
174
+ - lib/assets/javascripts/locales/jquery.ui.timepicker-tr.js
175
+ - lib/assets/javascripts/locales/jquery.ui.timepicker-vi.js
161
176
  - lib/assets/stylesheets/formize.css
162
177
  - lib/assets/stylesheets/jquery-ui.css
163
178
  - lib/formize.rb
@@ -172,11 +187,13 @@ files:
172
187
  - lib/formize/helpers.rb
173
188
  - lib/formize/helpers/asset_tag_helper.rb
174
189
  - lib/formize/helpers/form_helper.rb
190
+ - lib/formize/helpers/form_tag_helper.rb
175
191
  - lib/formize/helpers/tag_helper.rb
176
192
  - lib/formize/railtie.rb
177
193
  - lib/generators/formize/install/USAGE
178
194
  - lib/generators/formize/install/install_generator.rb
179
195
  - lib/generators/formize/install/templates/initializer.rb
196
+ - lib/tasks/formize.rake
180
197
  homepage: http://github.com/burisu/formize
181
198
  licenses:
182
199
  - MIT
@@ -190,6 +207,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
190
207
  - - ! '>='
191
208
  - !ruby/object:Gem::Version
192
209
  version: '0'
210
+ segments:
211
+ - 0
212
+ hash: 4502632806187008995
193
213
  required_rubygems_version: !ruby/object:Gem::Requirement
194
214
  none: false
195
215
  requirements: