simple_form-dojo 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ OWQ5YmFjNTBlNTZmY2JmN2E3YmRiY2Q1OWFmYWYxMDZjMWU5NWZhNw==
5
+ data.tar.gz: !binary |-
6
+ OWQ0Y2JkMWZmMWFkZDczYmY2YTY4Nzk0NTEyMDM4MDMwM2RiZDM5Yg==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ Njg0NjE1MWFmNDM1NDY2YWMzZjkzMDBkYjEzOTEzOTljNTNiMTdjYmI4OGJh
10
+ M2ZmMzdhMzg4MDljOWI2NWZhNjdlODY3MGIyMWMwNmMyOGNhNmMzZjE3MTQ1
11
+ MzEwNzNlYjkzMjNlNGVlOTM0NmVmMGFiMjg0M2VlNDNhNjVjMjk=
12
+ data.tar.gz: !binary |-
13
+ OTI5NjIzYzYwYmY3NDg2YjRmNzkxNjNiYTIyOGZiNTFiYWY3ZmM5ZGM5Y2Nl
14
+ MzU5MTViNjI5NjI1YmRmYjA0NTcyODI3NjZkMGFhOTVmMDMxMThhMDM3ZDk3
15
+ OGZiODZlYmE0N2ZmNjE2YWJjYTkzMjI0N2I1NDU3MTlmMWZmOTk=
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2011 Patrick Ward
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,90 @@
1
+ # SimpleFormDojo
2
+
3
+ SimpleFormDojo is a collection of helpers for use with [Dojo](http://dojotoolkit.org) and [Rails](http://rubyonrails.org). The goal of the project is to make it simple to create Dijit elements using the existing Rails helper infrastructure.
4
+
5
+ The FormBuilder is currently an extension to the [SimpleForm project](https://github.com/plataformatec/simple_form) from [Plataforma](http://blog.plataformatec.com.br/tag/simple_form).
6
+
7
+ The TabsHelper was inspired by code from CodeOfficer's [JQuery UI Helpers](https://github.com/CodeOfficer/jquery-ui-rails-helpers)
8
+
9
+ ## Requirements
10
+
11
+ SimpleFormDojo is based on Dojo 1.6.0 and uses the newer data-dojo-type and data-dojo-props attributes in order to be more compliant with HTML 5. It is being developed against the latest version of Rails (currently 3.0.5).
12
+
13
+ I don't include the 1.6 dojo toolkit files in the git repository. So, to run the dummy test rails environment you'll need to [grab a copy](http://download.dojotoolkit.org/) of the toolkit files and place them in the spec/dummy/public/javascripts/ directory to run the physical rails tests and see the generated markup correctly.
14
+
15
+ ## SimpleFormDojo::FormBuilder
16
+
17
+ Documentation is TBD, but in general, it works the same way that simple_form works:
18
+
19
+ <%= dojo_form_for(@user, :html => { :id => 'userForm' } ) do |f| %>
20
+ <%= f.error_messages %>
21
+ <%= f.input :username %>
22
+ <%= f.input :name %>
23
+ <%= f.input :email %>
24
+ <%= f.input :pay_rate, :as => :currency,
25
+ :dojo_html => { :promptMessage => 'Invalid Amount'
26
+ :currency => 'USD' }%>
27
+ <%= f.association :roles, :as => :check_boxes %>
28
+ <%= f.association :departments, :multiple => true %>
29
+ <%= f.input :created_at %>
30
+ <%= f.input :activated, :label => 'Active?', :as => :radio
31
+ <% end %>
32
+
33
+ ### Dijit objects currently included in SimpleFormDojo::FormBuilder
34
+
35
+ * dijit/form/CurrencyTextBox
36
+ * dijit/form/DateTextBox
37
+ * dijit/form/NumberTextBox
38
+ * dijit/form/SimpleTextarea
39
+ * dijit/form/Textarea
40
+ * dijit/form/TextBox
41
+ * dijit/form/ValidationTextBox
42
+ * dijit/form/MultiSelect (using option tags only - stores not implemented yet)
43
+ * dijit/form/FilteringSelect (using options tags only - stores not implemented yet)
44
+ * dijit/form/Button
45
+ * dijit/form/CheckBox
46
+ * dijit/form/Form
47
+ * dijit/form/RadioButton
48
+
49
+ ## SimpleFormDojo::Helpers::TabsHelper
50
+
51
+ The tabs helper creates markup for dijit.layout.TabContainer.
52
+
53
+ <%= dojo_tabs_for do |tab| %>
54
+ <%= tab.create('Tab Title One') do %>
55
+ #... tab contents
56
+ <% end %>
57
+ <%= tab.create('Tab Title Two') do %>
58
+ #... tab contents
59
+ <% end %>
60
+ <% end %>
61
+
62
+ **generates...**
63
+
64
+ <div data-dojo-props="doLayout:false" data-dojo-type="dijit.layout.TabContainer" id="tabs">
65
+ <div data-dojo-props="title:'Tab Title One'" data-dojo-type="dijit.layout.ContentPane">
66
+ #... tab contents
67
+ </div>
68
+ <div data-dojo-props="title:'Tab Title Two'" data-dojo-type="dijit.layout.ContentPane">
69
+ #... tab contents
70
+ </div>
71
+ </div>
72
+
73
+ Tabs are rendered in the order you create them.
74
+
75
+ Render tabs conditionally by appending a condition to the end of the 'create' block:
76
+
77
+ <%= tab.create('Conditional Tab') do %>
78
+ #... tab contents
79
+ <% end unless @current_user.nil? %>
80
+
81
+ Pass additional HTML options to either the parent DIV or any child tab's:
82
+
83
+ <%= dojo_tabs_for(:id => 'my-id', :class => 'new-class', :data-dojo-props => 'doLayout:true') do |tab| %>
84
+ <%= tab.create('Tab Title One', :style => 'color: #00f') do %>
85
+ #... tab contents
86
+ <% end %>
87
+ <% end %>
88
+
89
+ The default DOM ID for the parent div is 'id="tabs"' unless you pass an HTML option with a different value.
90
+
data/Rakefile ADDED
@@ -0,0 +1,35 @@
1
+ # encoding: UTF-8
2
+ require 'rubygems'
3
+ begin
4
+ require 'bundler/setup'
5
+ rescue LoadError
6
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
7
+ end
8
+
9
+ require 'rake'
10
+ require 'rdoc/task'
11
+
12
+ require 'rspec/core'
13
+ require 'rspec/core/rake_task'
14
+
15
+ RSpec::Core::RakeTask.new(:spec)
16
+
17
+ task :default => :spec
18
+
19
+ Rake::RDocTask.new(:rdoc) do |rdoc|
20
+ rdoc.rdoc_dir = 'rdoc'
21
+ rdoc.title = 'SimpleFormDojo'
22
+ rdoc.options << '--line-numbers' << '--inline-source'
23
+ rdoc.rdoc_files.include('README.rdoc')
24
+ rdoc.rdoc_files.include('lib/**/*.rb')
25
+ end
26
+
27
+ desc "Run watchr"
28
+ task :watchr do
29
+ sh %{bundle exec watchr .watchr}
30
+ end
31
+
32
+ desc "Open an irb session preloaded with this library"
33
+ task :console do
34
+ sh "irb -rubygems -r ./lib/simple_form-dojo.rb"
35
+ end
@@ -0,0 +1,52 @@
1
+ module SimpleFormDojo
2
+ module DojoPropsMethods
3
+ ##
4
+ # Retrieves and merges all dojo_props
5
+ def get_and_merge_dojo_props!
6
+ add_dojo_options_to_dojo_props
7
+ if object.id.present?
8
+ add_dojo_compliant_id
9
+ else
10
+ input_html_options["id"] = nil #let dojo generate internal id
11
+ end
12
+ input_html_options[:'data-dojo-props'] = SimpleFormDojo::FormBuilder.encode_as_dojo_props(@dojo_props) if !@dojo_props.blank?
13
+ end
14
+
15
+ private
16
+
17
+ ##
18
+ # Retrieves dojo props from :dojo_html => {} options
19
+ def add_dojo_options_to_dojo_props
20
+ @dojo_props ||= {}
21
+ @dojo_props.merge!(html_options_for(:dojo, []))
22
+ end
23
+
24
+ def tag_id index = nil
25
+ id = sanitized_object_name
26
+ id << "_#{object.id}"
27
+ id << index if index
28
+ id << "_#{sanitized_attribute_name}"
29
+ id
30
+ end
31
+
32
+ def add_dojo_compliant_id
33
+ opts = input_html_options
34
+ if opts.has_key?("index")
35
+ opts["id"] = opts.fetch("id"){ tag_id opts["index"] }
36
+ opts.delete("index")
37
+ elsif defined?(@auto_index)
38
+ opts["id"] = opts.fetch("id"){ tag_id @auto_index }
39
+ else
40
+ opts["id"] = opts.fetch("id"){ tag_id }
41
+ end
42
+ end
43
+
44
+ def sanitized_attribute_name
45
+ @sanitized_attribute_name ||= attribute_name.to_s.sub(/\?$/,"")
46
+ end
47
+
48
+ def sanitized_object_name
49
+ @sanitized_object_name ||= object_name.to_s.gsub(/\]\[|[^-a-zA-Z0-9:.]/, "_").sub(/_$/, "")
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,218 @@
1
+ module SimpleFormDojo
2
+ class FormBuilder < SimpleForm::FormBuilder
3
+ include SimpleFormDojo::Inputs
4
+ # need to include this in order to
5
+ # get the html_escape method
6
+ include ERB::Util
7
+
8
+ attr_accessor :dojo_props
9
+
10
+ map_type :currency, :to => SimpleFormDojo::Inputs::CurrencyInput
11
+ map_type :date, :time, :datetime, :to => SimpleFormDojo::Inputs::DateTimeInput
12
+ map_type :select, :radio_buttons, :check_boxes, :to => SimpleFormDojo::Inputs::CollectionInput
13
+ map_type :integer, :decimal, :float, :to => SimpleFormDojo::Inputs::NumericInput
14
+ #map_type :password, :text, :text_simple, :file, :to => SimpleFormDojo::Inputs::MappingInput
15
+ map_type :string, :email, :search, :tel, :url, :to => SimpleFormDojo::Inputs::StringInput
16
+ map_type :text, :text_simple, :to => SimpleFormDojo::Inputs::TextInput
17
+ map_type :password, :to => SimpleFormDojo::Inputs::PasswordInput
18
+ map_type :boolean, :to => SimpleFormDojo::Inputs::BooleanInput
19
+
20
+ # Simple override of initializer in order to add in the dojo_props attribute
21
+ def initialize(object_name, object, template, options, proc)
22
+ @dojo_props = nil
23
+ super(object_name, object, template, options, proc)
24
+ end
25
+
26
+ # Creates a button
27
+ #
28
+ # overrides simple_form's button method
29
+ #
30
+ # dojo_form_for @user do |f|
31
+ # f.button :submit, :value => 'Save Me'
32
+ # end
33
+ #
34
+ # To use dojox/form/BusyButton, pass :busy => true
35
+ # dojo_form_for @uswer do |f|
36
+ # f.button :submit, :busy => true, :value => 'Save Me'
37
+ # end
38
+ #
39
+ # If :value doesn't exist, tries to determine the
40
+ # the value based on the current object
41
+ def button(type, *args, &block)
42
+ # set options to value if first arg is a Hash
43
+ options = args.extract_options!
44
+ button_type = 'dijit/form/Button'
45
+ button_type = 'dojox/form/BusyButton' if options[:busy]
46
+ options.reverse_merge!(:'data-dojo-type' => button_type)
47
+ content = ''
48
+ if value = options.delete(:value)
49
+ content = value.html_safe
50
+ else
51
+ content = button_default_value
52
+ end
53
+ options.reverse_merge!({ :type => type, :value => content })
54
+ dojo_props = {}
55
+ dojo_props.merge!(options[:dojo_html]) if options.include?(:dojo_html)
56
+ options[:'data-dojo-props'] = SimpleFormDojo::FormBuilder.encode_as_dojo_props(dojo_props)
57
+ options[:class] = "button #{options[:class]}".strip
58
+ template.content_tag(:button, content, *(args << options), &block)
59
+ end
60
+
61
+ # Basically the same as rails submit_default_value
62
+ def button_default_value
63
+ obj = object.respond_to?(:to_model) ? object.to_model : object
64
+ key = obj ? (obj.persisted? ? :edit : :new) : :submit
65
+ model = if obj.class.respond_to?(:model_name)
66
+ obj.class.model_name.human
67
+ else
68
+ object_name.to_s.humanize
69
+ end
70
+
71
+ defaults = []
72
+ defaults << "helpers.submit.#{object_name}.#{key}"
73
+ defaults << "#{key.to_s.humanize} #{model}"
74
+
75
+ I18n.t(defaults.shift, :default => defaults)
76
+ end
77
+
78
+ def dojo_collection_radio_buttons(attribute, collection, value_method,
79
+ text_method, options={}, html_options={})
80
+ rendered_collection = render_collection(
81
+ collection, value_method, text_method, options, html_options
82
+ ) do |item, value, text, default_html_options|
83
+ local_dojo_props = @dojo_props.dup
84
+
85
+ ## Checked?
86
+ #if values_are_equal?(local_dojo_props[:value], value)
87
+ #local_dojo_props[:checked] = "checked"
88
+ #default_html_options[:checked] = "checked"
89
+ #end
90
+
91
+ default_html_options[:'data-dojo-props'] = SimpleFormDojo::FormBuilder.encode_as_dojo_props(local_dojo_props) if !local_dojo_props.nil?
92
+
93
+ # append the object id to the html id
94
+ default_html_options["id"] = "#{html_options["id"]}_#{value.to_s.gsub(/\s/, "_").gsub(/[^-\w]/, "").downcase}" if html_options["id"].present?
95
+
96
+ builder = instantiate_collection_builder(SimpleForm::ActionViewExtensions::RadioButtonBuilder, attribute, item, value, text, default_html_options)
97
+
98
+ if block_given?
99
+ yield builder
100
+ else
101
+ builder.radio_button + builder.label(:class => "collection_radio_buttons")
102
+ end
103
+ end
104
+ wrap_rendered_collection(rendered_collection, options)
105
+ end
106
+
107
+ def dojo_collection_check_boxes(attribute, collection, value_method,
108
+ text_method, options={}, html_options={})
109
+ rendered_collection = render_collection(
110
+ collection, value_method, text_method, options, html_options
111
+ ) do |item, value, text, default_html_options|
112
+ local_dojo_props = @dojo_props.dup
113
+
114
+ ## Checked
115
+ #if values_are_equal?(local_dojo_props[:value], value)
116
+ #local_dojo_props[:checked] = "checked"
117
+ #default_html_options[:checked] = "checked"
118
+ #end
119
+ default_html_options[:multiple] = true
120
+
121
+ default_html_options[:'data-dojo-props'] = SimpleFormDojo::FormBuilder.encode_as_dojo_props(local_dojo_props)
122
+
123
+ # append the object id to the html id
124
+ default_html_options["id"] = "#{html_options["id"]}_#{value.to_s.gsub(/\s/, "_").gsub(/[^-\w]/, "").downcase}" if html_options["id"].present?
125
+
126
+ builder = instantiate_collection_builder(SimpleForm::ActionViewExtensions::CheckBoxBuilder, attribute, item, value, text, default_html_options)
127
+
128
+ if block_given?
129
+ yield builder
130
+ else
131
+ builder.check_box + builder.label(:class => "collection_check_boxes")
132
+ end
133
+ end
134
+ wrap_rendered_collection(rendered_collection, options)
135
+ end
136
+
137
+ # Adds support for Ajax remote FilteringSelect using a QueryReadStore
138
+ #
139
+ # == Example
140
+ #
141
+ # simple_form_for @user do |f|
142
+ # f.association :company, :remote_path => '/companies/qrs'
143
+ # end
144
+ # # Will create a QueryReadStore linked to a FilteringSelect
145
+ #
146
+ def association(association, options={}, &block)
147
+ options = options.dup
148
+ reflection = find_association_reflection(association)
149
+ raise "Association #{association.inspect} not found" unless reflection
150
+ store = ""
151
+ if reflection.macro == :belongs_to
152
+ options[:input_html] ||= {}
153
+ attribute = (reflection.respond_to?(:options) && reflection.options[:foreign_key]) || :"#{reflection.name}_id"
154
+ options[:input_html][:value] ||= object.send(attribute)
155
+ options[:dojo_html] ||= {}
156
+ if options[:remote_path] && !options[:dojo_html][:store]
157
+ options[:collection] = [] #Prevent collections from being loaded
158
+ qrs_id = "#{object_name.to_s.underscore}_#{object.id.to_s.gsub(/[^\w]/, "")}_#{association}_qrs"
159
+ path = options.delete(:remote_path)
160
+ options[:dojo_html][:store] = qrs_id
161
+ store = qrs(qrs_id, path)
162
+ end
163
+ end
164
+
165
+ store.html_safe + super(association, options, &block)
166
+ end
167
+
168
+ # Creates a Dojo QueryReadStore
169
+ #
170
+ # dojo_form_for @user do |f|
171
+ # f.qrs :company_qrs, '/companies/qrs'
172
+ # end
173
+ def qrs id, path, dojo_props = {}
174
+ dojo_props = dojo_props.dup
175
+ options = {:'data-dojo-type' => 'dojox/data/QueryReadStore'}
176
+ dojo_props[:url] = "'#{path}'"
177
+ options[:'data-dojo-props'] = SimpleFormDojo::FormBuilder.encode_as_dojo_props(dojo_props)
178
+ options[:'data-dojo-id'] = id
179
+ options[:style] ||= "display: none;"
180
+ template.content_tag(:span, nil, options)
181
+ end
182
+
183
+ ##
184
+ # The dojo props string is evaluated as javascript,
185
+ # can therefore contain any valid javascript object
186
+ # and cannot be encoded as JSON
187
+ def self.encode_as_dojo_props(options)
188
+ encode_obj(options)
189
+ .slice(1..-2)
190
+ .html_safe
191
+ end
192
+
193
+ def self.encode_obj(obj)
194
+ case obj
195
+ when Hash
196
+ "{#{obj.collect{|k, v| "#{k}:#{encode_obj(v)}"}.join(', ')}}"
197
+ when Array
198
+ "[#{obj.collect{|v| encode_obj(v)}.join(', ')}]"
199
+ else
200
+ obj.to_s
201
+ end
202
+ end
203
+
204
+ private
205
+
206
+ def values_are_equal?(obj_value, item_value)
207
+ value = obj_value
208
+ if value.is_a?(String)
209
+ values = obj_value[/\[([,0-9\s]+)\]/,1]
210
+ unless values.nil?
211
+ return values.tr(' ','').split(',').include?(item_value.to_s)
212
+ end
213
+ end
214
+ (value.to_s == item_value.to_s ? true : false)
215
+ end
216
+
217
+ end
218
+ end
@@ -0,0 +1,32 @@
1
+ module SimpleFormDojo
2
+ module Helpers
3
+ module FormHelper
4
+
5
+ def dojo_form_for(record_or_name_or_array, *args, &block)
6
+ options = args.extract_options!.reverse_merge(:builder => SimpleFormDojo::FormBuilder)
7
+ options[:html] ||= {}
8
+ options[:html][:'data-dojo-id'] ||= options[:html][:id] if options[:html][:id]
9
+ options[:html][:'data-dojo-type'] ||= 'dijit/form/Form'
10
+ simple_form_for(record_or_name_or_array, *(args << options), &block).tap do |output|
11
+ form_callbacks.each do |callback|
12
+ output << callback.call
13
+ end
14
+ end
15
+ end
16
+
17
+ def dojo_fields_for(*args, &block)
18
+ options = args.extract_options!.reverse_merge(:builder => SimpleFormDojo::FormBuilder)
19
+ simple_fields_for(*(args << options), &block)
20
+ end
21
+
22
+ def form_associations
23
+ @form_associations ||= []
24
+ end
25
+
26
+ def form_callbacks
27
+ @form_callbacks ||= []
28
+ end
29
+ end
30
+ end
31
+ end
32
+ ActionView::Base.send(:include, SimpleFormDojo::Helpers::FormHelper)
@@ -0,0 +1,79 @@
1
+ require 'action_view'
2
+
3
+ module SimpleFormDojo
4
+ # = SimpleFormDojo Dojo Tabs Helper
5
+ module Helpers
6
+ # Provides methods to generate HTML markup for dijit/layout/TabContainer objects
7
+ #
8
+ # ==
9
+ module TabsHelper
10
+ # Returns an HTML block tag of type DIV with the appropriate dojo-data-type.
11
+ # You must pass a block of tabs as an argument.
12
+ #
13
+ # ==== Options
14
+ # The +options+ hash is used to pass additional HTML attributes to the parent DIV.
15
+ #
16
+ # The default dojo-data-props attribute is set to "doLayout:false".
17
+ #
18
+ # The default id attribute is set to "tabs".
19
+ #
20
+ # ==== Examples
21
+ #
22
+ # <%= dojo_tabs_for do |tab| %>
23
+ # <%= tab.create('Tab Title One') do %>
24
+ # #... tab contents
25
+ # <% end %>
26
+ # <% end %>
27
+ # # => <div data-dojo-props="doLayout:false" data-dojo-type="dijit/layout/TabContainer" id="tabs">
28
+ # # => <div data-dojo-props="title:'Tab Title One'" data-dojo-type="dijit/layout/ContentPane">
29
+ # # => ... tab contents
30
+ # # => </div>
31
+ # # => </div>
32
+ def dojo_tabs_for( *options, &block )
33
+ raise ArgumentError, "Missing block" unless block_given?
34
+ raw SimpleFormDojo::Helpers::TabsHelper::TabsRenderer.new( *options, &block ).render
35
+ end
36
+
37
+ class TabsRenderer
38
+ include ActionView::Helpers::CaptureHelper
39
+ def initialize( options={}, &block )
40
+ raise ArgumentError, "Missing block" unless block_given?
41
+ @template = eval( 'self', block.binding )
42
+ @options = options
43
+ @tabs = []
44
+ yield self
45
+ end
46
+
47
+ def create(title, options={}, &block)
48
+ raise ArgumentError, "Block needed for TabsRenderer#CREATE" unless block_given?
49
+ @tabs << [ title, options, block ]
50
+ # had to return an empty string. Otherwise, the @tabs object was being
51
+ # returned when used with the <%= tab.create('title') %> syntax
52
+ return ''
53
+ end
54
+
55
+ def render
56
+ content_tag( :div, raw([render_tabs].join), { :id => :tabs,
57
+ "data-dojo-props" => "doLayout:false",
58
+ "data-dojo-type" => "dijit/layout/TabContainer"
59
+ }.merge(@options) )
60
+ end
61
+
62
+ private
63
+
64
+ def render_tabs
65
+ @tabs.collect do |tab|
66
+ content_tag(:div, capture( &tab[2] ), tab[1].merge( "data-dojo-type" => "dijit/layout/ContentPane",
67
+ "data-dojo-props" => "title:'#{tab[0]}'"))
68
+ end.join.to_s
69
+ end
70
+
71
+ def method_missing( *args, &block )
72
+ @template.send( *args, &block )
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
78
+
79
+ ActionView::Base.send(:include, SimpleFormDojo::Helpers::TabsHelper)
@@ -0,0 +1,19 @@
1
+ module SimpleFormDojo
2
+ module Inputs
3
+ class BooleanInput < SimpleForm::Inputs::BooleanInput
4
+ include DojoPropsMethods
5
+
6
+ def input
7
+ input_html_options[:'data-dojo-type'] ||= dojo_type
8
+ get_and_merge_dojo_props!
9
+ super
10
+ end
11
+
12
+ protected
13
+
14
+ def dojo_type
15
+ 'dijit/form/CheckBox'
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,41 @@
1
+ module SimpleFormDojo
2
+ module Inputs
3
+ class CollectionInput < SimpleForm::Inputs::CollectionInput
4
+
5
+ include DojoPropsMethods
6
+
7
+ def input
8
+ input_html_options[:'data-dojo-type'] ||= dojo_type
9
+ infer_dojo_props_from_validations!
10
+ get_and_merge_dojo_props!
11
+
12
+ label_method, value_method = detect_collection_methods
13
+ collection_method = @builder.respond_to?(:"dojo_collection_#{input_type}") ?
14
+ "dojo_collection_#{input_type}" :
15
+ "collection_#{input_type}"
16
+ @builder.dojo_props = @dojo_props
17
+ @builder.send(collection_method, attribute_name, collection, value_method,
18
+ label_method, input_options, input_html_options)
19
+ end
20
+
21
+ protected
22
+
23
+ def dojo_type
24
+ case input_type
25
+ when :check_boxes
26
+ 'dijit/form/CheckBox'
27
+ when :radio_buttons
28
+ 'dijit/form/RadioButton'
29
+ when :select
30
+ (input_html_options.has_key?(:multiple) ? 'dijit/form/MultiSelect' : 'dijit/form/FilteringSelect')
31
+ end
32
+ end
33
+
34
+ def infer_dojo_props_from_validations!
35
+ @dojo_props ||= {}
36
+ @dojo_props.merge!(:required => has_required?)
37
+ end
38
+
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,9 @@
1
+ module SimpleFormDojo
2
+ module Inputs
3
+ class CurrencyInput < NumericInput
4
+ def dojo_type
5
+ 'dijit/form/CurrencyTextBox'
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,27 @@
1
+ module SimpleFormDojo
2
+ module Inputs
3
+ class DateTimeInput < SimpleForm::Inputs::StringInput
4
+
5
+ include DojoPropsMethods
6
+
7
+ def input
8
+ input_html_options[:type] = :text
9
+ input_html_options[:'data-dojo-type'] ||= dojo_type
10
+ get_and_merge_dojo_props!
11
+ super
12
+ end
13
+
14
+ protected
15
+
16
+ def dojo_type
17
+ case input_type
18
+ when :date, :datetime
19
+ 'dijit/form/DateTextBox'
20
+ when :time
21
+ 'dijit/form/TimeTextBox'
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+
@@ -0,0 +1,43 @@
1
+ module SimpleFormDojo
2
+ module Inputs
3
+ # Uses MapType to handle basic input types. See the original simple_form
4
+ # source for details.
5
+ class MappingInput < SimpleForm::Inputs::MappingInput
6
+ include DojoPropsMethods
7
+
8
+ map_type :text_simple, :to => :text_area
9
+
10
+ def input
11
+ input_html_options[:'data-dojo-type'] ||= dojo_type
12
+ infer_dojo_props_from_validations!
13
+ get_and_merge_dojo_props!
14
+ super
15
+ end
16
+
17
+ protected
18
+
19
+ def dojo_type
20
+ case input_type
21
+ when :password
22
+ if has_required?
23
+ 'dijit/form/ValidationTextBox'
24
+ else
25
+ 'dijit/form/TextBox'
26
+ end
27
+ when :text
28
+ 'dijit/form/Textarea'
29
+ when :text_simple
30
+ 'dijit/form/SimpleTextarea'
31
+ when :file
32
+ raise('File fields have not been implemented yet!')
33
+ end
34
+ end
35
+
36
+ def infer_dojo_props_from_validations!
37
+ @dojo_props ||= {}
38
+ @dojo_props.merge!(:required => true) if has_required?
39
+ end
40
+
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,48 @@
1
+ module SimpleFormDojo
2
+ module Inputs
3
+ class NumericInput < SimpleForm::Inputs::NumericInput
4
+
5
+ include DojoPropsMethods
6
+
7
+ def input
8
+ input_html_options[:type] = :text
9
+ input_html_options[:'data-dojo-type'] ||= dojo_type
10
+ infer_dojo_props_from_validations!
11
+ get_and_merge_dojo_props!
12
+ super
13
+ end
14
+
15
+ protected
16
+
17
+ def dojo_type
18
+ 'dijit/form/NumberTextBox'
19
+ end
20
+
21
+ def integer?
22
+ if input_type == :integer
23
+ @dojo_props ||= {}
24
+ @dojo_props[:constraints] ||= {}
25
+ @dojo_props[:constraints][:places] ||= 0;
26
+ true
27
+ else
28
+ false
29
+ end
30
+ end
31
+
32
+ def infer_dojo_props_from_validations!
33
+ @dojo_props ||= {}
34
+ @dojo_props.merge!(:required => true) if has_required?
35
+ if has_validators?
36
+ # numeric_validator and find_numericality_validator inherited from SimpleForm
37
+ numeric_validator = find_numericality_validator or return
38
+ validator_options = numeric_validator.options
39
+ @dojo_props[:constraints] ||= {}
40
+ @dojo_props[:constraints][:min] ||= minimum_value(validator_options)
41
+ @dojo_props[:constraints][:max] ||= maximum_value(validator_options)
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+
@@ -0,0 +1,30 @@
1
+ module SimpleFormDojo
2
+ module Inputs
3
+ class PasswordInput < SimpleForm::Inputs::PasswordInput
4
+ include DojoPropsMethods
5
+
6
+ def input
7
+ input_html_options[:'data-dojo-type'] ||= dojo_type
8
+ infer_dojo_props_from_validations!
9
+ get_and_merge_dojo_props!
10
+ super
11
+ end
12
+
13
+ protected
14
+
15
+ def dojo_type
16
+ if has_required?
17
+ 'dijit/form/ValidationTextBox'
18
+ else
19
+ 'dijit/form/TextBox'
20
+ end
21
+ end
22
+
23
+ def infer_dojo_props_from_validations!
24
+ @dojo_props ||= {}
25
+ @dojo_props.merge!(:required => true) if has_required?
26
+ end
27
+
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,39 @@
1
+ module SimpleFormDojo
2
+ module Inputs
3
+ class StringInput < SimpleForm::Inputs::StringInput
4
+ include DojoPropsMethods
5
+ EMAIL_REGEXP="^[\\\\w!#%$*+=?`{|}~^-]+(?:[\\\\w!#%$*+=?`{|}~^.-])*@(?:[a-zA-Z0-9-]+\\\\.)+[a-zA-Z]{2,6}$"
6
+
7
+ def input
8
+ input_html_options[:'data-dojo-type'] ||= dojo_type
9
+ infer_dojo_props_from_validations!
10
+ get_and_merge_dojo_props!
11
+ super
12
+ end
13
+
14
+ protected
15
+
16
+ def dojo_type
17
+ if has_required? || [:tel, :email].include?(input_type)
18
+ 'dijit/form/ValidationTextBox'
19
+ else
20
+ 'dijit/form/TextBox'
21
+ end
22
+ end
23
+
24
+ def infer_dojo_props_from_validations!
25
+ @dojo_props = {}
26
+ @dojo_props.merge!(:required => true) if has_required?
27
+ case input_type
28
+ when :email
29
+ @dojo_props[:pattern] ||= "'#{EMAIL_REGEXP}'"
30
+ @dojo_props[:invalidMessage] = "'Invalid email format.'"
31
+ when :tel
32
+ @dojo_props[:pattern] ||= "'^[\\\\d(.)+\\\\s-]+$'"
33
+ @dojo_props[:invalidMessage] = "'Invalid phone format.'"
34
+ end
35
+ end
36
+
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,33 @@
1
+ module SimpleFormDojo
2
+ module Inputs
3
+ class TextInput < SimpleForm::Inputs::TextInput
4
+ include DojoPropsMethods
5
+
6
+ #map_type :text_simple, :to => :text_area
7
+
8
+ def input
9
+ input_html_options[:'data-dojo-type'] ||= dojo_type
10
+ infer_dojo_props_from_validations!
11
+ get_and_merge_dojo_props!
12
+ super
13
+ end
14
+
15
+ protected
16
+
17
+ def dojo_type
18
+ case input_type
19
+ when :text
20
+ 'dijit/form/Textarea'
21
+ when :text_simple
22
+ 'dijit/form/SimpleTextarea'
23
+ end
24
+ end
25
+
26
+ def infer_dojo_props_from_validations!
27
+ @dojo_props ||= {}
28
+ @dojo_props.merge!(:required => true) if has_required?
29
+ end
30
+
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,12 @@
1
+ module SimpleFormDojo
2
+ module Inputs
3
+ autoload :StringInput, 'simple_form-dojo/inputs/string_input'
4
+ autoload :DateTimeInput, 'simple_form-dojo/inputs/date_time_input'
5
+ autoload :NumericInput, 'simple_form-dojo/inputs/numeric_input'
6
+ autoload :TextInput, 'simple_form-dojo/inputs/text_input'
7
+ autoload :PasswordInput, 'simple_form-dojo/inputs/password_input'
8
+ autoload :CollectionInput, 'simple_form-dojo/inputs/collection_input'
9
+ autoload :CurrencyInput, 'simple_form-dojo/inputs/currency_input'
10
+ autoload :BooleanInput, 'simple_form-dojo/inputs/boolean_input'
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ module SimpleFormDojo
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,12 @@
1
+ require 'action_view'
2
+ require 'simple_form'
3
+ require 'simple_form-dojo/version'
4
+ require 'simple_form-dojo/helpers/tabs_helper'
5
+ require 'simple_form-dojo/helpers/form_helper'
6
+
7
+ module SimpleFormDojo
8
+ autoload :FormBuilder, 'simple_form-dojo/form_builder'
9
+ autoload :Inputs, 'simple_form-dojo/inputs'
10
+ autoload :DojoPropsMethods, 'simple_form-dojo/dojo_props_methods'
11
+ end
12
+
metadata ADDED
@@ -0,0 +1,247 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple_form-dojo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Alex Giouzenis
8
+ - Patrick Ward
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: simple_form
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: 2.1.0
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ version: 2.1.0
28
+ - !ruby/object:Gem::Dependency
29
+ name: rspec
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: 2.12.0
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ~>
40
+ - !ruby/object:Gem::Version
41
+ version: 2.12.0
42
+ - !ruby/object:Gem::Dependency
43
+ name: rails
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ~>
47
+ - !ruby/object:Gem::Version
48
+ version: 3.2.9
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: 3.2.9
56
+ - !ruby/object:Gem::Dependency
57
+ name: rspec-rails
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ version: 2.12.0
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 2.12.0
70
+ - !ruby/object:Gem::Dependency
71
+ name: rspec-html-matchers
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ! '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: nokogiri
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ~>
89
+ - !ruby/object:Gem::Version
90
+ version: 1.5.5
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ~>
96
+ - !ruby/object:Gem::Version
97
+ version: 1.5.5
98
+ - !ruby/object:Gem::Dependency
99
+ name: capybara
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ~>
103
+ - !ruby/object:Gem::Version
104
+ version: 2.0.1
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ~>
110
+ - !ruby/object:Gem::Version
111
+ version: 2.0.1
112
+ - !ruby/object:Gem::Dependency
113
+ name: spork
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ~>
117
+ - !ruby/object:Gem::Version
118
+ version: 0.9.2
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ~>
124
+ - !ruby/object:Gem::Version
125
+ version: 0.9.2
126
+ - !ruby/object:Gem::Dependency
127
+ name: sqlite3
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ~>
131
+ - !ruby/object:Gem::Version
132
+ version: 1.3.6
133
+ type: :development
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ~>
138
+ - !ruby/object:Gem::Version
139
+ version: 1.3.6
140
+ - !ruby/object:Gem::Dependency
141
+ name: factory_girl_rails
142
+ requirement: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ~>
145
+ - !ruby/object:Gem::Version
146
+ version: 4.1.0
147
+ type: :development
148
+ prerelease: false
149
+ version_requirements: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ~>
152
+ - !ruby/object:Gem::Version
153
+ version: 4.1.0
154
+ - !ruby/object:Gem::Dependency
155
+ name: database_cleaner
156
+ requirement: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ~>
159
+ - !ruby/object:Gem::Version
160
+ version: 0.9.1
161
+ type: :development
162
+ prerelease: false
163
+ version_requirements: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ~>
166
+ - !ruby/object:Gem::Version
167
+ version: 0.9.1
168
+ - !ruby/object:Gem::Dependency
169
+ name: watchr
170
+ requirement: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - ! '>='
173
+ - !ruby/object:Gem::Version
174
+ version: '0'
175
+ type: :development
176
+ prerelease: false
177
+ version_requirements: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - ! '>='
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
182
+ - !ruby/object:Gem::Dependency
183
+ name: awesome_print
184
+ requirement: !ruby/object:Gem::Requirement
185
+ requirements:
186
+ - - ! '>='
187
+ - !ruby/object:Gem::Version
188
+ version: '0'
189
+ type: :development
190
+ prerelease: false
191
+ version_requirements: !ruby/object:Gem::Requirement
192
+ requirements:
193
+ - - ! '>='
194
+ - !ruby/object:Gem::Version
195
+ version: '0'
196
+ description: SimpleFormDojo is a collection of helpers for use with Dojo and Rails.
197
+ The goal of the project is to make it simple to create Dijit elements using the
198
+ existing Rails helper infrastructure.
199
+ email:
200
+ - alexandrosg@gmail.com
201
+ executables: []
202
+ extensions: []
203
+ extra_rdoc_files: []
204
+ files:
205
+ - lib/simple_form-dojo/form_builder.rb
206
+ - lib/simple_form-dojo/version.rb
207
+ - lib/simple_form-dojo/inputs/mapping_input.rb
208
+ - lib/simple_form-dojo/inputs/numeric_input.rb
209
+ - lib/simple_form-dojo/inputs/boolean_input.rb
210
+ - lib/simple_form-dojo/inputs/text_input.rb
211
+ - lib/simple_form-dojo/inputs/collection_input.rb
212
+ - lib/simple_form-dojo/inputs/password_input.rb
213
+ - lib/simple_form-dojo/inputs/date_time_input.rb
214
+ - lib/simple_form-dojo/inputs/string_input.rb
215
+ - lib/simple_form-dojo/inputs/currency_input.rb
216
+ - lib/simple_form-dojo/dojo_props_methods.rb
217
+ - lib/simple_form-dojo/inputs.rb
218
+ - lib/simple_form-dojo/helpers/form_helper.rb
219
+ - lib/simple_form-dojo/helpers/tabs_helper.rb
220
+ - lib/simple_form-dojo.rb
221
+ - MIT-LICENSE
222
+ - Rakefile
223
+ - README.markdown
224
+ homepage: https://github.com/agios/simple_form-dojo
225
+ licenses: []
226
+ metadata: {}
227
+ post_install_message:
228
+ rdoc_options: []
229
+ require_paths:
230
+ - lib
231
+ required_ruby_version: !ruby/object:Gem::Requirement
232
+ requirements:
233
+ - - ! '>='
234
+ - !ruby/object:Gem::Version
235
+ version: '0'
236
+ required_rubygems_version: !ruby/object:Gem::Requirement
237
+ requirements:
238
+ - - ! '>='
239
+ - !ruby/object:Gem::Version
240
+ version: '0'
241
+ requirements: []
242
+ rubyforge_project: simple_form-dojo
243
+ rubygems_version: 2.0.3
244
+ signing_key:
245
+ specification_version: 4
246
+ summary: Dojo Toolkit helpers for Rails 3
247
+ test_files: []