rocketeer 0.1.0 → 0.2.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/COPYING +24 -0
- data/lib/rocketeer/helpers/form.rb +90 -0
- data/lib/rocketeer/helpers/html.rb +52 -0
- data/lib/rocketeer/helpers/text.rb +25 -0
- data/lib/rocketeer.rb +15 -44
- metadata +5 -1
data/COPYING
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
Copyright (c) 2011, Jack Polgar
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
6
|
+
* Redistributions of source code must retain the above copyright
|
7
|
+
notice, this list of conditions and the following disclaimer.
|
8
|
+
* Redistributions in binary form must reproduce the above copyright
|
9
|
+
notice, this list of conditions and the following disclaimer in the
|
10
|
+
documentation and/or other materials provided with the distribution.
|
11
|
+
* Neither the name of the Rockets or Rocketeer nor the
|
12
|
+
names of its contributors may be used to endorse or promote products
|
13
|
+
derived from this software without specific prior written permission.
|
14
|
+
|
15
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
16
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
17
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
18
|
+
DISCLAIMED. IN NO EVENT SHALL JACK POLGAR BE LIABLE FOR ANY
|
19
|
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
20
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
21
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
22
|
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
23
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
24
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
@@ -0,0 +1,90 @@
|
|
1
|
+
#
|
2
|
+
# Rocketeer
|
3
|
+
# Copyright (C) 2011 Jack Polgar
|
4
|
+
# All Rights Reserved
|
5
|
+
# http://github.com/nirix/rockets
|
6
|
+
#
|
7
|
+
# Relased under the BSD 3-clause / New BSD License
|
8
|
+
# Please see the COPYING file for details.
|
9
|
+
#
|
10
|
+
|
11
|
+
module Sinatra
|
12
|
+
module FormHelper
|
13
|
+
def input_field(name, options = {})
|
14
|
+
if name.class == Array
|
15
|
+
name = "#{name[0]}[#{name[1]}]"
|
16
|
+
end
|
17
|
+
defaults = {
|
18
|
+
:id => name.to_s,
|
19
|
+
:name => name.to_s
|
20
|
+
}
|
21
|
+
|
22
|
+
html_options = []
|
23
|
+
options = defaults.merge(options)
|
24
|
+
options.each do |k, v|
|
25
|
+
html_options.push "#{k}=\"#{v}\""
|
26
|
+
end
|
27
|
+
|
28
|
+
"<input #{html_options.join(' ')}>"
|
29
|
+
end
|
30
|
+
|
31
|
+
def text_field(name, options = {})
|
32
|
+
input_field name, options.merge({:type => 'text'})
|
33
|
+
end
|
34
|
+
|
35
|
+
def password_field(name, options = {})
|
36
|
+
input_field name, options.merge({:type => 'password'})
|
37
|
+
end
|
38
|
+
|
39
|
+
def email_field(name, options = {})
|
40
|
+
input_field name, options.merge({:type => 'email'})
|
41
|
+
end
|
42
|
+
|
43
|
+
def select_box(name, options, selected = nil)
|
44
|
+
if name.class == Array
|
45
|
+
name = "#{name[0]}[#{name[1]}]"
|
46
|
+
end
|
47
|
+
|
48
|
+
html = ["<select name=\"#{name.to_s}\" id=\"#{name.to_s}\">"]
|
49
|
+
|
50
|
+
options.each do |option|
|
51
|
+
if option[1] == selected
|
52
|
+
selected_html = ' selected'
|
53
|
+
else
|
54
|
+
selected_html = ''
|
55
|
+
end
|
56
|
+
html.push " <option value=\"#{option[1]}\" #{selected_html}>#{option[0]}</option>"
|
57
|
+
end
|
58
|
+
|
59
|
+
html.push "</select>\n"
|
60
|
+
return html.join("\n")
|
61
|
+
end
|
62
|
+
|
63
|
+
def textarea(name, options = {})
|
64
|
+
if name.class == Array
|
65
|
+
name = "#{name[0]}[#{name[1]}]"
|
66
|
+
end
|
67
|
+
defaults = {
|
68
|
+
:id => name.to_s,
|
69
|
+
:name => name.to_s
|
70
|
+
}
|
71
|
+
if options[:value]
|
72
|
+
value = options[:value]
|
73
|
+
options[:value] = nil
|
74
|
+
else
|
75
|
+
value = ''
|
76
|
+
end
|
77
|
+
|
78
|
+
html_options = []
|
79
|
+
options = defaults.merge(options)
|
80
|
+
options.each do |k, v|
|
81
|
+
next if v == nil
|
82
|
+
html_options.push "#{k}=\"#{v}\""
|
83
|
+
end
|
84
|
+
|
85
|
+
"<textarea #{html_options.join(' ')}>#{value}</textarea>"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
helpers FormHelper
|
90
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
#
|
2
|
+
# Rocketeer
|
3
|
+
# Copyright (C) 2011 Jack Polgar
|
4
|
+
# All Rights Reserved
|
5
|
+
# http://github.com/nirix/rockets
|
6
|
+
#
|
7
|
+
# Relased under the BSD 3-clause / New BSD License
|
8
|
+
# Please see the COPYING file for details.
|
9
|
+
#
|
10
|
+
|
11
|
+
module Sinatra
|
12
|
+
module HTMLHelper
|
13
|
+
def link_to(text, the_url, options = {})
|
14
|
+
options = options.merge({
|
15
|
+
:href => the_url ? url(the_url) : request.path_info
|
16
|
+
})
|
17
|
+
if options[:confirm]
|
18
|
+
options[:"data-confirm"] = options[:confirm]
|
19
|
+
options[:confirm] = nil
|
20
|
+
end
|
21
|
+
if options[:remote]
|
22
|
+
options[:"data-remote"] = options[:remote]
|
23
|
+
options[:remote] = nil
|
24
|
+
end
|
25
|
+
|
26
|
+
html_options = []
|
27
|
+
options.each do |k, v|
|
28
|
+
html_options.push "#{k.to_s}=\"#{v.to_s}\""
|
29
|
+
end
|
30
|
+
|
31
|
+
"<a #{html_options.join(' ')}>#{text}</a>"
|
32
|
+
end
|
33
|
+
|
34
|
+
def link_to_unless_current(text, the_url, options = {})
|
35
|
+
if request.path_info == the_url
|
36
|
+
text
|
37
|
+
else
|
38
|
+
link_to text, the_url, options
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def css_inc_tag(url, media = "screen")
|
43
|
+
"<link rel=\"stylesheet\" href=\"#{url}?#{Time.now.to_i}\" media=\"#{media}\" />"
|
44
|
+
end
|
45
|
+
|
46
|
+
def js_inc_tag(url)
|
47
|
+
"<script src=\"#{url}\" type=\"text/javascript\"></script>"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
helpers HTMLHelper
|
52
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
#
|
2
|
+
# Rocketeer
|
3
|
+
# Copyright (C) 2011 Jack Polgar
|
4
|
+
# All Rights Reserved
|
5
|
+
# http://github.com/nirix/rockets
|
6
|
+
#
|
7
|
+
# Relased under the BSD 3-clause / New BSD License
|
8
|
+
# Please see the COPYING file for details.
|
9
|
+
#
|
10
|
+
|
11
|
+
module Sinatra
|
12
|
+
module TextHelper
|
13
|
+
def pluralize(count, singular, plural = nil)
|
14
|
+
"#{count || 0} " + ((count == 1 || count =~ /^1(\.0+)?$/) ? singular : (plural || singular.pluralize))
|
15
|
+
end
|
16
|
+
|
17
|
+
def short_text(text, length = 30, truncate_string = "...")
|
18
|
+
return if text.nil?
|
19
|
+
l = length - truncate_string.mb_chars.length
|
20
|
+
text.mb_chars.length > length ? text[/\A.{#{l}}\w*\;?/m][/.*[\w\;]/m] + truncate_string : text
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
helpers TextHelper
|
25
|
+
end
|
data/lib/rocketeer.rb
CHANGED
@@ -1,44 +1,15 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end
|
17
|
-
|
18
|
-
html_options = []
|
19
|
-
options.each do |k, v|
|
20
|
-
html_options.push "#{k.to_s}=\"#{v.to_s}\""
|
21
|
-
end
|
22
|
-
|
23
|
-
"<a #{html_options.join(' ')}>#{text}</a>"
|
24
|
-
end
|
25
|
-
|
26
|
-
def link_to_unless_current(text, the_url, options = {})
|
27
|
-
if request.path_info == the_url
|
28
|
-
text
|
29
|
-
else
|
30
|
-
link_to text, the_url, options
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def css_inc_tag(url, media = "screen")
|
35
|
-
"<link rel=\"stylesheet\" href=\"#{url}?#{Time.now.to_i}\" media=\"#{media}\" />"
|
36
|
-
end
|
37
|
-
|
38
|
-
def js_inc_tag(url)
|
39
|
-
"<script src=\"#{url}\" type=\"text/javascript\"></script>"
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
helpers HTMLHelper
|
44
|
-
end
|
1
|
+
#
|
2
|
+
# Rocketeer
|
3
|
+
# Copyright (C) 2011 Jack Polgar
|
4
|
+
# All Rights Reserved
|
5
|
+
# http://github.com/nirix/rockets
|
6
|
+
#
|
7
|
+
# Relased under the BSD 3-clause / New BSD License
|
8
|
+
# Please see the COPYING file for details.
|
9
|
+
#
|
10
|
+
|
11
|
+
require 'sinatra/base'
|
12
|
+
|
13
|
+
require 'rocketeer/helpers/html'
|
14
|
+
require 'rocketeer/helpers/form'
|
15
|
+
require 'rocketeer/helpers/text'
|
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.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -18,7 +18,11 @@ executables: []
|
|
18
18
|
extensions: []
|
19
19
|
extra_rdoc_files: []
|
20
20
|
files:
|
21
|
+
- COPYING
|
21
22
|
- lib/rocketeer.rb
|
23
|
+
- lib/rocketeer/helpers/html.rb
|
24
|
+
- lib/rocketeer/helpers/form.rb
|
25
|
+
- lib/rocketeer/helpers/text.rb
|
22
26
|
has_rdoc: true
|
23
27
|
homepage: http://rubygems.org/gems/rocketeer
|
24
28
|
licenses: []
|