garterbelt 0.0.3 → 0.0.4

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.
Files changed (5) hide show
  1. data/TODO +3 -0
  2. data/VERSION +1 -1
  3. data/garterbelt.gemspec +1 -1
  4. data/lib/support/string.rb +158 -150
  5. metadata +3 -3
data/TODO CHANGED
@@ -1,3 +1,6 @@
1
1
  Page
2
2
 
3
3
  - partial passes down params from parent view
4
+ - partial receives a block
5
+
6
+ Rails Helpers
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.0.4
data/garterbelt.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{garterbelt}
8
- s.version = "0.0.3"
8
+ s.version = "0.0.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kane Baccigalupi"]
@@ -1,165 +1,173 @@
1
- require 'active_support/inflector/methods'
2
- require 'active_support/inflector/inflections'
1
+ unless String.instance_methods.include?('underscore')
2
+ begin
3
+ # being selective if activesupport 3.0.x
4
+ require 'active_support/inflector/methods'
5
+ require 'active_support/inflector/inflections'
3
6
 
4
- # including the string extension directly require i18l gem, which is lame when not needed
5
- # String inflections define new methods on the String class to transform names for different purposes.
6
- # For instance, you can figure out the name of a database from the name of a class.
7
- #
8
- # "ScaleScore".tableize # => "scale_scores"
9
- #
7
+ # including the string extension directly require i18l gem, which is lame when not needed :(
8
+
9
+
10
+ # String inflections define new methods on the String class to transform names for different purposes.
11
+ # For instance, you can figure out the name of a database from the name of a class.
12
+ #
13
+ # "ScaleScore".tableize # => "scale_scores"
14
+ #
15
+ class String
16
+ # Returns the plural form of the word in the string.
17
+ #
18
+ # "post".pluralize # => "posts"
19
+ # "octopus".pluralize # => "octopi"
20
+ # "sheep".pluralize # => "sheep"
21
+ # "words".pluralize # => "words"
22
+ # "the blue mailman".pluralize # => "the blue mailmen"
23
+ # "CamelOctopus".pluralize # => "CamelOctopi"
24
+ def pluralize
25
+ ActiveSupport::Inflector.pluralize(self)
26
+ end
10
27
 
11
- class String
12
- # Returns the plural form of the word in the string.
13
- #
14
- # "post".pluralize # => "posts"
15
- # "octopus".pluralize # => "octopi"
16
- # "sheep".pluralize # => "sheep"
17
- # "words".pluralize # => "words"
18
- # "the blue mailman".pluralize # => "the blue mailmen"
19
- # "CamelOctopus".pluralize # => "CamelOctopi"
20
- def pluralize
21
- ActiveSupport::Inflector.pluralize(self)
22
- end
28
+ # The reverse of +pluralize+, returns the singular form of a word in a string.
29
+ #
30
+ # "posts".singularize # => "post"
31
+ # "octopi".singularize # => "octopus"
32
+ # "sheep".singularize # => "sheep"
33
+ # "word".singularize # => "word"
34
+ # "the blue mailmen".singularize # => "the blue mailman"
35
+ # "CamelOctopi".singularize # => "CamelOctopus"
36
+ def singularize
37
+ ActiveSupport::Inflector.singularize(self)
38
+ end
23
39
 
24
- # The reverse of +pluralize+, returns the singular form of a word in a string.
25
- #
26
- # "posts".singularize # => "post"
27
- # "octopi".singularize # => "octopus"
28
- # "sheep".singularize # => "sheep"
29
- # "word".singularize # => "word"
30
- # "the blue mailmen".singularize # => "the blue mailman"
31
- # "CamelOctopi".singularize # => "CamelOctopus"
32
- def singularize
33
- ActiveSupport::Inflector.singularize(self)
34
- end
40
+ # +constantize+ tries to find a declared constant with the name specified
41
+ # in the string. It raises a NameError when the name is not in CamelCase
42
+ # or is not initialized.
43
+ #
44
+ # Examples
45
+ # "Module".constantize # => Module
46
+ # "Class".constantize # => Class
47
+ def constantize
48
+ ActiveSupport::Inflector.constantize(self)
49
+ end
35
50
 
36
- # +constantize+ tries to find a declared constant with the name specified
37
- # in the string. It raises a NameError when the name is not in CamelCase
38
- # or is not initialized.
39
- #
40
- # Examples
41
- # "Module".constantize # => Module
42
- # "Class".constantize # => Class
43
- def constantize
44
- ActiveSupport::Inflector.constantize(self)
45
- end
51
+ # By default, +camelize+ converts strings to UpperCamelCase. If the argument to camelize
52
+ # is set to <tt>:lower</tt> then camelize produces lowerCamelCase.
53
+ #
54
+ # +camelize+ will also convert '/' to '::' which is useful for converting paths to namespaces.
55
+ #
56
+ # "active_record".camelize # => "ActiveRecord"
57
+ # "active_record".camelize(:lower) # => "activeRecord"
58
+ # "active_record/errors".camelize # => "ActiveRecord::Errors"
59
+ # "active_record/errors".camelize(:lower) # => "activeRecord::Errors"
60
+ def camelize(first_letter = :upper)
61
+ case first_letter
62
+ when :upper then ActiveSupport::Inflector.camelize(self, true)
63
+ when :lower then ActiveSupport::Inflector.camelize(self, false)
64
+ end
65
+ end
66
+ alias_method :camelcase, :camelize
46
67
 
47
- # By default, +camelize+ converts strings to UpperCamelCase. If the argument to camelize
48
- # is set to <tt>:lower</tt> then camelize produces lowerCamelCase.
49
- #
50
- # +camelize+ will also convert '/' to '::' which is useful for converting paths to namespaces.
51
- #
52
- # "active_record".camelize # => "ActiveRecord"
53
- # "active_record".camelize(:lower) # => "activeRecord"
54
- # "active_record/errors".camelize # => "ActiveRecord::Errors"
55
- # "active_record/errors".camelize(:lower) # => "activeRecord::Errors"
56
- def camelize(first_letter = :upper)
57
- case first_letter
58
- when :upper then ActiveSupport::Inflector.camelize(self, true)
59
- when :lower then ActiveSupport::Inflector.camelize(self, false)
60
- end
61
- end
62
- alias_method :camelcase, :camelize
68
+ # Capitalizes all the words and replaces some characters in the string to create
69
+ # a nicer looking title. +titleize+ is meant for creating pretty output. It is not
70
+ # used in the Rails internals.
71
+ #
72
+ # +titleize+ is also aliased as +titlecase+.
73
+ #
74
+ # "man from the boondocks".titleize # => "Man From The Boondocks"
75
+ # "x-men: the last stand".titleize # => "X Men: The Last Stand"
76
+ def titleize
77
+ ActiveSupport::Inflector.titleize(self)
78
+ end
79
+ alias_method :titlecase, :titleize
63
80
 
64
- # Capitalizes all the words and replaces some characters in the string to create
65
- # a nicer looking title. +titleize+ is meant for creating pretty output. It is not
66
- # used in the Rails internals.
67
- #
68
- # +titleize+ is also aliased as +titlecase+.
69
- #
70
- # "man from the boondocks".titleize # => "Man From The Boondocks"
71
- # "x-men: the last stand".titleize # => "X Men: The Last Stand"
72
- def titleize
73
- ActiveSupport::Inflector.titleize(self)
74
- end
75
- alias_method :titlecase, :titleize
81
+ # The reverse of +camelize+. Makes an underscored, lowercase form from the expression in the string.
82
+ #
83
+ # +underscore+ will also change '::' to '/' to convert namespaces to paths.
84
+ #
85
+ # "ActiveRecord".underscore # => "active_record"
86
+ # "ActiveRecord::Errors".underscore # => active_record/errors
87
+ def underscore
88
+ ActiveSupport::Inflector.underscore(self)
89
+ end
76
90
 
77
- # The reverse of +camelize+. Makes an underscored, lowercase form from the expression in the string.
78
- #
79
- # +underscore+ will also change '::' to '/' to convert namespaces to paths.
80
- #
81
- # "ActiveRecord".underscore # => "active_record"
82
- # "ActiveRecord::Errors".underscore # => active_record/errors
83
- def underscore
84
- ActiveSupport::Inflector.underscore(self)
85
- end
91
+ # Replaces underscores with dashes in the string.
92
+ #
93
+ # "puni_puni" # => "puni-puni"
94
+ def dasherize
95
+ ActiveSupport::Inflector.dasherize(self)
96
+ end
86
97
 
87
- # Replaces underscores with dashes in the string.
88
- #
89
- # "puni_puni" # => "puni-puni"
90
- def dasherize
91
- ActiveSupport::Inflector.dasherize(self)
92
- end
98
+ # Removes the module part from the constant expression in the string.
99
+ #
100
+ # "ActiveRecord::CoreExtensions::String::Inflections".demodulize # => "Inflections"
101
+ # "Inflections".demodulize # => "Inflections"
102
+ def demodulize
103
+ ActiveSupport::Inflector.demodulize(self)
104
+ end
93
105
 
94
- # Removes the module part from the constant expression in the string.
95
- #
96
- # "ActiveRecord::CoreExtensions::String::Inflections".demodulize # => "Inflections"
97
- # "Inflections".demodulize # => "Inflections"
98
- def demodulize
99
- ActiveSupport::Inflector.demodulize(self)
100
- end
106
+ # Replaces special characters in a string so that it may be used as part of a 'pretty' URL.
107
+ #
108
+ # ==== Examples
109
+ #
110
+ # class Person
111
+ # def to_param
112
+ # "#{id}-#{name.parameterize}"
113
+ # end
114
+ # end
115
+ #
116
+ # @person = Person.find(1)
117
+ # # => #<Person id: 1, name: "Donald E. Knuth">
118
+ #
119
+ # <%= link_to(@person.name, person_path %>
120
+ # # => <a href="/person/1-donald-e-knuth">Donald E. Knuth</a>
121
+ def parameterize(sep = '-')
122
+ ActiveSupport::Inflector.parameterize(self, sep)
123
+ end
101
124
 
102
- # Replaces special characters in a string so that it may be used as part of a 'pretty' URL.
103
- #
104
- # ==== Examples
105
- #
106
- # class Person
107
- # def to_param
108
- # "#{id}-#{name.parameterize}"
109
- # end
110
- # end
111
- #
112
- # @person = Person.find(1)
113
- # # => #<Person id: 1, name: "Donald E. Knuth">
114
- #
115
- # <%= link_to(@person.name, person_path %>
116
- # # => <a href="/person/1-donald-e-knuth">Donald E. Knuth</a>
117
- def parameterize(sep = '-')
118
- ActiveSupport::Inflector.parameterize(self, sep)
119
- end
125
+ # Creates the name of a table like Rails does for models to table names. This method
126
+ # uses the +pluralize+ method on the last word in the string.
127
+ #
128
+ # "RawScaledScorer".tableize # => "raw_scaled_scorers"
129
+ # "egg_and_ham".tableize # => "egg_and_hams"
130
+ # "fancyCategory".tableize # => "fancy_categories"
131
+ def tableize
132
+ ActiveSupport::Inflector.tableize(self)
133
+ end
120
134
 
121
- # Creates the name of a table like Rails does for models to table names. This method
122
- # uses the +pluralize+ method on the last word in the string.
123
- #
124
- # "RawScaledScorer".tableize # => "raw_scaled_scorers"
125
- # "egg_and_ham".tableize # => "egg_and_hams"
126
- # "fancyCategory".tableize # => "fancy_categories"
127
- def tableize
128
- ActiveSupport::Inflector.tableize(self)
129
- end
135
+ # Create a class name from a plural table name like Rails does for table names to models.
136
+ # Note that this returns a string and not a class. (To convert to an actual class
137
+ # follow +classify+ with +constantize+.)
138
+ #
139
+ # "egg_and_hams".classify # => "EggAndHam"
140
+ # "posts".classify # => "Post"
141
+ #
142
+ # Singular names are not handled correctly.
143
+ #
144
+ # "business".classify # => "Busines"
145
+ def classify
146
+ ActiveSupport::Inflector.classify(self)
147
+ end
130
148
 
131
- # Create a class name from a plural table name like Rails does for table names to models.
132
- # Note that this returns a string and not a class. (To convert to an actual class
133
- # follow +classify+ with +constantize+.)
134
- #
135
- # "egg_and_hams".classify # => "EggAndHam"
136
- # "posts".classify # => "Post"
137
- #
138
- # Singular names are not handled correctly.
139
- #
140
- # "business".classify # => "Busines"
141
- def classify
142
- ActiveSupport::Inflector.classify(self)
143
- end
149
+ # Capitalizes the first word, turns underscores into spaces, and strips '_id'.
150
+ # Like +titleize+, this is meant for creating pretty output.
151
+ #
152
+ # "employee_salary" # => "Employee salary"
153
+ # "author_id" # => "Author"
154
+ def humanize
155
+ ActiveSupport::Inflector.humanize(self)
156
+ end
144
157
 
145
- # Capitalizes the first word, turns underscores into spaces, and strips '_id'.
146
- # Like +titleize+, this is meant for creating pretty output.
147
- #
148
- # "employee_salary" # => "Employee salary"
149
- # "author_id" # => "Author"
150
- def humanize
151
- ActiveSupport::Inflector.humanize(self)
152
- end
153
-
154
- # Creates a foreign key name from a class name.
155
- # +separate_class_name_and_id_with_underscore+ sets whether
156
- # the method should put '_' between the name and 'id'.
157
- #
158
- # Examples
159
- # "Message".foreign_key # => "message_id"
160
- # "Message".foreign_key(false) # => "messageid"
161
- # "Admin::Post".foreign_key # => "post_id"
162
- def foreign_key(separate_class_name_and_id_with_underscore = true)
163
- ActiveSupport::Inflector.foreign_key(self, separate_class_name_and_id_with_underscore)
158
+ # Creates a foreign key name from a class name.
159
+ # +separate_class_name_and_id_with_underscore+ sets whether
160
+ # the method should put '_' between the name and 'id'.
161
+ #
162
+ # Examples
163
+ # "Message".foreign_key # => "message_id"
164
+ # "Message".foreign_key(false) # => "messageid"
165
+ # "Admin::Post".foreign_key # => "post_id"
166
+ def foreign_key(separate_class_name_and_id_with_underscore = true)
167
+ ActiveSupport::Inflector.foreign_key(self, separate_class_name_and_id_with_underscore)
168
+ end
169
+ end
170
+ rescue Exception => e
171
+ require 'activesupport'
164
172
  end
165
173
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: garterbelt
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Kane Baccigalupi