rocketeer 0.2.0 → 0.3.0
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/lib/rocketeer/helpers/form.rb +74 -4
- data/lib/rocketeer/helpers/html.rb +75 -0
- data/lib/rocketeer/helpers/text.rb +31 -3
- metadata +5 -7
@@ -8,8 +8,22 @@
|
|
8
8
|
# Please see the COPYING file for details.
|
9
9
|
#
|
10
10
|
|
11
|
+
#:nodoc:
|
11
12
|
module Sinatra
|
13
|
+
#:nodoc:
|
12
14
|
module FormHelper
|
15
|
+
##
|
16
|
+
# Input field builder
|
17
|
+
#
|
18
|
+
# Useage:
|
19
|
+
#
|
20
|
+
# input_field :my_field, :type => 'text'
|
21
|
+
#
|
22
|
+
# @param [Mixed] name The name of the field
|
23
|
+
# @param [Hash] options The fields options
|
24
|
+
# @author Jack Polgar
|
25
|
+
# @since 0.1
|
26
|
+
#
|
13
27
|
def input_field(name, options = {})
|
14
28
|
if name.class == Array
|
15
29
|
name = "#{name[0]}[#{name[1]}]"
|
@@ -28,38 +42,94 @@ module Sinatra
|
|
28
42
|
"<input #{html_options.join(' ')}>"
|
29
43
|
end
|
30
44
|
|
45
|
+
##
|
46
|
+
# Text field builder
|
47
|
+
#
|
48
|
+
# Useage:
|
49
|
+
# text_field :my_field, :class => 'text', :value => 'my value'
|
50
|
+
#
|
51
|
+
# @param [Mixed] name The name of the field
|
52
|
+
# @param [Hash] options The fields options
|
53
|
+
# @author Jack Polgar
|
54
|
+
# @since 0.1
|
55
|
+
#
|
31
56
|
def text_field(name, options = {})
|
32
57
|
input_field name, options.merge({:type => 'text'})
|
33
58
|
end
|
34
59
|
|
60
|
+
##
|
61
|
+
# Password field builder
|
62
|
+
#
|
63
|
+
# Useage:
|
64
|
+
# pasword_field :my_field, :class => 'text', :value => 'my value'
|
65
|
+
#
|
66
|
+
# @param [Mixed] name The name of the field
|
67
|
+
# @param [Hash] options The fields options
|
68
|
+
# @author Jack Polgar
|
69
|
+
# @since 0.1
|
70
|
+
#
|
35
71
|
def password_field(name, options = {})
|
36
72
|
input_field name, options.merge({:type => 'password'})
|
37
73
|
end
|
38
74
|
|
75
|
+
##
|
76
|
+
# Email field builder
|
77
|
+
#
|
78
|
+
# Useage:
|
79
|
+
# email_field :my_field, :class => 'text', :value => 'my value'
|
80
|
+
#
|
81
|
+
# @param [Mixed] name The name of the field
|
82
|
+
# @param [Hash] options The fields options
|
83
|
+
# @author Jack Polgar
|
84
|
+
# @since 0.1
|
85
|
+
#
|
39
86
|
def email_field(name, options = {})
|
40
87
|
input_field name, options.merge({:type => 'email'})
|
41
88
|
end
|
42
89
|
|
43
|
-
|
90
|
+
##
|
91
|
+
# Select box builder
|
92
|
+
#
|
93
|
+
# Useage:
|
94
|
+
# select_box :my_field, [['Hello', 1], ['World', 2]], 2
|
95
|
+
#
|
96
|
+
# @param [Mixed] name The name of the field
|
97
|
+
# @param [Array] rows Array of the select field options
|
98
|
+
# @param [Mixed] selected Value of the selected option
|
99
|
+
# @author Jack Polgar
|
100
|
+
# @since 0.1
|
101
|
+
#
|
102
|
+
def select_box(name, rows, selected = nil)
|
44
103
|
if name.class == Array
|
45
104
|
name = "#{name[0]}[#{name[1]}]"
|
46
105
|
end
|
47
106
|
|
48
107
|
html = ["<select name=\"#{name.to_s}\" id=\"#{name.to_s}\">"]
|
49
108
|
|
50
|
-
|
51
|
-
if
|
109
|
+
rows.each do |row|
|
110
|
+
if row[1] == selected
|
52
111
|
selected_html = ' selected'
|
53
112
|
else
|
54
113
|
selected_html = ''
|
55
114
|
end
|
56
|
-
html.push " <option value=\"#{
|
115
|
+
html.push " <option value=\"#{row[1]}\" #{selected_html}>#{row[0]}</option>"
|
57
116
|
end
|
58
117
|
|
59
118
|
html.push "</select>\n"
|
60
119
|
return html.join("\n")
|
61
120
|
end
|
62
121
|
|
122
|
+
##
|
123
|
+
# Text area builder
|
124
|
+
#
|
125
|
+
# Useage:
|
126
|
+
# textarea :my_field, :class => 'text', :value => 'my value'
|
127
|
+
#
|
128
|
+
# @param [Mixed] name The name of the field
|
129
|
+
# @param [Hash] options The fields options
|
130
|
+
# @author Jack Polgar
|
131
|
+
# @since 0.1
|
132
|
+
#
|
63
133
|
def textarea(name, options = {})
|
64
134
|
if name.class == Array
|
65
135
|
name = "#{name[0]}[#{name[1]}]"
|
@@ -8,8 +8,23 @@
|
|
8
8
|
# Please see the COPYING file for details.
|
9
9
|
#
|
10
10
|
|
11
|
+
#:nodoc:
|
11
12
|
module Sinatra
|
13
|
+
#:nodoc:
|
12
14
|
module HTMLHelper
|
15
|
+
##
|
16
|
+
# Creates a link to the specified URL with the specified text
|
17
|
+
#
|
18
|
+
# Useage:
|
19
|
+
#
|
20
|
+
# link_to 'Google', 'http://google.com.au'
|
21
|
+
#
|
22
|
+
# @param [String] text The text for the link
|
23
|
+
# @param [String] the_url The URL to link to
|
24
|
+
# @param [Hash] options Options for the link
|
25
|
+
# @author Jack Polgar
|
26
|
+
# @since 0.1
|
27
|
+
#
|
13
28
|
def link_to(text, the_url, options = {})
|
14
29
|
options = options.merge({
|
15
30
|
:href => the_url ? url(the_url) : request.path_info
|
@@ -25,12 +40,26 @@ module Sinatra
|
|
25
40
|
|
26
41
|
html_options = []
|
27
42
|
options.each do |k, v|
|
43
|
+
pass if v === nil
|
28
44
|
html_options.push "#{k.to_s}=\"#{v.to_s}\""
|
29
45
|
end
|
30
46
|
|
31
47
|
"<a #{html_options.join(' ')}>#{text}</a>"
|
32
48
|
end
|
33
49
|
|
50
|
+
##
|
51
|
+
# Creates a link to the specified URL unless the request matches the URL.
|
52
|
+
#
|
53
|
+
# Useage:
|
54
|
+
#
|
55
|
+
# link_to_unless_current 'Google', 'http://google.com.au'
|
56
|
+
#
|
57
|
+
# @param [String] text The text for the link
|
58
|
+
# @param [String] the_url The URL to link to
|
59
|
+
# @param [Hash] options Options for the link
|
60
|
+
# @author Jack Polgar
|
61
|
+
# @since 0.1
|
62
|
+
#
|
34
63
|
def link_to_unless_current(text, the_url, options = {})
|
35
64
|
if request.path_info == the_url
|
36
65
|
text
|
@@ -39,10 +68,56 @@ module Sinatra
|
|
39
68
|
end
|
40
69
|
end
|
41
70
|
|
71
|
+
##
|
72
|
+
# Creates a link to the specified URL if the condition is met.
|
73
|
+
#
|
74
|
+
# Useage:
|
75
|
+
#
|
76
|
+
# link_to 'Google', 'http://google.com.au'
|
77
|
+
#
|
78
|
+
# @param [Boolean] condition The condition to check
|
79
|
+
# @param [String] text The text for the link
|
80
|
+
# @param [String] the_url The URL to link to
|
81
|
+
# @param [Hash] options Options for the link
|
82
|
+
# @author Jack Polgar
|
83
|
+
# @since 0.3
|
84
|
+
#
|
85
|
+
def link_to_if(condition, text, the_url, options = {})
|
86
|
+
if condition
|
87
|
+
link_to text, the_url, options = {}
|
88
|
+
else
|
89
|
+
text
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
##
|
94
|
+
# Returns the code for linking CSS style sheets.
|
95
|
+
#
|
96
|
+
# Useage:
|
97
|
+
#
|
98
|
+
# css_inc_tag '/assets/css/master.css'
|
99
|
+
# css_inc_tag '/assets/css/print', 'screen'
|
100
|
+
#
|
101
|
+
# @param [String] url The URL of the stylesheet
|
102
|
+
# @param [String] media The media of the stylesheet
|
103
|
+
# @author Jack Polgar
|
104
|
+
# @since 0.1
|
105
|
+
#
|
42
106
|
def css_inc_tag(url, media = "screen")
|
43
107
|
"<link rel=\"stylesheet\" href=\"#{url}?#{Time.now.to_i}\" media=\"#{media}\" />"
|
44
108
|
end
|
45
109
|
|
110
|
+
##
|
111
|
+
# Returns the code for linking javascript files.
|
112
|
+
#
|
113
|
+
# Useage:
|
114
|
+
#
|
115
|
+
# js_inc_tag '/assets/js/app.js'
|
116
|
+
#
|
117
|
+
# @param [String] url The URL of the file
|
118
|
+
# @author Jack Polgar
|
119
|
+
# @since 0.1
|
120
|
+
#
|
46
121
|
def js_inc_tag(url)
|
47
122
|
"<script src=\"#{url}\" type=\"text/javascript\"></script>"
|
48
123
|
end
|
@@ -8,16 +8,44 @@
|
|
8
8
|
# Please see the COPYING file for details.
|
9
9
|
#
|
10
10
|
|
11
|
+
#:nodoc:
|
11
12
|
module Sinatra
|
13
|
+
#:nodoc:
|
12
14
|
module TextHelper
|
15
|
+
##
|
16
|
+
# Pluralizes the string.
|
17
|
+
#
|
18
|
+
# Useage:
|
19
|
+
#
|
20
|
+
# pluralize comments.count, 'comment'
|
21
|
+
#
|
22
|
+
# @param [Integer] count The count
|
23
|
+
# @param [String] singular The singular form of the string
|
24
|
+
# @param [String] plural The plural form of the word
|
25
|
+
# @author Jack Polgar
|
26
|
+
# @since 0.1
|
27
|
+
#
|
13
28
|
def pluralize(count, singular, plural = nil)
|
14
29
|
"#{count || 0} " + ((count == 1 || count =~ /^1(\.0+)?$/) ? singular : (plural || singular.pluralize))
|
15
30
|
end
|
16
31
|
|
17
|
-
|
32
|
+
##
|
33
|
+
# Shortens the string to the specified length
|
34
|
+
#
|
35
|
+
# Useage:
|
36
|
+
#
|
37
|
+
# shorten_string 'A very, very, long string', 5
|
38
|
+
#
|
39
|
+
# @param [String] text The string to shorten
|
40
|
+
# @param [Integer] length The length to shorten to
|
41
|
+
# @param [String] truncate_string Text to place at the end of the shortened string
|
42
|
+
# @author Jack Polgar
|
43
|
+
# @since 0.1
|
44
|
+
#
|
45
|
+
def shorten_string(text, length = 30, truncate_string = "...")
|
18
46
|
return if text.nil?
|
19
|
-
l = length - truncate_string.
|
20
|
-
text.
|
47
|
+
l = length - truncate_string.length
|
48
|
+
text.length > length ? text[/\A.{#{l}}\w*\;?/m][/.*[\w\;]/m] + truncate_string : text
|
21
49
|
end
|
22
50
|
end
|
23
51
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rocketeer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,10 +9,9 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-07-23 00:00:00.
|
13
|
-
default_executable:
|
12
|
+
date: 2011-07-23 00:00:00.000000000Z
|
14
13
|
dependencies: []
|
15
|
-
description:
|
14
|
+
description: Rocketeer is a collection of helpers for the Sinatra framework.
|
16
15
|
email: xocide@gmail.com
|
17
16
|
executables: []
|
18
17
|
extensions: []
|
@@ -23,7 +22,6 @@ files:
|
|
23
22
|
- lib/rocketeer/helpers/html.rb
|
24
23
|
- lib/rocketeer/helpers/form.rb
|
25
24
|
- lib/rocketeer/helpers/text.rb
|
26
|
-
has_rdoc: true
|
27
25
|
homepage: http://rubygems.org/gems/rocketeer
|
28
26
|
licenses: []
|
29
27
|
post_install_message:
|
@@ -44,8 +42,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
44
42
|
version: '0'
|
45
43
|
requirements: []
|
46
44
|
rubyforge_project:
|
47
|
-
rubygems_version: 1.5
|
45
|
+
rubygems_version: 1.8.5
|
48
46
|
signing_key:
|
49
47
|
specification_version: 3
|
50
|
-
summary:
|
48
|
+
summary: A collection of helpers for Sinatra
|
51
49
|
test_files: []
|