formize 0.0.10 → 0.0.11

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.
@@ -0,0 +1,8 @@
1
+ module Formize
2
+ # @private
3
+ module Helpers
4
+ autoload :AssetTagHelper, 'formize/helpers/asset_tag_helper'
5
+ autoload :TagHelper, 'formize/helpers/tag_helper'
6
+ autoload :FormHelper, 'formize/helpers/form_helper'
7
+ end
8
+ end
@@ -0,0 +1,33 @@
1
+ module Formize
2
+ module Helpers
3
+ module AssetTagHelper
4
+
5
+ # Include all stylesheets, javascripts and locales.
6
+ # For Rails 3.0 only, not needed since Rails 3.1.
7
+ #
8
+ # @example Classic use
9
+ # <%= formize_include_tag -%>
10
+ #
11
+ # @example Classic use with a specified locale
12
+ # <%= formize_include_tag :locale=>:jp -%>
13
+ #
14
+ # @option options [Symbol, String] :locale
15
+ # Select locale file to use for jQuery UI datepickers. The locale must be specified using 2 or 5 characters, like `:en` or `"en-GB"`. By default, `I18n.locale` is used to determine the current locale.
16
+ #
17
+ # @option options [TrueClass, FalseClass] :skip_stylesheet
18
+ # Skip the inclusion of default stylesheet: formize.css
19
+ def formize_include_tag(options={})
20
+ options[:locale] ||= ::I18n.locale
21
+ html = ""
22
+ html << javascript_include_tag('jquery.ui.formize')
23
+ html << javascript_include_tag('locales/jquery.ui.datepicker-' + locale.to_s)
24
+ html << javascript_include_tag('formize')
25
+ html << stylesheet_link_tag('jquery-ui')
26
+ html << stylesheet_link_tag('formize') unless options[:skip_stylesheet]
27
+ return html.html_safe
28
+ end
29
+
30
+
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,131 @@
1
+ module Formize
2
+ module Helpers
3
+ module FormHelper
4
+
5
+ # Code picked from Justin French's formtastic gem
6
+ FIELD_ERROR_PROC = proc do |html_tag, instance_tag| # :nodoc:
7
+ html_tag
8
+ end
9
+
10
+ def with_custom_field_error_proc(&block) # :nodoc:
11
+ default_field_error_proc = ::ActionView::Base.field_error_proc
12
+ ::ActionView::Base.field_error_proc = FIELD_ERROR_PROC
13
+ yield
14
+ ensure
15
+ ::ActionView::Base.field_error_proc = default_field_error_proc
16
+ end
17
+
18
+ # Generates a form with all its fields as defined in controller.
19
+ # If no name is given, it uses the name of the controller to find the corresponding model
20
+ def formize_form(*args)
21
+ name, options = nil, {}
22
+ name = args[0] if args[0].is_a? Symbol
23
+ options = args[-1] if args[-1].is_a? Hash
24
+ self.send("_#{options[:controller]||self.controller_name}_#{__method__}_#{name||self.controller_name}_tag")
25
+ end
26
+
27
+ # Generates all the fields as defined in controller with the <form> tag.
28
+ # If no name is given, it uses the name of the controller to find the corresponding model
29
+ def formize_fields(*args)
30
+ name, options = nil, {}
31
+ name = args[0] if args[0].is_a? Symbol
32
+ options = args[-1] if args[-1].is_a? Hash
33
+ self.send("_#{options[:controller]||self.controller_name}_#{__method__}_#{name||self.controller_name}_tag")
34
+ end
35
+
36
+ # Permits to create a submit button well named for the given record
37
+ def submit_for(record, value=nil, options={})
38
+ value, options = nil, value if value.is_a?(Hash)
39
+ value ||= ::I18n.translate("helpers.submit.#{record.new_record? ? 'create' : 'update'}", :model=>record.class.model_name.human, :record=>record.class.model_name.human.mb_chars.downcase)
40
+ submit_tag(value, options.reverse_merge(:id => "#{record.class.name.underscore}_submit"))
41
+ end
42
+
43
+ # Returns a list of radio buttons for specified attribute (identified by +method+)
44
+ # on an object assigned to the template (identified by +object_name+). It works like +select+
45
+ def radio(object_name, method, choices, options = {}, html_options = {})
46
+ html = ""
47
+ html_options[:class] ||= :rad
48
+ for choice in choices
49
+ html << content_tag(:span, radio_button(object_name, method, choice[1]) + '&nbsp;'.html_safe + label(object_name, method, choice[0], :value=>choice[1]), html_options)
50
+ end
51
+ return html
52
+ end
53
+
54
+ # Returns a text field which has the same behavior of +select+ but with a search
55
+ # action which permits to find easily in very long lists...
56
+ def unroll(object_name, method, choices, options = {}, input_options={}, html_options = {})
57
+ object = instance_variable_get("@#{object_name}")
58
+ label = options[:label]
59
+ if label.is_a?(String) or label.is_a?(Symbol)
60
+ label = Proc.new{|x| x.send(label)}
61
+ elsif !label.is_a?(Proc)
62
+ label = Proc.new{|x| x.inspect}
63
+ end
64
+ html = ""
65
+ html << hidden_field(object_name, method, input_options)
66
+ html << tag(:input, :type=>:text, "data-unroll"=>url_for(choices.merge(:format=>:json)), "data-value-container"=>"#{object_name}_#{method}", :value=>label.call(object.send(method.to_s.gsub(/_id$/, ''))), :size=>html_options.delete(:size)||32)
67
+ return content_tag(:span, html.html_safe, html_options)
68
+ end
69
+
70
+
71
+ # Returns a text field for selecting a Date with a hidden field containing
72
+ # the well formatted date
73
+ #
74
+ # @example Set a date field
75
+ # <%= date_field :post, :published_on -%>
76
+ # # => <input type="hidden" id="post_published_on" name="post[published_on]" value="#{@post.published_on}"/>
77
+ # # <input type="text" data-datepicker="post_published_on" data-date_format="<jQuery_format>" value="<formatted_date>" data-locale="#{I18n.locale}" size="10"/>
78
+ #
79
+ # @option options [Symbol] :format
80
+ # Select date format used in visible text field. The format must be defined in locale files. To maintain compatibility with jQuery only few tokens can be used to compose the format: `%d`, `%j`, `%a`, `%A`, `%m`, `%b`, `%B`, `%y` and `%Y`
81
+ # @option options [Integer] :size
82
+ # Set the size of the visible text field
83
+ def date_field(object_name, method, options = {})
84
+ object = instance_variable_get("@#{object_name}")
85
+ format = options[:format]||:default
86
+ raise ArgumentError.new("Option :format must be a Symbol referencing a translation 'date.formats.<format>'")unless format.is_a?(Symbol)
87
+ if localized_value = object.send(method)
88
+ localized_value = I18n.localize(localized_value, :format=>format)
89
+ end
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)}
103
+ html = ""
104
+ html << hidden_field(object_name, method)
105
+ 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)
106
+ return html
107
+ end
108
+
109
+
110
+ # Returns a text field for selecting a Date with hour
111
+ # with a hidden field containing the well formatted datetime
112
+ 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
118
+ end
119
+
120
+
121
+ # Returns a text area which can be resized in the south-east corner
122
+ # Works exactly the same as +textarea+
123
+ def resizable_text_area(object_name, method, options = {})
124
+ options["data-resizable"] = "true"
125
+ return text_area(object_name, method, options)
126
+ end
127
+
128
+
129
+ end
130
+ end
131
+ end
@@ -0,0 +1,14 @@
1
+ module Formize
2
+ module Helpers
3
+ module TagHelper
4
+
5
+ # Permits to use content_tag in helpers using string concatenation
6
+ def hard_content_tag(name, options={}, escape=true, &block)
7
+ content = ''
8
+ yield content
9
+ return content_tag(name, content.html_safe, options, escape)
10
+ end
11
+
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,17 @@
1
+ # encoding: utf-8
2
+
3
+ module Formize
4
+ # @private
5
+ class Railtie < Rails::Railtie
6
+ initializer 'formize.initialize' do
7
+ ActiveSupport.on_load(:action_view) do
8
+ include Formize::Helpers::AssetTagHelper
9
+ include Formize::Helpers::TagHelper
10
+ include Formize::Helpers::FormHelper
11
+ end
12
+ ActiveSupport.on_load(:action_controller) do
13
+ include Formize::ActionController
14
+ end
15
+ end
16
+ end
17
+ 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.10
4
+ version: 0.0.11
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-01 00:00:00.000000000Z
12
+ date: 2011-09-02 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &18150100 !ruby/object:Gem::Requirement
16
+ requirement: &20533840 !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: *18150100
24
+ version_requirements: *20533840
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: jquery-rails
27
- requirement: &18149300 !ruby/object:Gem::Requirement
27
+ requirement: &20526760 !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: *18149300
35
+ version_requirements: *20526760
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: fastercsv
38
- requirement: &18148300 !ruby/object:Gem::Requirement
38
+ requirement: &20523700 !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: *18148300
46
+ version_requirements: *20523700
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: jeweler
49
- requirement: &18147660 !ruby/object:Gem::Requirement
49
+ requirement: &20521280 !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: *18147660
57
+ version_requirements: *20521280
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rcov
60
- requirement: &18147100 !ruby/object:Gem::Requirement
60
+ requirement: &20510960 !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: *18147100
68
+ version_requirements: *20510960
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rdoc
71
- requirement: &18132320 !ruby/object:Gem::Requirement
71
+ requirement: &20509960 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,26 +76,19 @@ dependencies:
76
76
  version: 2.4.2
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *18132320
79
+ version_requirements: *20509960
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
83
83
  executables: []
84
84
  extensions: []
85
85
  extra_rdoc_files:
86
- - LICENSE.txt
87
86
  - README.rdoc
88
87
  files:
89
- - .document
90
- - .travis.yml
91
88
  - Gemfile
92
- - LICENSE.txt
89
+ - MIT-LICENSE
93
90
  - README.rdoc
94
- - Rakefile
95
91
  - VERSION
96
- - ci/Gemfile.rails-3.0.x
97
- - ci/Gemfile.rails-3.1.x
98
- - formize.gemspec
99
92
  - lib/assets/images/ui-bg_flat_0_aaaaaa_40x100.png
100
93
  - lib/assets/images/ui-bg_glass_55_fbf9ee_1x400.png
101
94
  - lib/assets/images/ui-bg_glass_65_ffffff_1x400.png
@@ -168,20 +161,22 @@ files:
168
161
  - lib/assets/stylesheets/formize.css
169
162
  - lib/assets/stylesheets/jquery-ui.css
170
163
  - lib/formize.rb
171
- - lib/formize/action_pack.rb
164
+ - lib/formize/action_controller.rb
172
165
  - lib/formize/definition.rb
173
- - lib/formize/definition/element.rb
174
166
  - lib/formize/definition/field.rb
175
167
  - lib/formize/definition/field_set.rb
176
168
  - lib/formize/definition/form.rb
177
169
  - lib/formize/definition/form_element.rb
178
- - lib/formize/form_helper.rb
170
+ - lib/formize/engine.rb
179
171
  - lib/formize/generator.rb
172
+ - lib/formize/helpers.rb
173
+ - lib/formize/helpers/asset_tag_helper.rb
174
+ - lib/formize/helpers/form_helper.rb
175
+ - lib/formize/helpers/tag_helper.rb
176
+ - lib/formize/railtie.rb
180
177
  - lib/generators/formize/install/USAGE
181
178
  - lib/generators/formize/install/install_generator.rb
182
179
  - lib/generators/formize/install/templates/initializer.rb
183
- - test/helper.rb
184
- - test/test_formize.rb
185
180
  homepage: http://github.com/burisu/formize
186
181
  licenses:
187
182
  - MIT
data/.document DELETED
@@ -1,5 +0,0 @@
1
- lib/**/*.rb
2
- bin/*
3
- -
4
- features/**/*.feature
5
- LICENSE.txt
@@ -1,8 +0,0 @@
1
- rvm:
2
- - 1.8.7
3
- - 1.9.2
4
- - 1.9.3
5
- gemfile:
6
- - ci/Gemfile.rails-3.0.x
7
- - ci/Gemfile.rails-3.1.x
8
- script: "bundle exec rake test"
data/Rakefile DELETED
@@ -1,54 +0,0 @@
1
- # encoding: utf-8
2
- # Used for a bug with ruby 1.9.1
3
- # http://rubyforge.org/tracker/index.php?func=detail&aid=28920&group_id=1513&atid=5921
4
-
5
- require 'rubygems'
6
- unless RUBY_VERSION.to_s.match(/^1\.8/)
7
- require 'psych'
8
- end
9
-
10
- require 'jeweler'
11
- Jeweler::Tasks.new do |gem|
12
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
13
- gem.name = "formize"
14
- gem.homepage = "http://github.com/burisu/formize"
15
- gem.license = "MIT"
16
- gem.summary = "Simple form DSL with dynamic interactions for Rails"
17
- gem.description = "Like simple_form or formtastic, it aims to handle easily forms but taking in account AJAX and HTML5 on depending fields mainly."
18
- gem.email = "brice.texier@ekylibre.org"
19
- gem.authors = ["Brice Texier"]
20
- # dependencies defined in Gemfile
21
- end
22
- Jeweler::RubygemsDotOrgTasks.new
23
-
24
- require 'rake/testtask'
25
- Rake::TestTask.new(:test) do |test|
26
- test.libs << 'lib' << 'test'
27
- test.test_files = Dir.glob("test/**/test_*.rb")
28
- test.verbose = true
29
- end
30
-
31
- require 'rcov/rcovtask'
32
- Rcov::RcovTask.new do |test|
33
- test.libs << 'test'
34
- test.pattern = 'test/**/test_*.rb'
35
- test.verbose = true
36
- test.rcov_opts << '--exclude "gems/*"'
37
- end
38
-
39
- task :default => :test
40
-
41
- gem 'rdoc'
42
- require 'rdoc/task'
43
- RDoc::Task.new do |rdoc|
44
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
45
- rdoc.rdoc_dir = 'rdoc'
46
- rdoc.title = "Formize #{version}"
47
- rdoc.rdoc_files.include('README*')
48
- rdoc.rdoc_files.include('lib/**/*.rb')
49
- end
50
-
51
- # Import all rake files
52
- for rakefile in Dir.glob('lib/tasks/*.rake')
53
- import(rakefile)
54
- end
@@ -1,11 +0,0 @@
1
- source "http://rubygems.org"
2
-
3
- gem "rails", "~> 3.0"
4
- gem "jquery-rails"
5
- gem "fastercsv", :platforms=>[:ruby_18, :mri_18, :mingw_18, :mswin]
6
-
7
- group :development do
8
- gem "jeweler", "~> 1.6.4"
9
- gem "rcov", ">= 0"
10
- gem "rdoc", ">= 2.4.2"
11
- end
@@ -1,11 +0,0 @@
1
- source "http://rubygems.org"
2
-
3
- gem "rails", "~> 3.1"
4
- gem "jquery-rails"
5
- gem "fastercsv", :platforms=>[:ruby_18, :mri_18, :mingw_18, :mswin]
6
-
7
- group :development do
8
- gem "jeweler", "~> 1.6.4"
9
- gem "rcov", ">= 0"
10
- gem "rdoc", ">= 2.4.2"
11
- end