sinatra_more 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -23,9 +23,9 @@ of tools, helpers and components that will make Sinatra suitable for more comple
23
23
 
24
24
  Here is a small list of what sinatra_more contains:
25
25
 
26
- * Generic view and tag helpers (tag, content_tag, input_tag, ...)
27
- * Asset helpers (link_to, image_tag, javascript_include_tag, ...)
28
- * Form helpers and builder support (form_tag, form_for, field_set_tag, text_field, ...)
26
+ * Generic view and tag helpers (<tt>tag</tt>, <tt>content_tag</tt>, <tt>input_tag</tt>, ...)
27
+ * Asset helpers (<tt>link_to</tt>, <tt>image_tag</tt>, <tt>javascript_include_tag</tt>, ...)
28
+ * Form helpers and builder support (<tt>form_tag</tt>, <tt>form_for</tt>, <tt>field_set_tag</tt>, <tt>text_field</tt>, ...)
29
29
  * Plug and play setup for the excellent Warden authentication system
30
30
  * Code generators for creating a new sinatra application
31
31
 
@@ -35,8 +35,8 @@ Please help me brainstorm and fork the project if you have any ideas to contribu
35
35
 
36
36
  == Installation
37
37
 
38
- This gem has very few runtime dependencies. The 'sinatra' gem needs to be installed and also 'activesupport'.
39
- If you want to use the WardenPlugin component, then the 'warden' gem is also required.
38
+ This gem has very few runtime dependencies. The 'sinatra' gem needs to be installed and also 'activesupport' (for the inflectors).
39
+ If you want to use the WardenPlugin component, then the 'warden' gem would also be required.
40
40
 
41
41
  To install sinatra_more, simply grab the latest version from gemcutter:
42
42
 
@@ -69,78 +69,78 @@ methods should be very familiar to anyone who has used rails view helpers.
69
69
 
70
70
  ==== Output Helpers
71
71
 
72
- * capture_html(*args, &block)
72
+ * <tt>capture_html(*args, &block)</tt>
73
73
  * Captures the html from a block of template code for erb or haml
74
- * capture_html(&block) => "...html..."
75
- * concat_content(text="")
74
+ * <tt>capture_html(&block)</tt> => "...html..."
75
+ * <tt>concat_content(text="")</tt>
76
76
  * Outputs the given text to the templates buffer directly in erb or haml
77
- * concat_content("This will be output to the template buffer in erb or haml")
77
+ * <tt>concat_content("This will be output to the template buffer in erb or haml")</tt>
78
78
 
79
79
  ==== Tag Helpers
80
80
 
81
- * tag(name, options={})
81
+ * <tt>tag(name, options={})</tt>
82
82
  * Creates an html tag with the given name and options
83
- * tag(:br, :style => 'clear:both') => <br style="clear:both" />
84
- * tag(:p, :content => "demo", :class => 'large') => <p class="large">demo</p>
85
- * content_tag(name, content, options={})
83
+ * <tt>tag(:br, :style => 'clear:both')</tt> => <br style="clear:both" />
84
+ * <tt>tag(:p, :content => "demo", :class => 'large')</tt> => <p class="large">demo</p>
85
+ * <tt>content_tag(name, content, options={})</tt>
86
86
  * Creates an html tag with given name, content and options
87
- * content_tag(:p, "demo", :class => 'light') => <p class="light">demo</p>
88
- * content_tag(:p, :class => 'dark') { ...content... } => <p class="dark">...content...</p>
89
- * input_tag(type, options = {})
87
+ * <tt>content_tag(:p, "demo", :class => 'light')</tt> => <p class="light">demo</p>
88
+ * <tt>content_tag(:p, :class => 'dark') { ...content... }</tt> => <p class="dark">...content...</p>
89
+ * <tt>input_tag(type, options = {})</tt>
90
90
  * Creates an html input field with given type and options
91
- * input_tag :text, :class => "demo"
92
- * input_tag :password, :value => "secret", :class => "demo"
91
+ * <tt>input_tag :text, :class => "demo"</tt>
92
+ * <tt>input_tag :password, :value => "secret", :class => "demo"</tt>
93
93
 
94
94
  ==== Asset Helpers
95
95
 
96
- * flash_tag(kind, options={})
96
+ * <tt>flash_tag(kind, options={})</tt>
97
97
  * Creates a div to display the flash of given type if it exists
98
- * flash_tag(:notice, :class => 'flash', :id => 'flash-notice')
99
- * link_to(*args, &block)
98
+ * <tt>flash_tag(:notice, :class => 'flash', :id => 'flash-notice')</tt>
99
+ * <tt>link_to(*args, &block)</tt>
100
100
  * Creates a link element with given name, url and options
101
- * link_to 'click me', '/dashboard', :class => 'linky'
102
- * link_to('/dashboard', :class => 'blocky') { ...content... }
103
- * image_tag(url, options={})
101
+ * <tt>link_to 'click me', '/dashboard', :class => 'linky'</tt>
102
+ * <tt>link_to('/dashboard', :class => 'blocky') { ...content... }</tt>
103
+ * <tt>image_tag(url, options={})</tt>
104
104
  * Creates an image element with given url and options
105
- * image_tag('icons/avatar.png')
106
- * stylesheet_link_tag(*sources)
105
+ * <tt>image_tag('icons/avatar.png')</tt>
106
+ * <tt>stylesheet_link_tag(*sources)</tt>
107
107
  * Returns a stylesheet link tag for the sources specified as arguments
108
- * stylesheet_link_tag 'style', 'application', 'layout'
109
- * javascript_include_tag(*sources)
108
+ * <tt>stylesheet_link_tag 'style', 'application', 'layout'</tt>
109
+ * <tt>javascript_include_tag(*sources)</tt>
110
110
  * Returns an html script tag for each of the sources provided.
111
- * javascript_include_tag 'application', 'special'
111
+ * <tt>javascript_include_tag 'application', 'special'</tt>
112
112
 
113
113
  ==== Form Helpers
114
114
 
115
- * form_tag(url, options={}, &block)
115
+ * <tt>form_tag(url, options={}, &block)</tt>
116
116
  * Constructs a form without object based on options
117
- * form_tag('/register', :class => 'example') { ... }
118
- * field_set_tag(*args, &block)
117
+ * <tt>form_tag('/register', :class => 'example') { ... }</tt>
118
+ * <tt>field_set_tag(*args, &block)</tt>
119
119
  * Constructs a field_set to group fields with given options
120
- * field_set_tag(:class => 'office-set') { }
121
- * field_set_tag("Office", :class => 'office-set') { }
122
- * error_messages_for(record, options={})
120
+ * <tt>field_set_tag(:class => 'office-set') { }</tt>
121
+ * <tt>field_set_tag("Office", :class => 'office-set') { }</tt>
122
+ * <tt>error_messages_for(record, options={})</tt>
123
123
  * Constructs list html for the errors for a given object
124
- * error_messages_for @user
125
- * label_tag(name, options={}, &block)
124
+ * <tt>error_messages_for @user</tt>
125
+ * <tt>label_tag(name, options={}, &block)</tt>
126
126
  * Constructs a label tag from the given options
127
- * label_tag :username, :class => 'long-label'
128
- * label_tag(:username, :class => 'blocked-label') { ... }
129
- * text_field_tag(name, options={})
127
+ * <tt>label_tag :username, :class => 'long-label'</tt>
128
+ * <tt>label_tag(:username, :class => 'blocked-label') { ... }</tt>
129
+ * <tt>text_field_tag(name, options={})</tt>
130
130
  * Constructs a text field input from the given options
131
- * text_field_tag :username, :class => 'long'
132
- * text_area_tag(name, options={})
131
+ * <tt>text_field_tag :username, :class => 'long'</tt>
132
+ * <tt>text_area_tag(name, options={})</tt>
133
133
  * Constructs a text area input from the given options
134
- * text_area_tag :username, :class => 'long'
135
- * password_field_tag(name, options={})
134
+ * <tt>text_area_tag :username, :class => 'long'</tt>
135
+ * <tt>password_field_tag(name, options={})</tt>
136
136
  * Constructs a password field input from the given options
137
- * password_field_tag :password, :class => 'long'
138
- * file_field_tag(name, options={})
137
+ * <tt>password_field_tag :password, :class => 'long'</tt>
138
+ * <tt>file_field_tag(name, options={})</tt>
139
139
  * Constructs a file field input from the given options
140
- * file_field_tag :photo, :class => 'long'
141
- * submit_tag(caption, options={})
140
+ * <tt>file_field_tag :photo, :class => 'long'</tt>
141
+ * <tt>submit_tag(caption, options={})</tt>
142
142
  * Constructs a submit button from the given options
143
- * submit_tag "Create", :class => 'success'
143
+ * <tt>submit_tag "Create", :class => 'success'</tt>
144
144
 
145
145
  A form_tag might look like:
146
146
 
@@ -158,27 +158,27 @@ A form_tag might look like:
158
158
 
159
159
  ==== FormBuilders
160
160
 
161
- * form_for(object, url, settings={}, &block)
161
+ * <tt>form_for(object, url, settings={}, &block)</tt>
162
162
  * Constructs a form using given or default form_builder
163
- * form_for(@user, '/register', :id => 'register') { |f| ...field-elements... }
163
+ * <tt>form_for(@user, '/register', :id => 'register') { |f| ...field-elements... }</tt>
164
164
 
165
165
  The following are fields provided by AbstractFormBuilder that can be used within a form_for:
166
166
 
167
- * error_messages(options={})
167
+ * <tt>error_messages(options={})</tt>
168
168
  * Displays list html for the errors on form object
169
- * f.errors_messages
170
- * label(field, options={})
171
- * f.label :name, :class => 'long'
172
- * text_field(field, options={})
173
- * f.text_field :username, :class => 'long'
174
- * text_area(field, options={})
175
- * f.text_area :summary, :class => 'long'
176
- * password_field(field, options={})
177
- * f.password_field :secret, :class => 'long'
178
- * file_field(field, options={})
179
- * f.file_field :photo, :class => 'long'
180
- * submit(caption, options={})
181
- * f.submit "Update", :class => 'long'
169
+ * <tt>f.errors_messages</tt>
170
+ * <tt>label(field, options={})</tt>
171
+ * <tt>f.label :name, :class => 'long'</tt>
172
+ * <tt>text_field(field, options={})</tt>
173
+ * <tt>f.text_field :username, :class => 'long'</tt>
174
+ * <tt>text_area(field, options={})</tt>
175
+ * <tt>f.text_area :summary, :class => 'long'</tt>
176
+ * <tt>password_field(field, options={})</tt>
177
+ * <tt>f.password_field :secret, :class => 'long'</tt>
178
+ * <tt>file_field(field, options={})</tt>
179
+ * <tt>f.file_field :photo, :class => 'long'</tt>
180
+ * <tt>submit(caption, options={})</tt>
181
+ * <tt>f.submit "Update", :class => 'long'</tt>
182
182
 
183
183
  A form_for using these basic fields might look like:
184
184
 
@@ -198,16 +198,16 @@ A form_for using these basic fields might look like:
198
198
 
199
199
  There is also a StandardFormBuilder which builds on the abstract fields that can be used within a form_for:
200
200
 
201
- * text_field_block(field, options={}, label_options={})
202
- * text_field_block(:nickname, :class => 'big', :caption => "Username")
203
- * text_area_block(field, options={}, label_options={})
204
- * text_area_block(:about, :class => 'big')
205
- * password_field_block(field, options={}, label_options={})
206
- * password_field_block(:code, :class => 'big')
207
- * file_field_block(field, options={}, label_options={})
208
- * file_field_block(:photo, :class => 'big')
209
- * submit_block(caption, options={})
210
- * submit_block(:username, :class => 'big')
201
+ * <tt>text_field_block(field, options={}, label_options={})</tt>
202
+ * <tt>text_field_block(:nickname, :class => 'big', :caption => "Username")</tt>
203
+ * <tt>text_area_block(field, options={}, label_options={})</tt>
204
+ * <tt>text_area_block(:about, :class => 'big')</tt>
205
+ * <tt>password_field_block(field, options={}, label_options={})</tt>
206
+ * <tt>password_field_block(:code, :class => 'big')</tt>
207
+ * <tt>file_field_block(field, options={}, label_options={})</tt>
208
+ * <tt>file_field_block(:photo, :class => 'big')</tt>
209
+ * <tt>submit_block(caption, options={})</tt>
210
+ * <tt>submit_block(:username, :class => 'big')</tt>
211
211
 
212
212
  A form_for using these standard fields might look like:
213
213
 
@@ -228,12 +228,12 @@ and would generate this html:
228
228
 
229
229
  ==== Format Helpers
230
230
 
231
- * relative_time_ago(date)
231
+ * <tt>relative_time_ago(date)</tt>
232
232
  * Returns relative time in words referencing the given date
233
- * relative_time_ago(2.days.ago) => "2 days ago"
234
- * escape_javascript(html_content)
233
+ * <tt>relative_time_ago(2.days.ago)</tt> => "2 days ago"
234
+ * <tt>escape_javascript(html_content)</tt>
235
235
  * Escapes html to allow passing information to javascript. Used for passing data inside an ajax .js.erb template
236
- * escape_javascript("<h1>Hey</h1>")
236
+ * <tt>escape_javascript("<h1>Hey</h1>")</tt>
237
237
 
238
238
  === RenderPlugin
239
239
 
@@ -241,20 +241,20 @@ This component provides a number of rendering helpers for sinatra, making the pr
241
241
  of displaying templates far smoother. This plugin also has support for useful additions
242
242
  such as partials (with support for :collection) into the templating system.
243
243
 
244
- * erb_template(template_path, options={})
244
+ * <tt>erb_template(template_path, options={})</tt>
245
245
  * Renders a erb template based on the given path
246
- * erb_template 'users/new'
247
- * haml_template(template_path, options={})
246
+ * <tt>erb_template 'users/new'</tt>
247
+ * <tt>haml_template(template_path, options={})</tt>
248
248
  * Renders a haml template based on the given path
249
- * haml_template 'users/new'
250
- * render_template(template_path, options={})
249
+ * <tt>haml_template 'users/new'</tt>
250
+ * <tt>render_template(template_path, options={})</tt>
251
251
  * Renders the first detected template based on the given path
252
- * render_template 'users/new'
253
- * render_template 'users/index', :template_engine => 'haml'
254
- * partial(template, *args)
252
+ * <tt>render_template 'users/new'</tt>
253
+ * <tt>render_template 'users/index', :template_engine => 'haml'</tt>
254
+ * <tt>partial(template, *args)</tt>
255
255
  * Renders the html related to the partial template for object or collection
256
- * partial 'photo/_item', :object => @photo, :locals => { :foo => 'bar' }
257
- * partial 'photo/_item', :collection => @photos
256
+ * <tt>partial 'photo/_item', :object => @photo, :locals => { :foo => 'bar' }</tt>
257
+ * <tt>partial 'photo/_item', :collection => @photos</tt>
258
258
 
259
259
  === WardenPlugin
260
260
 
@@ -262,21 +262,21 @@ This component provides out-of-the-box support for Warden authentication. With t
262
262
  plugin registered, warden will be automatically required, configured and helpers will be
263
263
  provided to make interacting with warden dead simple.
264
264
 
265
- * current_user
265
+ * <tt>current_user</tt>
266
266
  * Returns the current authenticated user
267
- * authenticate_user!
267
+ * <tt>authenticate_user!</tt>
268
268
  * Login the user through the default warden strategies
269
- * logout_user!
269
+ * <tt>logout_user!</tt>
270
270
  * Signs out the user from the session
271
- * logged_in?
271
+ * <tt>logged_in?</tt>
272
272
  * Returns true if the user has been authenticated
273
- * authenticated?(&block)
273
+ * <tt>authenticated?(&block)</tt>
274
274
  * If a block is given, only yields the content if the user is authenticated
275
- * authenticated? { puts "I am authenticated!" }
276
- * must_be_authorized!(failure_path=nil)
275
+ * <tt>authenticated? { puts "I am authenticated!" }</tt>
276
+ * <tt>must_be_authorized!(failure_path=nil)</tt>
277
277
  * Forces a user to return to a fail path unless they are authorized
278
278
  * Used to require a user be authenticated before routing to an action
279
- * must_be_authorized!('/login')
279
+ * <tt>must_be_authorized!('/login')</tt>
280
280
 
281
281
  == Acknowledgements
282
282
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.8
1
+ 0.1.9
@@ -1,3 +1,4 @@
1
+ require File.dirname(__FILE__) + '/support_lite'
1
2
  require File.dirname(__FILE__) + '/markup_plugin/form_builder/abstract_form_builder'
2
3
  require File.dirname(__FILE__) + '/markup_plugin/form_builder/standard_form_builder'
3
4
  Dir[File.dirname(__FILE__) + '/markup_plugin/*.rb'].each {|file| load file }
@@ -1,3 +1,4 @@
1
+ require File.dirname(__FILE__) + '/support_lite'
1
2
  Dir[File.dirname(__FILE__) + '/render_plugin/**/*.rb'].each {|file| load file }
2
3
 
3
4
  module SinatraMore
@@ -0,0 +1,41 @@
1
+ # This is for adding specific methods that are required by sinatra_more if activesupport isn't required
2
+
3
+ unless String.new.respond_to?(:titleize)
4
+ require 'active_support/inflector'
5
+ end
6
+
7
+ unless Hash.new.respond_to?(:reverse_merge!)
8
+ module HashExtensions
9
+ def reverse_merge(other_hash)
10
+ other_hash.merge(self)
11
+ end
12
+ def reverse_merge!(other_hash)
13
+ replace(reverse_merge(other_hash))
14
+ end
15
+ end
16
+ end
17
+
18
+ unless Hash.new.respond_to?(:symbolize_keys!)
19
+ module HashExtensions
20
+ def symbolize_keys
21
+ inject({}) do |options, (key, value)|
22
+ options[(key.to_sym rescue key) || key] = value
23
+ options
24
+ end
25
+ end
26
+ def symbolize_keys!
27
+ self.replace(self.symbolize_keys)
28
+ end
29
+ end
30
+ end
31
+
32
+ unless Array.new.respond_to?(:extract_options!)
33
+ module ArrayExtensions
34
+ def extract_options!
35
+ last.is_a?(::Hash) ? pop : {}
36
+ end
37
+ end
38
+ end
39
+
40
+ Hash.send(:include, HashExtensions) if defined?(HashExtensions)
41
+ Array.send(:include, ArrayExtensions) if defined?(ArrayExtensions)
@@ -1,3 +1,4 @@
1
+ require File.dirname(__FILE__) + '/support_lite'
1
2
  load File.dirname(__FILE__) + '/markup_plugin/output_helpers.rb'
2
3
  Dir[File.dirname(__FILE__) + '/warden_plugin/**/*.rb'].each {|file| load file }
3
4
 
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.1.8"
8
+ s.version = "0.1.9"
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"]
@@ -35,9 +35,11 @@ Gem::Specification.new do |s|
35
35
  "lib/sinatra_more/markup_plugin/tag_helpers.rb",
36
36
  "lib/sinatra_more/render_plugin.rb",
37
37
  "lib/sinatra_more/render_plugin/render_helpers.rb",
38
+ "lib/sinatra_more/support_lite.rb",
38
39
  "lib/sinatra_more/warden_plugin.rb",
39
40
  "lib/sinatra_more/warden_plugin/warden_helpers.rb",
40
41
  "sinatra_more.gemspec",
42
+ "test/active_support_helpers.rb",
41
43
  "test/fixtures/markup_app/app.rb",
42
44
  "test/fixtures/markup_app/views/capture_concat.erb",
43
45
  "test/fixtures/markup_app/views/capture_concat.haml",
@@ -73,7 +75,8 @@ Gem::Specification.new do |s|
73
75
  s.rubygems_version = %q{1.3.5}
74
76
  s.summary = %q{Expands sinatra to allow for complex applications}
75
77
  s.test_files = [
76
- "test/fixtures/markup_app/app.rb",
78
+ "test/active_support_helpers.rb",
79
+ "test/fixtures/markup_app/app.rb",
77
80
  "test/fixtures/render_app/app.rb",
78
81
  "test/fixtures/warden_app/app.rb",
79
82
  "test/helper.rb",
@@ -0,0 +1,7 @@
1
+ unless 5.respond_to?(:days)
2
+ require 'active_support/core_ext/object/misc'
3
+ require 'active_support/core_ext/date'
4
+ require 'active_support/core_ext/time'
5
+ require 'active_support/core_ext/numeric'
6
+ require 'active_support/duration'
7
+ end
@@ -1,5 +1,4 @@
1
1
  require 'sinatra/base'
2
- require 'active_support'
3
2
  require 'sinatra_more'
4
3
  require 'haml'
5
4
 
data/test/helper.rb CHANGED
@@ -7,6 +7,7 @@ require 'webrat'
7
7
 
8
8
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
9
9
  $LOAD_PATH.unshift(File.dirname(__FILE__))
10
+ require 'active_support_helpers'
10
11
  require 'sinatra_more'
11
12
 
12
13
  class Test::Unit::TestCase
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.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Esquenazi
@@ -120,9 +120,11 @@ files:
120
120
  - lib/sinatra_more/markup_plugin/tag_helpers.rb
121
121
  - lib/sinatra_more/render_plugin.rb
122
122
  - lib/sinatra_more/render_plugin/render_helpers.rb
123
+ - lib/sinatra_more/support_lite.rb
123
124
  - lib/sinatra_more/warden_plugin.rb
124
125
  - lib/sinatra_more/warden_plugin/warden_helpers.rb
125
126
  - sinatra_more.gemspec
127
+ - test/active_support_helpers.rb
126
128
  - test/fixtures/markup_app/app.rb
127
129
  - test/fixtures/markup_app/views/capture_concat.erb
128
130
  - test/fixtures/markup_app/views/capture_concat.haml
@@ -180,6 +182,7 @@ signing_key:
180
182
  specification_version: 3
181
183
  summary: Expands sinatra to allow for complex applications
182
184
  test_files:
185
+ - test/active_support_helpers.rb
183
186
  - test/fixtures/markup_app/app.rb
184
187
  - test/fixtures/render_app/app.rb
185
188
  - test/fixtures/warden_app/app.rb