rocketeer 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ .DS_Store
2
+ pkg
3
+ *.gem
data/COPYING CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2011, Jack Polgar
1
+ Copyright (c) 2011-2012, Jack Polgar
2
2
  All rights reserved.
3
3
 
4
4
  Redistribution and use in source and binary forms, with or without
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rocketeer.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
data/lib/rocketeer.rb CHANGED
@@ -12,4 +12,11 @@ require 'sinatra/base'
12
12
 
13
13
  require 'rocketeer/helpers/html'
14
14
  require 'rocketeer/helpers/form'
15
- require 'rocketeer/helpers/text'
15
+ require 'rocketeer/helpers/text'
16
+
17
+ # @private
18
+ module Sinatra
19
+ helpers Rocketeer::Helpers::HTML
20
+ helpers Rocketeer::Helpers::Form
21
+ helpers Rocketeer::Helpers::Text
22
+ end
@@ -8,153 +8,151 @@
8
8
  # Please see the COPYING file for details.
9
9
  #
10
10
 
11
- #:nodoc:
12
- module Sinatra
13
- #:nodoc:
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
- #
27
- def input_field(name, options = {})
28
- if name.class == Array
29
- name = "#{name[0]}[#{name[1]}]"
11
+ module Rocketeer
12
+ module Helpers
13
+ module Form
14
+ ##
15
+ # Input field builder
16
+ #
17
+ # Useage:
18
+ #
19
+ # input_field :my_field, :type => 'text'
20
+ #
21
+ # @param [Mixed] name The name of the field
22
+ # @param [Hash] options The fields options
23
+ # @author Jack Polgar
24
+ # @since 0.1
25
+ #
26
+ def input_field(name, options = {})
27
+ if name.class == Array
28
+ name = "#{name[0]}[#{name[1]}]"
29
+ end
30
+ defaults = {
31
+ :id => name.to_s,
32
+ :name => name.to_s
33
+ }
34
+
35
+ html_options = []
36
+ options = defaults.merge(options)
37
+ options.each do |k, v|
38
+ html_options.push "#{k}=\"#{v}\""
39
+ end
40
+
41
+ "<input #{html_options.join(' ')}>"
30
42
  end
31
- defaults = {
32
- :id => name.to_s,
33
- :name => name.to_s
34
- }
35
43
 
36
- html_options = []
37
- options = defaults.merge(options)
38
- options.each do |k, v|
39
- html_options.push "#{k}=\"#{v}\""
44
+ ##
45
+ # Text field builder
46
+ #
47
+ # Useage:
48
+ # text_field :my_field, :class => 'text', :value => 'my value'
49
+ #
50
+ # @param [Mixed] name The name of the field
51
+ # @param [Hash] options The fields options
52
+ # @author Jack Polgar
53
+ # @since 0.1
54
+ #
55
+ def text_field(name, options = {})
56
+ input_field name, options.merge({:type => 'text'})
40
57
  end
41
58
 
42
- "<input #{html_options.join(' ')}>"
43
- end
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
- #
56
- def text_field(name, options = {})
57
- input_field name, options.merge({:type => 'text'})
58
- end
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
- #
71
- def password_field(name, options = {})
72
- input_field name, options.merge({:type => 'password'})
73
- end
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
- #
86
- def email_field(name, options = {})
87
- input_field name, options.merge({:type => 'email'})
88
- end
89
-
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)
103
- if name.class == Array
104
- name = "#{name[0]}[#{name[1]}]"
59
+ ##
60
+ # Password field builder
61
+ #
62
+ # Useage:
63
+ # pasword_field :my_field, :class => 'text', :value => 'my value'
64
+ #
65
+ # @param [Mixed] name The name of the field
66
+ # @param [Hash] options The fields options
67
+ # @author Jack Polgar
68
+ # @since 0.1
69
+ #
70
+ def password_field(name, options = {})
71
+ input_field name, options.merge({:type => 'password'})
105
72
  end
106
73
 
107
- html = ["<select name=\"#{name.to_s}\" id=\"#{name.to_s}\">"]
108
-
109
- rows.each do |row|
110
- if row[1] == selected
111
- selected_html = ' selected'
112
- else
113
- selected_html = ''
114
- end
115
- html.push " <option value=\"#{row[1]}\" #{selected_html}>#{row[0]}</option>"
74
+ ##
75
+ # Email field builder
76
+ #
77
+ # Useage:
78
+ # email_field :my_field, :class => 'text', :value => 'my value'
79
+ #
80
+ # @param [Mixed] name The name of the field
81
+ # @param [Hash] options The fields options
82
+ # @author Jack Polgar
83
+ # @since 0.1
84
+ #
85
+ def email_field(name, options = {})
86
+ input_field name, options.merge({:type => 'email'})
116
87
  end
117
88
 
118
- html.push "</select>\n"
119
- return html.join("\n")
120
- end
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
- #
133
- def textarea(name, options = {})
134
- if name.class == Array
135
- name = "#{name[0]}[#{name[1]}]"
136
- end
137
- defaults = {
138
- :id => name.to_s,
139
- :name => name.to_s
140
- }
141
- if options[:value]
142
- value = options[:value]
143
- options[:value] = nil
144
- else
145
- value = ''
89
+ ##
90
+ # Select box builder
91
+ #
92
+ # Useage:
93
+ # select_box :my_field, [['Hello', 1], ['World', 2]], 2
94
+ #
95
+ # @param [Mixed] name The name of the field
96
+ # @param [Array] rows Array of the select field options
97
+ # @param [Mixed] selected Value of the selected option
98
+ # @author Jack Polgar
99
+ # @since 0.1
100
+ #
101
+ def select_box(name, rows, selected = nil)
102
+ if name.class == Array
103
+ name = "#{name[0]}[#{name[1]}]"
104
+ end
105
+
106
+ html = ["<select name=\"#{name.to_s}\" id=\"#{name.to_s}\">"]
107
+
108
+ rows.each do |row|
109
+ if row[1] == selected
110
+ selected_html = ' selected'
111
+ else
112
+ selected_html = ''
113
+ end
114
+ html.push " <option value=\"#{row[1]}\" #{selected_html}>#{row[0]}</option>"
115
+ end
116
+
117
+ html.push "</select>\n"
118
+ return html.join("\n")
146
119
  end
147
120
 
148
- html_options = []
149
- options = defaults.merge(options)
150
- options.each do |k, v|
151
- next if v == nil
152
- html_options.push "#{k}=\"#{v}\""
121
+ ##
122
+ # Text area builder
123
+ #
124
+ # Useage:
125
+ # textarea :my_field, :class => 'text', :value => 'my value'
126
+ #
127
+ # @param [Mixed] name The name of the field
128
+ # @param [Hash] options The fields options
129
+ # @author Jack Polgar
130
+ # @since 0.1
131
+ #
132
+ def textarea(name, options = {})
133
+ if name.class == Array
134
+ name = "#{name[0]}[#{name[1]}]"
135
+ end
136
+ defaults = {
137
+ :id => name.to_s,
138
+ :name => name.to_s
139
+ }
140
+ if options[:value]
141
+ value = options[:value]
142
+ options[:value] = nil
143
+ else
144
+ value = ''
145
+ end
146
+
147
+ html_options = []
148
+ options = defaults.merge(options)
149
+ options.each do |k, v|
150
+ next if v == nil
151
+ html_options.push "#{k}=\"#{v}\""
152
+ end
153
+
154
+ "<textarea #{html_options.join(' ')}>#{value}</textarea>"
153
155
  end
154
-
155
- "<textarea #{html_options.join(' ')}>#{value}</textarea>"
156
156
  end
157
157
  end
158
-
159
- helpers FormHelper
160
158
  end
@@ -8,120 +8,118 @@
8
8
  # Please see the COPYING file for details.
9
9
  #
10
10
 
11
- #:nodoc:
12
- module Sinatra
13
- #:nodoc:
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
- #
28
- def link_to(text, the_url, options = {})
29
- options = options.merge({
30
- :href => the_url ? url(the_url) : request.path_info
31
- })
32
- if options[:confirm]
33
- options[:"data-confirm"] = options[:confirm]
34
- options[:confirm] = nil
11
+ module Rocketeer
12
+ module Helpers
13
+ module HTML
14
+ ##
15
+ # Creates a link to the specified URL with the specified text
16
+ #
17
+ # Useage:
18
+ #
19
+ # link_to 'Google', 'http://google.com.au'
20
+ #
21
+ # @param [String] text The text for the link
22
+ # @param [String] the_url The URL to link to
23
+ # @param [Hash] options Options for the link
24
+ # @author Jack Polgar
25
+ # @since 0.1
26
+ #
27
+ def link_to(text, url, options = {})
28
+ options = options.merge({
29
+ :href => url ? url : request.path_info
30
+ })
31
+ if options[:confirm]
32
+ options[:"data-confirm"] = options[:confirm]
33
+ options[:confirm] = nil
34
+ end
35
+ if options[:remote]
36
+ options[:"data-remote"] = options[:remote]
37
+ options[:remote] = nil
38
+ end
39
+
40
+ html_options = []
41
+ options.each do |k, v|
42
+ pass if v === nil
43
+ html_options.push "#{k.to_s}=\"#{v.to_s}\""
44
+ end
45
+
46
+ "<a #{html_options.join(' ')}>#{text}</a>"
35
47
  end
36
- if options[:remote]
37
- options[:"data-remote"] = options[:remote]
38
- options[:remote] = nil
48
+
49
+ ##
50
+ # Creates a link to the specified URL unless the request matches the URL.
51
+ #
52
+ # Useage:
53
+ #
54
+ # link_to_unless_current 'Google', 'http://google.com.au'
55
+ #
56
+ # @param [String] text The text for the link
57
+ # @param [String] the_url The URL to link to
58
+ # @param [Hash] options Options for the link
59
+ # @author Jack Polgar
60
+ # @since 0.1
61
+ #
62
+ def link_to_unless_current(text, url, options = {})
63
+ if request.path_info == url
64
+ text
65
+ else
66
+ link_to text, url, options
67
+ end
39
68
  end
40
69
 
41
- html_options = []
42
- options.each do |k, v|
43
- pass if v === nil
44
- html_options.push "#{k.to_s}=\"#{v.to_s}\""
70
+ ##
71
+ # Creates a link to the specified URL if the condition is met.
72
+ #
73
+ # Useage:
74
+ #
75
+ # link_to_if Time.now.year == 2011, 'Google', 'http://google.com.au'
76
+ #
77
+ # @param [Boolean] condition The condition to check
78
+ # @param [String] text The text for the link
79
+ # @param [String] the_url The URL to link to
80
+ # @param [Hash] options Options for the link
81
+ # @author Jack Polgar
82
+ # @since 0.3
83
+ #
84
+ def link_to_if(condition, text, url, options = {})
85
+ if condition
86
+ link_to text, url, options = {}
87
+ else
88
+ text
89
+ end
45
90
  end
46
91
 
47
- "<a #{html_options.join(' ')}>#{text}</a>"
48
- end
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
- #
63
- def link_to_unless_current(text, the_url, options = {})
64
- if request.path_info == the_url
65
- text
66
- else
67
- link_to text, the_url, options
92
+ ##
93
+ # Returns the code for linking CSS style sheets.
94
+ #
95
+ # Useage:
96
+ #
97
+ # css_inc_tag '/assets/css/master.css'
98
+ # css_inc_tag '/assets/css/print.css', 'screen'
99
+ #
100
+ # @param [String] url The URL of the stylesheet
101
+ # @param [String] media The media of the stylesheet
102
+ # @author Jack Polgar
103
+ # @since 0.1
104
+ #
105
+ def css_link_tag(url, media = "screen")
106
+ "<link rel=\"stylesheet\" href=\"#{url}?#{Time.now.to_i}\" media=\"#{media}\" />"
68
107
  end
69
- end
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
108
+
109
+ ##
110
+ # Returns the code for linking javascript files.
111
+ #
112
+ # Useage:
113
+ #
114
+ # js_inc_tag '/assets/js/app.js'
115
+ #
116
+ # @param [String] url The URL of the file
117
+ # @author Jack Polgar
118
+ # @since 0.1
119
+ #
120
+ def js_inc_tag(url)
121
+ "<script src=\"#{url}\" type=\"text/javascript\"></script>"
90
122
  end
91
123
  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
- #
106
- def css_inc_tag(url, media = "screen")
107
- "<link rel=\"stylesheet\" href=\"#{url}?#{Time.now.to_i}\" media=\"#{media}\" />"
108
- end
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
- #
121
- def js_inc_tag(url)
122
- "<script src=\"#{url}\" type=\"text/javascript\"></script>"
123
- end
124
124
  end
125
-
126
- helpers HTMLHelper
127
125
  end
@@ -8,46 +8,44 @@
8
8
  # Please see the COPYING file for details.
9
9
  #
10
10
 
11
- #:nodoc:
12
- module Sinatra
13
- #:nodoc:
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
- #
28
- def pluralize(count, singular, plural = nil)
29
- "#{count || 0} " + ((count == 1 || count =~ /^1(\.0+)?$/) ? singular : (plural || singular.pluralize))
30
- end
31
-
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 = "...")
46
- return if text.nil?
47
- l = length - truncate_string.length
48
- text.length > length ? text[/\A.{#{l}}\w*\;?/m][/.*[\w\;]/m] + truncate_string : text
11
+ module Rocketeer
12
+ module Helpers
13
+ module Text
14
+ ##
15
+ # Pluralizes the string.
16
+ #
17
+ # Useage:
18
+ #
19
+ # pluralize comments.count, 'comment'
20
+ #
21
+ # @param [Integer] count The count
22
+ # @param [String] singular The singular form of the string
23
+ # @param [String] plural The plural form of the word
24
+ # @author Jack Polgar
25
+ # @since 0.1
26
+ #
27
+ def pluralize(count, singular, plural = nil)
28
+ "#{count || 0} " + ((count == 1 || count =~ /^1(\.0+)?$/) ? singular : (plural || singular.pluralize))
29
+ end
30
+
31
+ ##
32
+ # Shortens the string to the specified length
33
+ #
34
+ # Useage:
35
+ #
36
+ # shorten_string 'A very, very, long string', 5
37
+ #
38
+ # @param [String] text The string to shorten
39
+ # @param [Integer] length The length to shorten to
40
+ # @param [String] truncate_string Text to place at the end of the shortened string
41
+ # @author Jack Polgar
42
+ # @since 0.1
43
+ #
44
+ def shorten_string(text, length = 30, truncate_string = "...")
45
+ return if text.nil?
46
+ l = length - truncate_string.length
47
+ text.length > length ? text[/\A.{#{l}}\w*\;?/m][/.*[\w\;]/m] + truncate_string : text
48
+ end
49
49
  end
50
50
  end
51
-
52
- helpers TextHelper
53
51
  end
@@ -0,0 +1,13 @@
1
+ #
2
+ # Rocketeer
3
+ # Copyright (C) 2011-2012 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 Rocketeer
12
+ VERSION = "0.4.0"
13
+ end
data/rocketeer.gemspec ADDED
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/rocketeer/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = "rocketeer"
6
+ gem.version = Rocketeer::VERSION
7
+ gem.authors = ["Jack Polgar"]
8
+ gem.email = ["nrx@nirix.net"]
9
+ gem.summary = "A collection of helpers for Sinatra."
10
+ gem.description = "Rocketeer is a collection of helpers for the Sinatra framework."
11
+ gem.homepage = "https://github.com/nirix/rockets"
12
+
13
+ gem.files = `git ls-files`.split($\)
14
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
15
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
16
+ gem.require_paths = ["lib"]
17
+ end
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.3.0
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,20 +9,26 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-07-23 00:00:00.000000000Z
12
+ date: 2012-04-26 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Rocketeer is a collection of helpers for the Sinatra framework.
15
- email: xocide@gmail.com
15
+ email:
16
+ - nrx@nirix.net
16
17
  executables: []
17
18
  extensions: []
18
19
  extra_rdoc_files: []
19
20
  files:
21
+ - .gitignore
20
22
  - COPYING
23
+ - Gemfile
24
+ - Rakefile
21
25
  - lib/rocketeer.rb
22
- - lib/rocketeer/helpers/html.rb
23
26
  - lib/rocketeer/helpers/form.rb
27
+ - lib/rocketeer/helpers/html.rb
24
28
  - lib/rocketeer/helpers/text.rb
25
- homepage: http://rubygems.org/gems/rocketeer
29
+ - lib/rocketeer/version.rb
30
+ - rocketeer.gemspec
31
+ homepage: https://github.com/nirix/rockets
26
32
  licenses: []
27
33
  post_install_message:
28
34
  rdoc_options: []
@@ -42,8 +48,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
42
48
  version: '0'
43
49
  requirements: []
44
50
  rubyforge_project:
45
- rubygems_version: 1.8.5
51
+ rubygems_version: 1.8.11
46
52
  signing_key:
47
53
  specification_version: 3
48
- summary: A collection of helpers for Sinatra
54
+ summary: A collection of helpers for Sinatra.
49
55
  test_files: []