formtastic 2.0.0.rc1 → 2.0.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +4 -0
- data/README.textile +3 -49
- data/formtastic.gemspec +1 -1
- data/lib/formtastic/inputs/base/timeish.rb +84 -0
- data/lib/formtastic/inputs/boolean_input.rb +1 -1
- data/lib/formtastic/inputs/date_input.rb +2 -0
- data/lib/formtastic/inputs/datetime_input.rb +3 -0
- data/lib/formtastic/inputs/select_input.rb +1 -1
- data/lib/formtastic/inputs/time_input.rb +2 -0
- data/lib/formtastic/version.rb +1 -1
- data/spec/inputs/select_input_spec.rb +1 -1
- metadata +4 -4
data/CHANGELOG
CHANGED
data/README.textile
CHANGED
@@ -97,13 +97,13 @@ Simply add Formtastic to your Gemfile and bundle it up:
|
|
97
97
|
gem 'formtastic', '~> 1.2.3'
|
98
98
|
</pre>
|
99
99
|
|
100
|
-
If you want to try out our work towards Formtastic 2.0 (Rails
|
100
|
+
If you want to try out our work towards Formtastic 2.0 (Rails 3.x only):
|
101
101
|
|
102
102
|
<pre>
|
103
|
-
gem 'formtastic',
|
103
|
+
gem 'formtastic', '2.0.0.rc1'
|
104
104
|
</pre>
|
105
105
|
|
106
|
-
|
106
|
+
Run the installation generator to copy a stylesheet (Rails 3.0.x only) and a configuration initializer into your application:
|
107
107
|
|
108
108
|
<pre>
|
109
109
|
$ rails generate formtastic:install
|
@@ -536,52 +536,6 @@ h2. Configuration
|
|
536
536
|
Run @rails generate formtastic:install@ to copy a commented out config file into @config/initializers/formtastic.rb@. You can "view the configuration file on GitHub":http://github.com/justinfrench/formtastic/blob/master/lib/generators/templates/formtastic.rb
|
537
537
|
|
538
538
|
|
539
|
-
h2. Form Generator
|
540
|
-
|
541
|
-
There's a Formtastic form code generator to make your transition to Formtastic easier. All you have to do is to *specify an existing model name*, and optionally specify view template framework (ERB/HAML), and you are good to go. *Note:* This won't overwrite any of your exsting files without confirmation.
|
542
|
-
|
543
|
-
h3. Basic usage
|
544
|
-
|
545
|
-
<pre>
|
546
|
-
$ rails generate formtastic:form ModelName
|
547
|
-
exists app/views/posts
|
548
|
-
create app/views/posts/_form.html.erb
|
549
|
-
</pre>
|
550
|
-
|
551
|
-
The ERB code is saved to a partial file, but it will not overwrite existing files without a prompt.
|
552
|
-
|
553
|
-
h3. Copying the ERB code to the clipboard instead with @--copy@
|
554
|
-
|
555
|
-
<pre>
|
556
|
-
$ rails generate formtastic:form Post --copy
|
557
|
-
</pre>
|
558
|
-
|
559
|
-
h3. Specifying HAML instead of ERB with @--haml@
|
560
|
-
|
561
|
-
<pre>
|
562
|
-
$ rails generate formtastic:form Post --haml
|
563
|
-
exists app/views/posts
|
564
|
-
create app/views/posts/_form.html.haml
|
565
|
-
</pre>
|
566
|
-
|
567
|
-
h3. Specifying controller namespace with @--controller@
|
568
|
-
|
569
|
-
<pre>
|
570
|
-
$ rails generate formtastic:form Post --controller admin/posts
|
571
|
-
exists app/views/admin/posts
|
572
|
-
create app/views/admin/posts/_form.html.erb
|
573
|
-
</pre>
|
574
|
-
|
575
|
-
h3. Specifying which attributes need an input
|
576
|
-
|
577
|
-
<pre>
|
578
|
-
$ rails generate formtastic:form Post title:string body:text publication_state:select
|
579
|
-
exists app/views/posts
|
580
|
-
create app/views/posts/_form.html.erb
|
581
|
-
</pre>
|
582
|
-
|
583
|
-
|
584
|
-
|
585
539
|
h2. Modified & Custom Inputs
|
586
540
|
|
587
541
|
If you want to change the behaviour of an input, you can subclass it in your app. For example, to tweak @StringInput@, create a new file @app/inputs/string_input.rb@:
|
data/formtastic.gemspec
CHANGED
@@ -5,7 +5,7 @@ require "formtastic/version"
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = %q{formtastic}
|
7
7
|
s.version = Formtastic::VERSION
|
8
|
-
s.date = %q{2011-06-
|
8
|
+
s.date = %q{2011-06-13}
|
9
9
|
s.platform = Gem::Platform::RUBY
|
10
10
|
s.authors = [%q{Justin French}]
|
11
11
|
s.email = [%q{justin@indent.com.au}]
|
@@ -1,6 +1,90 @@
|
|
1
1
|
module Formtastic
|
2
2
|
module Inputs
|
3
3
|
module Base
|
4
|
+
# Timeish inputs (`:date`, `:datetime`, `:time`) are similar to the Rails date and time
|
5
|
+
# helpers (`date_select`, `datetime_select`, `time_select`), rendering a series of `<select>`
|
6
|
+
# tags for each fragment (year, month, day, hour, minute, seconds). The fragments are then
|
7
|
+
# re-combined to a date by ActiveRecord through multi-parameter assignment.
|
8
|
+
#
|
9
|
+
# The mark-up produced by Rails is simple but far from ideal, with no way to label the
|
10
|
+
# individual fragments for accessibility, no fieldset to group the related fields, and no
|
11
|
+
# legend describing the group. Formtastic addresses this within the standard `<li>` wrapper
|
12
|
+
# with a `<fieldset>` with a `<legend>` as a label, followed by an ordered list (`<ol>`) of
|
13
|
+
# list items (`<li>`), one for each fragment (year, month, ...). Each `<li>` fragment contains
|
14
|
+
# a `<label>` (eg "Year") for the fragment, and a `<select>` containing `<option>`s (eg a
|
15
|
+
# range of years).
|
16
|
+
#
|
17
|
+
# In the supplied formtastic.css file, the resulting mark-up is styled to appear a lot like a
|
18
|
+
# standard Rails date time select by:
|
19
|
+
#
|
20
|
+
# * styling the legend to look like the other labels (to the left hand side of the selects)
|
21
|
+
# * floating the `<li>` fragments against each other as a single line
|
22
|
+
# * hiding the `<label>` of each fragment with `display:none`
|
23
|
+
#
|
24
|
+
# @example `:date` input with full form context and sample HTMl output
|
25
|
+
#
|
26
|
+
# <%= semantic_form_for(@post) do |f| %>
|
27
|
+
# <%= f.inputs do %>
|
28
|
+
# ...
|
29
|
+
# <%= f.input :publish_at, :as => :date %>
|
30
|
+
# <% end %>
|
31
|
+
# <% end %>
|
32
|
+
#
|
33
|
+
# <form...>
|
34
|
+
# <fieldset class="inputs">
|
35
|
+
# <ol>
|
36
|
+
# <li class="date">
|
37
|
+
# <fieldset class="fragments">
|
38
|
+
# <ol class="fragments-group">
|
39
|
+
# <li class="fragment">
|
40
|
+
# <label for="post_publish_at_1i">Year</label>
|
41
|
+
# <select id="post_publish_at_1i" name="post[publish_at_1i]">...</select>
|
42
|
+
# </li>
|
43
|
+
# <li class="fragment">
|
44
|
+
# <label for="post_publish_at_2i">Month</label>
|
45
|
+
# <select id="post_publish_at_2i" name="post[publish_at_2i]">...</select>
|
46
|
+
# </li>
|
47
|
+
# <li class="fragment">
|
48
|
+
# <label for="post_publish_at_3i">Day</label>
|
49
|
+
# <select id="post_publish_at_3i" name="post[publish_at_3i]">...</select>
|
50
|
+
# </li>
|
51
|
+
# </ol>
|
52
|
+
# </fieldset>
|
53
|
+
# </li>
|
54
|
+
# </ol>
|
55
|
+
# </fieldset>
|
56
|
+
# </form>
|
57
|
+
#
|
58
|
+
#
|
59
|
+
# @example `:time` input
|
60
|
+
# <%= f.input :publish_at, :as => :time %>
|
61
|
+
#
|
62
|
+
# @example `:datetime` input
|
63
|
+
# <%= f.input :publish_at, :as => :datetime %>
|
64
|
+
#
|
65
|
+
# @example Change the labels for each fragment
|
66
|
+
# <%= f.input :publish_at, :as => :date, :labels => { :year => "Y", :month => "M", :day => "D" } %>
|
67
|
+
#
|
68
|
+
# @example Skip a fragment (defaults to 1, skips all following fragments)
|
69
|
+
# <%= f.input :publish_at, :as => :datetime, :discard_minute => true %>
|
70
|
+
# <%= f.input :publish_at, :as => :datetime, :discard_hour => true %>
|
71
|
+
# <%= f.input :publish_at, :as => :datetime, :discard_day => true %>
|
72
|
+
# <%= f.input :publish_at, :as => :datetime, :discard_month => true %>
|
73
|
+
# <%= f.input :publish_at, :as => :datetime, :discard_year => true %>
|
74
|
+
#
|
75
|
+
# @example Change the order
|
76
|
+
# <%= f.input :publish_at, :as => :date, :order => [:month, :day, :year] %>
|
77
|
+
#
|
78
|
+
# @example Include seconds with times (excluded by default)
|
79
|
+
# <%= f.input :publish_at, :as => :time, :include_seconds => true %>
|
80
|
+
#
|
81
|
+
# @example Specify if there should be a blank option at the start of each select or not
|
82
|
+
# <%= f.input :publish_at, :as => :time, :include_blank=> true %>
|
83
|
+
# <%= f.input :publish_at, :as => :time, :include_blank=> false %>
|
84
|
+
#
|
85
|
+
# @todo Document i18n
|
86
|
+
# @todo Check what other Rails options are supported (`start_year`, `end_year`, `use_month_numbers`, `use_short_month`, `add_month_numbers`, `prompt`), write tests for them, and otherwise support them
|
87
|
+
# @todo Could we take the rendering from Rails' helpers and inject better HTML in and around it rather than re-inventing the whee?
|
4
88
|
module Timeish
|
5
89
|
|
6
90
|
def to_html
|
@@ -1,5 +1,7 @@
|
|
1
1
|
module Formtastic
|
2
2
|
module Inputs
|
3
|
+
# Outputs a series of select boxes for the fragments that make up a date (year, month, day).
|
4
|
+
#
|
3
5
|
# @see Formtastic::Inputs::Timeish Timeish module for documetation of date, time and datetime input options.
|
4
6
|
class DateInput
|
5
7
|
include Base
|
@@ -1,5 +1,8 @@
|
|
1
1
|
module Formtastic
|
2
2
|
module Inputs
|
3
|
+
|
4
|
+
# Outputs a series of select boxes for the fragments that make up a date and time (year, month, day, hour, minute, second).
|
5
|
+
#
|
3
6
|
# @see Formtastic::Inputs::Timeish Timeish module for documetation of date, time and datetime input options.
|
4
7
|
class DatetimeInput
|
5
8
|
include Base
|
@@ -1,5 +1,7 @@
|
|
1
1
|
module Formtastic
|
2
2
|
module Inputs
|
3
|
+
# Outputs a series of select boxes for the fragments that make up a time (hour, minute, second).
|
4
|
+
#
|
3
5
|
# @see Formtastic::Inputs::Timeish Timeish module for documetation of date, time and datetime input options.
|
4
6
|
class TimeInput
|
5
7
|
include Base
|
data/lib/formtastic/version.rb
CHANGED
@@ -418,7 +418,7 @@ describe 'select input' do
|
|
418
418
|
end
|
419
419
|
|
420
420
|
it 'should have a select with prompt' do
|
421
|
-
output_buffer.should have_tag("form li select option[@value='']", /choose author
|
421
|
+
output_buffer.should have_tag("form li select option[@value='']", /choose author/, :count => 1)
|
422
422
|
end
|
423
423
|
|
424
424
|
it 'should not have a blank select option' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: formtastic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 977940591
|
5
5
|
prerelease: true
|
6
6
|
segments:
|
7
7
|
- 2
|
8
8
|
- 0
|
9
9
|
- 0
|
10
|
-
-
|
11
|
-
version: 2.0.0.
|
10
|
+
- rc2
|
11
|
+
version: 2.0.0.rc2
|
12
12
|
platform: ruby
|
13
13
|
authors:
|
14
14
|
- Justin French
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2011-06-
|
19
|
+
date: 2011-06-13 00:00:00 +10:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|