backbone_form_helper 0.0.1.1.alpha → 0.0.1.2.alpha
Sign up to get free protection for your applications and to get access to all the features.
data/README.md
CHANGED
@@ -5,13 +5,15 @@ This Rails gem provide javascript form helper based on Rails principle like 'f.t
|
|
5
5
|
template for each of them (eg. /templates/text_field). Now are templates
|
6
6
|
created in Twitter bootstrap style.
|
7
7
|
|
8
|
-
|
8
|
+
#### This is still alpha.
|
9
|
+
|
9
10
|
|
10
11
|
## Installation
|
11
12
|
|
12
13
|
External dependencies:
|
13
14
|
|
14
15
|
* underscore.js
|
16
|
+
* sass-rails
|
15
17
|
* coffee-rails for assets (now js are written in .coffee)
|
16
18
|
|
17
19
|
Add this line to your application's Gemfile:
|
@@ -26,6 +28,13 @@ Or install it yourself as:
|
|
26
28
|
|
27
29
|
$ gem install backbone_form_helper
|
28
30
|
|
31
|
+
Run this from command line:
|
32
|
+
|
33
|
+
$ rails g backbone_form_helper:copy
|
34
|
+
|
35
|
+
This will copy scss/css and coffee script files into your
|
36
|
+
vendor/assets/javascripts(stylesheets) directory. If you set as argument
|
37
|
+
different destination, it will be copied there (eg. 'app/assets/').
|
29
38
|
|
30
39
|
Add this line into your application.js:
|
31
40
|
|
@@ -39,40 +48,116 @@ Add this line into your application.scss:
|
|
39
48
|
@import 'form_helper/form_helper';
|
40
49
|
```
|
41
50
|
|
51
|
+
Templates for fields are in directory 'javascripts/form_helper/templates' so you can change them by your needs. They are in eco templates.
|
52
|
+
|
42
53
|
## Helper list
|
43
54
|
For now:
|
44
55
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
56
|
+
### new FormHelper(model, options=optional)
|
57
|
+
`f = new FormHelper @task` -> take prefix for fields name from class name of model. If task is instance of class Task, then **'f.text_field :name'** will generate name **task[name]**
|
58
|
+
|
59
|
+
`f = new FormHelper @task, {name: 'issue'}` -> **'f.text_field :name'** will generate **issue[name]**
|
60
|
+
### label(method, text=optional, {html_options=optional})
|
61
|
+
Return tag of label. If model has error on this method class 'error' will be added.
|
62
|
+
|
63
|
+
```rhtml
|
64
|
+
f.label 'name'
|
65
|
+
# => <label for="task_name">Name</label>
|
66
|
+
f.label :name, 'Title'
|
67
|
+
# => <label for="task_name">Title</label>
|
68
|
+
f.label :name, {class: 'red bold'}
|
69
|
+
# => <label for="task_name" class="red bold">Name</label>
|
70
|
+
|
71
|
+
```
|
72
|
+
### text_field(method, value=optional, html_options={optional})
|
73
|
+
Return text field with prefilled value from model if value isn't directly defined. Added class 'error' if model has error on method and show errors on method.
|
74
|
+
|
75
|
+
```rhtml
|
76
|
+
f.text_field 'name'
|
77
|
+
# => <input type="text" id="task_name" name="task[name]" value="#{model.name value}" />
|
78
|
+
# => <span class="help-inline">#{errors on name}</span>
|
79
|
+
|
80
|
+
f.text_field 'name', 'John'
|
81
|
+
# => <input type="text" id="task_name" name="task[name]" value="John" />
|
82
|
+
# => <span class="help-inline">#{errors on name}</span>
|
83
|
+
|
84
|
+
f.text_field 'name', {placeholder: 'name of person', class: 'mandatory'}
|
85
|
+
# => <input type="text" id="task_name" name="task[name]" placeholder="name of person" class="mandatory"/>
|
86
|
+
# => <span class="help-inline">#{errors on name}</span>
|
87
|
+
```
|
88
|
+
### text_area(method, value=optional, html_options={optional})
|
89
|
+
Same as text_field but with textarea tag.
|
90
|
+
|
91
|
+
### select(method, options, html_options={optional})
|
92
|
+
Return select tag with set options and selected option by value of method on model if value isn't set directly.
|
93
|
+
|
94
|
+
```rhtml
|
95
|
+
f.select 'group_id', {values: _.map(@groups, (g) -> [g.get('_id'), g.get('name')])}, {class: 'mandatory'}
|
96
|
+
# => <select id="task_group_id" name="task[group_id]" class="mandatory">#{generated options}</option>
|
97
|
+
|
98
|
+
f.select 'group_id', {values: _.map(@groups, (g) -> [g.get('_id'), g.get('name')]), value: '12'}
|
99
|
+
# => return select tag with selected option with value '12'
|
100
|
+
```
|
101
|
+
### select_tag
|
102
|
+
Similar as 'select', but is not relate to model (like in RoR)
|
103
|
+
|
104
|
+
```rhtml
|
105
|
+
f.select_tag 'only_group_id', {values: _.map(@groups, (g) -> [g.get('_id'), g.get('name')]), value: '12'}
|
106
|
+
# => <select id="only_group_id" name="only_group_id" class="mandatory">#{generated options}</option>
|
107
|
+
```
|
108
|
+
### check_box(method, value=optional, html_options={optional})
|
109
|
+
|
110
|
+
```rhtml
|
111
|
+
f.check_box 'is_done'
|
112
|
+
# =><label class="checkbox">
|
113
|
+
<input id="task_is_done" name="task[is_done]" type="hidden" value="false">
|
114
|
+
<input id="task_is_done" name="task[is_done]" type="checkbox"
|
115
|
+
value="true" #{'checked' if method of model is 1 or true}>
|
116
|
+
</label>
|
117
|
+
|
118
|
+
f.check_box 'is_done', {title: 'Tick this for done'}
|
119
|
+
# =><label class="checkbox">
|
120
|
+
<input id="task_is_done" name="task[is_done]" type="hidden" value="false">
|
121
|
+
<input id="task_is_done" name="task[is_done]" type="checkbox"
|
122
|
+
value="true" #{'checked' if method of model is 1 or true}>
|
123
|
+
Tick this for done
|
124
|
+
</label>
|
125
|
+
```
|
126
|
+
### date_field
|
127
|
+
Return bootstrap-datepicker date field (see on [http://www.eyecon.ro/bootstrap-datepicker](http://))
|
128
|
+
|
129
|
+
```rhtml
|
130
|
+
f.date_field 'date', class: 'text_field', placeholder: 'date'
|
131
|
+
```
|
52
132
|
|
53
133
|
## Usage
|
54
134
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
135
|
+
```rhtml
|
136
|
+
<% form = new FormHelper @task %>
|
137
|
+
<%- form.check_box 'is_done', title: 'Is done' %>
|
138
|
+
<%- form.date_field 'date', class: 'text_field', placeholder: 'datum' %>
|
139
|
+
<%- form.text_area 'description', placeholder: 'ukol' %>
|
140
|
+
<%- form.select 'group_id', values: _.map(@groups, (g) -> [g.get('_id'), g.get('name')]) %>
|
141
|
+
<%- form.select 'user_id', values: _.map(@users, (g) -> [g.get('_id'), g.get('name')]) %>
|
142
|
+
````
|
62
143
|
|
63
144
|
Value and errors are taken from model automaticly how Rails do it and shown in template (eg. text_field template):
|
64
145
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
146
|
+
```rhtml
|
147
|
+
<input type="text" id="<%= @field_id %>" <%- @unfold_options %> name="<%= @field_name %>" value="<%= @value %>" />
|
148
|
+
<span class="help-inline">
|
149
|
+
<%= @errors if @errors %>
|
150
|
+
</span>
|
151
|
+
```
|
69
152
|
|
70
153
|
so after render when model has error on name (model.errors['name'] or model.get('errors')['name']) it looks like:
|
71
154
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
155
|
+
```rhtml
|
156
|
+
<input type="text" id="task_name" placeholder="ukol" class="error" name="task[name]" value="">
|
157
|
+
<span class="help-inline">
|
158
|
+
can't be blank
|
159
|
+
</span>
|
160
|
+
```
|
76
161
|
|
77
162
|
## Contributing
|
78
163
|
|
@@ -81,3 +166,4 @@ so after render when model has error on name (model.errors['name'] or model.get(
|
|
81
166
|
3. Commit your changes (`git commit -am 'Added some feature'`)
|
82
167
|
4. Push to the branch (`git push origin my-new-feature`)
|
83
168
|
5. Create new Pull Request
|
169
|
+
|
data/lib/backbone_form_helper.rb
CHANGED
@@ -0,0 +1,14 @@
|
|
1
|
+
module BackboneFormHelper
|
2
|
+
module Generators
|
3
|
+
class CopyGenerator < ::Rails::Generators::Base
|
4
|
+
desc "Copy files into your project (default vendor/assetes/..)"
|
5
|
+
source_root File.expand_path('../../../../../vendor/assets/', __FILE__)
|
6
|
+
argument :destination, type: :string, default: 'vendor/assets/'
|
7
|
+
|
8
|
+
def create_initializer
|
9
|
+
directory "#{source_paths.first}/javascripts/form_helper", "#{destination}javascripts/form_helper"
|
10
|
+
directory "#{source_paths.first}/stylesheets/form_helper", "#{destination}stylesheets/form_helper"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: backbone_form_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1.
|
4
|
+
version: 0.0.1.2.alpha
|
5
5
|
prerelease: 8
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-11-18 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Form helper for backbone based on Rails priciple -> f.text_field :name
|
15
15
|
email:
|
@@ -26,7 +26,9 @@ files:
|
|
26
26
|
- backbone_form_helper.gemspec
|
27
27
|
- lib/backbone_form_helper.rb
|
28
28
|
- lib/backbone_form_helper/engine.rb
|
29
|
+
- lib/backbone_form_helper/railtie.rb
|
29
30
|
- lib/backbone_form_helper/version.rb
|
31
|
+
- lib/rails/generators/backbone_form_helper/copy_generator.rb
|
30
32
|
- vendor/assets/javascripts/form_helper/bootstrap-datepicker.js
|
31
33
|
- vendor/assets/javascripts/form_helper/form_helper.js.coffee
|
32
34
|
- vendor/assets/javascripts/form_helper/templates/check_box.jst.eco
|