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.
@@ -1,150 +0,0 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
- # -*- encoding: utf-8 -*-
5
-
6
- Gem::Specification.new do |s|
7
- s.name = %q{formize}
8
- s.version = "0.0.10"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = [%q{Brice Texier}]
12
- s.date = %q{2011-09-01}
13
- s.description = %q{Like simple_form or formtastic, it aims to handle easily forms but taking in account AJAX and HTML5 on depending fields mainly.}
14
- s.email = %q{brice.texier@ekylibre.org}
15
- s.extra_rdoc_files = [
16
- "LICENSE.txt",
17
- "README.rdoc"
18
- ]
19
- s.files = [
20
- ".document",
21
- ".travis.yml",
22
- "Gemfile",
23
- "LICENSE.txt",
24
- "README.rdoc",
25
- "Rakefile",
26
- "VERSION",
27
- "ci/Gemfile.rails-3.0.x",
28
- "ci/Gemfile.rails-3.1.x",
29
- "formize.gemspec",
30
- "lib/assets/images/ui-bg_flat_0_aaaaaa_40x100.png",
31
- "lib/assets/images/ui-bg_glass_55_fbf9ee_1x400.png",
32
- "lib/assets/images/ui-bg_glass_65_ffffff_1x400.png",
33
- "lib/assets/images/ui-bg_glass_75_dadada_1x400.png",
34
- "lib/assets/images/ui-bg_glass_75_e6e6e6_1x400.png",
35
- "lib/assets/images/ui-bg_glass_75_ffffff_1x400.png",
36
- "lib/assets/images/ui-bg_highlight-soft_75_cccccc_1x100.png",
37
- "lib/assets/images/ui-bg_inset-soft_95_fef1ec_1x100.png",
38
- "lib/assets/images/ui-icons_222222_256x240.png",
39
- "lib/assets/images/ui-icons_2e83ff_256x240.png",
40
- "lib/assets/images/ui-icons_454545_256x240.png",
41
- "lib/assets/images/ui-icons_888888_256x240.png",
42
- "lib/assets/images/ui-icons_cd0a0a_256x240.png",
43
- "lib/assets/javascripts/formize.js",
44
- "lib/assets/javascripts/jquery.ui.formize.js",
45
- "lib/assets/javascripts/locales/jquery.ui.datepicker-af.js",
46
- "lib/assets/javascripts/locales/jquery.ui.datepicker-ar.js",
47
- "lib/assets/javascripts/locales/jquery.ui.datepicker-az.js",
48
- "lib/assets/javascripts/locales/jquery.ui.datepicker-bg.js",
49
- "lib/assets/javascripts/locales/jquery.ui.datepicker-bs.js",
50
- "lib/assets/javascripts/locales/jquery.ui.datepicker-ca.js",
51
- "lib/assets/javascripts/locales/jquery.ui.datepicker-cs.js",
52
- "lib/assets/javascripts/locales/jquery.ui.datepicker-da.js",
53
- "lib/assets/javascripts/locales/jquery.ui.datepicker-de-CH.js",
54
- "lib/assets/javascripts/locales/jquery.ui.datepicker-de.js",
55
- "lib/assets/javascripts/locales/jquery.ui.datepicker-el.js",
56
- "lib/assets/javascripts/locales/jquery.ui.datepicker-en-GB.js",
57
- "lib/assets/javascripts/locales/jquery.ui.datepicker-eo.js",
58
- "lib/assets/javascripts/locales/jquery.ui.datepicker-es.js",
59
- "lib/assets/javascripts/locales/jquery.ui.datepicker-et.js",
60
- "lib/assets/javascripts/locales/jquery.ui.datepicker-eu.js",
61
- "lib/assets/javascripts/locales/jquery.ui.datepicker-fa.js",
62
- "lib/assets/javascripts/locales/jquery.ui.datepicker-fi.js",
63
- "lib/assets/javascripts/locales/jquery.ui.datepicker-fo.js",
64
- "lib/assets/javascripts/locales/jquery.ui.datepicker-fr-CH.js",
65
- "lib/assets/javascripts/locales/jquery.ui.datepicker-fr.js",
66
- "lib/assets/javascripts/locales/jquery.ui.datepicker-he.js",
67
- "lib/assets/javascripts/locales/jquery.ui.datepicker-hr.js",
68
- "lib/assets/javascripts/locales/jquery.ui.datepicker-hu.js",
69
- "lib/assets/javascripts/locales/jquery.ui.datepicker-hy.js",
70
- "lib/assets/javascripts/locales/jquery.ui.datepicker-id.js",
71
- "lib/assets/javascripts/locales/jquery.ui.datepicker-is.js",
72
- "lib/assets/javascripts/locales/jquery.ui.datepicker-it.js",
73
- "lib/assets/javascripts/locales/jquery.ui.datepicker-ja.js",
74
- "lib/assets/javascripts/locales/jquery.ui.datepicker-ko.js",
75
- "lib/assets/javascripts/locales/jquery.ui.datepicker-lt.js",
76
- "lib/assets/javascripts/locales/jquery.ui.datepicker-lv.js",
77
- "lib/assets/javascripts/locales/jquery.ui.datepicker-ms.js",
78
- "lib/assets/javascripts/locales/jquery.ui.datepicker-nl-BE.js",
79
- "lib/assets/javascripts/locales/jquery.ui.datepicker-nl.js",
80
- "lib/assets/javascripts/locales/jquery.ui.datepicker-no.js",
81
- "lib/assets/javascripts/locales/jquery.ui.datepicker-pl.js",
82
- "lib/assets/javascripts/locales/jquery.ui.datepicker-pt-BR.js",
83
- "lib/assets/javascripts/locales/jquery.ui.datepicker-ro.js",
84
- "lib/assets/javascripts/locales/jquery.ui.datepicker-ru.js",
85
- "lib/assets/javascripts/locales/jquery.ui.datepicker-sk.js",
86
- "lib/assets/javascripts/locales/jquery.ui.datepicker-sl.js",
87
- "lib/assets/javascripts/locales/jquery.ui.datepicker-sq.js",
88
- "lib/assets/javascripts/locales/jquery.ui.datepicker-sr-SR.js",
89
- "lib/assets/javascripts/locales/jquery.ui.datepicker-sr.js",
90
- "lib/assets/javascripts/locales/jquery.ui.datepicker-sv.js",
91
- "lib/assets/javascripts/locales/jquery.ui.datepicker-ta.js",
92
- "lib/assets/javascripts/locales/jquery.ui.datepicker-th.js",
93
- "lib/assets/javascripts/locales/jquery.ui.datepicker-tr.js",
94
- "lib/assets/javascripts/locales/jquery.ui.datepicker-uk.js",
95
- "lib/assets/javascripts/locales/jquery.ui.datepicker-vi.js",
96
- "lib/assets/javascripts/locales/jquery.ui.datepicker-zh-CN.js",
97
- "lib/assets/javascripts/locales/jquery.ui.datepicker-zh-HK.js",
98
- "lib/assets/javascripts/locales/jquery.ui.datepicker-zh-TW.js",
99
- "lib/assets/stylesheets/formize.css",
100
- "lib/assets/stylesheets/jquery-ui.css",
101
- "lib/formize.rb",
102
- "lib/formize/action_pack.rb",
103
- "lib/formize/definition.rb",
104
- "lib/formize/definition/element.rb",
105
- "lib/formize/definition/field.rb",
106
- "lib/formize/definition/field_set.rb",
107
- "lib/formize/definition/form.rb",
108
- "lib/formize/definition/form_element.rb",
109
- "lib/formize/form_helper.rb",
110
- "lib/formize/generator.rb",
111
- "lib/generators/formize/install/USAGE",
112
- "lib/generators/formize/install/install_generator.rb",
113
- "lib/generators/formize/install/templates/initializer.rb",
114
- "test/helper.rb",
115
- "test/test_formize.rb"
116
- ]
117
- s.homepage = %q{http://github.com/burisu/formize}
118
- s.licenses = [%q{MIT}]
119
- s.require_paths = [%q{lib}]
120
- s.rubygems_version = %q{1.8.6}
121
- s.summary = %q{Simple form DSL with dynamic interactions for Rails}
122
-
123
- if s.respond_to? :specification_version then
124
- s.specification_version = 3
125
-
126
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
127
- s.add_runtime_dependency(%q<rails>, ["~> 3"])
128
- s.add_runtime_dependency(%q<jquery-rails>, [">= 0"])
129
- s.add_runtime_dependency(%q<fastercsv>, [">= 0"])
130
- s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
131
- s.add_development_dependency(%q<rcov>, [">= 0"])
132
- s.add_development_dependency(%q<rdoc>, [">= 2.4.2"])
133
- else
134
- s.add_dependency(%q<rails>, ["~> 3"])
135
- s.add_dependency(%q<jquery-rails>, [">= 0"])
136
- s.add_dependency(%q<fastercsv>, [">= 0"])
137
- s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
138
- s.add_dependency(%q<rcov>, [">= 0"])
139
- s.add_dependency(%q<rdoc>, [">= 2.4.2"])
140
- end
141
- else
142
- s.add_dependency(%q<rails>, ["~> 3"])
143
- s.add_dependency(%q<jquery-rails>, [">= 0"])
144
- s.add_dependency(%q<fastercsv>, [">= 0"])
145
- s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
146
- s.add_dependency(%q<rcov>, [">= 0"])
147
- s.add_dependency(%q<rdoc>, [">= 2.4.2"])
148
- end
149
- end
150
-
@@ -1,56 +0,0 @@
1
- module Formize
2
-
3
- # Main class for Form definitions
4
- # It permits to manage tree of form elements
5
- class Element
6
- attr_reader :parent, :children, :method_name, :id
7
- @@count = 0
8
-
9
- def initialize(parent = nil, is_method = false)
10
- @parent = parent
11
- @children = []
12
- @is_method = is_method
13
- @@count += 1
14
- @id = @@count.to_s(36)
15
- @method_name = "_formize_#{@id}"
16
- end
17
-
18
- def is_method?
19
- @is_method
20
- end
21
-
22
- def is_method!(value = true)
23
- raise ArgumentError.new("Must be true or false (not #{value.inspect})") unless [TrueClass, FalseClass].include?(value.class)
24
- @is_method = value
25
- end
26
-
27
- def method_name=(name)
28
- raise ArgumentError.new("Name of field_set must be written only with a-z and 0-9 and _ (not #{name.inspect})") unless name.to_s == name.to_s.downcase.gsub(/[^a-z0-9\_]/, '')
29
- @method_name = name
30
- end
31
-
32
-
33
- def method_code(options={})
34
- varh = options[:html_variable] ||= 'html'
35
- code = "def #{method_name}(record)\n"
36
- code << inner_method_code(options).gsub(/^/, ' ')
37
- code << " return #{varh}\n"
38
- code << "end\n"
39
- return code
40
- end
41
-
42
- def method_call_code(options={})
43
- return inner_method_code(options) unless self.is_method?
44
- return "#{method_name}(record)"
45
- end
46
-
47
- def inner_method_code(options={})
48
- # raise NotImplementedError.new
49
- return content_tag(:strong, "'#{self.class.name} does not implement :#{__method__} method'", options)
50
- end
51
-
52
-
53
- end
54
-
55
-
56
- end
@@ -1,150 +0,0 @@
1
- module Formize
2
- module FormHelper
3
-
4
- # Code picked from Justin French's formtastic gem
5
- FIELD_ERROR_PROC = proc do |html_tag, instance_tag|
6
- html_tag
7
- end
8
-
9
- def with_custom_field_error_proc(&block)
10
- default_field_error_proc = ::ActionView::Base.field_error_proc
11
- ::ActionView::Base.field_error_proc = FIELD_ERROR_PROC
12
- yield
13
- ensure
14
- ::ActionView::Base.field_error_proc = default_field_error_proc
15
- end
16
-
17
-
18
-
19
- # Include all stylesheets, javascripts and locales
20
- # For Rails 3.0, not needed in Rails 3.1
21
- def formize_include_tag(options={})
22
- options[:locale] ||= I18n.locale
23
- html = ""
24
- html << javascript_include_tag('jquery.ui.formize')
25
- html << javascript_include_tag('locales/jquery.ui.datepicker-' + locale.to_s)
26
- html << javascript_include_tag('formize')
27
- html << stylesheet_link_tag('jquery-ui')
28
- html << stylesheet_link_tag('formize') unless options[:skip_stylesheet]
29
- return html.html_safe
30
- end
31
-
32
- # Generates a form with all its fields as defined in controller.
33
- # If no name is given, it uses the name of the controller to find the corresponding model
34
- def formize_form(*args)
35
- name, options = nil, {}
36
- name = args[0] if args[0].is_a? Symbol
37
- options = args[-1] if args[-1].is_a? Hash
38
- self.send("_#{options[:controller]||self.controller_name}_#{__method__}_#{name||self.controller_name}_tag")
39
- end
40
-
41
- # Generates all the fields as defined in controller with the <form> tag.
42
- # If no name is given, it uses the name of the controller to find the corresponding model
43
- def formize_fields(*args)
44
- name, options = nil, {}
45
- name = args[0] if args[0].is_a? Symbol
46
- options = args[-1] if args[-1].is_a? Hash
47
- self.send("_#{options[:controller]||self.controller_name}_#{__method__}_#{name||self.controller_name}_tag")
48
- end
49
-
50
- # Permits to use content_tag in helpers with easy add
51
- def hard_content_tag(name, options={}, escape=true, &block)
52
- content = ''
53
- yield content
54
- return content_tag(name, content.html_safe, options, escape)
55
- end
56
-
57
- # Permits to create a submit button well named for the given record
58
- def submit_for(record, value=nil, options={})
59
- value, options = nil, value if value.is_a?(Hash)
60
- 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)
61
- submit_tag(value, options.reverse_merge(:id => "#{record.class.name.underscore}_submit"))
62
- end
63
-
64
- # Returns a list of radio buttons for specified attribute (identified by +method+)
65
- # on an object assigned to the template (identified by +object_name+). It works like +select+
66
- def radio(object_name, method, choices, options = {}, html_options = {})
67
- html = ""
68
- html_options[:class] ||= :rad
69
- for choice in choices
70
- 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)
71
- end
72
- return html
73
- end
74
-
75
- # Returns a text field which has the same behavior of +select+ but with a search
76
- # action which permits to find easily in very long lists...
77
- def unroll(object_name, method, choices, options = {}, input_options={}, html_options = {})
78
- object = instance_variable_get("@#{object_name}")
79
- label = options[:label]
80
- if label.is_a?(String) or label.is_a?(Symbol)
81
- label = Proc.new{|x| x.send(label)}
82
- elsif !label.is_a?(Proc)
83
- label = Proc.new{|x| x.inspect}
84
- end
85
- html = ""
86
- html << hidden_field(object_name, method, input_options)
87
- 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)
88
- return content_tag(:span, html.html_safe, html_options)
89
- end
90
-
91
-
92
- # Returns a text field for selecting a Date with a hidden field containing
93
- # the well formatted date
94
- # Options are:
95
- # - +:format+: If +format+ is a +String+ it specify date format using a little subset of strftime options
96
- # %d, %j, %a, %A, %m, %b, %B, %y and %Y
97
- # else if +format+ is a +Symbol+ it uses I18n to find format
98
- def date_field(object_name, method, options = {})
99
- object = instance_variable_get("@#{object_name}")
100
- format = options[:format]||:default
101
- raise ArgumentError.new("Option :format must be a Symbol referencing a translation 'date.formats.<format>'")unless format.is_a?(Symbol)
102
- if localized_value = object.send(method)
103
- localized_value = I18n.localize(localized_value, :format=>format)
104
- end
105
- format = I18n.translate('date.formats.'+format.to_s)
106
- conv = {
107
- 'dd' => '%d',
108
- 'oo' => '%j',
109
- 'D' => '%a',
110
- 'DD' => '%A',
111
- 'mm' => '%m',
112
- 'M' => '%b',
113
- 'MM' => '%B',
114
- 'y' => '%y',
115
- 'yy' => '%Y'
116
- }
117
- conv.each{|js, rb| format.gsub!(rb, js)}
118
- html = ""
119
- html << hidden_field(object_name, method)
120
- 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)
121
- return html
122
- end
123
-
124
-
125
- # Returns a text field for selecting a Date with hour
126
- # with a hidden field containing the well formatted datetime
127
- def datetime_field(object_name, method, options = {})
128
- object = instance_variable_get("@#{object_name}")
129
- html = ""
130
- html << hidden_field(object_name, method)
131
- html << tag(:input, :type=>:text, "data-datepicker"=>"#{object_name}_#{method}", :size=>options.delete(:size)||10)
132
- return html
133
- end
134
-
135
-
136
- # Returns a text area which can be resized in the south-east corner
137
- # Works exactly the same as +textarea+
138
- def resizable_text_area(object_name, method, options = {})
139
- # options["data-resize-in"] = "ri"+rand.to_s[2..-1].to_i.to_s(36)
140
- # return content_tag(:div, text_area(object_name, method, options), :id=>options["data-resize-in"])
141
- options["data-resizable"] = "true"
142
- return text_area(object_name, method, options)
143
- end
144
-
145
-
146
- end
147
-
148
- end
149
-
150
- ActionView::Base.send :include, Formize::FormHelper
@@ -1,9 +0,0 @@
1
- require 'rubygems'
2
- require 'test/unit'
3
-
4
- $LOAD_PATH.unshift(File.dirname(__FILE__))
5
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
- require 'formize'
7
-
8
- class Test::Unit::TestCase
9
- end
@@ -1,9 +0,0 @@
1
- require 'helper'
2
-
3
- class TestFormize < Test::Unit::TestCase
4
- def test_configuration
5
- assert_not_nil Formize.default_source
6
- assert_not_nil Formize.radio_count_max
7
- assert_not_nil Formize.select_count_max
8
- end
9
- end