railhead_autoformat 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 [name of plugin creator]
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,23 @@
1
+ = RailheadAutoformat
2
+
3
+ RailheadAutoformat is a Ruby on Rails plugin that automatically cleans up input fields.
4
+
5
+ == Installation
6
+
7
+ Installation is available as gem (recommended):
8
+
9
+ gem 'railhead_autoformat'
10
+
11
+ Or as Rails plugin:
12
+
13
+ $ ruby script/plugin install git://github.com/nagybence/railhead_autoformat.git
14
+
15
+ == Usage
16
+
17
+ It works fully automatically, but there is one options to modify the default behavior.
18
+
19
+ auto_format :except => [:title]
20
+
21
+ == License
22
+
23
+ Copyright (c) 2012 Bence Nagy (nagybence@tipogral.hu), released under the MIT license.
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'railhead_autoformat'
@@ -0,0 +1,35 @@
1
+ module RailheadAutoformat
2
+
3
+ def self.included(base)
4
+ base.extend ClassMethods
5
+ base.class_eval do
6
+ class_attribute :format_options
7
+ before_validation :format_fields
8
+ end
9
+ end
10
+
11
+ def format(text)
12
+ text.gsub(/ +/, ' ').strip
13
+ end
14
+
15
+ def format_fields
16
+ self.class.columns.each do |column|
17
+ next unless column.type == :string or column.type == :text
18
+ field = column.name.to_sym
19
+ if self[field].is_a?(String) && format_options && format_options[:except].include?(field)
20
+ self[field] = format(self[field])
21
+ end
22
+ end
23
+ end
24
+
25
+ module ClassMethods
26
+
27
+ def auto_format(options = {})
28
+ self.format_options = {
29
+ :except => (options[:except] || [])
30
+ }
31
+ end
32
+ end
33
+ end
34
+
35
+ ActiveRecord::Base.send :include, RailheadAutoformat
@@ -0,0 +1,18 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "railhead_autoformat"
3
+ s.version = "0.0.1"
4
+ s.date = "2012-08-15"
5
+ s.summary = "RailheadAutoformat is a Ruby on Rails plugin that automatically cleans up input fields."
6
+ s.email = "nagybence@tipogral.hu"
7
+ s.homepage = "http://github.com/nagybence/railhead_autoformat"
8
+ s.description = "RailheadAutoformat is a Ruby on Rails plugin that automatically cleans up input fields."
9
+ s.has_rdoc = true
10
+ s.authors = ["Bence Nagy"]
11
+ s.files = ["MIT-LICENSE",
12
+ "README.rdoc",
13
+ "init.rb",
14
+ "railhead_autoformat.gemspec",
15
+ "lib/railhead_autoformat.rb"]
16
+ s.rdoc_options = ["--main", "README.rdoc"]
17
+ s.extra_rdoc_files = ["README.rdoc"]
18
+ end
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: railhead_autoformat
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Bence Nagy
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-15 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: RailheadAutoformat is a Ruby on Rails plugin that automatically cleans
15
+ up input fields.
16
+ email: nagybence@tipogral.hu
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files:
20
+ - README.rdoc
21
+ files:
22
+ - MIT-LICENSE
23
+ - README.rdoc
24
+ - init.rb
25
+ - railhead_autoformat.gemspec
26
+ - lib/railhead_autoformat.rb
27
+ homepage: http://github.com/nagybence/railhead_autoformat
28
+ licenses: []
29
+ post_install_message:
30
+ rdoc_options:
31
+ - --main
32
+ - README.rdoc
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ requirements: []
48
+ rubyforge_project:
49
+ rubygems_version: 1.8.24
50
+ signing_key:
51
+ specification_version: 3
52
+ summary: RailheadAutoformat is a Ruby on Rails plugin that automatically cleans up
53
+ input fields.
54
+ test_files: []