sinatra_more 0.0.13 → 0.0.14

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.
data/README.rdoc CHANGED
@@ -98,21 +98,128 @@ methods should be very familiar to anyone who has used rails view helpers.
98
98
 
99
99
  ==== Form Helpers
100
100
 
101
- * form_for(object, url, settings={}, &block)
102
101
  * form_tag(url, options={}, &block)
102
+ * Constructs a form without object based on options
103
+ * form_tag('/register', :class => 'example') { ... }
103
104
  * field_set_tag(*args, &block)
105
+ * Constructs a field_set to group fields with given options
106
+ * field_set_tag(:class => 'office-set') { }
107
+ * field_set_tag("Office", :class => 'office-set') { }
104
108
  * error_messages_for(record, options={})
109
+ * Constructs list html for the errors for a given object
110
+ * error_messages_for @user
105
111
  * label_tag(name, options={}, &block)
112
+ * Constructs a label tag from the given options
113
+ * label_tag :username, :class => 'long-label'
114
+ * label_tag(:username, :class => 'blocked-label') { ... }
106
115
  * text_field_tag(name, options={})
116
+ * Constructs a text field input from the given options
117
+ * text_field_tag :username, :class => 'long'
107
118
  * text_area_tag(name, options={})
119
+ * Constructs a text area input from the given options
120
+ * text_area_tag :username, :class => 'long'
108
121
  * password_field_tag(name, options={})
122
+ * Constructs a password field input from the given options
123
+ * password_field_tag :password, :class => 'long'
109
124
  * file_field_tag(name, options={})
125
+ * Constructs a file field input from the given options
126
+ * file_field_tag :photo, :class => 'long'
110
127
  * submit_tag(caption, options={})
128
+ * Constructs a submit button from the given options
129
+ * submit_tag "Create", :class => 'success'
130
+
131
+ A form_tag might look like:
132
+
133
+ - form_tag '/login', :class => 'login-form' do
134
+ = flash_tag(:notice)
135
+ - field_set_tag do
136
+ %p
137
+ = label_tag :username, :class => 'first'
138
+ = text_field_tag :username, :value => params[:username]
139
+ %p
140
+ = label_tag :password, :class => 'first'
141
+ = text_field_tag :password, :value => params[:password]
142
+ - field_set_tag(:class => 'buttons') do
143
+ = submit_tag "Login"
144
+
145
+ ==== FormBuilders ====
146
+
147
+ * form_for(object, url, settings={}, &block)
148
+ * Constructs a form using given or default form_builder
149
+ * form_for(@user, '/register', :id => 'register') { |f| ...field-elements... }
150
+
151
+ The following are fields provided by AbstractFormBuilder that can be used within a form_for:
152
+
153
+ * error_messages(options={})
154
+ * Displays list html for the errors on form object
155
+ * f.errors_messages
156
+ * label(field, options={})
157
+ * f.label :name, :class => 'long'
158
+ * text_field(field, options={})
159
+ * f.text_field :username, :class => 'long'
160
+ * text_area(field, options={})
161
+ * f.text_area :summary, :class => 'long'
162
+ * password_field(field, options={})
163
+ * f.password_field :secret, :class => 'long'
164
+ * file_field(field, options={})
165
+ * f.file_field :photo, :class => 'long'
166
+ * submit(caption, options={})
167
+ * f.submit "Update", :class => 'long'
168
+
169
+ A form_for using these basic fields might look like:
170
+
171
+ - form_for @user, '/register', :id => 'register' do |f|
172
+ = f.error_messages
173
+ %p
174
+ = f.label :username
175
+ = f.text_field :username
176
+ %p
177
+ = f.label :email
178
+ = f.text_field :email
179
+ %p
180
+ = f.label :password
181
+ = f.password_field :password
182
+ %p
183
+ = f.submit "Create"
184
+
185
+ There is also a StandardFormBuilder which builds on the abstract fields that can be used within a form_for:
186
+
187
+ * text_field_block(field, options={}, label_options={})
188
+ * text_field_block(:nickname, :class => 'big', :caption => "Username")
189
+ * text_area_block(field, options={}, label_options={})
190
+ * text_area_block(:about, :class => 'big')
191
+ * password_field_block(field, options={}, label_options={})
192
+ * password_field_block(:code, :class => 'big')
193
+ * file_field_block(field, options={}, label_options={})
194
+ * file_field_block(:photo, :class => 'big')
195
+ * submit_block(caption, options={})
196
+ * submit_block(:username, :class => 'big')
197
+
198
+ A form_for using these standard fields might look like:
199
+
200
+ - form_for @user, '/register', :id => 'register' do |f|
201
+ = f.error_messages
202
+ = f.text_field_block :username
203
+ = f.text_field_block :email
204
+ = f.password_field_block :password
205
+ = f.submit_block "Create"
206
+
207
+ and would generate this html:
208
+
209
+ <form id="register" action="/register" method="post">
210
+ <p><label for="user_name">Name: </label><input type="text" id="user_name" name="user[name]"></p>
211
+ ...omitted...
212
+ <p><input type="submit" value="Create"></p>
213
+ </form>
111
214
 
112
215
  ==== Format Helpers
113
216
 
114
217
  * relative_time_ago(date)
218
+ * Returns relative time in words referencing the given date
219
+ * relative_time_ago(2.days.ago) => "2 days ago"
115
220
  * escape_javascript(html_content)
221
+ * Escapes html to allow passing information to javascript. Used for passing data inside an ajax .js.erb template
222
+ * escape_javascript("<h1>Hey</h1>")
116
223
 
117
224
  === RenderPlugin
118
225
 
@@ -121,9 +228,19 @@ of displaying templates far smoother. This plugin also has support for useful ad
121
228
  such as partials (with support for :collection) into the templating system.
122
229
 
123
230
  * erb_template(template_path, options={})
231
+ * Renders a erb template based on the given path
232
+ * erb_template 'users/new'
124
233
  * haml_template(template_path, options={})
234
+ * Renders a haml template based on the given path
235
+ * haml_template 'users/new'
125
236
  * render_template(template_path, options={})
237
+ * Renders the first detected template based on the given path
238
+ * render_template 'users/new'
239
+ * render_template 'users/index', :template_engine => 'haml'
126
240
  * partial(template, *args)
241
+ * Renders the html related to the partial template for object or collection
242
+ * partial 'photo/_item', :object => @photo, :locals => { :foo => 'bar' }
243
+ * partial 'photo/_item', :collection => @photos
127
244
 
128
245
  === WardenPlugin
129
246
 
@@ -132,11 +249,20 @@ plugin registered, warden will be automatically required, configured and helpers
132
249
  provided to make interacting with warden dead simple.
133
250
 
134
251
  * current_user
252
+ * Returns the current authenticated user
135
253
  * authenticate_user!
254
+ * Login the user through the default warden strategies
136
255
  * logout_user!
256
+ * Signs out the user from the session
137
257
  * logged_in?
258
+ * Returns true if the user has been authenticated
138
259
  * authenticated?(&block)
260
+ * If a block is given, only yields the content if the user is authenticated
261
+ * authenticated? { puts "I am authenticated!" }
139
262
  * must_be_authorized!(failure_path=nil)
263
+ * Forces a user to return to a fail path unless they are authorized
264
+ * Used to require a user be authenticated before routing to an action
265
+ * must_be_authorized!('/login')
140
266
 
141
267
  == Acknowledgements
142
268
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.13
1
+ 0.0.14
@@ -17,9 +17,9 @@ class StandardFormBuilder < AbstractFormBuilder
17
17
  end
18
18
 
19
19
  # submit_block("Update")
20
- def submit_block(caption)
20
+ def submit_block(caption, options={})
21
21
  @template.content_block_tag(:p) do
22
- @template.submit_tag(caption)
22
+ @template.submit_tag(caption, options)
23
23
  end
24
24
  end
25
25
  end
@@ -1,20 +1,24 @@
1
1
  module SinatraMore
2
2
  module FormHelpers
3
+ # Constructs a form for object using given or default form_builder
3
4
  # form_for @user, '/register', :id => 'register' do |f| ... end
4
5
  def form_for(object, url, settings={}, &block)
5
- configured_builder = settings[:builder] || self.options.default_builder.constantize
6
+ configured_builder = settings[:builder] || self.options.default_builder || 'StandardFormBuilder'
7
+ configured_builder = configured_builder.constantize if configured_builder.is_a?(String)
6
8
  settings.reverse_merge!(:method => 'post', :action => url)
7
9
  settings[:enctype] = "multipart/form-data" if settings.delete(:multipart)
8
10
  form_html = capture_html(configured_builder.new(self, object), &block)
9
11
  concat_content content_tag('form', form_html, settings)
10
12
  end
11
13
 
14
+ # Constructs a form without object based on options
12
15
  # form_tag '/register' do ... end
13
16
  def form_tag(url, options={}, &block)
14
17
  options.reverse_merge!(:method => 'post', :action => url)
15
18
  concat_content content_tag('form', capture_html(&block), options)
16
19
  end
17
20
 
21
+ # Constructs a field_set to group fields with given options
18
22
  # field_set_tag("Office", :class => 'office-set')
19
23
  # parameters: legend_text=nil, options={}
20
24
  def field_set_tag(*args, &block)
@@ -25,6 +29,7 @@ module SinatraMore
25
29
  concat_content content_tag('fieldset', field_set_content, options)
26
30
  end
27
31
 
32
+ # Constructs list html for the errors for a given object
28
33
  # error_messages_for @user
29
34
  def error_messages_for(record, options={})
30
35
  return "" if record.blank? or record.errors.none?
@@ -38,6 +43,7 @@ module SinatraMore
38
43
  end
39
44
  end
40
45
 
46
+ # Constructs a label tag from the given options
41
47
  # label_tag :username, :class => 'long-label'
42
48
  # label_tag :username, :class => 'long-label' do ... end
43
49
  def label_tag(name, options={}, &block)
@@ -51,30 +57,35 @@ module SinatraMore
51
57
  end
52
58
  end
53
59
 
60
+ # Constructs a text field input from the given options
54
61
  # text_field_tag :username, :class => 'long'
55
62
  def text_field_tag(name, options={})
56
63
  options.reverse_merge!(:name => name)
57
64
  input_tag(:text, options)
58
65
  end
59
66
 
67
+ # Constructs a text area input from the given options
60
68
  # text_area_tag :username, :class => 'long'
61
69
  def text_area_tag(name, options={})
62
70
  options.reverse_merge!(:name => name)
63
71
  content_tag(:textarea, '', options)
64
72
  end
65
73
 
74
+ # Constructs a password field input from the given options
66
75
  # password_field_tag :password, :class => 'long'
67
76
  def password_field_tag(name, options={})
68
77
  options.reverse_merge!(:name => name)
69
78
  input_tag(:password, options)
70
79
  end
71
80
 
72
- # field_field_tag :photo, :class => 'long'
81
+ # Constructs a file field input from the given options
82
+ # file_field_tag :photo, :class => 'long'
73
83
  def file_field_tag(name, options={})
74
84
  options.reverse_merge!(:name => name)
75
85
  input_tag(:file, options)
76
86
  end
77
87
 
88
+ # Constructs a submit button from the given options
78
89
  # submit_tag "Create", :class => 'success'
79
90
  def submit_tag(caption, options={})
80
91
  options.reverse_merge!(:value => caption)
@@ -1,6 +1,7 @@
1
1
  module SinatraMore
2
2
  module FormatHelpers
3
3
 
4
+ # Returns relative time in words referencing the given date
4
5
  # relative_time_ago(Time.now)
5
6
  def relative_time_ago(date)
6
7
  date = date.to_date
@@ -18,8 +19,8 @@ module SinatraMore
18
19
  return date.strftime('%A, %B %e, %Y')
19
20
  end
20
21
 
21
- # escape_javascript("<h1>Hey</h1>")
22
22
  # Used in xxxx.js.erb files to escape html so that it can be passed to javascript from sinatra
23
+ # escape_javascript("<h1>Hey</h1>")
23
24
  def escape_javascript(html_content)
24
25
  return '' unless html_content
25
26
  javascript_mapping = { '\\' => '\\\\', '</' => '<\/', "\r\n" => '\n', "\n" => '\n' }
@@ -39,6 +39,7 @@ module SinatraMore
39
39
  render_template(template_path, options)
40
40
  end
41
41
  end
42
+ alias render_partial partial
42
43
 
43
44
  private
44
45
 
data/sinatra_more.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{sinatra_more}
8
- s.version = "0.0.13"
8
+ s.version = "0.0.14"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Nathan Esquenazi"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra_more
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.13
4
+ version: 0.0.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Esquenazi